Skip to content

Commit

Permalink
Additional checks on null/no string when reading partmodule values fr…
Browse files Browse the repository at this point in the history
…om save file
  • Loading branch information
KSP-TaxiService committed Jan 15, 2022
1 parent d6c9309 commit 8f30f0b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,20 @@ protected List<CNCAntennaPartInfo> readAntennaData()
}
}

newAntennaPartInfo.frequency = short.Parse(partModuleSnapshot.moduleValues.GetValue("Frequency"));
string oname = partModuleSnapshot.moduleValues.GetValue("OptionalName");
newAntennaPartInfo.name = (oname.Length == 0) ? partSnapshot.partInfo.title : oname;
newAntennaPartInfo.inUse = bool.Parse(partModuleSnapshot.moduleValues.GetValue("InUse"));
newAntennaPartInfo.CosAngle = double.Parse(partModuleSnapshot.moduleValues.GetValue("CosAngle"));
if (!short.TryParse(partModuleSnapshot.moduleValues.GetValue("Frequency"), out newAntennaPartInfo.frequency))
{
newAntennaPartInfo.frequency = CNCSettings.Instance.PublicRadioFrequency; // default value
}
if (!bool.TryParse(partModuleSnapshot.moduleValues.GetValue("InUse"), out newAntennaPartInfo.inUse))
{
newAntennaPartInfo.inUse = true; // default value
}
if (!double.TryParse(partModuleSnapshot.moduleValues.GetValue("CosAngle"), out newAntennaPartInfo.CosAngle))
{
newAntennaPartInfo.CosAngle = 0.0; // default value
}
}
else
{
Expand Down Expand Up @@ -707,8 +716,9 @@ public void replaceAllFrequencies(short oldFrequency, short newFrequency)
{
for (int i = 0; i < this.vessel.protoVessel.protoPartSnapshots.Count; i++)
{
short freq;
ProtoPartModuleSnapshot cncAntMod = this.vessel.protoVessel.protoPartSnapshots[i].FindModule("CNConstellationAntennaModule");
if (cncAntMod != null && short.Parse(cncAntMod.moduleValues.GetValue("Frequency")) == oldFrequency)
if (cncAntMod != null && short.TryParse(cncAntMod.moduleValues.GetValue("Frequency"), out freq) && freq == oldFrequency)
cncAntMod.moduleValues.SetValue("Frequency", newFrequency);
}
}
Expand Down

0 comments on commit 8f30f0b

Please sign in to comment.