public void UpdateDataFromPlaylist() { _packName = _playlist.playlistTitle; _coverImage = _playlist.icon; _packID = $"Playlist_{playlist.playlistTitle}_{playlist.playlistAuthor}"; // _isPackAlwaysOwned = false; PlaylistsCollection.MatchSongsForPlaylist(playlist); //bananabread playlist CustomPreviewBeatmapLevel[] levels = playlist.songs.Where(x => x.level != null).Select(x => x.level).ToArray(); SongCoreCustomLevelCollection levelCollection = new SongCoreCustomLevelCollection(levels); _customBeatmapLevelCollection = levelCollection; }
public void UpdateDataFromPlaylist() { _packName = _playlist.playlistTitle; _coverImage = _playlist.icon; _packID = $"Playlist_{playlist.playlistTitle}_{playlist.playlistAuthor}"; _isPackAlwaysOwned = false; PlaylistsCollection.MatchSongsForPlaylist(playlist); IPreviewBeatmapLevel[] levels = playlist.songs.Where(x => x.level != null).Select(x => x.level).ToArray(); CustomLevelCollectionSO levelCollection = ScriptableObject.CreateInstance <CustomLevelCollectionSO>(); levelCollection.SetPrivateField("_levelList", levels.Where(x => x is BeatmapLevelSO).Cast <BeatmapLevelSO>().ToList()); levelCollection.SetPrivateField("_beatmapLevels", levels); _beatmapLevelCollection = levelCollection; }
public void DeleteSong(Song song) { bool zippedSong = false; string path = ""; // Console.WriteLine("Deleting: " + song.path); SongCore.Loader.Instance.DeleteSong(song.path, false); PlaylistsCollection.MatchSongsForAllPlaylists(true); /* * CustomLevel level = SongLoader.CustomLevels.FirstOrDefault(x => x.levelID.StartsWith(song.hash)); * * if (level != null) * SongLoader.Instance.RemoveSongWithLevelID(level.levelID); * * if (string.IsNullOrEmpty(song.path)) * { * if (level != null) * path = level.customSongInfo.path; * } * else * { * path = song.path; * } */ path = song.path.Replace('\\', '/'); if (string.IsNullOrEmpty(path)) { return; } if (!Directory.Exists(path)) { return; } if (path.Contains("/.cache/")) { zippedSong = true; } Task.Run(() => { if (zippedSong) { Plugin.log.Info("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } string songHash = Directory.GetParent(path).Name; try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Plugin.log.Info("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Plugin.log.Warn("Can't find or delete empty folder!"); } string docPath = Application.dataPath; docPath = docPath.Substring(0, docPath.Length - 5); docPath = docPath.Substring(0, docPath.LastIndexOf("/")); string customSongsPath = docPath + "/CustomSongs/"; string hash = ""; foreach (string file in Directory.GetFiles(customSongsPath, "*.zip")) { if (CreateMD5FromFile(file, out hash)) { if (hash == songHash) { File.Delete(file); break; } } } } else { try { Plugin.log.Info("Deleting \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Plugin.log.Info("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Plugin.log.Warn("Unable to delete empty folder!"); } } catch (Exception ex) { Plugin.log.Error("Error Deleting Song:" + song.path); Plugin.log.Error(ex.ToString()); } } Plugin.log.Info($"{_alreadyDownloadedSongs.RemoveAll(x => x.Compare(song))} song removed"); }).ConfigureAwait(false); }