internal static bool Read(string filename, ReadHandler handler, VoidDelegate onFail = null) { if (!File.Exists(filename)) { return(false); } try { using (Stream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) using (SerializationReader reader = new SerializationReader(stream)) { handler(reader); return(true); } } catch (Exception e) { onFail?.Invoke(); try { GeneralHelper.CreateBackup(filename); } catch { } ErrorSubmission.Submit(new OsuError(e) { Feedback = "database-corrupt" }); return(false); } }
internal static bool Write(string filename, WriteHandler handler) { try { using (SafeWriteStream stream = new SafeWriteStream(filename)) using (SerializationWriter writer = new SerializationWriter(stream)) { try { handler(writer); return(true); } catch { stream.Abort(); throw; } } } catch (Exception e) { ErrorSubmission.Submit(new OsuError(e) { Feedback = "database-entry" }); return(false); } }
/// <summary> /// Saves user settings and database data to disk. /// </summary> internal bool Save() { try { ConfigManager.SaveConfig(); BeatmapManager.DatabaseSerialize(); PresenceCache.DatabaseSerialize(); CollectionManager.SaveToDisk(); ScoreManager.SaveToDisk(); return(true); } catch (Exception e) { ErrorSubmission.Submit(new OsuError(e) { Feedback = "background-save" }); return(false); } finally { lastSave = GameBase.Time; modeChangeCount = 0; } }