private static void databaseDeserialize() { DatabaseHelper.Read(DATABASE_FILENAME, sr => { DatabaseVersion = sr.ReadInt32(); int count = sr.ReadInt32(); for (int i = 0; i < count; i++) { string checksum = sr.ReadString(); int scoreCount = sr.ReadInt32(); List <Score> list = new List <Score>(scoreCount); for (int j = 0; j < scoreCount; j++) { Score s = ScoreFactory.Create((PlayModes)sr.ReadByte(), null); s.ReadHeaderFromStream(sr); if (ModManager.CheckActive(s.EnabledMods, Mods.Target)) { s = new ScoreTarget(s); } s.ReadFromStream(sr); list.Add(s); } if (BeatmapManager.GetBeatmapByChecksum(checksum) != null) { LocalScores.Add(checksum, list); } else { foreach (Score s in list) { s.PurgeReplay(); } } } }); }
public static Score ReadReplayFromFile(string filename, bool handlePickup) { //Make sure the score manager is already initialized. InitializeScoreManager(); Score inScore = null; bool success = false; try { using (Stream stream = File.Open(filename, FileMode.Open)) { SerializationReader sr = new SerializationReader(stream); inScore = ScoreFactory.Create((PlayModes)sr.ReadByte(), null); inScore.ReadHeaderFromStream(sr); if (ModManager.CheckActive(inScore.EnabledMods, Mods.Target)) { inScore = new ScoreTarget(inScore); } inScore.ReadFromStream(sr); if (inScore.Date < DateTime.UtcNow + new TimeSpan(365 * 5, 0, 0, 0)) { success = true; } } } catch { } if (!success) { try { using (Stream stream = File.Open(filename, FileMode.Open)) inScore = (Score)DynamicDeserializer.Deserialize(stream); } catch { NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_ReplayCorrupt)); return(null); } } if (inScore == null) { NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_ReplayCorrupt)); return(null); } if (inScore.Date.Year > 2050 || inScore.Date == DateTime.MinValue) { string[] split = filename.Split('-'); if (split.Length > 1) { long outfiletime = 0; if (long.TryParse(split[1].Replace(@".osr", string.Empty), out outfiletime)) { inScore.Date = DateTime.FromFileTimeUtc(outfiletime); } } } if (inScore.Date.Year > 2050) { //this score is TOTALLY f****d. File.Delete(filename); NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_ReplayCorrupt)); return(null); } if (BeatmapManager.GetBeatmapByChecksum(inScore.FileChecksum) == null) { //attempt pickup. if (handlePickup) { OsuDirect.HandlePickup(inScore.FileChecksum, null, delegate { NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_DontHaveBeatmap)); }); } return(null); } InsertScore(inScore, false); return(inScore); }