KSP-KOS/KOS — pull request #247 by NoPanShabuShabu (2014-09-22 02:37:30+00:00)
Title: Fixes #239: Ship with kOS part won't load with Quickload (better).

The problem turns out to be with how the Context Node is written into
the save files: string values are written without enclosing
double-quotes. This causes the parse error, which throws an exception,
etc.

So, in Variable.cs I added this function to get the type of information
stored in the variable:
~~~
public Type GetType()
{
return _value.GetType();
}
~~~

Then in CPU.cs, in the OnSave, I added a check for if the type is
"System.String", and have it write the double quotes:
~~~
if (kvp.Value.GetType().ToString() == "System.String") // if the
variable is a string, enclose the value in ""
{
varNode.AddValue(kvp.Key.TrimStart('$'), (char)34 +
Persistence.ProgramFile.EncodeLine(kvp.Value.Value.ToString()) +
(char)34);
}
else
{
varNode.AddValue(kvp.Key.TrimStart('$'),
Persistence.ProgramFile.EncodeLine(kvp.Value.Value.ToString()));
}
~~~

I also added logging in the OnLoad where it tries to run the Context
information so that it will log the whole text that's going to be run.
This would be helpful in figuring out just what has gone wrong here in
the future if something else like this comes up.