private void Initalize(string beatmapSetPath)
        {
            if (!Directory.Exists(beatmapSetPath))
            {
                throw new DirectoryNotFoundException("The folder \"" + beatmapSetPath + "\" does not exist.");
            }

            string[] filePaths = Directory.GetFiles(beatmapSetPath, "*.*", SearchOption.AllDirectories);

            List <BeatmapFile> beatmapFiles = new List <BeatmapFile>();

            foreach (string filePath in filePaths)
            {
                songFilePaths.Add(filePath);
                if (!filePath.EndsWith(".osu"))
                {
                    continue;
                }

                string fileName = filePath.Substring(songPath.Length + 1);
                string code     = File.ReadAllText(filePath);

                beatmapFiles.Add(new BeatmapFile(fileName, code));
            }

            Beatmap.ClearCache();
            ConcurrentBag <Beatmap> concurrentBeatmaps = new ConcurrentBag <Beatmap>();

            Parallel.ForEach(beatmapFiles, beatmapFile =>
            {
                Track beatmapTrack = new Track("Parsing " + beatmapFile.name + "...");
                concurrentBeatmaps.Add(new Beatmap(beatmapFile.code, starRating: null, songPath, beatmapFile.name));
                beatmapTrack.Complete();
            });

            foreach (Beatmap beatmap in concurrentBeatmaps)
            {
                beatmaps.Add(beatmap);
            }

            string expectedOsbFileName = GetOsbFileName()?.ToLower();

            foreach (string filePath in filePaths)
            {
                string currentFileName = filePath.Substring(songPath.Length + 1);
                if (filePath.EndsWith(".osb") && currentFileName.ToLower() == expectedOsbFileName)
                {
                    Track osbTrack = new Track("Parsing " + currentFileName + "...");
                    osb = new Osb(File.ReadAllText(filePath));
                    osbTrack.Complete();
                }
            }
        }
Esempio n. 2
0
        public BeatmapSet(string aBeatmapSetPath)
        {
            Track mapsetTrack = new Track("Parsing mapset \"" + PathStatic.CutPath(aBeatmapSetPath) + "\"...");

            beatmaps = new List <Beatmap>();
            osb      = null;
            songPath = aBeatmapSetPath;

            Initalize(aBeatmapSetPath);

            Track hsTrack = new Track("Finding hit sound files...");

            hitSoundFiles = GetUsedHitSoundFiles().ToList();
            hsTrack.Complete();

            beatmaps = beatmaps.OrderBy(aBeatmap => aBeatmap.GetDifficulty(true)).ThenBy(aBeatmap => aBeatmap.starRating).ToList();

            mapsetTrack.Complete();
        }