Skip to content

Commit

Permalink
マネージド規則適応
Browse files Browse the repository at this point in the history
  • Loading branch information
denpadokei committed Mar 14, 2021
1 parent ae4e56a commit 37dc99a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
10 changes: 5 additions & 5 deletions SyncSaber/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ namespace SyncSaber
{
internal static class Logger
{
internal static IPALogger log { get; set; }
internal static IPALogger Log { get; set; }

public static void Info(string log, [CallerFilePath] string filepath = "", [CallerMemberName] string member = "", [CallerLineNumber] int? linenum = 0)
{
#if DEBUG
Logger.log.Info($"[{filepath}] [{member}:({linenum})] : {log}");
#else
Logger.log.Info($"[{member}:({linenum})] : {log}");
Logger.Log.Info($"[{member}:({linenum})] : {log}");
#endif
}
public static void Error(string log, [CallerFilePath] string filepath = "", [CallerMemberName] string member = "", [CallerLineNumber] int? linenum = 0)
{
#if DEBUG
Logger.log.Error($"[{filepath}] [{member}:({linenum})] : {log}");
#else
Logger.log.Error($"[{member}:({linenum})] : {log}");
Logger.Log.Error($"[{member}:({linenum})] : {log}");
#endif
}

Expand All @@ -30,7 +30,7 @@ public static void Error(Exception e, [CallerFilePath] string filepath = "", [Ca
#if DEBUG
Logger.log.Error($"[{filepath}] [{member}:({linenum})] : {e}\r\n{e.Message}");
#else
Logger.log.Error($"[{member}:({linenum})] : {e}\r\n{e.Message}");
Logger.Log.Error($"[{member}:({linenum})] : {e}\r\n{e.Message}");
#endif
}

Expand All @@ -39,7 +39,7 @@ public static void Notice(string log, [CallerFilePath] string filepath = "", [Ca
#if DEBUG
Logger.log.Notice($"[{filepath}] [{member}:({linenum})] : {log}");
#else
Logger.log.Notice($"[{member}:({linenum})] : {log}");
Logger.Log.Notice($"[{member}:({linenum})] : {log}");
#endif
}

Expand Down
12 changes: 6 additions & 6 deletions SyncSaber/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Plugin

public bool IsPlaylistDownlaoderInstalled => PluginManager.GetPlugin("PlaylistDownLoader") != null;
public static HashSet<string> SongDownloadHistory { get; } = new HashSet<string>();
internal static Plugin instance { get; private set; }
internal static Plugin Instance { get; private set; }
public string Name => "SyncSaber";

[Init]
Expand All @@ -34,11 +34,11 @@ public class Plugin
/// </summary>
public void Init(IPALogger logger, IPA.Config.Config conf, Zenjector zenjector)
{
instance = this;
Logger.log = logger;
Logger.log.Debug("Logger initialized.");
Instance = this;
Logger.Log = logger;
Logger.Log.Debug("Logger initialized.");
Configuration.PluginConfig.Instance = conf.Generated<Configuration.PluginConfig>();
Logger.log.Debug("Config loaded");
Logger.Log.Debug("Config loaded");
zenjector.OnMenu<SyncSaberInstaller>();
}

Expand All @@ -56,7 +56,7 @@ private async Task DelayedStartup()
[OnStart]
public void OnApplicationStart()
{
instance = this;
Instance = this;

BSEvents.earlyMenuSceneLoadedFresh += this.BSEvents_earlyMenuSceneLoadedFresh;
SceneManager.activeSceneChanged += this.SceneManagerOnActiveSceneChanged;
Expand Down
2 changes: 1 addition & 1 deletion SyncSaber/SongListUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class SongListUtils
{
public static IEnumerator RefreshSongs(bool fullRefresh = false)
{
yield return new WaitWhile(() => !Loader.AreSongsLoaded || Loader.AreSongsLoading || Plugin.instance.IsInGame);
yield return new WaitWhile(() => !Loader.AreSongsLoaded || Loader.AreSongsLoading || Plugin.Instance.IsInGame);
Loader.Instance.RefreshSongs(fullRefresh);
}
}
Expand Down
30 changes: 15 additions & 15 deletions SyncSaber/SyncSaber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void FinishInitialization()

private void DisplayNotification(string text)
{
if (Plugin.instance?.IsInGame == true && !string.IsNullOrEmpty(text)) {
if (Plugin.Instance?.IsInGame == true && !string.IsNullOrEmpty(text)) {
return;
}
Logger.Info(text);
Expand Down Expand Up @@ -163,7 +163,7 @@ public async Task Sync()
}
await Task.WhenAll(tasks);
this.StartCoroutine(this.BeforeDownloadSongs());
if (Plugin.instance.IsPlaylistDownlaoderInstalled) {
if (Plugin.Instance.IsPlaylistDownlaoderInstalled) {
this.StartCoroutine(this.CheckPlaylist());
}
}
Expand Down Expand Up @@ -195,11 +195,11 @@ private int GetMaxBeastSaberPages(int feedToDownload)

private IEnumerator BeforeDownloadSongs()
{
yield return new WaitWhile(() => !Loader.AreSongsLoaded || Loader.AreSongsLoading || Plugin.instance.IsInGame);
yield return new WaitWhile(() => !Loader.AreSongsLoaded || Loader.AreSongsLoading || Plugin.Instance.IsInGame);
if (this._didDownloadAnySong) {
yield return this.StartCoroutine(SongListUtils.RefreshSongs());
}
yield return new WaitWhile(() => !Loader.AreSongsLoaded || Loader.AreSongsLoading || Plugin.instance.IsInGame);
yield return new WaitWhile(() => !Loader.AreSongsLoaded || Loader.AreSongsLoading || Plugin.Instance.IsInGame);
this.DisplayNotification("Finished checking for new songs!");
yield return null;
this._didDownloadAnySong = false;
Expand Down Expand Up @@ -262,15 +262,15 @@ private async Task DownloadAllSongsByAuthor(string author)
}

Logger.Info($"Downloading all songs from {author}");
JSONNode result = null;
JSONNode result;
var stopWatch = new Stopwatch();
var pageCount = 0;
var lastPage = 0;
int lastPage;

try {
stopWatch.Start();
do {
while (Plugin.instance?.IsInGame == true) {
while (Plugin.Instance?.IsInGame == true) {
await Task.Delay(200);
}
this.DisplayNotification($"Checking {author}'s maps. ({pageCount} page)");
Expand Down Expand Up @@ -306,15 +306,15 @@ private async Task DownloadAllSongsByAuthor(string author)
var url = $"https://beatsaver.com{song["downloadURL"].Value}";
Logger.Info(url);
this.DisplayNotification($"Download - {songName}");
while (Plugin.instance?.IsInGame == true) {
while (Plugin.Instance?.IsInGame == true) {
await Task.Delay(200);
}
var buff = await WebClient.DownloadSong(url, new CancellationTokenSource().Token);
if (buff == null) {
Logger.Notice($"Failed to download song : {songName}");
continue;
}
while (Plugin.instance?.IsInGame == true) {
while (Plugin.Instance?.IsInGame == true) {
await Task.Delay(200);
}
using (var st = new MemoryStream(buff)) {
Expand Down Expand Up @@ -373,7 +373,7 @@ private async Task DownloadBeastSaberFeeds(int feedToDownload)
this.DisplayNotification($"Checking page {pageIndex} of {this._beastSaberFeeds.ElementAt(feedToDownload).Key} feed from BeastSaber!");

try {
while (Plugin.instance?.IsInGame == true) {
while (Plugin.Instance?.IsInGame == true) {
await Task.Delay(200);
}
var res = await WebClient.GetAsync($"{this._beastSaberFeeds.ElementAt(feedToDownload).Value.Replace("%BeastSaberUserName%", PluginConfig.Instance.BeastSaberUsername)}/feed/?acpage={pageIndex}", new CancellationTokenSource().Token);
Expand All @@ -393,7 +393,7 @@ private async Task DownloadBeastSaberFeeds(int feedToDownload)
XmlNodeList nodes = doc.DocumentElement.SelectNodes("/rss/channel/item");
if (nodes?.Count != 0) {
foreach (XmlNode node in nodes) {
while (Plugin.instance?.IsInGame != false || Loader.AreSongsLoading) {
while (Plugin.Instance?.IsInGame != false || Loader.AreSongsLoading) {
await Task.Delay(200);
}

Expand Down Expand Up @@ -426,15 +426,15 @@ private async Task DownloadBeastSaberFeeds(int feedToDownload)
if (PluginConfig.Instance.AutoDownloadSongs) {
this.DisplayNotification($"Downloading {songName}");

while (Plugin.instance?.IsInGame == true) {
while (Plugin.Instance?.IsInGame == true) {
await Task.Delay(200);
}
var buff = await WebClient.DownloadSong(downloadUrl, new CancellationTokenSource().Token);
if (buff == null) {
Logger.Notice($"Failed to download song : {songName}");
continue;
}
while (Plugin.instance?.IsInGame == true) {
while (Plugin.Instance?.IsInGame == true) {
await Task.Delay(200);
}
using (var st = new MemoryStream(buff)) {
Expand Down Expand Up @@ -496,7 +496,7 @@ private async Task DownloadPPSongs()
}
foreach (var ppMap in songlist.Values) {
try {
while (Plugin.instance?.IsInGame != false) {
while (Plugin.Instance?.IsInGame != false) {
await Task.Delay(200);
}
var hash = ppMap["id"].Value;
Expand All @@ -521,7 +521,7 @@ private async Task DownloadPPSongs()
Logger.Notice($"Failed to download song : {jsonObject["name"].Value}");
continue;
}
while (Plugin.instance?.IsInGame == true) {
while (Plugin.Instance?.IsInGame == true) {
await Task.Delay(200);
}
var songDirectory = Path.Combine(_customLevelsPath, Regex.Replace($"{key} ({jsonObject["name"].Value} - {author})", "[\\\\:*/?\"<>|]", "_")); ;
Expand Down
2 changes: 1 addition & 1 deletion SyncSaber/Utilities/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static void WriteStringListSafe(string path, List<string> data, bool sort

public static IPlaylistDownloader GetPlaylistDownloader(DiContainer container)
{
if (!Plugin.instance.IsPlaylistDownlaoderInstalled) {
if (!Plugin.Instance.IsPlaylistDownlaoderInstalled) {
return null;
}
return container.Resolve<IPlaylistDownloader>();
Expand Down
4 changes: 1 addition & 3 deletions SyncSaber/Views/SyncSaberController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public string NotificationText
}
[Inject]
private readonly ISyncSaber _syncSaber;
[Inject]
private readonly DiContainer _diContainer;
private DateTime _uiResetTime;
private FloatingScreen _floatingScreen;

Expand Down Expand Up @@ -69,7 +67,7 @@ public async void Initialize()
try {
this._syncSaber.NotificationTextChange -= this.NotificationTextChange;
this._syncSaber.NotificationTextChange += this.NotificationTextChange;
if (Plugin.instance.IsPlaylistDownlaoderInstalled) {
if (Plugin.Instance.IsPlaylistDownlaoderInstalled) {
this._syncSaber.SetEvent();
}
await this._syncSaber.Sync();
Expand Down

0 comments on commit 37dc99a

Please sign in to comment.