Ejemplo n.º 1
0
        private async Task ScanPrivateFolderAsync(DirectoryInfo privateFolder)
        {
            var beatmaps = new List <Beatmap>();

            foreach (var fileInfo in privateFolder.EnumerateFiles("*.osu", SearchOption.TopDirectoryOnly))
            {
                if (_scanCts.IsCancellationRequested)
                {
                    return;
                }
                try
                {
                    var osuFile = await OsuFile.ReadFromFileAsync(fileInfo.FullName,
                                                                  options =>
                    {
                        options.IncludeSection("General", "Metadata", "TimingPoints", "Difficulty", "HitObjects",
                                               "Events");
                        options.IgnoreSample();
                        options.IgnoreStoryboard();
                    });

                    if (!osuFile.ReadSuccess)
                    {
                        Logger.Warn(osuFile.ReadException, "Osu file format error, skipped {0}", fileInfo.FullName);
                        continue;
                    }

                    var beatmap = GetBeatmapObj(osuFile, fileInfo);
                    beatmaps.Add(beatmap);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Error during scanning file, ignored {0}", fileInfo.FullName);
                }
            }

            try
            {
                _dbOperator.AddNewMaps(beatmaps);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw;
            }
        }