PluginConfig.cs 5.2 KB

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