예제 #1
0
        /// <summary> Returns whether the given full file path is used by the beatmapset. </summary>
        public bool IsFileUsed(string filePath)
        {
            string relativePath = PathStatic.RelativePath(filePath, songPath);
            string fileName     = relativePath.Split(new char[] { '/', '\\' }).Last().ToLower();
            string parsedPath   = PathStatic.ParsePath(relativePath);
            string strippedPath = PathStatic.ParsePath(relativePath, withoutExtension: true);

            if (beatmaps.Any(beatmap => beatmap.generalSettings.audioFileName.ToLower() == parsedPath))
            {
                return(true);
            }

            // When the path is "go", and "go.png" is over "go.jpg" in order, then "go.jpg" will be the one used.
            // So we basically want to find the last path which matches the name.
            string lastMatchingPath = PathStatic.ParsePath(GetLastMatchingPath(parsedPath));

            // These are always used, but you won't be able to update them unless they have the right format.
            if (fileName.EndsWith(".osu"))
            {
                return(true);
            }

            if (beatmaps.Any(beatmap =>
                             beatmap.sprites.Any(element => element.path.ToLower() == parsedPath) ||
                             beatmap.videos.Any(element => element.path.ToLower() == parsedPath) ||
                             beatmap.backgrounds.Any(element => element.path.ToLower() == parsedPath) ||
                             beatmap.animations.Any(element => element.path.ToLower() == parsedPath) ||
                             beatmap.samples.Any(element => element.path.ToLower() == parsedPath)))
            {
                return(true);
            }

            // animations cannot be stripped of their extension
            if (beatmaps.Any(beatmap =>
                             beatmap.sprites.Any(element => element.strippedPath == strippedPath) ||
                             beatmap.videos.Any(element => element.strippedPath == strippedPath) ||
                             beatmap.backgrounds.Any(element => element.strippedPath == strippedPath) ||
                             beatmap.samples.Any(element => element.strippedPath == strippedPath)) &&
                parsedPath == lastMatchingPath)
            {
                return(true);
            }

            if (osb != null && (
                    osb.sprites.Any(element => element.path.ToLower() == parsedPath) ||
                    osb.videos.Any(element => element.path.ToLower() == parsedPath) ||
                    osb.backgrounds.Any(element => element.path.ToLower() == parsedPath) ||
                    osb.animations.Any(element => element.path.ToLower() == parsedPath) ||
                    osb.samples.Any(anElement => anElement.path.ToLower() == parsedPath)))
            {
                return(true);
            }

            if (osb != null && (
                    osb.sprites.Any(element => element.strippedPath == strippedPath) ||
                    osb.videos.Any(element => element.strippedPath == strippedPath) ||
                    osb.backgrounds.Any(element => element.strippedPath == strippedPath) ||
                    osb.samples.Any(element => element.strippedPath == strippedPath)) &&
                parsedPath == lastMatchingPath)
            {
                return(true);
            }

            if (beatmaps.Any(beatmap => beatmap.hitObjects.Any(hitObject =>
                                                               (hitObject.filename != null ? PathStatic.ParsePath(hitObject.filename, true) : null) == strippedPath)))
            {
                return(true);
            }

            if (hitSoundFiles.Any(hsPath => PathStatic.ParsePath(hsPath) == parsedPath))
            {
                return(true);
            }

            if (SkinStatic.IsUsed(fileName, this))
            {
                return(true);
            }

            if (fileName == GetOsbFileName().ToLower() && osb.IsUsed())
            {
                return(true);
            }

            foreach (Beatmap beatmap in beatmaps)
            {
                if (IsAnimationPathUsed(parsedPath, beatmap.animations))
                {
                    return(true);
                }
            }

            if (osb != null && IsAnimationPathUsed(parsedPath, osb.animations))
            {
                return(true);
            }

            return(false);
        }
예제 #2
0
        /// <summary> Returns whether the given full file path is used by the beatmapset. </summary>
        public bool IsFileUsed(string aFilePath)
        {
            string relativePath = PathStatic.RelativePath(aFilePath, songPath);
            string fileName     = relativePath.Split(new char[] { '/', '\\' }).Last().ToLower();
            string parsedPath   = PathStatic.ParsePath(relativePath);
            string strippedPath = PathStatic.ParsePath(relativePath, true);

            if (beatmaps.Any(aBeatmap => aBeatmap.generalSettings.audioFileName.ToLower() == parsedPath))
            {
                return(true);
            }

            // When the path is "go", and "go.png" is over "go.jpg" in order, then "go.jpg" will be the one used.
            // So we basically want to find the last path which matches the name.
            string lastStripped = null;

            foreach (string file in Directory.EnumerateFiles(songPath, "*", SearchOption.AllDirectories))
            {
                string relPath = PathStatic.RelativePath(file, songPath).Replace("\\", "/");
                if (relPath.StartsWith(strippedPath + ".", StringComparison.OrdinalIgnoreCase))
                {
                    lastStripped = file.Substring(songPath.Length + 1);
                    break;
                }
            }

            if (lastStripped == null)
            {
                return(false);
            }

            // these are always used, but you won't be able to update them unless they have the right format
            if (fileName.EndsWith(".osu"))
            {
                return(true);
            }

            if (beatmaps.Any(aBeatmap =>
                             aBeatmap.sprites.Any(anElement => anElement.path.ToLower() == parsedPath) ||
                             aBeatmap.videos.Any(anElement => anElement.path.ToLower() == parsedPath) ||
                             aBeatmap.backgrounds.Any(anElement => anElement.path.ToLower() == parsedPath) ||
                             aBeatmap.animations.Any(anElement => anElement.path.ToLower() == parsedPath) ||
                             aBeatmap.storyHitSounds.Any(anElement => anElement.path.ToLower() == parsedPath)))
            {
                return(true);
            }

            // animations cannot be stripped of their extension
            if (beatmaps.Any(aBeatmap =>
                             aBeatmap.sprites.Any(anElement => anElement.strippedPath == strippedPath && lastStripped.StartsWith(anElement.path)) ||
                             aBeatmap.videos.Any(anElement => anElement.strippedPath == strippedPath && lastStripped.StartsWith(anElement.path)) ||
                             aBeatmap.backgrounds.Any(anElement => anElement.strippedPath == strippedPath && lastStripped.StartsWith(anElement.path)) ||
                             aBeatmap.storyHitSounds.Any(anElement => anElement.strippedPath == strippedPath && lastStripped.StartsWith(anElement.path))) &&
                parsedPath == lastStripped)
            {
                return(true);
            }

            if (osb != null && (
                    osb.sprites.Any(anElement => anElement.path.ToLower() == parsedPath) ||
                    osb.videos.Any(anElement => anElement.path.ToLower() == parsedPath) ||
                    osb.backgrounds.Any(anElement => anElement.path.ToLower() == parsedPath) ||
                    osb.animations.Any(anElement => anElement.path.ToLower() == parsedPath) ||
                    osb.storyHitSounds.Any(anElement => anElement.path.ToLower() == parsedPath)))
            {
                return(true);
            }

            if (osb != null && (
                    osb.sprites.Any(anElement => anElement.strippedPath == strippedPath && lastStripped.StartsWith(anElement.path)) ||
                    osb.videos.Any(anElement => anElement.strippedPath == strippedPath && lastStripped.StartsWith(anElement.path)) ||
                    osb.backgrounds.Any(anElement => anElement.strippedPath == strippedPath && lastStripped.StartsWith(anElement.path)) ||
                    osb.storyHitSounds.Any(anElement => anElement.strippedPath == strippedPath && lastStripped.StartsWith(anElement.path))) &&
                parsedPath == lastStripped)
            {
                return(true);
            }

            if (beatmaps.Any(aBeatmap => aBeatmap.hitObjects.Any(anObject =>
                                                                 (anObject.filename != null ? PathStatic.ParsePath(anObject.filename, true) : null) == strippedPath)))
            {
                return(true);
            }

            if (hitSoundFiles.Any(aHitSoundPath => PathStatic.ParsePath(aHitSoundPath) == parsedPath))
            {
                return(true);
            }

            if (SkinStatic.IsUsed(fileName, this))
            {
                return(true);
            }

            if (fileName == GetOsbFileName().ToLower() && osb.IsUsed())
            {
                return(true);
            }

            foreach (Beatmap beatmap in beatmaps)
            {
                if (IsAnimationUsed(parsedPath, beatmap.animations))
                {
                    return(true);
                }
            }

            if (osb != null && IsAnimationUsed(parsedPath, osb.animations))
            {
                return(true);
            }

            return(false);
        }