private void writeObject(KSP.IO.TextWriter writer, object obj) { Type t = obj.GetType(); writer.WriteLine(t.Name); writer.WriteLine("{"); foreach (FieldInfo info in t.GetFields()) { object o = info.GetValue(obj); if (o == null) { continue; } if (info.FieldType.Equals(typeof(Enum))) { writer.WriteLine(" " + info.Name + " = " + info.GetValue(obj)); } if (info.FieldType.Equals(typeof(String))) { writer.WriteLine(" " + info.Name + " = " + info.GetValue(obj)); } if (info.FieldType.Equals(typeof(float))) { writer.WriteLine(" " + info.Name + " = " + info.GetValue(obj)); } if (info.FieldType.Equals(typeof(double))) { writer.WriteLine(" " + info.Name + " = " + info.GetValue(obj)); } if (info.FieldType.Equals(typeof(int))) { writer.WriteLine(" " + info.Name + " = " + info.GetValue(obj)); } if (info.FieldType.Equals(typeof(bool))) { writer.WriteLine(" " + info.Name + " = " + info.GetValue(obj)); } if (o.GetType().GetInterface("IList") != null) { IList ilist = (IList)o; foreach (object v in ilist) { writeObject(writer, v); } } } writer.WriteLine("}"); }
public void SaveAlarms2() { KACWorker.DebugLogFormatted("Saving Alarms"); KSP.IO.TextWriter tw = KSP.IO.TextWriter.CreateForType <KerbalAlarmClock>(String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title)); //Write the header tw.WriteLine("VesselID|Name|Notes|AlarmTime.UT|AlarmMarginSecs|Type|Enabled|HaltWarp|PauseGame|Options-Manuever/Xfer/Target|<ENDLINE>"); foreach (KACAlarm tmpAlarm in Alarms.BySaveName(HighLogic.CurrentGame.Title)) { //Now Write Each alarm //tw.WriteLine(tmpAlarm.SerializeString2() + "|<ENDLINE>"); tw.WriteLine(tmpAlarm.SerializeString3() + "|<ENDLINE>"); } //And close the file tw.Close(); KACWorker.DebugLogFormatted("Saved Alarms"); }
public void SaveAlarms(Boolean BypassLogging = false) { if (!BypassLogging) { KACWorker.DebugLogFormatted("Saving Alarms-v3"); } KSP.IO.TextWriter tw = KSP.IO.TextWriter.CreateForType <KerbalAlarmClock>(String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title)); //Write the header tw.WriteLine("AlarmsFileVersion|3|<ENDLINE>"); tw.WriteLine("VesselID|Name|Notes|AlarmTime.UT|AlarmMarginSecs|Type|Enabled|HaltWarp|PauseGame|ActionedAt|Manuever|Xfer|Target|Options|<ENDLINE>"); foreach (KACAlarm tmpAlarm in Alarms.BySaveName(HighLogic.CurrentGame.Title)) { //Now Write Each alarm tw.WriteLine(tmpAlarm.SerializeString3() + "|<ENDLINE>"); } //And close the file tw.Close(); }
public void logSet(bool urlResult) { //} while (KSP.IO.File.Exists<IDisposable>(filename)); //System.IO.File.WriteAllBytes(filename, bytes); KSP.IO.TextWriter fileWriter = KSP.IO.TextWriter.CreateForType <IDisposable>("asdf.asdf");//thanks kethane SVN :) https://mmi-kethane-plugin.googlecode.com/svn-history/r2/trunk/Controller.cs fileWriter.WriteLine(JsonConvert.SerializeObject(dataLog)); fileWriter.Close(); //KSP.IO.File.WriteAllText<MuMechJebPod2>(KSP.IO.File.ReadAllText<MuMechJebPod2>(KSPUtil.ApplicationRootPath + "Parts/mumech_MechJebPod2/default.craft"), KSPUtil.ApplicationRootPath + "Ships/__mechjebpod_tmp.craft"); //System.IO.File.Copy(KSPUtil.ApplicationRootPath + "Parts/mumech_MechJebPod2/default.craft", KSPUtil.ApplicationRootPath + "Ships/__mechjebpod_tmp.craft", true); }
private void writeObject(KSP.IO.TextWriter writer, object obj) { Type t = obj.GetType(); writer.WriteLine(JsonConvert.SerializeObject(obj)); }
public void WriteCSVs() { if (pitchRateWriter == null) { pitchRateWriter = KSP.IO.File.AppendText<PIDLoop>( string.Format(FILE_BASE_NAME, fileDateString, shared.Vessel.vesselName, "pitchRate")); pitchRateWriter.WriteLine("LastSampleTime,Error,ErrorSum,Output,Kp,Ki,Kd,MaxOutput"); } if (yawRateWriter == null) { yawRateWriter = KSP.IO.File.AppendText<PIDLoop>( string.Format(FILE_BASE_NAME, fileDateString, shared.Vessel.vesselName, "yawRate")); yawRateWriter.WriteLine("LastSampleTime,Error,ErrorSum,Output,Kp,Ki,Kd,MaxOutput"); } if (rollRateWriter == null) { rollRateWriter = KSP.IO.File.AppendText<PIDLoop>( string.Format(FILE_BASE_NAME, fileDateString, shared.Vessel.vesselName, "rollRate")); rollRateWriter.WriteLine("LastSampleTime,Error,ErrorSum,Output,Kp,Ki,Kd,MaxOutput"); } if (pitchTorqueWriter == null) { pitchTorqueWriter = KSP.IO.File.AppendText<PIDLoop>( string.Format(FILE_BASE_NAME, fileDateString, shared.Vessel.vesselName, "pitchTorque")); pitchTorqueWriter.WriteLine("LastSampleTime,Input,Setpoint,Error,ErrorSum,Output,Kp,Ki,Tr,Ts,I,MaxOutput"); } if (yawTorqueWriter == null) { yawTorqueWriter = KSP.IO.File.AppendText<PIDLoop>( string.Format(FILE_BASE_NAME, fileDateString, shared.Vessel.vesselName, "yawTorque")); yawTorqueWriter.WriteLine("LastSampleTime,Input,Setpoint,Error,ErrorSum,Output,Kp,Ki,Tr,Ts,I,MaxOutput"); } if (rollTorqueWriter == null) { rollTorqueWriter = KSP.IO.File.AppendText<PIDLoop>( string.Format(FILE_BASE_NAME, fileDateString, shared.Vessel.vesselName, "rollTorque")); rollTorqueWriter.WriteLine("LastSampleTime,Input,Setpoint,Error,ErrorSum,Output,Kp,Ki,Tr,Ts,I,MaxOutput"); } if (adjustTorqueWriter == null) { adjustTorqueWriter = KSP.IO.File.AppendText<SteeringManager>( string.Format(FILE_BASE_NAME, fileDateString, shared.Vessel.vesselName, "adjustTorque")); adjustTorqueWriter.WriteLine("LastSampleTime,Target Pitch,Measured Pitch,Average Adjust Pitch,Raw Pitch,Target Yaw,Measured Yaw,Average Adjust Yaw,Raw Yaw,Target Roll,Measured Roll,Average Adjust Roll,Raw Roll,Samples Roll"); } pitchRateWriter.WriteLine(pitchRatePI.ToCSVString()); yawRateWriter.WriteLine(yawRatePI.ToCSVString()); rollRateWriter.WriteLine(rollRatePI.ToCSVString()); pitchTorqueWriter.WriteLine(pitchPI.ToCSVString()); yawTorqueWriter.WriteLine(yawPI.ToCSVString()); rollTorqueWriter.WriteLine(rollPI.ToCSVString()); adjustTorqueWriter.WriteLine(string.Join(",", new[] { sessionTime.ToString(), tgtPitchTorque.ToString(), measuredTorque.x.ToString(), pitchTorqueCalc.Mean.ToString(), rawTorque.x.ToString(), tgtYawTorque.ToString(), measuredTorque.z.ToString(), yawTorqueCalc.Mean.ToString(), rawTorque.z.ToString(), tgtRollTorque.ToString(), measuredTorque.y.ToString(), rollTorqueCalc.Mean.ToString(), rawTorque.y.ToString(), rollTorqueCalc.ValueCount.ToString() })); }