Exemplo n.º 1
0
        /// <summary>
        /// Устанавливает текущий язык программы
        /// </summary>
        /// <param name="language"></param>
        /// <param name="showDialog"></param>
        public static void SetLanguageOfApp(string language, bool showDialog = false)
        {
            if (TranslateService.SupportedProgramLangs.All(lang => lang != language))
                return;

            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(language);
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(language);
            AppSettings.LanguageOfApp = language;
            
            if (showDialog && MessBox.ShowDial(StringResources.RestartProgramToApplyLanguage, null,
                MessBox.MessageButtons.Yes, MessBox.MessageButtons.No) ==
                MessBox.MessageButtons.Yes)
            {
                Process.Start(GlobalVariables.PathToExe);
                Environment.Exit(0);
            }

            TranslateService.ReloadItems();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Загружает настройки программы
        /// </summary>
        public static void LoadSettings()
        {
            if (AppSettings.TargetLanguage.IsNullOrEmpty())
                AppSettings.TargetLanguage = "ru";

            if (AppSettings.OnlineTranslator == Guid.Empty)
                AppSettings.OnlineTranslator = TranslateService.OnlineTranslators.First().Key;

            if (AppSettings.TranslatorServicesKeys == null)
                AppSettings.TranslatorServicesKeys = new Dictionary<Guid, string>();

            if (AppSettings.LanguageOfApp.IsNullOrEmpty())
            {
                SetLanguageOfApp(
                    TranslateService.SupportedProgramLangs.FirstOrDefault(lang => lang == GetCurrentLanguage()) 
                    ?? TranslateService.SupportedProgramLangs.First()
                );
            }
            else
            {
                SetLanguageOfApp(AppSettings.LanguageOfApp);
            }

            if (AppSettings.XmlRules == null || AppSettings.XmlRules.Count == 0)
            {
                AppSettings.XmlRules = new List<string>
                {
                    "android:text", "android:title", "android:summary", "android:dialogTitle", 
                    "android:summaryOff", "android:summaryOn", "value"
                };
            }

            if (AppSettings.AvailToEditFiles == null || AppSettings.AvailToEditFiles.Count == 0)
            {
                AppSettings.AvailToEditFiles = new List<string> {".xml", ".smali"};
            }

            if (AppSettings.ImageExtensions == null || 
                AppSettings.ImageExtensions.Count == 0 ||
                AppSettings.ImageExtensions.Count == 1 && AppSettings.ImageExtensions[0].IsNullOrEmpty())
            {
                AppSettings.ImageExtensions = new List<string> {".png", ".jpg", ".jpeg"};
            }

            if (AppSettings.OtherExtensions == null)
                AppSettings.OtherExtensions = new List<string>();

            if (AppSettings.XmlRules != null)
                XmlFile.XmlRules = AppSettings.XmlRules.Select(it => new Regex(it)).ToList();

            if (AppSettings.Theme.IsNullOrEmpty() || GlobalVariables.Themes.All(theme => theme.name != AppSettings.Theme))
                AppSettings.Theme = GlobalVariables.Themes.First().name;

            ThemeUtils.ChangeTheme(AppSettings.Theme);

            string apktoolVersion = AppSettings.ApktoolVersion;

            if (apktoolVersion.IsNullOrEmpty() || !File.Exists(Path.Combine(GlobalVariables.PathToApktoolVersions, $"apktool_{apktoolVersion}.jar")))
            {
                if (Directory.Exists(GlobalVariables.PathToApktoolVersions))
                {
                    string vers = Directory.EnumerateFiles(GlobalVariables.PathToApktoolVersions, "*.jar").LastOrDefault();

                    if (vers != null)
                    {
                        AppSettings.ApktoolVersion = Path.GetFileNameWithoutExtension(vers).SplitRemove("apktool_")[0];
                    }
                }
            }

            TranslateService.ReloadItems();

            UpdateApiKeys();
        }