Пример #1
0
        public static void Configure()
        {
            try
            {
                var fi = new FileInfo(typeof(TranslationManager).Assembly.Location);
                var di = fi.Directory;
                TranslatorsPath = Path.Combine(di.FullName, TranslatorsFolder);

                try
                {
                    ApplicationName = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName);
                }
                catch (Exception e)
                {
                    XuaLogger.AutoTranslator.Warn(e, "An error occurred while obtaining the path to the executable. {GameExeName} variable in configuration files will not work correctly.");

                    ApplicationName = string.Empty;
                }

                ServiceEndpoint = PluginEnvironment.Current.Preferences.GetOrDefault("Service", "Endpoint", KnownTranslateEndpointNames.GoogleTranslate);

                Language     = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "Language", DefaultLanguage));
                FromLanguage = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "FromLanguage", DefaultFromLanguage));

                TranslationDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "Directory", Path.Combine("Translation", Path.Combine("{Lang}", "Text")));
                OutputFile           = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "OutputFile", Path.Combine("Translation", Path.Combine("{Lang}", Path.Combine("Text", "_AutoGeneratedTranslations.txt"))));
                SubstitutionFile     = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "SubstitutionFile", Path.Combine("Translation", Path.Combine("{Lang}", Path.Combine("Text", "_Substitutions.txt"))));
                PreprocessorsFile    = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "PreprocessorsFile", Path.Combine("Translation", Path.Combine("{Lang}", Path.Combine("Text", "_Preprocessors.txt"))));

                EnableIMGUI       = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableIMGUI", false);
                EnableUGUI        = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableUGUI", true);
                EnableNGUI        = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableNGUI", true);
                EnableTextMeshPro = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMeshPro", true);
                EnableTextMesh    = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMesh", false);
                EnableFairyGUI    = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableFairyGUI", true);

                MaxCharactersPerTranslation   = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxCharactersPerTranslation", 200);
                IgnoreWhitespaceInDialogue    = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInDialogue", true);
                IgnoreWhitespaceInNGUI        = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInNGUI", true);
                MinDialogueChars              = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MinDialogueChars", 20);
                ForceSplitTextAfterCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceSplitTextAfterCharacters", 0);
                CopyToClipboard            = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CopyToClipboard", false);
                MaxClipboardCopyCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxClipboardCopyCharacters", 1000);
                EnableUIResizing           = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableUIResizing", true);
                EnableBatching             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableBatching", true);
                UseStaticTranslations      = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "UseStaticTranslations", true);
                OverrideFont             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFont", string.Empty);
                OverrideFontTextMeshPro  = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFontTextMeshPro", string.Empty);
                ResizeUILineSpacingScale = PluginEnvironment.Current.Preferences.GetOrDefault <float?>("Behaviour", "ResizeUILineSpacingScale", null);
                ForceUIResizing          = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceUIResizing", false);
                IgnoreTextStartingWith   = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreTextStartingWith", "\\u180e;")
                                           ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => JsonHelper.Unescape(x)).ToArray() ?? new string[0];
                TextGetterCompatibilityMode = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TextGetterCompatibilityMode", false);
                GameLogTextPaths            = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GameLogTextPaths", string.Empty)
                                              ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>();
                GameLogTextPaths.RemoveWhere(x => !x.StartsWith("/")); // clean up to ensure no 'empty' entries
                RomajiPostProcessing                   = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "RomajiPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex | TextPostProcessing.RemoveApostrophes);
                TranslationPostProcessing              = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TranslationPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex);
                CacheRegexPatternResults               = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexPatternResults", false);
                CacheRegexLookups                      = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexLookups", false);
                CacheWhitespaceDifferences             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheWhitespaceDifferences", false);
                GenerateStaticSubstitutionTranslations = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GenerateStaticSubstitutionTranslations", false);
                GeneratePartialTranslations            = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GeneratePartialTranslations", false);
                EnableTranslationScoping               = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTranslationScoping", false);
                EnableSilentMode        = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableSilentMode", true);
                BlacklistedIMGUIPlugins = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "BlacklistedIMGUIPlugins", string.Empty)
                                          ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                                          .Select(x => x.Trim())
                                          .Where(x => !string.IsNullOrEmpty(x))
                                          .ToHashSet(StringComparer.OrdinalIgnoreCase) ?? new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                EnableTextPathLogging               = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTextPathLogging", false);
                OutputUntranslatableText            = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OutputUntranslatableText", false);
                IgnoreVirtualTextSetterCallingRules = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreVirtualTextSetterCallingRules", false);
                MaxTextParserRecursion              = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxTextParserRecursion", 1);
                HtmlEntityPreprocessing             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "HtmlEntityPreprocessing", true);
                HandleRichText                = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "HandleRichText", true);
                EnableTranslationHelper       = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTranslationHelper", false);
                ForceMonoModHooks             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceMonoModHooks", false);
                InitializeHarmonyDetourBridge = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "InitializeHarmonyDetourBridge", !Features.SupportsReflectionEmit && PluginEnvironment.Current.AllowDefaultInitializeHarmonyDetourBridge);


                TextureDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureDirectory", Path.Combine("Translation", Path.Combine("{Lang}", "Texture")));
                TexturesPath     = Path.Combine(PluginEnvironment.Current.TranslationPath, Settings.TextureDirectory).Parameterize();

                EnableTextureTranslation     = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureTranslation", Directory.Exists(TexturesPath));
                EnableTextureDumping         = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureDumping", false);
                EnableTextureToggling        = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureToggling", false);
                EnableTextureScanOnSceneLoad = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureScanOnSceneLoad", false);
                EnableSpriteRendererHooking  = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableSpriteRendererHooking", false);
                LoadUnmodifiedTextures       = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "LoadUnmodifiedTextures", false);
                DetectDuplicateTextureNames  = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DetectDuplicateTextureNames", false);
                DuplicateTextureNames        = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DuplicateTextureNames", string.Empty)
                                               ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>();
                EnableLegacyTextureLoading    = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableLegacyTextureLoading", false);
                TextureHashGenerationStrategy = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureHashGenerationStrategy", TextureHashGenerationStrategy.FromImageName);
                CacheTexturesInMemory         = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "CacheTexturesInMemory", true);
                EnableSpriteHooking           = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableSpriteHooking", false);

                PreferredStoragePath      = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "PreferredStoragePath", Path.Combine("Translation", Path.Combine("{Lang}", "RedirectedResources")));
                EnableTextAssetRedirector = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "EnableTextAssetRedirector", false);
                LogAllLoadedResources     = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "LogAllLoadedResources", false);
                EnableDumping             = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "EnableDumping", false);
                CacheMetadataForAllFiles  = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "CacheMetadataForAllFiles", true);

                if (CacheMetadataForAllFiles && EnableDumping)
                {
                    XuaLogger.AutoTranslator.Warn("'EnableDumping' and 'CacheMetadataForAllFiles' cannot be enabled at the same time. Disabling 'CacheMetadataForAllFiles'...");

                    CacheMetadataForAllFiles = false;
                }

                // FIXME: UseCorrectDirectorySeparators() is called on entire path because redirected resource path lookups has the same changes (requires v. 5.x.x)
                RedirectedResourcesPath = Path.Combine(PluginEnvironment.Current.TranslationPath, PreferredStoragePath).UseCorrectDirectorySeparators().Parameterize();

                if (MaxCharactersPerTranslation > MaxMaxCharactersPerTranslation)
                {
                    PluginEnvironment.Current.Preferences["Behaviour"]["MaxCharactersPerTranslation"].Value = MaxMaxCharactersPerTranslation.ToString(CultureInfo.InvariantCulture);
                    MaxCharactersPerTranslation = MaxMaxCharactersPerTranslation;
                }

                UserAgent = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "UserAgent", string.Empty);
                DisableCertificateValidation = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "DisableCertificateValidation", true);


                Width              = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "Width", 400.0f);
                Height             = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "Height", 100.0f);
                EnabledTranslators = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "EnabledTranslators", string.Empty)
                                     ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>();


                EnableConsole = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnableConsole", false);

                EnableMigrations = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Enable", true);
                MigrationsTag    = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Tag", string.Empty);

                AutoTranslationsFilePath = Path.Combine(PluginEnvironment.Current.TranslationPath, OutputFile.UseCorrectDirectorySeparators()).Parameterize();
                SubstitutionFilePath     = Path.Combine(PluginEnvironment.Current.TranslationPath, SubstitutionFile.UseCorrectDirectorySeparators()).Parameterize();
                PreprocessorsFilePath    = Path.Combine(PluginEnvironment.Current.TranslationPath, PreprocessorsFile.UseCorrectDirectorySeparators()).Parameterize();

                TranslationsPath = Path.Combine(PluginEnvironment.Current.TranslationPath, Settings.TranslationDirectory.UseCorrectDirectorySeparators()).Parameterize();

                FromLanguageUsesWhitespaceBetweenWords = LanguageHelper.RequiresWhitespaceUponLineMerging(FromLanguage);
                ToLanguageUsesWhitespaceBetweenWords   = LanguageHelper.RequiresWhitespaceUponLineMerging(Language);

                if (EnableTranslationScoping && !Features.SupportsSceneManager)
                {
                    EnableTranslationScoping = false;

                    XuaLogger.AutoTranslator.Warn("Disabling translation scoping because the SceneManager API is not supported in this version of Unity.");
                }

                if (EnableMigrations)
                {
                    Migrate();
                }

                // update tag
                MigrationsTag = PluginEnvironment.Current.Preferences["Migrations"]["Tag"].Value = PluginData.Version;

                Save();
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred during configuration. Shutting plugin down.");

                IsShutdown = true;
            }
        }
Пример #2
0
        public static void Configure()
        {
            try
            {
                ApplicationName = Path.GetFileNameWithoutExtension(ApplicationInformation.StartupPath);

                ServiceEndpoint = PluginEnvironment.Current.Preferences.GetOrDefault("Service", "Endpoint", KnownTranslateEndpointNames.GoogleTranslate);

                Language     = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "Language", DefaultLanguage));
                FromLanguage = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "FromLanguage", DefaultFromLanguage));

                TranslationDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "Directory", "Translation");
                OutputFile           = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "OutputFile", @"Translation\_AutoGeneratedTranslations.{lang}.txt");

                EnableIMGUI             = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableIMGUI", false);
                EnableUGUI              = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableUGUI", true);
                EnableNGUI              = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableNGUI", true);
                EnableTextMeshPro       = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMeshPro", true);
                AllowPluginHookOverride = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "AllowPluginHookOverride", true);

                Delay = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "Delay", 0f);
                MaxCharactersPerTranslation   = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxCharactersPerTranslation", 200);
                IgnoreWhitespaceInDialogue    = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInDialogue", true);
                IgnoreWhitespaceInNGUI        = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInNGUI", true);
                MinDialogueChars              = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MinDialogueChars", 20);
                ForceSplitTextAfterCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceSplitTextAfterCharacters", 0);
                CopyToClipboard            = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CopyToClipboard", false);
                MaxClipboardCopyCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxClipboardCopyCharacters", 1000);
                EnableUIResizing           = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableUIResizing", true);
                EnableBatching             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableBatching", true);
                UseStaticTranslations      = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "UseStaticTranslations", true);
                OverrideFont             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFont", string.Empty);
                ResizeUILineSpacingScale = PluginEnvironment.Current.Preferences.GetOrDefault <float?>("Behaviour", "ResizeUILineSpacingScale", null);
                ForceUIResizing          = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceUIResizing", false);
                IgnoreTextStartingWith   = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreTextStartingWith", "\\u180e;")
                                           ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => JsonHelper.Unescape(x)).ToArray() ?? new string[0];
                TextGetterCompatibilityMode = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TextGetterCompatibilityMode", false);
                GameLogTextPaths            = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GameLogTextPaths", string.Empty)
                                              ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>();
                GameLogTextPaths.RemoveWhere(x => !x.StartsWith("/")); // clean up to ensure no 'empty' entries
                WhitespaceRemovalStrategy  = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "WhitespaceRemovalStrategy", WhitespaceHandlingStrategy.TrimPerNewline);
                RomajiPostProcessing       = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "RomajiPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex | TextPostProcessing.RemoveApostrophes);
                TranslationPostProcessing  = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TranslationPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex);
                EnableExperimentalHooks    = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableExperimentalHooks", false);
                ForceExperimentalHooks     = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceExperimentalHooks", false);
                CacheRegexLookups          = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexLookups", false);
                CacheWhitespaceDifferences = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheWhitespaceDifferences", true);

                TextureDirectory             = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureDirectory", @"Translation\Texture");
                EnableTextureTranslation     = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureTranslation", false);
                EnableTextureDumping         = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureDumping", false);
                EnableTextureToggling        = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureToggling", false);
                EnableTextureScanOnSceneLoad = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureScanOnSceneLoad", false);
                EnableSpriteRendererHooking  = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableSpriteRendererHooking", false);
                LoadUnmodifiedTextures       = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "LoadUnmodifiedTextures", false);
                DetectDuplicateTextureNames  = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DetectDuplicateTextureNames", false);
                DuplicateTextureNames        = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DuplicateTextureNames", string.Empty)
                                               ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>();

                TextureHashGenerationStrategy = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureHashGenerationStrategy", TextureHashGenerationStrategy.FromImageName);

                if (MaxCharactersPerTranslation > MaxMaxCharactersPerTranslation)
                {
                    PluginEnvironment.Current.Preferences["Behaviour"]["MaxCharactersPerTranslation"].Value = MaxMaxCharactersPerTranslation.ToString(CultureInfo.InvariantCulture);
                    MaxCharactersPerTranslation = MaxMaxCharactersPerTranslation;
                }

                UserAgent = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "UserAgent", string.Empty);
                DisableCertificateValidation = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "DisableCertificateValidation", GetInitialDisableCertificateChecks());

                EnablePrintHierarchy = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnablePrintHierarchy", false);
                EnableConsole        = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnableConsole", false);
                EnableDebugLogs      = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnableLog", false);

                EnableMigrations = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Enable", true);
                MigrationsTag    = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Tag", string.Empty);

                AutoTranslationsFilePath   = Path.Combine(PluginEnvironment.Current.TranslationPath, OutputFile.Replace("{lang}", Language)).Replace("/", "\\").Parameterize();
                UsesWhitespaceBetweenWords = LanguageHelper.RequiresWhitespaceUponLineMerging(FromLanguage);



                if (EnableMigrations)
                {
                    Migrate();
                }

                // update tag
                MigrationsTag = PluginEnvironment.Current.Preferences["Migrations"]["Tag"].Value = PluginData.Version;

                Save();
            }
            catch (Exception e)
            {
                XuaLogger.Current.Error(e, "An error occurred during configuration. Shutting plugin down.");

                IsShutdown = true;
            }
        }
Пример #3
0
        public static void Configure()
        {
            try
            {
                ApplicationName = Path.GetFileNameWithoutExtension(ApplicationInformation.StartupPath);

                ServiceEndpoint = PluginEnvironment.Current.Preferences.GetOrDefault("Service", "Endpoint", KnownTranslateEndpointNames.GoogleTranslate);

                Language     = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "Language", DefaultLanguage));
                FromLanguage = string.Intern(PluginEnvironment.Current.Preferences.GetOrDefault("General", "FromLanguage", DefaultFromLanguage));

                TranslationDirectory = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "Directory", "Translation");
                OutputFile           = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "OutputFile", @"Translation\_AutoGeneratedTranslations.{lang}.txt");
                SubstitutionFile     = PluginEnvironment.Current.Preferences.GetOrDefault("Files", "SubstitutionFile", @"Translation\_Substitutions.{lang}.txt");

                EnableIMGUI             = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableIMGUI", false);
                EnableUGUI              = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableUGUI", true);
                EnableNGUI              = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableNGUI", true);
                EnableTextMeshPro       = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMeshPro", true);
                EnableTextMesh          = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "EnableTextMesh", false);
                AllowPluginHookOverride = PluginEnvironment.Current.Preferences.GetOrDefault("TextFrameworks", "AllowPluginHookOverride", true);

                MaxCharactersPerTranslation   = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxCharactersPerTranslation", 200);
                IgnoreWhitespaceInDialogue    = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInDialogue", true);
                IgnoreWhitespaceInNGUI        = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreWhitespaceInNGUI", true);
                MinDialogueChars              = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MinDialogueChars", 20);
                ForceSplitTextAfterCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceSplitTextAfterCharacters", 0);
                CopyToClipboard            = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CopyToClipboard", false);
                MaxClipboardCopyCharacters = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "MaxClipboardCopyCharacters", 1000);
                EnableUIResizing           = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableUIResizing", true);
                EnableBatching             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableBatching", true);
                UseStaticTranslations      = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "UseStaticTranslations", true);
                OverrideFont             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFont", string.Empty);
                OverrideFontTextMeshPro  = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "OverrideFontTextMeshPro", string.Empty);
                ResizeUILineSpacingScale = PluginEnvironment.Current.Preferences.GetOrDefault <float?>("Behaviour", "ResizeUILineSpacingScale", null);
                ForceUIResizing          = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceUIResizing", false);
                IgnoreTextStartingWith   = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "IgnoreTextStartingWith", "\\u180e;")
                                           ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => JsonHelper.Unescape(x)).ToArray() ?? new string[0];
                TextGetterCompatibilityMode = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TextGetterCompatibilityMode", false);
                GameLogTextPaths            = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GameLogTextPaths", string.Empty)
                                              ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>();
                GameLogTextPaths.RemoveWhere(x => !x.StartsWith("/")); // clean up to ensure no 'empty' entries
                RomajiPostProcessing                   = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "RomajiPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex | TextPostProcessing.RemoveApostrophes);
                TranslationPostProcessing              = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "TranslationPostProcessing", TextPostProcessing.ReplaceMacronWithCircumflex);
                ForceMonoModHooks                      = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "ForceMonoModHooks", false);
                CacheRegexPatternResults               = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexPatternResults", false);
                CacheRegexLookups                      = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheRegexLookups", false);
                CacheWhitespaceDifferences             = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "CacheWhitespaceDifferences", false);
                GenerateStaticSubstitutionTranslations = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GenerateStaticSubstitutionTranslations", false);
                GeneratePartialTranslations            = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "GeneratePartialTranslations", false);
                EnableTranslationScoping               = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTranslationScoping", false);
                EnableSilentMode        = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableSilentMode", false);
                BlacklistedIMGUIPlugins = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "BlacklistedIMGUIPlugins", string.Empty)
                                          ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                                          .Select(x => x.Trim())
                                          .Where(x => !string.IsNullOrEmpty(x))
                                          .ToHashSet(StringComparer.OrdinalIgnoreCase) ?? new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                EnableTextPathLogging = PluginEnvironment.Current.Preferences.GetOrDefault("Behaviour", "EnableTextPathLogging", false);

                TextureDirectory             = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureDirectory", @"Translation\Texture");
                EnableTextureTranslation     = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureTranslation", false);
                EnableTextureDumping         = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureDumping", false);
                EnableTextureToggling        = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureToggling", false);
                EnableTextureScanOnSceneLoad = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableTextureScanOnSceneLoad", false);
                EnableSpriteRendererHooking  = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableSpriteRendererHooking", false);
                LoadUnmodifiedTextures       = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "LoadUnmodifiedTextures", false);
                DetectDuplicateTextureNames  = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DetectDuplicateTextureNames", false);
                DuplicateTextureNames        = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "DuplicateTextureNames", string.Empty)
                                               ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>();
                EnableLegacyTextureLoading    = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "EnableLegacyTextureLoading", false);
                TextureHashGenerationStrategy = PluginEnvironment.Current.Preferences.GetOrDefault("Texture", "TextureHashGenerationStrategy", TextureHashGenerationStrategy.FromImageName);

                PreferredStoragePath      = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "PreferredStoragePath", @"RedirectedResources");
                EnableTextAssetRedirector = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "EnableTextAssetRedirector", false);
                LogAllLoadedResources     = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "LogAllLoadedResources", false);
                EnableDumping             = PluginEnvironment.Current.Preferences.GetOrDefault("ResourceRedirector", "EnableDumping", false);

                RedirectedResourcesPath = Path.Combine(PluginEnvironment.Current.TranslationPath, PreferredStoragePath).Replace("/", "\\").Parameterize();

                if (MaxCharactersPerTranslation > MaxMaxCharactersPerTranslation)
                {
                    PluginEnvironment.Current.Preferences["Behaviour"]["MaxCharactersPerTranslation"].Value = MaxMaxCharactersPerTranslation.ToString(CultureInfo.InvariantCulture);
                    MaxCharactersPerTranslation = MaxMaxCharactersPerTranslation;
                }

                UserAgent = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "UserAgent", string.Empty);
                DisableCertificateValidation = PluginEnvironment.Current.Preferences.GetOrDefault("Http", "DisableCertificateValidation", GetInitialDisableCertificateChecks());


                Width              = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "Width", 400.0f);
                Height             = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "Height", 100.0f);
                EnabledTranslators = PluginEnvironment.Current.Preferences.GetOrDefault("TranslationAggregator", "EnabledTranslators", string.Empty)
                                     ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet() ?? new HashSet <string>();


                EnableConsole = PluginEnvironment.Current.Preferences.GetOrDefault("Debug", "EnableConsole", false);

                EnableMigrations = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Enable", true);
                MigrationsTag    = PluginEnvironment.Current.Preferences.GetOrDefault("Migrations", "Tag", string.Empty);

                AutoTranslationsFilePath = Path.Combine(PluginEnvironment.Current.TranslationPath, OutputFile.Replace("{lang}", Language)).Replace("/", "\\").Parameterize();
                SubstitutionFilePath     = Path.Combine(PluginEnvironment.Current.TranslationPath, SubstitutionFile.Replace("{lang}", Language)).Replace("/", "\\").Parameterize();

                FromLanguageUsesWhitespaceBetweenWords = LanguageHelper.RequiresWhitespaceUponLineMerging(FromLanguage);
                ToLanguageUsesWhitespaceBetweenWords   = LanguageHelper.RequiresWhitespaceUponLineMerging(Language);

                if (EnableTranslationScoping && !Features.SupportsSceneManager)
                {
                    EnableTranslationScoping = false;

                    XuaLogger.AutoTranslator.Warn("Disabling translation scoping because the SceneManager API is not supported in this version of Unity.");
                }

                //// workaround to handle text translation toggling in KK
                //if( ApplicationName != null )
                //{
                //   var n = ApplicationName.ToLower();
                //   if( n == "koikatu" || n == "koikatsu" )
                //   {
                //      RequiresToggleFix = true;
                //   }
                //}

                if (EnableMigrations)
                {
                    Migrate();
                }

                // update tag
                MigrationsTag = PluginEnvironment.Current.Preferences["Migrations"]["Tag"].Value = PluginData.Version;

                Save();
            }
            catch (Exception e)
            {
                XuaLogger.AutoTranslator.Error(e, "An error occurred during configuration. Shutting plugin down.");

                IsShutdown = true;
            }
        }
Пример #4
0
        public static void Configure()
        {
            try
            {
                // clear configuration from old versions...
                var section = Config.Current.Preferences["AutoTranslator"];
                foreach (var key in section.Keys.ToList())
                {
                    section.DeleteKey(key.Key);
                }

                Config.Current.Preferences.DeleteSection("AutoTranslator");
                Config.Current.Preferences["Service"].DeleteKey("EnableSSL");
            }
            catch { }



            ServiceEndpoint = Config.Current.Preferences["Service"]["Endpoint"].GetOrDefault(KnownEndpointNames.GoogleTranslate, true);

            Language     = Config.Current.Preferences["General"]["Language"].GetOrDefault(DefaultLanguage);
            FromLanguage = Config.Current.Preferences["General"]["FromLanguage"].GetOrDefault(DefaultFromLanguage, true);

            TranslationDirectory = Config.Current.Preferences["Files"]["Directory"].GetOrDefault(@"Translation");
            OutputFile           = Config.Current.Preferences["Files"]["OutputFile"].GetOrDefault(@"Translation\_AutoGeneratedTranslations.{lang}.txt");

            EnableIMGUI             = Config.Current.Preferences["TextFrameworks"]["EnableIMGUI"].GetOrDefault(false);
            EnableUGUI              = Config.Current.Preferences["TextFrameworks"]["EnableUGUI"].GetOrDefault(true);
            EnableNGUI              = Config.Current.Preferences["TextFrameworks"]["EnableNGUI"].GetOrDefault(true);
            EnableTextMeshPro       = Config.Current.Preferences["TextFrameworks"]["EnableTextMeshPro"].GetOrDefault(true);
            EnableUtage             = Config.Current.Preferences["TextFrameworks"]["EnableUtage"].GetOrDefault(true);
            AllowPluginHookOverride = Config.Current.Preferences["TextFrameworks"]["AllowPluginHookOverride"].GetOrDefault(true);

            Delay = Config.Current.Preferences["Behaviour"]["Delay"].GetOrDefault(0f);
            MaxCharactersPerTranslation   = Config.Current.Preferences["Behaviour"]["MaxCharactersPerTranslation"].GetOrDefault(200);
            IgnoreWhitespaceInDialogue    = Config.Current.Preferences["Behaviour"]["IgnoreWhitespaceInDialogue"].GetOrDefault(ClrTypes.AdvEngine == null);
            IgnoreWhitespaceInNGUI        = Config.Current.Preferences["Behaviour"]["IgnoreWhitespaceInNGUI"].GetOrDefault(true);
            MinDialogueChars              = Config.Current.Preferences["Behaviour"]["MinDialogueChars"].GetOrDefault(20);
            ForceSplitTextAfterCharacters = Config.Current.Preferences["Behaviour"]["ForceSplitTextAfterCharacters"].GetOrDefault(0);
            CopyToClipboard            = Config.Current.Preferences["Behaviour"]["CopyToClipboard"].GetOrDefault(false);
            MaxClipboardCopyCharacters = Config.Current.Preferences["Behaviour"]["MaxClipboardCopyCharacters"].GetOrDefault(450);
            EnableUIResizing           = Config.Current.Preferences["Behaviour"]["EnableUIResizing"].GetOrDefault(true);
            EnableBatching             = Config.Current.Preferences["Behaviour"]["EnableBatching"].GetOrDefault(true);
            TrimAllText              = Config.Current.Preferences["Behaviour"]["TrimAllText"].GetOrDefault(ClrTypes.AdvEngine == null);
            UseStaticTranslations    = Config.Current.Preferences["Behaviour"]["UseStaticTranslations"].GetOrDefault(true);
            OverrideFont             = Config.Current.Preferences["Behaviour"]["OverrideFont"].GetOrDefault(string.Empty);
            ResizeUILineSpacingScale = Config.Current.Preferences["Behaviour"]["ResizeUILineSpacingScale"].GetOrDefault <float?>(null, true);
            ForceUIResizing          = Config.Current.Preferences["Behaviour"]["ForceUIResizing"].GetOrDefault(false);
            IgnoreTextStartingWith   = Config.Current.Preferences["Behaviour"]["IgnoreTextStartingWith"].GetOrDefault("\\u180e;", true)
                                       ?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.UnescapeJson()).ToArray() ?? new string[0];

            TextureDirectory             = Config.Current.Preferences["Texture"]["TextureDirectory"].GetOrDefault(@"Translation\Texture");
            EnableTextureTranslation     = Config.Current.Preferences["Texture"]["EnableTextureTranslation"].GetOrDefault(false);
            EnableTextureDumping         = Config.Current.Preferences["Texture"]["EnableTextureDumping"].GetOrDefault(false);
            EnableTextureToggling        = Config.Current.Preferences["Texture"]["EnableTextureToggling"].GetOrDefault(false);
            EnableTextureScanOnSceneLoad = Config.Current.Preferences["Texture"]["EnableTextureScanOnSceneLoad"].GetOrDefault(false);
            LoadUnmodifiedTextures       = Config.Current.Preferences["Texture"]["LoadUnmodifiedTextures"].GetOrDefault(false);
            //DeleteUnmodifiedTextures = Config.Current.Preferences[ "Texture" ][ "DeleteUnmodifiedTextures" ].GetOrDefault( false );
            TextureHashGenerationStrategy = Config.Current.Preferences["Texture"]["TextureHashGenerationStrategy"].GetOrDefault(TextureHashGenerationStrategy.FromImageName);

            // special handling because of enum parsing
            try
            {
                WhitespaceRemovalStrategy = Config.Current.Preferences["Behaviour"]["WhitespaceRemovalStrategy"].GetOrDefault(WhitespaceHandlingStrategy.TrimPerNewline);
            }
            catch (Exception e)
            {
                WhitespaceRemovalStrategy = WhitespaceHandlingStrategy.TrimPerNewline;

                Logger.Current.Warn(e, "An error occurred while configuring 'WhitespaceRemovalStrategy'. Using default.");
            }

            UserAgent = Config.Current.Preferences["Http"]["UserAgent"].GetOrDefault(string.Empty);

            GoogleAPIKey = Config.Current.Preferences["GoogleLegitimate"]["GoogleAPIKey"].GetOrDefault("");

            BingOcpApimSubscriptionKey = Config.Current.Preferences["BingLegitimate"]["OcpApimSubscriptionKey"].GetOrDefault("");

            BaiduAppId     = Config.Current.Preferences["Baidu"]["BaiduAppId"].GetOrDefault("");
            BaiduAppSecret = Config.Current.Preferences["Baidu"]["BaiduAppSecret"].GetOrDefault("");

            YandexAPIKey = Config.Current.Preferences["Yandex"]["YandexAPIKey"].GetOrDefault("");

            WatsonAPIUrl      = Config.Current.Preferences["Watson"]["WatsonAPIUrl"].GetOrDefault("");
            WatsonAPIUsername = Config.Current.Preferences["Watson"]["WatsonAPIUsername"].GetOrDefault("");
            WatsonAPIPassword = Config.Current.Preferences["Watson"]["WatsonAPIPassword"].GetOrDefault("");

            EnablePrintHierarchy = Config.Current.Preferences["Debug"]["EnablePrintHierarchy"].GetOrDefault(false);
            EnableConsole        = Config.Current.Preferences["Debug"]["EnableConsole"].GetOrDefault(false);
            EnableDebugLogs      = Config.Current.Preferences["Debug"]["EnableLog"].GetOrDefault(false);

            EnableMigrations = Config.Current.Preferences["Migrations"]["Enable"].GetOrDefault(true);
            MigrationsTag    = Config.Current.Preferences["Migrations"]["Tag"].GetOrDefault(string.Empty);

            AutoTranslationsFilePath   = Path.Combine(Config.Current.DataPath, OutputFile.Replace("{lang}", Language));
            UsesWhitespaceBetweenWords = TextHelper.RequiresWhitespaceUponLineMerging(FromLanguage);

            if (EnableMigrations)
            {
                Migrate();
            }

            // update tag
            MigrationsTag = Config.Current.Preferences["Migrations"]["Tag"].Value = PluginData.Version;

            Config.Current.SaveConfig();
        }