Ejemplo n.º 1
0
 public static void LoadState(string instanceGUID, DateTime saveTime)
 {
     try {
         int    unixTimestamp = (int)(saveTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
         string baseDirectory = Directory.GetParent(Directory.GetParent($"{ MercDeployments.ModDirectory}").FullName).FullName;
         string filePath      = baseDirectory + $"/ModSaves/MercDeployments/" + instanceGUID + "-" + unixTimestamp + ".json";
         if (File.Exists(filePath))
         {
             using (StreamReader r = new StreamReader(filePath)) {
                 string     json = r.ReadToEnd();
                 SaveFields save = JsonConvert.DeserializeObject <SaveFields>(json);
                 Fields.Deployment                  = save.Deployment;
                 Fields.DeploymentEmployer          = save.DeploymentEmployer;
                 Fields.DeploymentTarget            = save.DeploymentTarget;
                 Fields.DeploymentDifficulty        = save.DeploymentDifficulty;
                 Fields.DeploymentNegotiatedSalvage = save.DeploymentNegotiatedSalvage;
                 Fields.DeploymentNegotiatedPayment = save.DeploymentNegotiatedPayment;
                 Fields.DeploymentSalary            = save.DeploymentSalary;
                 Fields.DeploymentSalvage           = save.DeploymentSalvage;
                 Fields.AlreadyRaised               = save.AlreadyRaised;
                 Fields.DeploymentLenght            = save.DeploymentLenght;
                 Fields.DeploymentRemainingDays     = save.DeploymentRemainingDays;
                 Fields.MissionsDoneCurrentMonth    = save.MissionsDoneCurrentMonth;
             }
         }
     }
     catch (Exception ex) {
         Logger.LogError(ex);
     }
 }
Ejemplo n.º 2
0
 public static void SaveState(string instanceGUID, DateTime saveTime)
 {
     try {
         int    unixTimestamp = (int)(saveTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
         string baseDirectory = Directory.GetParent(Directory.GetParent($"{ MercDeployments.ModDirectory}").FullName).FullName;
         string filePath      = baseDirectory + $"/ModSaves/MercDeployments/" + instanceGUID + "-" + unixTimestamp + ".json";
         (new FileInfo(filePath)).Directory.Create();
         using (StreamWriter writer = new StreamWriter(filePath, true)) {
             /*JsonSerializerSettings settings = new JsonSerializerSettings {
              *  ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
              *  PreserveReferencesHandling = PreserveReferencesHandling.Objects,one
              *  Formatting = Formatting.Indented
              * };*/
             SaveFields fields = new SaveFields(Fields.Deployment,
                                                Fields.DeploymentEmployer, Fields.DeploymentTarget, Fields.DeploymentDifficulty,
                                                Fields.DeploymentNegotiatedSalvage, Fields.DeploymentNegotiatedPayment, Fields.DeploymentSalary,
                                                Fields.DeploymentSalvage, Fields.AlreadyRaised, Fields.DeploymentLenght, Fields.DeploymentRemainingDays, Fields.MissionsDoneCurrentMonth);
             string json = JsonConvert.SerializeObject(fields);
             writer.Write(json);
         }
     }
     catch (Exception ex) {
         Logger.LogError(ex);
     }
 }