using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;

namespace s3sr
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        /// <param name="args">Command Line Arguments</param>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            bool forceFirstRun = false;
            if (args.Length == 1)
                if (args[0].Trim().ToLower() == "/forcefirstrun") // Force First Run
                    forceFirstRun = true;
                else if (args[0].Trim().ToLower() == "/cleanExtensions") // Clean Custom Extension
                    Settings.DeleteExtensionRef();

            Settings.Read(forceFirstRun);
            Settings.CreateExtensionRef();
            if (forceFirstRun | args.Length == 0)
                Application.Run(new frmGUI());
            else
            {
                if (Settings.firstRun)
                {
                    MessageBox.Show("Please, run the application to set your settings before running a script.", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Environment.Exit(0);
                }

                string[] cmdArgs = args;
                List<string> lstCmdArgs = new List<string>(cmdArgs);
                if (forceFirstRun)
                {
                    lstCmdArgs.RemoveAt(0);
                    cmdArgs = lstCmdArgs.ToArray();
                }

                ParseScript.Start(args);
            }
        }
    }
}