public void RefreshLang() { try{ var clangname = new System.Globalization.CultureInfo((int)Locales.GetCurrentLocale()); ChangeLD(clangname.ThreeLetterISOLanguageName.Substring(0, 1).ToUpper() + clangname.ThreeLetterISOLanguageName.Substring(1)); } catch {} }
public void RefreshLang() { var lcid = (int)Locales.GetCurrentLocale(); if (lcid > 0) { var clangname = new System.Globalization.CultureInfo(lcid); ChangeLD(clangname.ThreeLetterISOLanguageName.Substring(0, 1).ToUpper() + clangname.ThreeLetterISOLanguageName.Substring(1)); } else { Logging.Log("Language tooltip text NOT changed, locale id = [" + lcid + "].", 2); } }
public static void Init() { if (!MahouUI.ENABLED) { return; } if (running) { bool exist = true; if (Environment.Is64BitOperatingSystem) { if (Process.GetProcessesByName("jkl").Length > 0) { Logging.Log("[JKL] > JKL already running."); } else { exist = false; } } else { if (Process.GetProcessesByName("jklx86").Length > 0) { Logging.Log("[JKL] > JKLx86 already running."); } else { exist = false; } } if (!exist) { Logging.Log("[JKL] > JKL seems closed, restarting..."); running = false; } } if (HWND == IntPtr.Zero) { Logging.Log("[JKL] > Initializing JKL HWND server..."); WNDPROC_DELEGATE = jklWndProc; var wnd_class = new WinAPI.WNDCLASS(); wnd_class.lpszClassName = "_XHIDDEN_HWND_SERVER"; wnd_class.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(WNDPROC_DELEGATE); UInt16 cls_reg = WinAPI.RegisterClassW(ref wnd_class); int last_error = Marshal.GetLastWin32Error(); if (cls_reg == 0 && last_error != 0) { Logging.Log("[JKL] > Could not register window class, for jkl Hidden Server, err: " + last_error, 1); } HWND = WinAPI.CreateWindowExW(0, "_XHIDDEN_HWND_SERVER", "_XHIDDEN_HWND_SERVER", 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); Logging.Log("[JKL] > SERVER HWND: " + HWND); } if (!running) { if (jklExist()) { if (Environment.Is64BitOperatingSystem) { Logging.Log("[JKL] > Starting jkl.exe..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jkl.exe"); jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } else { Logging.Log("[JKL] > Starting \"jklx86.exe -msg\"..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jklx86.exe"); jkl.Arguments = "-msg"; jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } var umsgID = Path.Combine(Path.GetTempPath(), "umsg.id"); var tries = 0; while (!File.Exists(umsgID)) { Thread.Sleep(350); tries++; if (tries > 20) { Logging.Log("[JKL] > Error, umsg.id not found after 20 tries by 350 ms timeout.", 1); Destroy(); break; } } if (tries <= 20) { Logging.Log("[JKL] > umsg.id found, after " + tries + " tries * 350ms timeout."); Logging.Log("[JKL] > Retrieving umsg.id..."); jkluMSG = Int32.Parse(File.ReadAllText(umsgID)); File.Delete(umsgID); // KMHook.DoLater(() => CycleAllLayouts(Locales.ActiveWindow()), 350); KMHook.DoLater(() => { MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetCurrentLocale(); }, 200); running = true; } } else { Logging.Log("[JKL] > " + jklInfoStr, 1); } if (jkluMSG == -1) { KMHook.JKLERR = true; } else { KMHook.JKLERR = false; } Logging.Log("[JKL] > Init done, umsg: [" + jkluMSG + "], JKLXServ: [" + HWND + "]."); } }
public MahouForm() { InitializeComponent(); res.Tick += (_, __) => { // Console.WriteLine("hiding"); onepass = true; langDisplay.HideWnd(); res.Stop(); }; res.Interval = ICheck.Interval * 4; ICheck.Tick += (_, __) => { if (MMain.MyConfs.ReadBool("Functions", "DTTOnChange")) { if (onepass) { latestL = Locales.GetCurrentLocale(); onepass = false; } if (latestL != Locales.GetCurrentLocale()) { langDisplay.ShowInactiveTopmost(); res.Start(); } } else { if (ICheckings.IsICursor()) { langDisplay.ShowInactiveTopmost(); } else { langDisplay.HideWnd(); } } langDisplay.Location = new Point(Cursor.Position.X + MMain.MyConfs.ReadInt("TTipUI", "xpos"), Cursor.Position.Y + MMain.MyConfs.ReadInt("TTipUI", "ypos")); langDisplay.RefreshLang(); }; ScrlCheck.Tick += (_, __) => { if (MMain.MyConfs.ReadBool("Functions", "ScrollTip") && !KMHook.self) { KMHook.self = true; if (Locales.GetCurrentLocale() == MMain.MyConfs.ReadInt("Locales", "locale1uId")) { if (!Control.IsKeyLocked(Keys.Scroll)) // Turn on { KMHook.KeybdEvent(Keys.Scroll, 0); KMHook.KeybdEvent(Keys.Scroll, 2); } } else { if (Control.IsKeyLocked(Keys.Scroll)) // Turn off { KMHook.KeybdEvent(Keys.Scroll, 0); KMHook.KeybdEvent(Keys.Scroll, 2); } } KMHook.self = false; } }; ScrlCheck.Interval = 250; if (MMain.MyConfs.ReadBool("Functions", "ScrollTip")) { ScrlCheck.Start(); } KMHook.doublekey.Tick += (_, __) => { if (KMHook.hklOK) { KMHook.hklOK = false; } if (KMHook.hksOK) { KMHook.hksOK = false; } if (KMHook.hklineOK) { KMHook.hklineOK = false; } if (KMHook.hkSIOK) { KMHook.hkSIOK = false; } KMHook.doublekey.Stop(); //Console.WriteLine("Timeout!"); }; langDisplay.ChangeColors(ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLForeColor")), ColorTranslator.FromHtml(MMain.MyConfs.Read("Functions", "DLBackColor"))); langDisplay.ChangeSizes((Font)moreConfigs.fcv.ConvertFromString(MMain.MyConfs.Read("TTipUI", "Font")), MMain.MyConfs.ReadInt("TTipUI", "Height"), MMain.MyConfs.ReadInt("TTipUI", "Width")); ICheck.Interval = MMain.MyConfs.ReadInt("Functions", "DLRefreshRate"); if (MMain.MyConfs.ReadBool("Functions", "DisplayLang")) { ICheck.Start(); } icon = new TrayIcon(MMain.MyConfs.ReadBool("Functions", "IconVisibility")); icon.Exit += exitToolStripMenuItem_Click; icon.ShowHide += showHideToolStripMenuItem_Click; //↓ Dummy(none) hotkey, makes it possible WndProc to handle messages at startup //↓ when form isn't was shown. RegisterHotKey(Handle, 0xffff ^ 0xffff, 0, 0); //HWND must be this form handle RefreshIconAll(); InitializeHotkeys(); //Background startup check for updates if (MMain.MyConfs.ReadBool("Functions", "UpdatesEnabled")) { var uche = new System.Threading.Thread(update.StartupCheck); uche.Name = "Startup Check"; uche.Start(); } }
/// <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); } }
public static void Init() { if (!MahouUI.ENABLED) { return; } if (running) { bool exist = true; if (Environment.Is64BitOperatingSystem) { if (Process.GetProcessesByName("jkl").Length > 0) { Logging.Log("[JKL] > JKL already running."); } else { exist = false; } } else { if (Process.GetProcessesByName("jklx86").Length > 0) { Logging.Log("[JKL] > JKLx86 already running."); } else { exist = false; } } if (!exist) { Logging.Log("[JKL] > JKL seems closed, restarting..."); running = false; } } if (s == null) { Logging.Log("[JKL] > Initializing JKL HWND server..."); s = new HServer(); Logging.Log("[JKL] > SERVER HWND: " + s.Handle + " WinTitle: " + s.Text); } if (!running) { if (jklExist()) { if (Environment.Is64BitOperatingSystem) { Logging.Log("[JKL] > Starting jkl.exe..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jkl.exe"); jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } else { Logging.Log("[JKL] > Starting \"jklx86.exe -msg\"..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jklx86.exe"); jkl.Arguments = "-msg"; jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } var umsgID = Path.Combine(Path.GetTempPath(), "umsg.id"); var tries = 0; while (!File.Exists(umsgID)) { Thread.Sleep(350); tries++; if (tries > 20) { Logging.Log("[JKL] > Error, umsg.id not found after 20 tries by 350 ms timeout.", 1); Destroy(); break; } } if (tries <= 20) { Logging.Log("[JKL] > umsg.id found, after " + tries + " tries * 350ms timeout."); Logging.Log("[JKL] > Retrieving umsg.id..."); jkluMSG = Int32.Parse(File.ReadAllText(umsgID)); File.Delete(umsgID); // KMHook.DoLater(() => CycleAllLayouts(Locales.ActiveWindow()), 350); KMHook.DoLater(() => { MahouUI.GlobalLayout = MahouUI.currentLayout = Locales.GetCurrentLocale(); }, 200); running = true; } } else { Logging.Log("[JKL] > " + jklInfoStr, 1); } if (jkluMSG == -1) { KMHook.JKLERR = true; } else { KMHook.JKLERR = false; } Logging.Log("[JKL] > Init done, umsg: [" + jkluMSG + "], JKLXServ: [" + s.Handle + "]."); } }
[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(); } }
[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(); } } }