public static void SaveState(string instanceGUID, DateTime saveTime) { try { int unixTimestamp = (int)(saveTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; string filePath = "mods/MultiMissions/saves/" + instanceGUID + "-" + unixTimestamp + ".json"; (new FileInfo(filePath)).Directory.Create(); using (StreamWriter writer = new StreamWriter(filePath, true)) { SaveFields fields = new SaveFields(Fields.missionNumber, Fields.alreadyRaised, Fields.currentMultiMissions); string json = JsonConvert.SerializeObject(fields); writer.Write(json); } } catch (Exception ex) { Logger.LogError(ex); } }
public static void LoadState(string instanceGUID, DateTime saveTime) { try { int unixTimestamp = (int)(saveTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; string filePath = "mods/MultiMissions/saves/" + instanceGUID + "-" + unixTimestamp + ".json"; if (File.Exists(filePath)) { using (StreamReader r = new StreamReader(filePath)) { string json = r.ReadToEnd(); SaveFields save = JsonConvert.DeserializeObject <SaveFields>(json); Fields.alreadyRaised = save.alreadyRaised; Fields.missionNumber = save.missionNumber; } } } catch (Exception ex) { Logger.LogError(ex); } }