PluginConfig.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using IllusionPlugin;
  2. using Microsoft.Win32;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Xml.Serialization;
  9. using SongBrowser;
  10. using Newtonsoft.Json;
  11. using Newtonsoft.Json.Converters;
  12. using Logger = SongBrowser.Logging.Logger;
  13. namespace SongBrowser
  14. {
  15. // Downloader config
  16. class PluginConfig
  17. {
  18. public static int maxSimultaneousDownloads = 3;
  19. public static string beatsaverURL = "https://beatsaver.com";
  20. public static String CUSTOM_SONG_LEVEL_PACK_ID = "custom_levelpack_CustomLevels";
  21. public static bool beatDropInstalled = false;
  22. public static string beatDropPlaylistsLocation = "";
  23. public static bool disableDeleteButton = false;
  24. public static bool deleteToRecycleBin = true;
  25. public static void LoadOrCreateConfig()
  26. {
  27. if (!Directory.Exists("UserData"))
  28. {
  29. Directory.CreateDirectory("UserData");
  30. }
  31. if (!ModPrefs.HasKey("BeatSaverDownloader", "beatsaverURL"))
  32. {
  33. ModPrefs.SetString("BeatSaverDownloader", "beatsaverURL", "https://beatsaver.com");
  34. Logger.Log("Created config");
  35. }
  36. else
  37. {
  38. beatsaverURL = ModPrefs.GetString("BeatSaverDownloader", "beatsaverURL");
  39. if (string.IsNullOrEmpty(beatsaverURL))
  40. {
  41. ModPrefs.SetString("BeatSaverDownloader", "beatsaverURL", "https://beatsaver.com");
  42. beatsaverURL = "https://beatsaver.com";
  43. Logger.Log("Created config");
  44. }
  45. }
  46. if (!ModPrefs.HasKey("BeatSaverDownloader", "disableDeleteButton"))
  47. {
  48. ModPrefs.SetBool("BeatSaverDownloader", "disableDeleteButton", false);
  49. }
  50. else
  51. {
  52. disableDeleteButton = ModPrefs.GetBool("BeatSaverDownloader", "disableDeleteButton", false, true);
  53. }
  54. if (!ModPrefs.HasKey("BeatSaverDownloader", "deleteToRecycleBin"))
  55. {
  56. ModPrefs.SetBool("BeatSaverDownloader", "deleteToRecycleBin", true);
  57. }
  58. else
  59. {
  60. deleteToRecycleBin = ModPrefs.GetBool("BeatSaverDownloader", "deleteToRecycleBin", true, true);
  61. }
  62. if (!ModPrefs.HasKey("BeatSaverDownloader", "maxSimultaneousDownloads"))
  63. {
  64. ModPrefs.SetInt("BeatSaverDownloader", "maxSimultaneousDownloads", 3);
  65. }
  66. else
  67. {
  68. maxSimultaneousDownloads = ModPrefs.GetInt("BeatSaverDownloader", "maxSimultaneousDownloads", 3, true);
  69. }
  70. /*if (!File.Exists(configPath))
  71. {
  72. File.Create(configPath).Close();
  73. }
  74. favoriteSongs.AddRange(File.ReadAllLines(configPath, Encoding.UTF8)); */
  75. try
  76. {
  77. if (Registry.CurrentUser.OpenSubKey(@"Software").GetSubKeyNames().Contains("178eef3d-4cea-5a1b-bfd0-07a21d068990"))
  78. {
  79. beatDropPlaylistsLocation = (string)Registry.CurrentUser.OpenSubKey(@"Software\178eef3d-4cea-5a1b-bfd0-07a21d068990").GetValue("InstallLocation", "");
  80. if (Directory.Exists(beatDropPlaylistsLocation))
  81. {
  82. beatDropInstalled = true;
  83. }
  84. else if (Directory.Exists("%LocalAppData%\\Programs\\BeatDrop\\playlists"))
  85. {
  86. beatDropInstalled = true;
  87. beatDropPlaylistsLocation = "%LocalAppData%\\Programs\\BeatDrop\\playlists";
  88. }
  89. else
  90. {
  91. beatDropInstalled = false;
  92. beatDropPlaylistsLocation = "";
  93. }
  94. }
  95. }
  96. catch (Exception e)
  97. {
  98. Logger.Log($"Can't open registry key! Exception: {e}");
  99. if (Directory.Exists("%LocalAppData%\\Programs\\BeatDrop\\playlists"))
  100. {
  101. beatDropInstalled = true;
  102. beatDropPlaylistsLocation = "%LocalAppData%\\Programs\\BeatDrop\\playlists";
  103. }
  104. else
  105. {
  106. Logger.Log("Unable to find BeatDrop installation folder!");
  107. }
  108. }
  109. if (!Directory.Exists("Playlists"))
  110. {
  111. Directory.CreateDirectory("Playlists");
  112. }
  113. }
  114. public static void SaveConfig()
  115. {
  116. //File.WriteAllText(votedSongsPath, JsonConvert.SerializeObject(votedSongs, Formatting.Indented), Encoding.UTF8);
  117. //File.WriteAllText(reviewedSongsPath, JsonConvert.SerializeObject(reviewedSongs, Formatting.Indented), Encoding.UTF8);
  118. //File.WriteAllLines(configPath, favoriteSongs.Distinct().ToArray(), Encoding.UTF8);
  119. //ModPrefs.SetBool("BeatSaverDownloader", "disableDeleteButton", disableDeleteButton);
  120. //ModPrefs.SetBool("BeatSaverDownloader", "deleteToRecycleBin", deleteToRecycleBin);
  121. //ModPrefs.SetInt("BeatSaverDownloader", "maxSimultaneousDownloads", maxSimultaneousDownloads);
  122. }
  123. }
  124. }