Пример #1
0
        private static void BuildGlobalConfigFile()
        {
            var defaultProfile = new LEProfile("Run in Japanese",
                                               Guid.NewGuid().ToString(),
                                               false,
                                               String.Empty,
                                               "ja-JP",
                                               "MS Gothic",
                                               "Tokyo Standard Time",
                                               false
                                               );

            WriteConfig(GlobalConfigPath, defaultProfile);
        }
Пример #2
0
        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);
        }
Пример #3
0
        private static void DoRunWithLEProfile(string path, LEProfile profile)
        {
            try
            {
                if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
                {
                    ElevateProcess();

                    return;
                }

                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                                        "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
                                        "\r\n" +
                                        "The exectuable will be executed after you click the \"Yes\" button, " +
                                        "But as a background process which has no notfications at all." +
                                        "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
                                        "Locale Emulator Debug Mode Warning",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Information
                            ))
                        return;
                }

                string applicationName = string.Empty;
                string commandLine = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? string.Format("{0} ", path)
                                      : String.Format("\"{0}\" ", path);

                    commandLine += profile.Parameter;
                }
                else
                {
                    string[] jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                        return;

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? string.Format("{0} ", jb[0])
                                      : String.Format("\"{0}\" ", jb[0]);
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                string currentDirectory = Path.GetDirectoryName(path);
                bool debugMode = profile.RunWithSuspend;
                var ansiCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset = (uint)
                                     GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
                                                                           .TextInfo.ANSICodePage);

                TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(profile.Timezone);
                var timezoneBias = (int)-tzi.BaseUtcOffset.TotalMinutes;

                TimeZoneInfo.AdjustmentRule[] adjustmentRules = tzi.GetAdjustmentRules();
                TimeZoneInfo.AdjustmentRule adjustmentRule = null;
                if (adjustmentRules.Length > 0)
                {
                    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
                    adjustmentRule =
                        adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
                }
                int timezoneDaylightBias = adjustmentRule == null ? 0 : (int)-adjustmentRule.DaylightDelta.TotalMinutes;

                string timezoneStandardName = tzi.StandardName;

                string timezoneDaylightName = tzi.DaylightName;

                LERegistryEntry[] registries = profile.RedirectRegistry
                                                   ? new LERegistry().GetRegistryEntries()
                                                   : new LERegistryEntry[0];

                var l = new LoaderWrapper
                        {
                            ApplicationName = applicationName,
                            CommandLine = commandLine,
                            CurrentDirectory = currentDirectory,
                            AnsiCodePage = ansiCodePage,
                            OemCodePage = oemCodePage,
                            LocaleID = localeID,
                            DefaultCharset = defaultCharset,
                            TimezoneBias = timezoneBias,
                            TimezoneDaylightBias = timezoneDaylightBias,
                            TimezoneStandardName = timezoneStandardName,
                            TimezoneDaylightName = timezoneDaylightName,
                            NumberOfRegistryRedirectionEntries = registries.Length,
                            DebugMode = debugMode,
                        };

                registries.ToList()
                          .ForEach(
                                   item =>
                                   l.AddRegistryRedirectEntry(item.Root, item.Key, item.Name, item.Type, item.Data));

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (SystemHelper.IsAdministrator())
                    {
                        MessageBox.Show(String.Format(
                                                      "Launch failed.\r\n" +
                                                      "\r\n" +
                                                      "Commands: {0}\r\n" +
                                                      "Error Number: {1}\r\n" +
                                                      "Administrator: {2}\r\n" +
                                                      "\r\n" +
                                                      "If you have any antivirus software running, please turn it off and try again.\r\n"
                                                      +
                                                      "If you think this error is related to LE itself, feel free to submit an issue at\r\n"
                                                      +
                                                      "https://github.com/xupefei/Locale-Emulator/issues.\r\n" +
                                                      "\r\n" +
                                                      "\r\n" +
                                                      "You can press CTRL+C to copy this message to your clipboard.\r\n",
                                                      commandLine,
                                                      Convert.ToString(ret, 16).ToUpper(),
                                                      SystemHelper.IsAdministrator()
                                            ),
                                        "Locale Emulator Version " + GlobalHelper.GetLEVersion());
                    }
                    else
                    {
                        ElevateProcess();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #4
0
        private static void BuildGlobalConfigFile()
        {
            var defaultProfile = new LEProfile("Run in Japanese",
                                               Guid.NewGuid().ToString(),
                                               false,
                                               String.Empty,
                                               "ja-JP",
                                               "MS Gothic",
                                               "Tokyo Standard Time",
                                               false
                );

            WriteConfig(GlobalConfigPath, defaultProfile);
        }
Пример #5
0
 public static void SaveApplicationConfigFile(string path, LEProfile profile)
 {
     WriteConfig(path, profile);
 }
Пример #6
0
        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,
                                    cbDefaultFont.Text,
                                    _timezones[cbTimezone.SelectedIndex].Id,
                                    cbStartAsAdmin.IsChecked != null && (bool)cbStartAsAdmin.IsChecked,
                                    cbStartAsSuspend.IsChecked != null && (bool)cbStartAsSuspend.IsChecked);

            _profiles.Add(pro);

            LEConfig.SaveGlobalConfigFile(_profiles.ToArray());

            // Update cbGlobalProfiles.
            cbGlobalProfiles.ItemsSource = _profiles.Select(p => p.Name);
        }
Пример #7
0
        private static void DoRunWithLEProfile(string path, int argumentsStart, LEProfile profile)
        {
            try
            {
                if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
                {
                    ElevateProcess();

                    return;
                }

                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                                        "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
                                        "\r\n" +
                                        "The exectuable will be executed after you click the \"Yes\" button, " +
                                        "but as a background process which has no notifications at all." +
                                        "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
                                        "Locale Emulator Debug Mode Warning",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Information
                            ))
                        return;
                }

                var applicationName = string.Empty;
                var commandLine = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? $"{path} "
                                      : $"\"{path}\" ";

                    // use arguments in le.config, prior to command line arguments
                    commandLine += string.IsNullOrEmpty(profile.Parameter) && Args.Skip(argumentsStart).Any()
                                       ? Args.Skip(argumentsStart).Aggregate((a, b) => $"{a} {b}")
                                       : profile.Parameter;
                }
                else
                {
                    var jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                        return;

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? $"{jb[0]} "
                                      : $"\"{jb[0]}\" ";
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                var currentDirectory = Path.GetDirectoryName(path);
                var ansiCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset = (uint)
                                     GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
                                                                           .TextInfo.ANSICodePage);

                var registries = profile.RedirectRegistry
                                     ? new RegistryEntriesLoader().GetRegistryEntries(profile.IsAdvancedRedirection)
                                     : null;

                var l = new LoaderWrapper
                        {
                            ApplicationName = applicationName,
                            CommandLine = commandLine,
                            CurrentDirectory = currentDirectory,
                            AnsiCodePage = ansiCodePage,
                            OemCodePage = oemCodePage,
                            LocaleID = localeID,
                            DefaultCharset = defaultCharset,
                            HookUILanguageAPI = profile.IsAdvancedRedirection ? (uint)1 : 0,
                            Timezone = profile.Timezone,
                            NumberOfRegistryRedirectionEntries = registries?.Length ?? 0,
                            DebugMode = profile.RunWithSuspend
                };

                registries?.ToList()
                           .ForEach(
                                    item =>
                                    l.AddRegistryRedirectEntry(item.Root,
                                                               item.Key,
                                                               item.Name,
                                                               item.Type,
                                                               item.GetValue(CultureInfo.GetCultureInfo(profile.Location))));

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (SystemHelper.IsAdministrator())
                    {
                        GlobalHelper.ShowErrorDebugMessageBox(commandLine, ret);
                    }
                    else
                    {
                        ElevateProcess();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #8
0
 public static void SaveApplicationConfigFile(string path, LEProfile profile)
 {
     WriteConfig(path, profile);
 }
Пример #9
0
        private static void DoRunWithLEProfile(string path, LEProfile profile)
        {
            try
            {
                if (profile.RunAsAdmin && !SystemHelper.IsAdministrator())
                {
                    ElevateProcess();

                    return;
                }

                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                                        "You are running a exectuable with CREATE_SUSPENDED flag.\r\n" +
                                        "\r\n" +
                                        "The exectuable will be executed after you click the \"Yes\" button, " +
                                        "But as a background process which has no notfications at all." +
                                        "You can attach it by using OllyDbg, or stop it with Task Manager.\r\n",
                                        "Locale Emulator Debug Mode Warning",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Information
                            ))
                        return;
                }

                var applicationName = string.Empty;
                var commandLine = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? string.Format("{0} ", path)
                                      : String.Format("\"{0}\" ", path);

                    commandLine += profile.Parameter;
                }
                else
                {
                    var jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                        return;

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? string.Format("{0} ", jb[0])
                                      : String.Format("\"{0}\" ", jb[0]);
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                var currentDirectory = Path.GetDirectoryName(path);
                var debugMode = profile.RunWithSuspend;
                var ansiCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset = (uint)
                                     GetCharsetFromANSICodepage(CultureInfo.GetCultureInfo(profile.Location)
                                                                           .TextInfo.ANSICodePage);

                var tzi = TimeZoneInfo.FindSystemTimeZoneById(profile.Timezone);
                var timezoneBias = (int)-tzi.BaseUtcOffset.TotalMinutes;

                var adjustmentRules = tzi.GetAdjustmentRules();
                TimeZoneInfo.AdjustmentRule adjustmentRule = null;
                if (adjustmentRules.Length > 0)
                {
                    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
                    adjustmentRule =
                        adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
                }
                var timezoneDaylightBias = adjustmentRule == null ? 0 : (int)-adjustmentRule.DaylightDelta.TotalMinutes;

                var timezoneStandardName = tzi.StandardName;

                var timezoneDaylightName = tzi.DaylightName;

                var registries = profile.RedirectRegistry
                                     ? new LERegistry().GetRegistryEntries()
                                     : new LERegistryEntry[0];

                var l = new LoaderWrapper
                        {
                            ApplicationName = applicationName,
                            CommandLine = commandLine,
                            CurrentDirectory = currentDirectory,
                            AnsiCodePage = ansiCodePage,
                            OemCodePage = oemCodePage,
                            LocaleID = localeID,
                            DefaultCharset = defaultCharset,
                            TimezoneBias = timezoneBias,
                            TimezoneDaylightBias = timezoneDaylightBias,
                            TimezoneStandardName = timezoneStandardName,
                            TimezoneDaylightName = timezoneDaylightName,
                            NumberOfRegistryRedirectionEntries = registries.Length,
                            DebugMode = debugMode
                        };

                registries.ToList()
                          .ForEach(
                                   item =>
                                   l.AddRegistryRedirectEntry(item.Root, item.Key, item.Name, item.Type, item.Data));

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (SystemHelper.IsAdministrator())
                    {
                        GlobalHelper.ShowErrorDebugMessageBox(commandLine, ret);
                    }
                    else
                    {
                        ElevateProcess();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Пример #10
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();
        }
Пример #11
0
        private static void DoRunWithLEProfile(string path, LEProfile profile)
        {
            try
            {
                if (profile.RunWithSuspend)
                {
                    if (DialogResult.No ==
                        MessageBox.Show(
                            "You are running a process with CREATE_SUSPEND flag.\r\nIs this really what you want?",
                            "Locale Emulator Debug Mode Warning", MessageBoxButtons.YesNo)) return;
                }

                string applicationName = string.Empty;
                string commandLine = string.Empty;

                if (Path.GetExtension(path).ToLower() == ".exe")
                {
                    applicationName = path;

                    commandLine = path.StartsWith("\"")
                                      ? string.Format("{0} ", path)
                                      : String.Format("\"{0}\" ", path);

                    commandLine += profile.Parameter;
                }
                else
                {
                    string[] jb = AssociationReader.GetAssociatedProgram(Path.GetExtension(path));

                    if (jb == null)
                        return;

                    applicationName = jb[0];

                    commandLine = jb[0].StartsWith("\"")
                                      ? string.Format("{0} ", jb[0])
                                      : String.Format("\"{0}\" ", jb[0]);
                    commandLine += jb[1].Replace("%1", path).Replace("%*", profile.Parameter);
                }

                string currentDirectory = Path.GetDirectoryName(path);
                bool debugMode = profile.RunWithSuspend;
                var ansiCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage;
                var oemCodePage = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.OEMCodePage;
                var localeID = (uint)CultureInfo.GetCultureInfo(profile.Location).TextInfo.LCID;
                var defaultCharset = (uint)
                                     GetCharsetFromANSICodepage(
                                         CultureInfo.GetCultureInfo(profile.Location).TextInfo.ANSICodePage);
                string defaultFaceName = profile.DefaultFont;

                TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(profile.Timezone);
                var timezoneBias = (int)-tzi.BaseUtcOffset.TotalMinutes;

                TimeZoneInfo.AdjustmentRule[] adjustmentRules = tzi.GetAdjustmentRules();
                TimeZoneInfo.AdjustmentRule adjustmentRule = null;
                if (adjustmentRules.Length > 0)
                {
                    // Find the single record that encompasses today's date. If none exists, sets adjustmentRule to null.
                    adjustmentRule =
                        adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
                }
                int timezoneDaylightBias = adjustmentRule == null ? 0 : (int)-adjustmentRule.DaylightDelta.TotalMinutes;

                string timezoneStandardName = tzi.StandardName;

                string timezoneDaylightName = tzi.DaylightName;

                var l = new LoaderWrapper
                    {
                        ApplicationName = applicationName,
                        CommandLine = commandLine,
                        CurrentDirectory = currentDirectory,
                        AnsiCodePage = ansiCodePage,
                        OemCodePage = oemCodePage,
                        LocaleID = localeID,
                        DefaultCharset = defaultCharset,
                        DefaultFaceName = defaultFaceName,
                        TimezoneBias = timezoneBias,
                        TimezoneDaylightBias = timezoneDaylightBias,
                        TimezoneStandardName = timezoneStandardName,
                        TimezoneDaylightName = timezoneDaylightName,
                        DebugMode = debugMode,
                    };

                uint ret;
                if ((ret = l.Start()) != 0)
                {
                    if (IsAdministrator())
                    {
                        MessageBox.Show(
                            String.Format(
                                "Error number {0} detected.\r\n\r\nThis may because the target executable is a 64-bit binary which is not supported by the current version of Locale Emulator.",
                                Convert.ToString(ret, 16).ToUpper()),
                            "Locale Emulator");
                    }
                    else
                    {
                        RunWithElevatedProcess(Args);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }