public FileContextMenuExt() { var is4K = SystemHelper.Is4KDisplay(); //Load the bitmap for the menu item. _menuBmpPink = is4K ? Resource.purple_200.GetHbitmap() : Resource.purple.GetHbitmap(); _menuBmpGray = is4K ? Resource.gray_200.GetHbitmap() : Resource.gray.GetHbitmap(); _menuBmpBlue = is4K ? Resource.blue_200.GetHbitmap() : Resource.blue.GetHbitmap(); _menuBmpYellow = is4K ? Resource.yellow_200.GetHbitmap() : Resource.yellow.GetHbitmap(); //Load default items. menuItems.Add(new LEMenuItem(I18n.GetString("Submenu"), true, null, _menuBmpYellow, "")); menuItems.Add(new LEMenuItem(I18n.GetString("RunDefault"), true, null, _menuBmpYellow, "-run \"%APP%\"")); menuItems.Add(new LEMenuItem(I18n.GetString("ManageApp"), true, null, _menuBmpGray, "-manage \"%APP%\"")); menuItems.Add(new LEMenuItem(I18n.GetString("ManageAll"), true, null, _menuBmpBlue, "-global")); //Load global profiles. Array.ForEach(LEConfig.GetProfiles(), p => menuItems.Add(new LEMenuItem(p.Name, true, p.ShowInMainMenu, _menuBmpPink, $"-runas \"{p.Guid}\" \"%APP%\""))); //Config does not exist if (LEConfig.GetProfiles().Length == 0) { menuItems.Add(new LEMenuItem("No profile, please run LEGUI.exe.", false, false, _menuBmpPink, "")); } }
public AppConfig() { InitializeComponent(); // Region. _cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures).OrderBy(i => i.DisplayName).ToList(); cbLocation.ItemsSource = _cultureInfos.Select(c => c.DisplayName); cbLocation.SelectedIndex = _cultureInfos.FindIndex(c => c.Name == "ja-JP"); //Timezone. _timezones = TimeZoneInfo.GetSystemTimeZones().ToList(); cbTimezone.ItemsSource = _timezones.Select(t => t.DisplayName); cbTimezone.SelectedIndex = _timezones.FindIndex(tz => tz.Id == "Tokyo Standard Time"); // Load exists config. var configs = LEConfig.GetProfiles(App.StandaloneFilePath); if (configs.Length > 0) { var conf = configs[0]; if (!string.IsNullOrEmpty(conf.Parameter)) { tbAppParameter.FontStyle = FontStyles.Normal; tbAppParameter.Text = conf.Parameter; } cbTimezone.SelectedIndex = _timezones.FindIndex(tz => tz.Id == conf.Timezone); cbLocation.SelectedIndex = _cultureInfos.FindIndex(ci => ci.Name == conf.Location); cbStartAsAdmin.IsChecked = conf.RunAsAdmin; cbRedirectRegistry.IsChecked = conf.RedirectRegistry; cbStartAsSuspend.IsChecked = conf.RunWithSuspend; } }
private static void RunWithGlobalProfile(string guid, string path) { // We do not check whether the config exists because only when it exists can this method be called. var profile = LEConfig.GetProfiles().First(p => p.Guid == guid); DoRunWithLEProfile(path, profile); }
private static void RunWithIndependentProfile(string path) { string conf = path + ".le.config"; if (!File.Exists(conf)) Process.Start( Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "LEGUI.exe"), String.Format("\"{0}.le.config\"", path)); else { LEProfile profile = LEConfig.GetProfiles(conf)[0]; DoRunWithLEProfile(path, profile); } }
private void SaveSetting() { var crt = new LEProfile(Path.GetFileName(App.StandaloneFilePath), Guid.NewGuid().ToString(), false, tbAppParameter.Text, _cultureInfos[cbLocation.SelectedIndex].Name, _timezones[cbTimezone.SelectedIndex].Id, cbStartAsAdmin.IsChecked != null && (bool)cbStartAsAdmin.IsChecked, cbRedirectRegistry.IsChecked != null && (bool)cbRedirectRegistry.IsChecked, cbStartAsSuspend.IsChecked != null && (bool)cbStartAsSuspend.IsChecked ); LEConfig.SaveApplicationConfigFile(App.StandaloneFilePath, crt); }
private void App_OnStartup(object sender, StartupEventArgs e) { if (e.Args.Length != 0) { StandaloneFilePath = e.Args[0]; } I18n.LoadLanguage(); LEConfig.CheckGlobalConfigFile(true); Current.StartupUri = String.IsNullOrEmpty(StandaloneFilePath) ? new Uri("GlobalConfig.xaml", UriKind.RelativeOrAbsolute) : new Uri("AppConfig.xaml", UriKind.RelativeOrAbsolute); }
private static void RunWithIndependentProfile(string path) { var conf = path + ".le.config"; if (!File.Exists(conf)) { Process.Start( Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "LEGUI.exe"), $"\"{path}.le.config\""); } else { var profile = LEConfig.GetProfiles(conf)[0]; DoRunWithLEProfile(path, 2, profile); } }
private static void RunWithDefaultProfile(string path) { path = SystemHelper.EnsureAbsolutePath(path); var conf = path + ".le.config"; var appProfile = LEConfig.GetProfiles(conf); var globalProfiles = LEConfig.GetProfiles(); // app profile > first global profile > new profile(ja-JP) var profile = appProfile.Any() ? appProfile.First() : globalProfiles.Any() ? globalProfiles.First() : new LEProfile(true); DoRunWithLEProfile(path, 1, profile); }
public GlobalConfig() { InitializeComponent(); // Region. _cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures).OrderBy(i => i.DisplayName).ToList(); cbLocation.ItemsSource = _cultureInfos.Select(c => c.DisplayName); //Timezone. _timezones = TimeZoneInfo.GetSystemTimeZones().ToList(); cbTimezone.ItemsSource = _timezones.Select(t => t.DisplayName); //Profiles. _profiles = LEConfig.GetProfiles().ToList(); cbGlobalProfiles.ItemsSource = _profiles.Select(p => p.Name); }
public FileContextMenuExt() { //Load the bitmap for the menu item. _menuBmpPink = Resource.Pink.GetHbitmap(); _menuBmpGray = Resource.Gray.GetHbitmap(); //Load default items. menuItems.Add(new LEMenuItem(I18n.GetString("RunDefault"), null, _menuBmpPink, "-run \"%APP%\"")); menuItems.Add(new LEMenuItem(I18n.GetString("Submenu"), null, _menuBmpGray, "")); menuItems.Add(new LEMenuItem(I18n.GetString("ManageApp"), null, _menuBmpGray, "-manage \"%APP%\"")); menuItems.Add(new LEMenuItem(I18n.GetString("ManageAll"), null, _menuBmpGray, "-global")); //Load global profiles. Array.ForEach(LEConfig.GetProfiles(), p => menuItems.Add(new LEMenuItem(p.Name, p.ShowInMainMenu, _menuBmpGray, string.Format("-runas \"{0}\" \"%APP%\"", p.Guid)))); }
private void SaveProfileAs(string name) { var pro = new LEProfile(name, Guid.NewGuid().ToString(), cbShowInMainMenu.IsChecked != null && (bool)cbShowInMainMenu.IsChecked, String.Empty, _cultureInfos[cbLocation.SelectedIndex].Name, _timezones[cbTimezone.SelectedIndex].Id, cbStartAsAdmin.IsChecked != null && (bool)cbStartAsAdmin.IsChecked, cbRedirectRegistry.IsChecked != null && (bool)cbRedirectRegistry.IsChecked, cbStartAsSuspend.IsChecked != null && (bool)cbStartAsSuspend.IsChecked); _profiles.Add(pro); LEConfig.SaveGlobalConfigFile(_profiles.ToArray()); // Update cbGlobalProfiles. cbGlobalProfiles.ItemsSource = _profiles.Select(p => p.Name); }
private void bSaveGlobalSetting_Click(object sender, RoutedEventArgs e) { if (cbGlobalProfiles.Items.Count == 0) { return; } LEProfile crt = _profiles[cbGlobalProfiles.SelectedIndex]; crt.DefaultFont = cbDefaultFont.Text; crt.Location = _cultureInfos[cbLocation.SelectedIndex].Name; crt.Timezone = _timezones[cbTimezone.SelectedIndex].Id; crt.ShowInMainMenu = cbShowInMainMenu.IsChecked != null && (bool)cbShowInMainMenu.IsChecked; crt.RunWithSuspend = cbStartAsSuspend.IsChecked != null && (bool)cbStartAsSuspend.IsChecked; _profiles[cbGlobalProfiles.SelectedIndex] = crt; LEConfig.SaveGlobalConfigFile(_profiles.ToArray()); }
private void bDeleteGlobalSetting_Click(object sender, RoutedEventArgs e) { if (cbGlobalProfiles.SelectedIndex == -1) { return; } if (MessageBoxResult.No == MessageBox.Show(I18n.GetString("ConfirmDel"), "", MessageBoxButton.YesNo)) { return; } _profiles.RemoveAt(cbGlobalProfiles.SelectedIndex); LEConfig.SaveGlobalConfigFile(_profiles.ToArray()); // Update cbGlobalProfiles. cbGlobalProfiles.ItemsSource = _profiles.Select(p => p.Name); cbGlobalProfiles.SelectedIndex = 0; }
private void bSaveAppSetting_Click(object sender, RoutedEventArgs e) { var crt = new LEProfile { Name = Path.GetFileName(App.StandaloneFilePath), Guid = Guid.NewGuid().ToString(), ShowInMainMenu = false, Parameter = I18n.GetString("EnterArgument") == tbAppParameter.Text ? String.Empty : tbAppParameter.Text, DefaultFont = cbDefaultFont.Text, Location = _cultureInfos[cbLocation.SelectedIndex].Name, Timezone = _timezones[cbTimezone.SelectedIndex].Id, RunWithSuspend = cbStartAsSuspend.IsChecked != null && (bool)cbStartAsSuspend.IsChecked }; LEConfig.SaveApplicationConfigFile(App.StandaloneFilePath, crt); //Run the application. Process.Start( Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "LEProc.exe"), string.Format("-run \"{0}\"", App.StandaloneFilePath.Replace(".le.config", ""))); Application.Current.Shutdown(); }
private static void Main(string[] args) { SystemHelper.DisableDPIScale(); if (!GlobalHelper.CheckCoreDLLs()) { MessageBox.Show( "Some of the core Dlls are missing.\r\n" + "Please whitelist these Dlls in your antivirus software, then download and re-install LE.\r\n" + "\r\n" + "These Dlls are:\r\n" + "LoaderDll.dll\r\n" + "LocaleEmulator.dll", "Locale Emulator Version " + GlobalHelper.GetLEVersion(), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //If global config does not exist, create a new one. LEConfig.CheckGlobalConfigFile(true); if (args.Length == 0) { MessageBox.Show( "Welcome to Locale Emulator command line tool.\r\n" + "\r\n" + "Usage: LEProc.exe\r\n" + "\tpath\r\n" + "\t-run path [args]\r\n" + "\t-runas guid path [args]\r\n" + "\t-manage path\r\n" + "\t-global\r\n" + "\r\n" + "path\tFull path of the target application.\r\n" + "guid\tGuid of the target profile (in LEConfig.xml).\r\n" + "args\tAdditional arguments will be passed to the application.\r\n" + "\r\n" + "path\tRun an application with \r\n" + "\t\t(i) its own profile (if any) or \r\n" + "\t\t(ii) first global profile (if any) or \r\n" + "\t\t(iii) default ja-JP profile.\r\n" + "-run\tRun an application with it's own profile.\r\n" + "-runas\tRun an application with a global profile of specific Guid.\r\n" + "-manage\tModify the profile of one application.\r\n" + "-global\tOpen Global Profile Manager.\r\n" + "\r\n" + "\r\n" + "You can press CTRL+C to copy this message to your clipboard.\r\n", "Locale Emulator Version " + GlobalHelper.GetLEVersion() ); // GlobalHelper.ShowErrorDebugMessageBox("SYSTEM_REPORT", 0); return; } try { // To keep original quotes in the command line. If we directly use args[] to make the command line, // {_cmd1.exe / c _cmd2.exe "path with space"} will become {_cmd1.exe / c _cmd2.exe path with space} // and will cause issues. var argWithQuotesList = Regex.Matches(Environment.CommandLine, @"[\""].+?[\""]|[^ ]+") .Cast <Match>() .ToArray(); Args = new string[argWithQuotesList.Length - 1]; for (var i = 1; i < argWithQuotesList.Length; i += 1) { Args[i - 1] = argWithQuotesList[i].ToString(); } switch (Args[0]) { case "-run": //-run %APP% RunWithIndependentProfile(Args[1]); break; case "-manage": //-manage %APP% Process.Start(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "LEGUI.exe"), $"\"{Args[1]}.le.config\""); break; case "-global": //-global Process.Start(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "LEGUI.exe")); break; case "-runas": //-runas %GUID% %APP% RunWithGlobalProfile(Args[1], Args[2]); break; default: if (File.Exists(Args[0].Trim('"'))) { RunWithDefaultProfile(Args[0].Trim('"')); } break; } } catch { } }
private static void Main(string[] args) { SystemHelper.DisableDPIScale(); try { Process.Start(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "LEUpdater.exe"), "schedule"); } catch { } if (!GlobalHelper.CheckCoreDLLs()) { MessageBox.Show( "Some of the core Dlls are missing.\r\n" + "Please whitelist these Dlls in your antivirus software, then download and re-install LE.\r\n" + "\r\n" + "These Dlls are:\r\n" + "LoaderDll.dll\r\n" + "LocaleEmulator.dll", "Locale Emulator Version " + GlobalHelper.GetLEVersion(), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //If global config does not exist, create a new one. LEConfig.CheckGlobalConfigFile(true); if (args.Length == 0) { MessageBox.Show( "Welcome to Locale Emulator command line tool.\r\n" + "\r\n" + "Usage: LEProc.exe\r\n" + "\tpath\r\n" + "\t-run path [args]\r\n" + "\t-runas guid path [args]\r\n" + "\t-manage path\r\n" + "\t-global\r\n" + "\r\n" + "path\tFull path of the target application.\r\n" + "guid\tGuid of the target profile (in LEConfig.xml).\r\n" + "args\tAdditional arguments will be passed to the application.\r\n" + "\r\n" + "path\tRun an application with \r\n" + "\t\t(i) its own profile (if any) or \r\n" + "\t\t(ii) first global profile (if any) or \r\n" + "\t\t(iii) default ja-JP profile.\r\n" + "-run\tRun an application with it's own profile.\r\n" + "-runas\tRun an application with a global profile of specific Guid.\r\n" + "-manage\tModify the profile of one application.\r\n" + "-global\tOpen Global Profile Manager.\r\n" + "\r\n" + "\r\n" + "You can press CTRL+C to copy this message to your clipboard.\r\n", "Locale Emulator Version " + GlobalHelper.GetLEVersion() ); GlobalHelper.ShowErrorDebugMessageBox("SYSTEM_REPORT", 0); return; } try { Args = args; switch (Args[0]) { case "-run": //-run %APP% RunWithIndependentProfile(Args[1]); break; case "-manage": //-manage %APP% Process.Start(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "LEGUI.exe"), $"\"{Args[1]}.le.config\""); break; case "-global": //-global Process.Start(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "LEGUI.exe")); break; case "-runas": //-runas %GUID% %APP% RunWithGlobalProfile(Args[1], Args[2]); break; default: if (File.Exists(Args[0])) { RunWithDefaultProfile(Args[0]); } break; } } catch { } }
private void App_OnStartup(object sender, StartupEventArgs e) { if (e.Args.Length != 0) { StandaloneFilePath = e.Args[0]; // This happens when user is trying to drop a exe onto LEGUI. if (!StandaloneFilePath.EndsWith(".le.config", true, null)) { StandaloneFilePath += ".le.config"; } } var isGlobalProfile = String.IsNullOrEmpty(StandaloneFilePath); LEConfig.CheckGlobalConfigFile(true); // We check StandaloneFilePath before loading UI, because this wil be faster. if ( !SystemHelper.CheckPermission(isGlobalProfile ? Path.GetDirectoryName(LEConfig.GlobalConfigPath) : Path.GetDirectoryName(StandaloneFilePath))) { if (SystemHelper.IsAdministrator()) { // We can do nothing now. if (isGlobalProfile) { MessageBox.Show( string.Format("Home directory is not writable. \r\n" + "Please move LE to another location and try again.\r\n" + "Home directory: {0}", Path.GetDirectoryName(LEConfig.GlobalConfigPath)), "Locale Emulator", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show(string.Format("The directory is not writable.\r\n" + "Please use global profile instead.\r\n" + "Current Directory: {0}", Path.GetDirectoryName(StandaloneFilePath)), "Locale Emulator", MessageBoxButton.OK, MessageBoxImage.Error); } Current.Shutdown(); } else { // If we are not administrator, we can ask for administrator permission. try { SystemHelper.RunWithElevatedProcess( Path.Combine( Path.GetDirectoryName(LEConfig.GlobalConfigPath), "LEGUI.exe"), e.Args); } catch (Exception ex) { MessageBox.Show("LEGUI requires administrator privilege to write to the current directory.", "Locale Emulator", MessageBoxButton.OK, MessageBoxImage.Error); } finally { Current.Shutdown(); } } } I18n.LoadLanguage(); Current.StartupUri = isGlobalProfile ? new Uri("GlobalConfig.xaml", UriKind.RelativeOrAbsolute) : new Uri("AppConfig.xaml", UriKind.RelativeOrAbsolute); }