Settings.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 int MaxErrors = 5;
  13. public static readonly float ClipboardDebounceTime = 1f;
  14. public static readonly int MaxTranslationsBeforeSlowdown = 1000;
  15. public static readonly int MaxTranslationsBeforeShutdown = 6000;
  16. public static readonly int MaxUnstartedJobs = 3500;
  17. public static int DefaultMaxConcurrentTranslations = 2;
  18. public static int MaxConcurrentTranslations = DefaultMaxConcurrentTranslations;
  19. public static bool IsShutdown = false;
  20. public static readonly float MaxTranslationsQueuedPerSecond = 5;
  21. public static readonly int MaxSecondsAboveTranslationThreshold = 30;
  22. public static readonly int TranslationQueueWatchWindow = 10;
  23. // can be changed
  24. public static string ServiceEndpoint;
  25. public static string Language;
  26. public static string FromLanguage;
  27. public static string OutputFile;
  28. public static string TranslationDirectory;
  29. public static float Delay;
  30. public static int MaxCharactersPerTranslation;
  31. public static bool EnablePrintHierarchy;
  32. public static string AutoTranslationsFilePath;
  33. public static bool EnableIMGUI;
  34. public static bool EnableUGUI;
  35. public static bool EnableNGUI;
  36. public static bool EnableTextMeshPro;
  37. public static bool AllowPluginHookOverride;
  38. public static bool IgnoreWhitespaceInDialogue;
  39. public static int MinDialogueChars;
  40. public static bool EnableSSL;
  41. public static string BaiduAppId;
  42. public static string BaiduAppSecret;
  43. public static int ForceSplitTextAfterCharacters;
  44. public static bool CopyToClipboard;
  45. public static int MaxClipboardCopyCharacters;
  46. public static void Configure()
  47. {
  48. try
  49. {
  50. // clear configuration from old versions...
  51. var section = Config.Current.Preferences[ "AutoTranslator" ];
  52. foreach( var key in section.Keys.ToList() )
  53. {
  54. section.DeleteKey( key.Key );
  55. }
  56. Config.Current.Preferences.DeleteSection( "AutoTranslator" );
  57. }
  58. catch( Exception e )
  59. {
  60. Console.WriteLine( "[XUnity.AutoTranslator][ERROR]: An error occurred while removing legacy configuration. " + Environment.NewLine + e );
  61. }
  62. ServiceEndpoint = Config.Current.Preferences[ "Service" ][ "Endpoint" ].GetOrDefault( KnownEndpointNames.GoogleTranslateLegacy, true );
  63. EnableSSL = Config.Current.Preferences[ "Service" ][ "EnableSSL" ].GetOrDefault( true);
  64. Language = Config.Current.Preferences[ "General" ][ "Language" ].GetOrDefault( "en" );
  65. FromLanguage = Config.Current.Preferences[ "General" ][ "FromLanguage" ].GetOrDefault( "ja", true );
  66. TranslationDirectory = Config.Current.Preferences[ "Files" ][ "Directory" ].GetOrDefault( @"Translation" );
  67. OutputFile = Config.Current.Preferences[ "Files" ][ "OutputFile" ].GetOrDefault( @"Translation\_AutoGeneratedTranslations.{lang}.txt" );
  68. EnableIMGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableIMGUI" ].GetOrDefault( false );
  69. EnableUGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableUGUI" ].GetOrDefault( true );
  70. EnableNGUI = Config.Current.Preferences[ "TextFrameworks" ][ "EnableNGUI" ].GetOrDefault( true );
  71. EnableTextMeshPro = Config.Current.Preferences[ "TextFrameworks" ][ "EnableTextMeshPro" ].GetOrDefault( true );
  72. AllowPluginHookOverride = Config.Current.Preferences[ "TextFrameworks" ][ "AllowPluginHookOverride" ].GetOrDefault( true );
  73. Delay = Config.Current.Preferences[ "Behaviour" ][ "Delay" ].GetOrDefault( 0f );
  74. MaxCharactersPerTranslation = Config.Current.Preferences[ "Behaviour" ][ "MaxCharactersPerTranslation" ].GetOrDefault( 150 );
  75. IgnoreWhitespaceInDialogue = Config.Current.Preferences[ "Behaviour" ][ "IgnoreWhitespaceInDialogue" ].GetOrDefault( true );
  76. MinDialogueChars = Config.Current.Preferences[ "Behaviour" ][ "MinDialogueChars" ].GetOrDefault( 20 );
  77. ForceSplitTextAfterCharacters = Config.Current.Preferences[ "Behaviour" ][ "ForceSplitTextAfterCharacters" ].GetOrDefault( 0 );
  78. CopyToClipboard = Config.Current.Preferences[ "Behaviour" ][ "CopyToClipboard" ].GetOrDefault( false );
  79. MaxClipboardCopyCharacters = Config.Current.Preferences[ "Behaviour" ][ "MaxClipboardCopyCharacters" ].GetOrDefault( 450 );
  80. BaiduAppId = Config.Current.Preferences[ "Baidu" ][ "BaiduAppId" ].GetOrDefault( "" );
  81. BaiduAppSecret = Config.Current.Preferences[ "Baidu" ][ "BaiduAppSecret" ].GetOrDefault( "" );
  82. EnablePrintHierarchy = Config.Current.Preferences[ "Debug" ][ "EnablePrintHierarchy" ].GetOrDefault( false );
  83. AutoTranslationsFilePath = Path.Combine( Config.Current.DataPath, OutputFile.Replace( "{lang}", Language ) );
  84. Config.Current.SaveConfig();
  85. }
  86. }
  87. }