AutoTranslatorPlugin.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using ExIni;
  7. using XUnity.AutoTranslator.Plugin.Core;
  8. using XUnity.AutoTranslator.Plugin.Core.Configuration;
  9. using XUnity.AutoTranslator.Plugin.Core.Constants;
  10. namespace XUnity.AutoTranslator.Plugin.BepIn
  11. {
  12. [BepInEx.BepInPlugin( GUID: PluginData.Identifier, Name: PluginData.Name, Version: PluginData.Version )]
  13. public class AutoTranslatorPlugin : BepInEx.BaseUnityPlugin, IConfiguration
  14. {
  15. private IniFile _file;
  16. private string _configPath;
  17. private string _dataFolder;
  18. public AutoTranslatorPlugin()
  19. {
  20. _dataFolder = "BepInEx";
  21. _configPath = Path.Combine( _dataFolder, "AutoTranslatorConfig.ini" );
  22. Logger.Current = new BepInLogger();
  23. }
  24. public IniFile Preferences
  25. {
  26. get
  27. {
  28. return ( _file ?? ( _file = ReloadConfig() ) ); ;
  29. }
  30. }
  31. public string DataPath
  32. {
  33. get
  34. {
  35. return _dataFolder;
  36. }
  37. }
  38. public IniFile ReloadConfig()
  39. {
  40. if( !File.Exists( _configPath ) )
  41. {
  42. return ( _file ?? new IniFile() );
  43. }
  44. IniFile ini = IniFile.FromFile( _configPath );
  45. if( _file == null )
  46. {
  47. return ( _file = ini );
  48. }
  49. _file.Merge( ini );
  50. return _file;
  51. }
  52. public void SaveConfig()
  53. {
  54. _file.Save( _configPath );
  55. }
  56. void Awake()
  57. {
  58. PluginLoader.LoadWithConfig( this );
  59. }
  60. }
  61. }