Exemple #1
0
 [STAThread]         //DO NOT REMOVE THIS
 public static void Main(string[] args)
 {
     Application.EnableVisualStyles();             // at first enable styles.
     //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.");
     using (var mutex = new Mutex(false, GGPU_Mutex)) {
         if (!mutex.WaitOne(0, false))
         {
             if (args.Length > 0)
             {
                 var arg1 = args[0].ToUpper();
                 if (arg1.StartsWith("/R") || arg1.StartsWith("-R") || arg1.StartsWith("R"))
                 {
                     WinAPI.PostMessage((IntPtr)0xffff, re, 0, 0);
                     return;
                 }
             }
             WinAPI.PostMessage((IntPtr)0xffff, ao, 0, 0);
             return;
         }
         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");
             }
         }
         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 (!mahou.TrayIconVisible)
                 {
                     KMHook.DoLater(() => mahou.Invoke((MethodInvoker) delegate { mahou.icon.trIcon.Visible = false; }), 1005);
                 }
             }
         }
         MyConfs.WriteToDisk();
         if (!string.IsNullOrEmpty(mahou.MainLayout1))
         {
             MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetLocaleFromString(mahou.MainLayout1).uId;
         }
         Application.Run();
     }
 }
Exemple #2
0
 [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, GGPU_Mutex)) {
         if (!mutex.WaitOne(0, false))
         {
             WinAPI.PostMessage((IntPtr)0xffff, ao, 0, 0);
             return;
         }
         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);
             }
             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.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();
         rif   = new RawInputForm();
         Locales.IfLessThan2();
         if (MyConfs.Read("Layouts", "MainLayout1") == "" && MyConfs.Read("Layouts", "MainLayout2") == "")
         {
             mahou.cbb_MainLayout1.SelectedIndex = 0;
             mahou.cbb_MainLayout2.SelectedIndex = 1;
         }
         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);
             }
         }
         MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetLocaleFromString(mahou.MainLayout1).uId;
         Application.Run();
     }
 }