示例#1
0
        public bool DeleteSong(Song song)
        {
            bool   zippedSong = false;
            string path       = "";

            CustomLevel level = SongLoader.CustomLevels.FirstOrDefault(x => x.levelID.StartsWith(song.hash));

            if (string.IsNullOrEmpty(song.path))
            {
                if (level != null)
                {
                    path = level.customSongInfo.path;
                }
            }
            else
            {
                path = song.path;
            }

            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }
            if (!Directory.Exists(path))
            {
                return(false);
            }

            if (path.Contains("/.cache/"))
            {
                zippedSong = true;
            }

            if (zippedSong)
            {
                Logger.Log("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)
                    {
                        Logger.Log("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"...");
                        Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false);
                    }
                }
                catch
                {
                    Logger.Warning("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
            {
                Logger.Log("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"...");

                if (PluginConfig.deleteToRecycleBin)
                {
                    FileOperationAPIWrapper.MoveToRecycleBin(path);
                }
                else
                {
                    Directory.Delete(path, true);
                }

                try
                {
                    if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0)
                    {
                        Logger.Log("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"...");
                        Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false);
                    }
                }
                catch
                {
                    Logger.Warning("Unable to delete empty folder!");
                }
            }

            if (level != null)
            {
                SongLoader.Instance.RemoveSongWithLevelID(level.levelID);
            }
            Logger.Log($"{_alreadyDownloadedSongs.RemoveAll(x => x.Compare(song))} song removed");
            return(true);
        }
示例#2
0
        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);
        }