예제 #1
0
        public static string GetImageLocation(this IBeatmap beatmap, ISettings settings)
        {
            var    songsDirectory  = BeatmapHelpers.GetFullSongsLocation(settings);
            var    osuFileLocation = beatmap.FullOsuFileLocation(songsDirectory);
            string ImageLocation   = string.Empty;

            using (StreamReader file = new StreamReader(osuFileLocation))
            {
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    if (line.ToLower().Contains(".jpg") || line.ToLower().Contains(".png") || line.ToLower().Contains(".jpeg"))
                    {
                        var split = line.Split(',');
                        if (split.Length < 3)
                        {
                            continue;
                        }

                        ImageLocation = Path.Combine(beatmap.BeatmapDirectory(songsDirectory), split[2].Trim('"'));
                        if (!File.Exists(ImageLocation))
                        {
                            return(string.Empty);
                        }
                        break;
                    }
                }
            }
            return(ImageLocation);
        }
예제 #2
0
        public Dictionary <string, string> GetMapReplacements(MapSearchResult map)
        {
            var ret = new Dictionary <string, string>
            {
                { "!MaxCombo!", "" },
                { "!SSPP!", "" },
                { "!99.9PP!", "" },
                { "!99PP!", "" },
                { "!98PP!", "" },
                { "!95PP!", "" },
                { "!90PP!", "" },
                { "!mMod!", "" },
                { "!mSSPP!", "" },
                { "!m99.9PP!", "" },
                { "!m99PP!", "" },
                { "!m98PP!", "" },
                { "!m95PP!", "" },
                { "!m90PP!", "" },
            };

            if (!map.FoundBeatmaps)
            {
                return(ret);
            }
            if (map.BeatmapsFound[0].PlayMode != PlayMode.Osu)
            {
                return(ret);
            }
            var mapLocation = map.BeatmapsFound[0].FullOsuFileLocation(BeatmapHelpers.GetFullSongsLocation(_settings));

            if (!File.Exists(mapLocation))
            {
                return(ret);
            }
            FileInfo file = new FileInfo(mapLocation);

            Thread.Sleep(50);//If we acquire lock before osu it'll force "soft" beatmap reprocessing(no data loss, but time consuming).
            while (FileIsLocked(file))
            {
                Thread.Sleep(1);
            }

            if (file.Length == 0)
            {
                return(ret);
            }
            try
            {
                using (var stream = new FileStream(mapLocation, FileMode.Open))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        var beatmap = Beatmap.Read(reader);

                        ret["!MaxCombo!"] = beatmap.GetMaxCombo().ToString(CultureInfo.InvariantCulture);

                        ret["!SSPP!"]   = GetPp(beatmap, 100d).ToString(CultureInfo.InvariantCulture);
                        ret["!99.9PP!"] = GetPp(beatmap, 99.9d).ToString(CultureInfo.InvariantCulture);
                        ret["!99PP!"]   = GetPp(beatmap, 99d).ToString(CultureInfo.InvariantCulture);
                        ret["!98PP!"]   = GetPp(beatmap, 98d).ToString(CultureInfo.InvariantCulture);
                        ret["!95PP!"]   = GetPp(beatmap, 95d).ToString(CultureInfo.InvariantCulture);
                        ret["!90PP!"]   = GetPp(beatmap, 90d).ToString(CultureInfo.InvariantCulture);

                        Mods   mods;
                        string modsStr;
                        if (map.Action == OsuStatus.Playing || map.Action == OsuStatus.Watching)
                        {
                            mods         = (map.Mods?.Item1 ?? CollectionManager.DataTypes.Mods.Omod).Convert();
                            modsStr      = map.Mods?.Item2 ?? "NM";
                            _lastMods    = mods;
                            _lastModsStr = modsStr;
                        }
                        else
                        {
                            mods    = _lastMods;
                            modsStr = _lastModsStr;
                        }
                        ret["!mMod!"]    = modsStr;
                        ret["!mSSPP!"]   = GetPp(beatmap, 100d, mods).ToString(CultureInfo.InvariantCulture);
                        ret["!m99.9PP!"] = GetPp(beatmap, 99.9d, mods).ToString(CultureInfo.InvariantCulture);
                        ret["!m99PP!"]   = GetPp(beatmap, 99d, mods).ToString(CultureInfo.InvariantCulture);
                        ret["!m98PP!"]   = GetPp(beatmap, 98d, mods).ToString(CultureInfo.InvariantCulture);
                        ret["!m95PP!"]   = GetPp(beatmap, 95d, mods).ToString(CultureInfo.InvariantCulture);
                        ret["!m90PP!"]   = GetPp(beatmap, 90d, mods).ToString(CultureInfo.InvariantCulture);
                    }
                }
                return(ret);
            }
            catch
            {
                return(ret);
            }
        }