VOID_DataLogger: Add a null gate in CloseFileIfOpen.
[VOID.git] / VOID_DataLogger.cs
blob:a/VOID_DataLogger.cs -> blob:b/VOID_DataLogger.cs
--- a/VOID_DataLogger.cs
+++ b/VOID_DataLogger.cs
@@ -45,6 +45,9 @@
 
 		protected bool _loggingActive;
 		protected bool firstWrite;
+
+		[AVOID_SaveValue("waitForLaunch")]
+		protected VOID_SaveValue<bool> waitForLaunch;
 
 		[AVOID_SaveValue("logInterval")]
 		protected VOID_SaveValue<float> logInterval;
@@ -101,7 +104,7 @@
 				if (this._fileName == null || this._fileName == string.Empty)
 				{
 					this._fileName = KSP.IO.IOUtils.GetFilePathFor(
-						typeof(VOID_Core),
+						typeof(VOIDCore),
 						string.Format(
 							"{0}_{1}",
 							this.vessel.vesselName,
@@ -194,7 +197,7 @@
 
 			// CSV Logging
 			// from ISA MapSat
-			if (loggingActive)
+			if (loggingActive && (!waitForLaunch || this.vessel.situation != Vessel.Situations.PRELAUNCH))
 			{
 				//data logging is on
 				//increment timers
@@ -234,7 +237,7 @@
 			this.logIntervalStr = this.logInterval.value.ToString("#.0##");
 		}
 
-		public override void ModuleWindow(int _)
+		public override void ModuleWindow(int id)
 		{
 			GUILayout.BeginVertical();
 
@@ -255,12 +258,17 @@
 				activeLabelStyle = VOID_Styles.labelGreen;
 			}
 
-			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
-
-			this.loggingActive = GUILayout.Toggle(loggingActive, "Data logging: ", GUILayout.ExpandWidth(false));
-			GUILayout.Label(activeLabelText, activeLabelStyle, GUILayout.ExpandWidth(true));
-
-			GUILayout.EndHorizontal();
+			this.loggingActive = GUITools.Toggle(
+				loggingActive,
+				string.Format("Data logging: {0}", activeLabelText),
+				null,
+				activeLabelStyle
+			);
+
+			this.waitForLaunch.value = GUITools.Toggle(
+				this.waitForLaunch,
+				"Wait for launch"
+			);
 
 			GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
 
@@ -280,7 +288,7 @@
 
 			GUILayout.EndVertical();
 
-			GUI.DragWindow();
+			base.ModuleWindow(id);
 		}
 
 		#endregion
@@ -454,13 +462,15 @@
 
 		public VOID_DataLogger()
 		{
-			this._Name = "CSV Data Logger";
+			this.Name = "CSV Data Logger";
 
 			this.loggingActive = false;
 			this.firstWrite = true;
 
-			this.logInterval = 0.5f;
-			this.csvCollectTimer = 0f;
+			this.waitForLaunch = (VOID_SaveValue<bool>)true;
+
+			this.logInterval = (VOID_SaveValue<float>)0.5f;
+			this.csvCollectTimer = (VOID_SaveValue<float>)0f;
 
 			this.outstandingWrites = 0;