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"));

            //If global config does not exist, create a new one.
            LEConfig.CheckGlobalConfigFile(true);

            //Load global profiles.
            Array.ForEach(LEConfig.GetProfiles(),
                          p =>
                          menuItems.Add(new LEMenuItem(p.Name,
                                                       true,
                                                       p.ShowInMainMenu,
                                                       _menuBmpPink,
                                                       $"-runas \"{p.Guid}\" \"%APP%\"")));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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
            {
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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
            {
            }
        }