コード例 #1
0
        [STAThread]         //DO NOT REMOVE THIS
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();             // at first enable styles.
            SetProcessDPIAware();
            //Catch any error during program runtime
            AppDomain.CurrentDomain.UnhandledException += (obj, arg) => {
                var e = (Exception)arg.ExceptionObject;
                Logging.Log("Unexpected error occurred, Mahou exited, error details:\r\n" + e.Message + "\r\n" + e.StackTrace, 1);
            };
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            if (System.Globalization.CultureInfo.InstalledUICulture.TwoLetterISOLanguageName == "ru")
            {
                Lang = Languages.Russian;
            }
            MyConfs = new Configs();
            if (Configs.forceAppData && Configs.fine)
            {
                MyConfs.Write("Functions", "AppDataConfigs", "true");
            }
            Logging.Log("Mahou started.");
            var ind = 0;

            using (var mutex = new Mutex(false, GGPU_Mutex)) {
                if (!mutex.WaitOne(0, false))
                {
                    if (args.Length > 0)
                    {
                        var arg1 = args[ind].ToUpper();
                        if (arg1.StartsWith("/R") || arg1.StartsWith("-R") || arg1.StartsWith("R"))
                        {
                            ind = 1;
                            WinAPI.PostMessage((IntPtr)0xffff, re, 0, 0);
                            return;
                        }
                    }
                    WinAPI.PostMessage((IntPtr)0xffff, ao, 0, 0);
                    return;
                }
                if (args.Length > ind)
                {
                    var arg1 = args[ind].ToUpper();
                    if (arg1.StartsWith("/C") || arg1.StartsWith("-C") || arg1.StartsWith("C"))
                    {
                        if (args.Length > ind + 1)
                        {
                            var ok = false;
                            if (Directory.Exists(args[ind + 1]))
                            {
                                ok = true;
                            }
                            else
                            {
                                try {
                                    Directory.CreateDirectory(args[ind + 1]);
                                    ok = true;
                                } catch (Exception e) {
                                    Logging.Log("Can't create directory: " + args[ind + 1]);
                                }
                            }
                            if (ok)
                            {
                                Logging.Log("Switching config directory to : " + args[ind + 1]);
                                MahouUI.nPath = args[ind + 1];
                                C_SWITCH      = true;
                            }
                        }
                    }
                }
                if (MMain.MyConfs.ReadBool("Functions", "AppDataConfigs"))
                {
                    var mahou_folder_appd = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mahou");
                    if (!Directory.Exists(mahou_folder_appd))
                    {
                        Directory.CreateDirectory(mahou_folder_appd);
                    }
                    if (!File.Exists(Path.Combine(mahou_folder_appd, "Mahou.ini")))                     // Copy main configs to appdata
                    {
                        File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mahou.ini"),
                                  Path.Combine(mahou_folder_appd, "Mahou.ini"), true);
                    }
                    Configs.filePath = Path.Combine(mahou_folder_appd, "Mahou.ini");
                    MyConfs          = new Configs();
                }
                else
                {
                    Configs.filePath = Path.Combine(MahouUI.nPath, "Mahou.ini");
                }
                MahouUI.latest_save_dir = Configs.filePath;
                if (MyConfs.ReadBool("FirstStart", "First"))
                {
                    if (System.Globalization.CultureInfo.InstalledUICulture.TwoLetterISOLanguageName == "ru")
                    {
                        MyConfs.WriteSave("Appearence", "Language", "Русский");
                        MahouUI.InitLanguage();
                        MyConfs.WriteSave("Layouts", "SpecificLayout1", Lang[Languages.Element.SwitchBetween]);
                        MyConfs.WriteSave("FirstStart", "First", "False");
                        MyConfs.WriteSave("Timings", "ExcludedPrograms", "LA.exe SomeProg.exe");
                    }
                }
                else
                {
                    MahouUI.InitLanguage();
                }
                RefreshLCnMID();
                //for first run, add your locale 1 & locale 2 to settings
                if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "")
                {
                    Logging.Log("Initializing locales.");
                    MyConfs.Write("Layouts", "MainLayout1", lcnmid[0]);
                    if (lcnmid.Count > 1)
                    {
                        MyConfs.Write("Layouts", "MainLayout2", lcnmid[1]);
                    }
                    MyConfs.WriteToDisk();
                }
                mahou = new MahouUI();
                rif   = new RawInputForm();
                Locales.IfLessThan2();
                if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "")
                {
                    mahou.cbb_MainLayout1.SelectedIndex = 0;
                    if (lcnmid.Count > 1)
                    {
                        mahou.cbb_MainLayout2.SelectedIndex = 1;
                    }
                }
                _evt_hookID = WinAPI.SetWinEventHook(WinAPI.EVENT_SYSTEM_FOREGROUND, WinAPI.EVENT_SYSTEM_FOREGROUND,
                                                     IntPtr.Zero, _evt_proc, 0, 0, WinAPI.WINEVENT_OUTOFCONTEXT);
                _LDevt_hookID = WinAPI.SetWinEventHook(WinAPI.EVENT_OBJECT_FOCUS, WinAPI.EVENT_OBJECT_FOCUS,
                                                       IntPtr.Zero, _LDevt_proc, 0, 0, WinAPI.WINEVENT_OUTOFCONTEXT);
                if (args.Length != 0)
                {
                    if (args[0] == "_!_updated_!_")
                    {
                        Logging.Log("Mahou updated.");
                        mahou.ToggleVisibility();
                        MessageBox.Show(Lang[Languages.Element.UpdateComplete], Lang[Languages.Element.UpdateComplete],
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    if (args[0] == "_!_silent_updated_!_")
                    {
                        Logging.Log("Mahou silently updated.");
                        mahou.icon.trIcon.Visible = true;
                        mahou.icon.trIcon.ShowBalloonTip(1000, Lang[Languages.Element.UpdateComplete], "Mahou -> " + mahou.Text, ToolTipIcon.Info);
                        mahou.icon.trIcon.BalloonTipClicked += (_, __) => mahou.ToggleVisibility();
                        if (!MahouUI.TrayIconVisible)
                        {
                            KMHook.DoLater(() => mahou.Invoke((MethodInvoker) delegate { mahou.icon.trIcon.Visible = false; }), 1005);
                        }
                    }
                }
                MyConfs.WriteToDisk();
                if (!string.IsNullOrEmpty(MahouUI.MainLayout1))
                {
                    MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetLocaleFromString(MahouUI.MainLayout1).uId;
                }
                Application.Run();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: grengray/Mahou
        [STAThread]         //DO NOT REMOVE THIS
        public static void Main(string[] args)
        {
            Logging.Log("Mahou started.");
            //Catch any error during program runtime
            AppDomain.CurrentDomain.UnhandledException += (obj, arg) => {
                var e = (Exception)arg.ExceptionObject;
                Logging.Log("Unexpected error occurred, Mahou exited, error details:\r\n" + e.Message + "\r\n" + e.StackTrace, 1);
            };
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            using (var mutex = new Mutex(false, "Global\\" + appGUid)) {
                if (!mutex.WaitOne(0, false))
                {
                    WinAPI.PostMessage((IntPtr)0xffff, ao, 0, 0);
                    return;
                }
                if (locales.Length < 2)
                {
                    Logging.Log("Too less layouts/locales. Program will exit.");
                    Locales.IfLessThan2();
                }
                else
                {
                    if (MyConfs.ReadBool("FirstStart", "First"))
                    {
                        if (System.Globalization.CultureInfo.InstalledUICulture.TwoLetterISOLanguageName == "ru")
                        {
                            MyConfs.Write("Appearence", "Language", "Русский");
                            MahouUI.InitLanguage();
                            MyConfs.Write("Layouts", "SpecificLayout1", Lang[Languages.Element.SwitchBetween]);
                            MyConfs.Write("FirstStart", "First", "False");
                        }
                    }
                    else
                    {
                        MahouUI.InitLanguage();
                    }
                    foreach (Locales.Locale lc in MMain.locales)
                    {
                        MMain.lcnmid.Add(lc.Lang + "(" + lc.uId + ")");
                    }
                    //for first run, add your locale 1 & locale 2 to settings
                    if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "")
                    {
                        Logging.Log("Initializing locales.");
                        MyConfs.Write("Layouts", "MainLayout1", lcnmid[0]);
                        MyConfs.Write("Layouts", "MainLayout2", lcnmid[1]);
                    }
                    mahou = new MahouUI();
                    if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "")
                    {
                        mahou.cbb_MainLayout1.SelectedIndex = 0;
                        mahou.cbb_MainLayout2.SelectedIndex = 1;
                    }
                    //Refreshes icon text language at startup
//					mahou.icon.RefreshText(MMain.UI[44], MMain.UI[42], MMain.UI[43]);
                    KMHook.ReInitSnippets();
                    Application.EnableVisualStyles();                     // Huh i did not noticed that it was missing... '~'
                    _evt_hookID = WinAPI.SetWinEventHook(WinAPI.EVENT_SYSTEM_FOREGROUND, WinAPI.EVENT_SYSTEM_FOREGROUND,
                                                         IntPtr.Zero, _evt_proc, 0, 0, WinAPI.WINEVENT_OUTOFCONTEXT);
                    KMHook.CheckLayoutLater.Tick += (_, __) => { MahouUI.GlobalLayout = Locales.GetCurrentLocale(); KMHook.CheckLayoutLater.Stop(); };
                    if (args.Length != 0)
                    {
                        if (args[0] == "_!_updated_!_")
                        {
                            Logging.Log("Mahou updated.");
                            mahou.ToggleVisibility();
                            MessageBox.Show(Lang[Languages.Element.UpdateComplete], Lang[Languages.Element.UpdateComplete], MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    StartHook();
                    MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetLocaleFromString(mahou.MainLayout1).uId;
                    Application.Run();
                    StopHook();
                }
            }
        }