[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 occured, Mahou exitted, 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)) { KMHook.PostMessage((IntPtr)0xffff, ao, 0, 0); return; } if (locales.Length < 2) { Logging.Log("Too less layouts/locales. Program will exit."); Locales.IfLessThan2(); } else { mahou = new MahouForm(); InitLanguage(); //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... '~' if (args.Length != 0) { if (args[0] == "_!_updated_!_") { Logging.Log("Mahou updated."); mahou.ToggleVisibility(); MessageBox.Show(Msgs[0], Msgs[1], MessageBoxButtons.OK, MessageBoxIcon.Information); } } StartHook(); //for first run, add your locale 1 & locale 2 to settings if (MyConfs.Read("Locales", "locale1Lang") == "" && MyConfs.Read("Locales", "locale2Lang") == "") { Logging.Log("Initializing locales."); MyConfs.Write("Locales", "locale1uId", locales[0].uId.ToString()); MyConfs.Write("Locales", "locale2uId", locales[1].uId.ToString()); MyConfs.Write("Locales", "locale1Lang", locales[0].Lang); MyConfs.Write("Locales", "locale2Lang", locales[1].Lang); } Application.Run(); StopHook(); } } }
[STAThread] //DO NOT REMOVE THIS public static void Main(string[] args) { LogHelper.ConfigureNlog(); log.Trace("Program start"); using (var mutex = new Mutex(false, "Global\\" + appGUid)) { log.Trace("Mutex created"); if (!mutex.WaitOne(0, false)) { KMHook.PostMessage((IntPtr)0xffff, ao, 0, 0); return; } if (locales.Length < 2) { Locales.IfLessThan2(); } else { mahou = new MahouForm(); InitLanguage(); //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... '~' if (args.Length != 0) { if (args[0] == "_!_updated_!_") { mahou.ToggleVisibility(); MessageBox.Show(Msgs[0], Msgs[1], MessageBoxButtons.OK, MessageBoxIcon.Information); } } StartHook(); //for first run, add your locale 1 & locale 2 to settings if (MyConfs.Read("Locales", "locale1Lang") == "" && MyConfs.Read("Locales", "locale2Lang") == "") { MyConfs.Write("Locales", "locale1uId", locales[0].uId.ToString()); MyConfs.Write("Locales", "locale2uId", locales[1].uId.ToString()); MyConfs.Write("Locales", "locale1Lang", locales[0].Lang); MyConfs.Write("Locales", "locale2Lang", locales[1].Lang); } try { Application.Run(); } catch (Exception ex) { log.Fatal(ex, "Global error handler caught the exception in app"); } StopHook(); } } }
void load() // Loads configurations { MMain.mahou.IfNotExist(); try { cbLCLocalesList.SelectedIndex = String.IsNullOrEmpty(MMain.MyConfs.Read("ExtCtrls", "LCLocaleName")) ? 0 : MMain.lcnmid.IndexOf(MMain.MyConfs.Read("ExtCtrls", "LCLocaleName") + "(" + MMain.MyConfs.Read("ExtCtrls", "LCLocale") + ")"); cbRCLocalesList.SelectedIndex = String.IsNullOrEmpty(MMain.MyConfs.Read("ExtCtrls", "RCLocaleName")) ? 1 : MMain.lcnmid.IndexOf(MMain.MyConfs.Read("ExtCtrls", "RCLocaleName") + "(" + MMain.MyConfs.Read("ExtCtrls", "RCLocale") + ")"); } catch { MessageBox.Show(MMain.Msgs[9], MMain.Msgs[5], MessageBoxButtons.OK, MessageBoxIcon.Exclamation); RefreshLocales(); cbLCLocalesList.SelectedIndex = 0; cbRCLocalesList.SelectedIndex = 1; } cbUseLRC.Checked = MMain.MyConfs.ReadBool("ExtCtrls", "UseExtCtrls"); cbSymIgn.Checked = MMain.MyConfs.ReadBool("EnabledHotkeys", "HKSymIgnEnabled"); cbMoreTries.Checked = MMain.MyConfs.ReadBool("Functions", "MoreTries"); nudMTCount.Value = MMain.MyConfs.ReadInt("Functions", "TriesCount"); nudRefreshRate.Value = MMain.MyConfs.ReadInt("Functions", "DLRefreshRate"); cbDisplayLang.Checked = MMain.MyConfs.ReadBool("Functions", "DisplayLang"); btCol1.BackColor = ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLForeColor")); btCol2.BackColor = ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLBackColor")); cbExCSSwitch.Checked = MMain.MyConfs.ReadBool("Functions", "ExperimentalCSSwitch"); cbUseSnippets.Checked = MMain.MyConfs.ReadBool("Functions", "Snippets"); nudTTHeight.Value = MMain.MyConfs.ReadInt("TTipUI", "Height"); nudTTWidth.Value = MMain.MyConfs.ReadInt("TTipUI", "Width"); btFont.Font = (Font)fcv.ConvertFromString(MMain.MyConfs.Read("TTipUI", "Font")); nudXpos.Value = MMain.MyConfs.ReadInt("TTipUI", "xpos"); nudYpos.Value = MMain.MyConfs.ReadInt("TTipUI", "ypos"); cbTrBLT.Checked = MMain.MyConfs.ReadBool("TTipUI", "TransparentBack"); nudDoubleDelay.Value = MMain.MyConfs.ReadInt("DoubleKey", "Delay"); cbDoublePress.Checked = MMain.MyConfs.ReadBool("DoubleKey", "Use"); cbOnChange.Checked = MMain.MyConfs.ReadBool("Functions", "DTTOnChange"); cbScrollLight.Checked = MMain.MyConfs.ReadBool("Functions", "ScrollTip"); cbCheckForUPD.Checked = MMain.MyConfs.ReadBool("Functions", "UpdatesEnabled"); cbLogging.Checked = MMain.MyConfs.ReadBool("Functions", "Logging"); if (File.Exists(snipfile)) { tbSnippets.Text = File.ReadAllText(snipfile); KMHook.ReInitSnippets(); } Logging.Log("More Configs configurations loaded."); }
void Save() // Saves configurations { MMain.mahou.IfNotExist(); var getname = new Regex("\\w+"); var getUID = new Regex("\\w+\\W(\\d+)"); MMain.MyConfs.Write("ExtCtrls", "LCLocaleName", getname.Match(cbLCLocalesList.Text).Value); MMain.MyConfs.Write("ExtCtrls", "RCLocaleName", getname.Match(cbRCLocalesList.Text).Value); MMain.MyConfs.Write("ExtCtrls", "LCLocale", getUID.Match(cbLCLocalesList.Text).Groups[1].Value); MMain.MyConfs.Write("ExtCtrls", "RCLocale", getUID.Match(cbRCLocalesList.Text).Groups[1].Value); MMain.MyConfs.Write("ExtCtrls", "UseExtCtrls", cbUseLRC.Checked.ToString()); MMain.MyConfs.Write("EnabledHotkeys", "HKSymIgnEnabled", cbSymIgn.Checked.ToString()); MMain.MyConfs.Write("Functions", "MoreTries", cbMoreTries.Checked.ToString()); MMain.MyConfs.Write("Functions", "TriesCount", nudMTCount.Value.ToString()); MMain.MyConfs.Write("Functions", "DLRefreshRate", nudRefreshRate.Value.ToString()); MMain.MyConfs.Write("Functions", "DisplayLang", cbDisplayLang.Checked.ToString()); MMain.MyConfs.Write("Functions", "DLForeColor", ColorTranslator.ToHtml(btCol1.BackColor)); MMain.MyConfs.Write("Functions", "DLBackColor", ColorTranslator.ToHtml(btCol2.BackColor)); MMain.MyConfs.Write("Functions", "ExperimentalCSSwitch", cbExCSSwitch.Checked.ToString()); MMain.MyConfs.Write("Functions", "Snippets", cbUseSnippets.Checked.ToString()); MMain.MyConfs.Write("TTipUI", "Height", nudTTHeight.Value.ToString()); MMain.MyConfs.Write("TTipUI", "Width", nudTTWidth.Value.ToString()); MMain.MyConfs.Write("TTipUI", "Font", fcv.ConvertToString(btFont.Font)); MMain.MyConfs.Write("TTipUI", "xpos", nudXpos.Value.ToString()); MMain.MyConfs.Write("TTipUI", "ypos", nudYpos.Value.ToString()); MMain.MyConfs.Write("TTipUI", "TransparentBack", cbTrBLT.Checked.ToString()); MMain.MyConfs.Write("Functions", "DTTOnChange", cbOnChange.Checked.ToString()); MMain.MyConfs.Write("Functions", "ScrollTip", cbScrollLight.Checked.ToString()); MMain.MyConfs.Write("Functions", "UpdatesEnabled", cbCheckForUPD.Checked.ToString()); MMain.mahou.langDisplay.ChangeColors(ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLForeColor")), ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLBackColor"))); MMain.mahou.langDisplay.ChangeSizes((Font)fcv.ConvertFromString(MMain.MyConfs.Read("TTipUI", "Font")), MMain.MyConfs.ReadInt("TTipUI", "Height"), MMain.MyConfs.ReadInt("TTipUI", "Width")); MMain.MyConfs.Write("DoubleKey", "Delay", nudDoubleDelay.Value.ToString()); MMain.MyConfs.Write("DoubleKey", "Use", cbDoublePress.Checked.ToString()); File.WriteAllText(snipfile, tbSnippets.Text); KMHook.ReInitSnippets(); MMain.mahou.langDisplay.SetVisInvis(); if (!string.IsNullOrEmpty(tmpSIMods) && tmpSIKey != 0) { MMain.MyConfs.Write("Hotkeys", "HKSymIgnMods", tmpSIMods); } if (tmpSIKey != 0) { MMain.MyConfs.Write("Hotkeys", "HKSymIgnKey", tmpSIKey.ToString()); } else { MessageBox.Show(MMain.Msgs[6], MMain.Msgs[5], MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (!string.IsNullOrEmpty(tempConMorWorMods) && tempConMorWorKey != 0) { MMain.MyConfs.Write("Hotkeys", "HKConvertMoreMods", tempConMorWorMods); } if (tempConMorWorKey != 0) { MMain.MyConfs.Write("Hotkeys", "HKConvertMore", tempConMorWorKey.ToString()); } else { MessageBox.Show(MMain.Msgs[6], MMain.Msgs[5], MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (MMain.MyConfs.ReadBool("Functions", "DisplayLang")) { MMain.mahou.ICheck.Start(); } else { MMain.mahou.ICheck.Stop(); } if (MMain.MyConfs.ReadBool("Functions", "ScrollTip")) { MMain.mahou.ScrlCheck.Start(); } else { MMain.mahou.ScrlCheck.Stop(); } MMain.mahou.ICheck.Interval = Convert.ToInt32(nudRefreshRate.Value); MMain.mahou.res.Interval = Convert.ToInt32(nudRefreshRate.Value) * 7; MMain.mahou.RefreshIconAll(); MMain.mahou.InitializeHotkeys(); }
[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(); } } }