コード例 #1
0
ファイル: Helper.cs プロジェクト: wmtorode/DropCostPerMech
 public static void SaveState(string instanceGUID, DateTime saveTime)
 {
     try {
         int    unixTimestamp = (int)(saveTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
         string filePath      = $"{DropCostPerMech.ModDirectory}/saves/" + instanceGUID + "-" + unixTimestamp + ".json";
         (new FileInfo(filePath)).Directory.Create();
         using (StreamWriter writer = new StreamWriter(filePath, true)) {
             SaveFields fields = new SaveFields(Fields.DropCost, Fields.LanceTonnage, Fields.FormattedDropCost, Fields.FreeTonnageText);
             string     json   = JsonConvert.SerializeObject(fields);
             writer.Write(json);
         }
     }
     catch (Exception ex) {
         Logger.LogError(ex);
     }
 }
コード例 #2
0
ファイル: Helper.cs プロジェクト: wmtorode/DropCostPerMech
 public static void LoadState(string instanceGUID, DateTime saveTime)
 {
     try {
         int    unixTimestamp = (int)(saveTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
         string filePath      = $"{DropCostPerMech.ModDirectory}/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.DropCost          = save.DropCost;
                 Fields.LanceTonnage      = save.LanceTonnage;
                 Fields.FormattedDropCost = save.FormattedDropCost;
                 Fields.FreeTonnageText   = save.FreeTonnageText;
             }
         }
     }
     catch (Exception ex) {
         Logger.LogError(ex);
     }
 }