From 7ccce887729172d3c0e222084d0e8b73fde65ad5 Mon Sep 17 00:00:00 2001 From: 0aubsq <0aubsq@gmail.com> Date: Tue, 24 May 2022 07:24:22 +0200 Subject: [PATCH] Fix crash on song download if Songs/S3 Download does not exist, allows it to work with any folder with 'Download' genre and with any songs folder name --- .gitignore | 1 + TJAPlayer3/Songs/CSong管理.cs | 29 ++++++++++++------- .../12.OnlineLounge/CStageOnlineLounge.cs | 20 ++++++++++++- Test/Songs/S3 Download/box.def | 10 ------- Test/Songs/X4 Downloaded Songs/box.def | 10 +++++++ 5 files changed, 49 insertions(+), 21 deletions(-) delete mode 100644 Test/Songs/S3 Download/box.def create mode 100644 Test/Songs/X4 Downloaded Songs/box.def diff --git a/.gitignore b/.gitignore index 8670196f..9ba1a4f6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.swp *.DotSettings.user /packages +/Test/Cache /Test/Capture_img /Test/Config.ini /Test/bs1770gain** diff --git a/TJAPlayer3/Songs/CSong管理.cs b/TJAPlayer3/Songs/CSong管理.cs index 51f8ba5b..d8b5d5a6 100644 --- a/TJAPlayer3/Songs/CSong管理.cs +++ b/TJAPlayer3/Songs/CSong管理.cs @@ -104,17 +104,26 @@ namespace TJAPlayer3 if (TJAPlayer3.Songs管理.list曲ルート[i].strジャンル == "Download") downloadBox = TJAPlayer3.Songs管理.list曲ルート[i]; } - for (int i = 0; i < downloadBox.list子リスト.Count; i++) - { - if (downloadBox.list子リスト[i].eノード種別 != C曲リストノード.Eノード種別.BACKBOX) - { - downloadBox.list子リスト.Remove(downloadBox.list子リスト[i]); - i--; + + if (downloadBox != null) + { + for (int i = 0; i < downloadBox.list子リスト.Count; i++) + { + if (downloadBox.list子リスト[i].eノード種別 != C曲リストノード.Eノード種別.BACKBOX) + { + downloadBox.list子リスト.Remove(downloadBox.list子リスト[i]); + i--; + } } - } - - t曲を検索してリストを作成する(@"Songs\S3 Download", true, downloadBox.list子リスト, downloadBox); - tSongsDBになかった曲をファイルから読み込んで反映する(downloadBox.list子リスト); + + var path = downloadBox.arスコア[0].ファイル情報.フォルダの絶対パス; + + + //t曲を検索してリストを作成する(@"Songs\S3 Download", true, downloadBox.list子リスト, downloadBox); + t曲を検索してリストを作成する(path, true, downloadBox.list子リスト, downloadBox); + tSongsDBになかった曲をファイルから読み込んで反映する(downloadBox.list子リスト); + } + } public void t曲を検索してリストを作成する( string str基点フォルダ, bool b子BOXへ再帰する ) { diff --git a/TJAPlayer3/Stages/12.OnlineLounge/CStageOnlineLounge.cs b/TJAPlayer3/Stages/12.OnlineLounge/CStageOnlineLounge.cs index 38f34e9e..cf790c34 100644 --- a/TJAPlayer3/Stages/12.OnlineLounge/CStageOnlineLounge.cs +++ b/TJAPlayer3/Stages/12.OnlineLounge/CStageOnlineLounge.cs @@ -516,17 +516,35 @@ namespace TJAPlayer3 { IsDownloading = true; + // Create Cache folder if does not exist System.IO.Directory.CreateDirectory($@"Cache\"); var song = apiMethods.FetchedSongsList[this.cdnSongListIndex - 1]; var zipPath = $@"Cache\{song.Md5}.zip"; + // Download zip from cdn System.Net.WebClient wc = new System.Net.WebClient(); wc.DownloadFile($"{dbCDNData.BaseUrl}{dbCDNData.Download["default"]}{song.Id}", zipPath); wc.Dispose(); - System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, $@"Songs\S3 Download\{song.Md5}"); + // Fetch closest Download folder node + C曲リストノード downloadBox = null; + for (int i = 0; i < TJAPlayer3.Songs管理.list曲ルート.Count; i++) + { + if (TJAPlayer3.Songs管理.list曲ルート[i].strジャンル == "Download") + downloadBox = TJAPlayer3.Songs管理.list曲ルート[i]; + } + + // If there is at least one download folder, transfer the zip contents in it + if (downloadBox != null) + { + var path = downloadBox.arスコア[0].ファイル情報.フォルダの絶対パス; + + System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, $@"{path}{song.Md5}"); + } + + //System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, $@"Songs\S3 Download\{song.Md5}"); IsDownloading = false; } diff --git a/Test/Songs/S3 Download/box.def b/Test/Songs/S3 Download/box.def deleted file mode 100644 index 28f3c100..00000000 --- a/Test/Songs/S3 Download/box.def +++ /dev/null @@ -1,10 +0,0 @@ -#TITLE:Download -#GENRE:Download -#BOXEXPLANATION1: -#BOXEXPLANATION2: -#BOXEXPLANATION3: -#BGCOLOR:#ff00a2 -#BOXCOLOR:#ff00a2 -#BOXTYPE:0 -#BGTYPE:1 -#BOXCHARA:0 \ No newline at end of file diff --git a/Test/Songs/X4 Downloaded Songs/box.def b/Test/Songs/X4 Downloaded Songs/box.def new file mode 100644 index 00000000..125b32ba --- /dev/null +++ b/Test/Songs/X4 Downloaded Songs/box.def @@ -0,0 +1,10 @@ +#TITLE:Downloaded Songs +#GENRE:Download +#BOXEXPLANATION1: Play songs downloaded +#BOXEXPLANATION2: from the Online Lounge ! +#BOXEXPLANATION3: +#BGCOLOR:#ff00a2 +#BOXCOLOR:#ff00a2 +#BOXTYPE:0 +#BGTYPE:1 +#BOXCHARA:0 \ No newline at end of file