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); }
private void ConsumerTask() { try { while (true) { string fileFullPath; if (_filesChanged.TryDequeue(out fileFullPath)) { Beatmap beatmap = null; _settings.Add(_names.LoadingRawBeatmaps.Name, true); Interlocked.Increment(ref _numberOfBeatmapsCurrentlyBeingLoaded); _logger.Log("Processing new beatmap", LogLevel.Debug); beatmap = BeatmapHelpers.ReadBeatmap(fileFullPath); _sqlite.StoreTempBeatmap(beatmap); _logger.Log("Added new Temporary beatmap {0} - {1} [{2}]", LogLevel.Debug, beatmap.ArtistRoman, beatmap.TitleRoman, beatmap.DiffName); if (Interlocked.Decrement(ref _numberOfBeatmapsCurrentlyBeingLoaded) == 0) { _settings.Add(_names.LoadingRawBeatmaps.Name, false); } } Thread.Sleep(5); } } catch (ThreadAbortException ex) { return; } }
private void Watcher_FileCreated(object sender, FileSystemEventArgs e) { _settings.Add(_names.LoadingRawBeatmaps.Name, true); Interlocked.Increment(ref _numberOfBeatmapsCurrentlyBeingLoaded); _logger.Log("Detected new beatmap in songs folder", LogLevel.Debug); var beatmap = BeatmapHelpers.ReadBeatmap(e.FullPath); _sqlite.StoreTempBeatmap(beatmap); _logger.Log("Added new Temporary beatmap {0} - {1}", LogLevel.Debug, beatmap.ArtistRoman, beatmap.TitleRoman); if (Interlocked.Decrement(ref _numberOfBeatmapsCurrentlyBeingLoaded) == 0) { _settings.Add(_names.LoadingRawBeatmaps.Name, false); } }
public Beatmap ReadBeatmapData(string fullFileDir) { var map = new Beatmap(); map.Dir = Path.GetFullPath(fullFileDir); map.OsuFileName = Path.GetFileName(fullFileDir); var filename = Path.GetFileNameWithoutExtension(map.OsuFileName); if (!filename.EndsWith("]")) { var idx = filename.LastIndexOf("]", StringComparison.InvariantCulture); filename = filename.Remove(idx + 1); } map.DiffName = BeatmapHelpers.GetDiffFromString(filename); List <string> lines = new List <string>(); //dirty & temporary file in use problem fix int tryCount = 0; do { try { tryCount++; using (var fileHandle = new StreamReader(fullFileDir, true)) { while (!fileHandle.EndOfStream) { lines.Add(fileHandle.ReadLine()); } } tryCount = 5; } catch (IOException e) { if (tryCount < 2) { Thread.Sleep(1000); } } } while (tryCount < 2); if (tryCount != 5) { return(map); } using (var md5 = System.Security.Cryptography.MD5.Create()) { using (var stream = System.IO.File.OpenRead(fullFileDir)) { map.Md5 = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower(); } } if (string.IsNullOrEmpty(map.TitleUnicode)) { map.TitleUnicode = map.TitleRoman; } if (string.IsNullOrEmpty(map.ArtistUnicode)) { map.ArtistUnicode = map.ArtistRoman; } map.EditDate = DateTime.Now; map.LastPlayed = DateTime.MinValue; map.LastSync = DateTime.Now; ParseLines(lines, map); return(map); }
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); } }