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

namespace GCMM
{
    static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            //Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (args.Length > 0)
            {
                DealWithCommandLineAsync(args);
                Application.Run();
                return;
            }
            Application.Run(new MainForm());
        }

        private static async void DealWithCommandLineAsync(string[] args)
        {
            var form = new MainForm();
            await form.LoadEverything(false);
            bool? shouldStay = null;
            if (args[0] == "-start" && args.Length > 1)
                shouldStay = await form.PatchStartGame(args[1]);
            else
                MessageBox.Show("Supported options:\n-start <command> - Starts the game using the given command");
            if (shouldStay.HasValue)
            {
                form.FormClosed += (sender, e) => Application.Exit();
                if (!shouldStay.Value)
                {
                    await Task.Delay(2000);
                    form.Close();
                }
            }
            else
                Environment.Exit(0);
        }
    }
}