PluginConfig.cs 5.4 KB

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