Settings.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using XUnity.AutoTranslator.Plugin.Core.Constants;
  7. namespace XUnity.AutoTranslator.Plugin.Core.Configuration
  8. {
  9. public static class Settings
  10. {
  11. // cannot be changed
  12. public static readonly string DefaultLanguage = "en";
  13. public static readonly string DefaultFromLanguage = "ja";
  14. public static readonly int MaxErrors = 5;
  15. public static readonly float ClipboardDebounceTime = 1f;
  16. public static readonly int MaxTranslationsBeforeShutdown = 10000;
  17. public static readonly int MaxUnstartedJobs = 3500;
  18. public static readonly float IncreaseBatchOperationsEvery = 30;
  19. public static readonly bool EnableObjectTracking = true;
  20. public static readonly int MaximumStaggers = 5;
  21. public static readonly int MaximumConsecutiveFramesTranslated = 90;
  22. public static readonly int MaximumConsecutiveSecondsTranslated = 60;
  23. public static bool IsShutdown = false;
  24. public static int TranslationCount = 0;
  25. public static int MaxAvailableBatchOperations = 40;
  26. public static readonly float MaxTranslationsQueuedPerSecond = 5;
  27. public static readonly int MaxSecondsAboveTranslationThreshold = 30;
  28. public static readonly int TranslationQueueWatchWindow = 6;
  29. public static readonly int BatchSize = 10;
  30. // can be changed
  31. public static string ServiceEndpoint;
  32. public static string Language;
  33. public static string FromLanguage;
  34. public static string OutputFile;
  35. public static string TranslationDirectory;
  36. public static float Delay;
  37. public static int MaxCharactersPerTranslation;
  38. public static bool EnablePrintHierarchy;
  39. public static bool EnableConsole;
  40. public static bool EnableDebugLogs;
  41. public static string AutoTranslationsFilePath;
  42. public static bool EnableIMGUI;
  43. public static bool EnableUGUI;
  44. public static bool EnableNGUI;
  45. public static bool EnableTextMeshPro;
  46. public static bool EnableUtage;
  47. public static bool AllowPluginHookOverride;
  48. public static bool IgnoreWhitespaceInDialogue;
  49. public static int MinDialogueChars;
  50. public static string BaiduAppId;
  51. public static string BaiduAppSecret;
  52. public static string YandexAPIKey;
  53. public static string WatsonAPIUrl;
  54. public static string WatsonAPIUsername;
  55. public static string WatsonAPIPassword;
  56. public static int ForceSplitTextAfterCharacters;
  57. public static bool EnableMigrations;
  58. public static string MigrationsTag;
  59. public static bool EnableBatching;
  60. public static bool TrimAllText;
  61. public static bool EnableUIResizing;
  62. public static string GoogleAPIKey;
  63. public static bool UseStaticTranslations;
  64. public static string OverrideFont;
  65. public static bool CopyToClipboard;
  66. public static int MaxClipboardCopyCharacters;
  67. public static void Configure()
  68. {
  69. try
  70. {
  71. // clear configuration from old versions...
  72. var section = Config.Current.Preferences[ "AutoTranslator" ];
  73. foreach( var key in section.Keys.ToList() )
  74. {
  75. section.DeleteKey( key.Key );
  76. }
  77. Config.Current.Preferences.DeleteSection( "AutoTranslator" );
  78. Config.Current.Preferences[ "Service" ].DeleteKey( "EnableSSL" );
  79. }
  80. catch { }
  81. ServiceEndpoint = Config.Current.Preferences[ "Service" ][ "Endpoint" ].GetOrDefault( KnownEndpointNames.GoogleTranslate, true );
  82. Language = Config.Current.Preferences[ "General" ][ "Language" ].GetOrDefault( DefaultLanguage );
  83. FromLanguage = Config.Current.Preferences[ "General" ][ "FromLanguage" ].GetOrDefault( DefaultFromLanguage, true );
  84. TranslationDirectory = Config.Current.Preferences[ "Files" ][ "Directory" ].GetOrDefault( @"Translation" );
  85. OutputFile = Config.Current.Preferences[ "Files" ][ "OutputFile" ].GetOrDefault( @"Translation\_AutoGeneratedTranslations.{lang}.txt" );
  86. EnableIMGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableIMGUI" ].GetOrDefault( false );
  87. EnableUGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableUGUI" ].GetOrDefault( true );
  88. EnableNGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableNGUI" ].GetOrDefault( true );
  89. EnableTextMeshPro = Config.Current.Preferences[ "TextFrameworks" ][ "EnableTextMeshPro" ].GetOrDefault( true );
  90. EnableUtage = Config.Current.Preferences[ "TextFrameworks" ][ "EnableUtage" ].GetOrDefault( true );
  91. AllowPluginHookOverride = Config.Current.Preferences[ "TextFrameworks" ][ "AllowPluginHookOverride" ].GetOrDefault( true );
  92. Delay = Config.Current.Preferences[ "Behaviour" ][ "Delay" ].GetOrDefault( 0f );
  93. MaxCharactersPerTranslation = Config.Current.Preferences[ "Behaviour" ][ "MaxCharactersPerTranslation" ].GetOrDefault( 150 );
  94. IgnoreWhitespaceInDialogue = Config.Current.Preferences[ "Behaviour" ][ "IgnoreWhitespaceInDialogue" ].GetOrDefault( Types.AdvEngine == null );
  95. MinDialogueChars = Config.Current.Preferences[ "Behaviour" ][ "MinDialogueChars" ].GetOrDefault( 20 );
  96. ForceSplitTextAfterCharacters = Config.Current.Preferences[ "Behaviour" ][ "ForceSplitTextAfterCharacters" ].GetOrDefault( 0 );
  97. CopyToClipboard = Config.Current.Preferences[ "Behaviour" ][ "CopyToClipboard" ].GetOrDefault( false );
  98. MaxClipboardCopyCharacters = Config.Current.Preferences[ "Behaviour" ][ "MaxClipboardCopyCharacters" ].GetOrDefault( 450 );
  99. EnableUIResizing = Config.Current.Preferences[ "Behaviour" ][ "EnableUIResizing" ].GetOrDefault( true );
  100. EnableBatching = Config.Current.Preferences[ "Behaviour" ][ "EnableBatching" ].GetOrDefault( true );
  101. TrimAllText = Config.Current.Preferences[ "Behaviour" ][ "TrimAllText" ].GetOrDefault( Types.AdvEngine == null );
  102. UseStaticTranslations = Config.Current.Preferences[ "Behaviour" ][ "UseStaticTranslations" ].GetOrDefault( true );
  103. OverrideFont = Config.Current.Preferences[ "Behaviour" ][ "OverrideFont" ].GetOrDefault( string.Empty );
  104. GoogleAPIKey = Config.Current.Preferences[ "GoogleLegitimate" ][ "GoogleAPIKey" ].GetOrDefault( "" );
  105. BaiduAppId = Config.Current.Preferences[ "Baidu" ][ "BaiduAppId" ].GetOrDefault( "" );
  106. BaiduAppSecret = Config.Current.Preferences[ "Baidu" ][ "BaiduAppSecret" ].GetOrDefault( "" );
  107. YandexAPIKey = Config.Current.Preferences[ "Yandex" ][ "YandexAPIKey" ].GetOrDefault( "" );
  108. WatsonAPIUrl = Config.Current.Preferences[ "Watson" ][ "WatsonAPIUrl" ].GetOrDefault( "" );
  109. WatsonAPIUsername = Config.Current.Preferences[ "Watson" ][ "WatsonAPIUsername" ].GetOrDefault( "" );
  110. WatsonAPIPassword = Config.Current.Preferences[ "Watson" ][ "WatsonAPIPassword" ].GetOrDefault( "" );
  111. EnablePrintHierarchy = Config.Current.Preferences[ "Debug" ][ "EnablePrintHierarchy" ].GetOrDefault( false );
  112. EnableConsole = Config.Current.Preferences[ "Debug" ][ "EnableConsole" ].GetOrDefault( false );
  113. EnableDebugLogs = Config.Current.Preferences[ "Debug" ][ "EnableLog" ].GetOrDefault( false );
  114. EnableMigrations = Config.Current.Preferences[ "Migrations" ][ "Enable" ].GetOrDefault( true );
  115. MigrationsTag = Config.Current.Preferences[ "Migrations" ][ "Tag" ].GetOrDefault( string.Empty );
  116. AutoTranslationsFilePath = Path.Combine( Config.Current.DataPath, OutputFile.Replace( "{lang}", Language ) );
  117. if( EnableMigrations )
  118. {
  119. Migrate();
  120. }
  121. // update tag
  122. MigrationsTag = Config.Current.Preferences[ "Migrations" ][ "Tag" ].Value = PluginData.Version;
  123. Config.Current.SaveConfig();
  124. }
  125. private static void Migrate()
  126. {
  127. var currentTag = MigrationsTag;
  128. var newTag = PluginData.Version;
  129. // migrate from unknown version to known version. Reset to google translate
  130. if( string.IsNullOrEmpty( currentTag ) )
  131. {
  132. if( ServiceEndpoint == KnownEndpointNames.GoogleTranslateHack )
  133. {
  134. ServiceEndpoint = Config.Current.Preferences[ "Service" ][ "Endpoint" ].Value = KnownEndpointNames.GoogleTranslate;
  135. }
  136. }
  137. }
  138. }
  139. }