/* This file is part of AHD Subtitles Maker Professional
   A program can create and edit subtitles

   Copyright © Ala I Hadid 2009 - 2012

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
using System.Resources;
using System.Reflection;
using AHD.SM.Formats;
using AHD.SM.ASMP;

namespace AHD.SM
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// <param name="Args">The commandlines list</param>
        [STAThread]
        static void Main(string[] Args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //load formats
            SubtitleFormats.DetectSupportedFormats(true, true);
            //Load settings
            bool settingsReset = false;
            for (int i = 0; i < Args.Length; i++)
            {
                switch (Args[i])
                {
                    case "/rst": settings.Reset(); settingsReset = true; MessageBox.Show("Settings reset done !"); break;
                }
            }
            if (!settingsReset)
                settings.Reload();
            //set the language before loading resources
            Language = settings.Language;
            resources = new ResourceManager("AHD.SM.LanguageResources.Resource",
              Assembly.GetExecutingAssembly());
            //show splash and load things
            Frm_StartUp startUp = new Frm_StartUp(Args);
            startUp.Show();
            //run !!
            Application.Run();
        }
        static Properties.Settings settings = new Properties.Settings();
        static Frm_Main frmMain;
        static ProjectManager projectManager = new ProjectManager();
        static ResourceManager resources;
        //TODO: find another way to detect supported languages
        static string[,] supportedLanguages =
        { { "English (United States)", "en-US","English (United States)" },
          { "Arabic (Saudi Arabia)", "ar-SA","(العربية (السعودية العربية" } };

        /// <summary>
        /// Get the settings class
        /// </summary>
        public static Properties.Settings Settings
        { get { return settings; } }
        /// <summary>
        /// Get or set the main form
        /// </summary>
        public static Frm_Main MainForm
        { get { return frmMain; } set { frmMain = value; } }
        /// <summary>
        /// Get or set the project manager which hold the project
        /// </summary>
        public static ProjectManager ProjectManager
        { get { return projectManager; } set { projectManager = value; } }
        /// <summary>
        /// Get the version of ASM
        /// </summary>
        public static string Version
        {
            get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
        }
        public static string StartUpPath
        {
            get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
        }
        public static string[,] SupportedLanguages
        { get { return supportedLanguages; } }
        public static string Language
        {
            get
            {
                return Thread.CurrentThread.CurrentUICulture.NativeName;
            }
            set
            {
                for (int i = 0; i < Program.SupportedLanguages.Length / 3; i++)
                {
                    if (Program.SupportedLanguages[i, 0] == value)
                    {
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo(Program.SupportedLanguages[i, 1]);
                        break;
                    }
                }
            }
        }
        public static CultureInfo CultureInfo
        { get { return Thread.CurrentThread.CurrentUICulture; } }
        /// <summary>
        /// Get or set the resources manager
        /// </summary>
        public static ResourceManager ResourceManager
        { get { return resources; } set { resources = value; } }
    }
}