Пример #1
0
        private static void databasePostProcess()
        {
            if (Beatmaps == null)
            {
                Beatmaps        = new List <Beatmap>();
                DatabaseVersion = General.VERSION;
                return;
            }

#if FAKE_MAPS
            for (int i = 0; i < 20000; i++)
            {
                Beatmap b = new Beatmap()
                {
                    Title            = "beatmap " + (i / 5).ToString(),
                    Artist           = "peppy" + (i / 100).ToString(),
                    Creator          = "no one",
                    ContainingFolder = (i / 5).ToString(),
                    Filename         = i.ToString() + ".osu",
                    BeatmapPresent   = true
                };

                b.PopulateTitleStatics();
                b.AudioPresent = true;

                Beatmaps.Add(b);
            }
#endif

            InitialLoadComplete = true;

            Root.Beatmaps.AddRange(Beatmaps.FindAll(b => b.ContainingFolderAbsolute.LastIndexOf(Path.DirectorySeparatorChar) < SongsDirectory.Length));

            Dictionary <string, BeatmapTreeLevel> treeMatch = new Dictionary <string, BeatmapTreeLevel>();
            foreach (Beatmap bm in Beatmaps)
            {
                BeatmapTreeLevel tl;
                if (!treeMatch.TryGetValue(bm.ContainingFolderAbsolute, out tl))
                {
                    tl = GetTreeLevel(bm.ContainingFolderAbsolute, true);
                    treeMatch.Add(bm.ContainingFolderAbsolute, tl);
                }

                tl.Beatmaps.Add(bm);
            }

            TotalAudioOnly = Beatmaps.FindAll(b => !b.AudioPresent).Count;
        }
Пример #2
0
        internal static void ProcessHeaders(Beatmap b)
        {
            b.TimingPoints.Clear();
            b.PreviewTime = -1;
            b.AudioLeadIn = 0;

            b.ObjectCount = 0;
            b.DrainLength = 0;

            b.countSlider    = 0;
            b.countNormal    = 0;
            b.countSpinner   = 0;
            b.BeatmapVersion = 4;

            b.VersionOffset = 0;

            b.StackLeniency = 0.7f;

            b.Countdown = Countdown.Normal;

            b.CustomColours = false;

            b.Mode = 0;

            b.DefaultSampleSet        = SampleSet.Normal;
            AudioEngine.CustomSamples = false;

            b.IncorrectChecksum = false;

            b.BeatmapPresent = File.Exists(b.Filename);
            if (!b.BeatmapPresent)
            {
                return;
            }

            b.BeatmapChecksum = CryptoHelper.GetMd5(b.Filename);

            StreamReader r = File.OpenText(b.Filename);

            b.DateModified = File.GetLastWriteTimeUtc(b.Filename);

            FileSection currentSection = FileSection.Unknown;

            int    firstTime   = -1;
            int    lastTime    = -1;
            string lastTimeStr = "";
            int    breakTime   = 0;

            string[] split;

            char[] sep = new[] { ',' };

            try
            {
                if (!r.EndOfStream)
                {
                    string headerInfo = r.ReadLine();
                    if (headerInfo.Contains("osu file format"))
                    {
                        b.BeatmapVersion          = Int32.Parse(headerInfo.Remove(0, headerInfo.LastIndexOf('v') + 1));
                        AudioEngine.CustomSamples = b.BeatmapVersion < 4;
                        b.VersionOffset           = b.BeatmapVersion < 5 && GameBase.Mode == Modes.Edit ? 24 : 0;
                    }
                }

                while (!r.EndOfStream)
                {
                    string line = r.ReadLine().Trim();

                    if (line.Length == 0)
                    {
                        continue;
                    }

                    string left  = "";
                    string right = "";

                    if (currentSection != FileSection.HitObjects)
                    {
                        int index = line.IndexOf(':');

                        if (index >= 0)
                        {
                            left  = line.Remove(index).Trim();
                            right = line.Remove(0, index + 1).Trim();
                        }
                        else if (line[0] == '[')
                        {
                            try
                            {
                                currentSection =
                                    (FileSection)Enum.Parse(typeof(FileSection), line.Trim(new[] { '[', ']' }));
                            }
                            catch
                            {
                            }
                            continue;
                        }
                    }

                    switch (currentSection)
                    {
                    case FileSection.TimingPoints:
                        split = line.Split(sep);
                        if (split.Length > 2)
                        {
                            b.TimingPoints.Add(
                                new TimingPoint(Double.Parse(split[0].Trim(), GameBase.nfi) + b.VersionOffset,
                                                Double.Parse(split[1].Trim(), GameBase.nfi),
                                                (TimeSignatures)Int32.Parse(split[2]),
                                                (SampleSet)Int32.Parse(split[3]),
                                                split.Length > 4 && split[4][0] == '1',
                                                split.Length > 5 ? Int32.Parse(split[5]) : b.SampleVolume));
                        }
                        else if (split.Length == 2)
                        {
                            b.TimingPoints.Add(
                                new TimingPoint(Double.Parse(split[0].Trim(), GameBase.nfi) + b.VersionOffset,
                                                Double.Parse(split[1].Trim(), GameBase.nfi),
                                                TimeSignatures.SimpleQuadruple,
                                                b.DefaultSampleSet,
                                                AudioEngine.CustomSamples,
                                                100));
                        }
                        break;

                    case FileSection.General:
                        switch (left)
                        {
                        case "SampleSet":
                            b.DefaultSampleSet           = (SampleSet)Enum.Parse(typeof(SampleSet), right);
                            AudioEngine.CurrentSampleSet = b.DefaultSampleSet;
                            break;

                        case "CustomSamples":
                            AudioEngine.CustomSamples = right[0] == '1';
                            break;

                        case "Countdown":
                            b.Countdown = (Countdown)Int32.Parse(right);
                            break;

                        case "AudioFilename":
                            if (right.Length > 0)
                            {
                                b.AudioFilename = string.Format("{0}\\{1}", b.ContainingFolder, right);
                            }
                            break;

                        case "AudioHash":
                            b.AudioExpectedMd5 = right;
                            break;

                        case "AudioLeadIn":
                            b.AudioLeadIn = Int32.Parse(right);
                            break;

                        case "PreviewTime":
                            b.PreviewTime = Int32.Parse(right);
                            break;

                        case "SampleVolume":
                            b.SampleVolume = Int32.Parse(right);
                            break;

                        case "StackLeniency":
                            b.StackLeniency = Math.Max(0, Math.Min(1, float.Parse(right, GameBase.nfi)));
                            break;

                        case "Mode":
                            b.Mode = Int32.Parse(right);
                            break;
                        }
                        break;

                    case FileSection.Metadata:
                        switch (left)
                        {
                        case "Artist":
                            b.Artist = right;
                            break;

                        case "Title":
                            b.Title = right;
                            break;

                        case "Creator":
                            b.Creator = right;
                            break;

                        case "Version":
                            b.Version = right;
                            break;
                        }
                        break;

                    case FileSection.Difficulty:
                        switch (left)
                        {
                        case "HPDrainRate":
                            b.DifficultyHpDrainRate = byte.Parse(right);
                            break;

                        case "CircleSize":
                            b.DifficultyCircleSize = byte.Parse(right);
                            break;

                        case "OverallDifficulty":
                            b.DifficultyOverall = byte.Parse(right);
                            break;

                        case "SliderMultiplier":
                            b.DifficultySliderMultiplier =
                                Math.Max(0.4, Math.Min(2.6, Double.Parse(right, GameBase.nfi)));
                            break;

                        case "SliderTickRate":
                            b.DifficultySliderTickRate =
                                Math.Max(0.5, Math.Min(8, Double.Parse(right, GameBase.nfi)));
                            break;
                        }
                        break;

                    case FileSection.Events:
                        if (line[0] == '2')
                        {
                            int rs;
                            split = line.Split(',');
                            if (Int32.TryParse(split[0], out rs) && rs == (int)EventTypes.Break)
                            {
                                breakTime += (Int32.Parse(split[2]) - Int32.Parse(split[1]));
                            }
                        }
                        break;

                    case FileSection.HitObjects:
                        split = line.Split(sep, 5);

                        if (firstTime == -1)
                        {
                            firstTime = Int32.Parse(split[2]);
                        }

                        /*
                         *     internal enum HitObjectType
                         *      {
                         *          Normal = 1,
                         *          Slider = 2,
                         *          NewCombo = 4,
                         *          NormalNewCombo = 5,
                         *          SliderNewCombo = 6,
                         *          Spinner = 8
                         *      } ;
                         *
                         * */

                        if (split[3][0] == '8' || split[3].Length > 1)
                        {
                            b.countSpinner++;
                        }
                        else if (split[3][0] == '1' || split[3][0] == '5')
                        {
                            b.countNormal++;
                        }
                        else if (split[3][0] == '2' || split[3][0] == '6')
                        {
                            b.countSlider++;
                        }

                        lastTimeStr = split[2];
                        b.ObjectCount++;
                        break;

                    case FileSection.Colours:
                        b.CustomColours = true;
                        break;
                    }
                }
                r.Close();
            }
            catch (Exception)
            {
                if (DialogResult.Yes ==
                    MessageBox.Show(
                        "Error loading beatmap file " + Path.GetFileName(b.Filename) + "\nDelete this file?", "error'd",
                        MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1))
                {
                    r.Close();
                    File.Delete(b.Filename);
                }
            }

            b.PopulateTitleStatics();

            if (lastTimeStr.Length > 0)
            {
                lastTime = Int32.Parse(lastTimeStr);
            }

            b.DrainLength = (lastTime - firstTime - breakTime) / 1000;
            b.TotalLength = lastTime;
        }