コード例 #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();
     }
 }
コード例 #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();
     }
 }
コード例 #3
0
        /// <summary>
        /// Refresh language text.
        /// </summary>
        public void RefreshLang()
        {
            if (!Visible)
            {
                return;
            }
            uint cLid = Locales.GetCurrentLocale();

            if (cLid == 0)
            {
                cLid = MahouUI.currentLayout;
            }
            if (MMain.mahou.OneLayout)
            {
                cLid = MahouUI.GlobalLayout;
            }
            if (MMain.mahou.LDCaretTransparentBack_temp && caretDisplay)
            {
                transparentBG = true;
            }
            else if (MMain.mahou.LDMouseTransparentBack_temp && mouseDisplay)
            {
                transparentBG = true;
            }
            else
            {
                transparentBG = false;
            }
            var notTwo = false;

            if ((cLid & 0xffff) > 0)
            {
                var clangname = new System.Globalization.CultureInfo((int)(cLid & 0xffff));
                if (MMain.mahou.DiffAppearenceForLayouts && !DisplayFlag)
                {
                    if (cLid == Locales.GetLocaleFromString(MMain.mahou.MainLayout1).uId)
                    {
                        ChangeColors(MMain.mahou.Layout1Font_temp, MMain.mahou.Layout1Fore_temp,
                                     MMain.mahou.Layout1Back_temp, MMain.mahou.Layout1TransparentBack_temp);
                        ChangeSize(MMain.mahou.Layout1Height_temp, MMain.mahou.Layout1Width_temp);
                        ChangeLD(MMain.mahou.Layout1TText);
                    }
                    else if (cLid == Locales.GetLocaleFromString(MMain.mahou.MainLayout2).uId)
                    {
                        ChangeColors(MMain.mahou.Layout2Font_temp, MMain.mahou.Layout2Fore_temp,
                                     MMain.mahou.Layout2Back_temp, MMain.mahou.Layout2TransparentBack_temp);
                        ChangeSize(MMain.mahou.Layout2Height_temp, MMain.mahou.Layout2Width_temp);
                        ChangeLD(MMain.mahou.Layout2TText);
                    }
                    else
                    {
                        notTwo = true;
                    }
                }
                else
                {
                    notTwo = true;
                }
                if (notTwo)
                {
                    if (mouseDisplay)
                    {
                        ChangeColors(MMain.mahou.LDMouseFont_temp, MMain.mahou.LDMouseFore_temp,
                                     MMain.mahou.LDMouseBack_temp, MMain.mahou.LDMouseTransparentBack_temp);
                        ChangeSize(MMain.mahou.LDMouseHeight_temp, MMain.mahou.LDMouseWidth_temp);
                    }
                    if (caretDisplay)
                    {
                        ChangeColors(MMain.mahou.LDCaretFont_temp, MMain.mahou.LDCaretFore_temp,
                                     MMain.mahou.LDCaretBack_temp, MMain.mahou.LDCaretTransparentBack_temp);
                        ChangeSize(MMain.mahou.LDCaretHeight_temp, MMain.mahou.LDCaretWidth_temp);
                    }
                    ChangeLD(clangname.ThreeLetterISOLanguageName.Substring(0, 1).ToUpper() + clangname.ThreeLetterISOLanguageName.Substring(1));
                }
                if (!MMain.mahou.DiffAppearenceForLayouts || lbLang.Text == "")
                {
                    ChangeLD(clangname.ThreeLetterISOLanguageName.Substring(0, 1).ToUpper() + clangname.ThreeLetterISOLanguageName.Substring(1));
                }
                if (transparentBG)
                {
                    TransparencyKey = BackColor = lbLang.BackColor = pct_UpperArrow.BackColor = Color.Pink;
                }
                if (lastTransparentBG != transparentBG)
                {
                    SetVisInvis();
                }
                lastTransparentBG = transparentBG;
                if ((caretDisplay && !MahouUI.caretLTUpperArrow) || (mouseDisplay && !MahouUI.mouseLTUpperArrow) || onInit)
                {
                    ReSize(); onInit = false;
                }
            }
            else
            {
                Logging.Log("Language tooltip text NOT changed, locale id = [" + cLid + "].", 2);
            }
        }
コード例 #4
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();
                }
            }
        }