VOID_DatALogger: Subscribe to Core's onApplicationQuit event for closing files. Maybe will help complete writes in Linux?
VOID_DatALogger: Subscribe to Core's onApplicationQuit event for closing files. Maybe will help complete writes in Linux?

--- a/VOIDEditorMaster.cs
+++ b/VOIDEditorMaster.cs
@@ -105,6 +105,26 @@
 
 			this.Core.OnGUI();
 		}
+
+		public void OnDestroy()
+		{
+			if (this.Core == null)
+			{
+				return;
+			}
+
+			this.Core.OnDestroy();
+		}
+
+		public void OnApplicationQuit()
+		{
+			if (this.Core == null)
+			{
+				return;
+			}
+
+			this.Core.OnApplicationQuit();
+		}
 	}
 }
 

--- a/VOIDFlightMaster.cs
+++ b/VOIDFlightMaster.cs
@@ -104,6 +104,26 @@
 
 			this.Core.OnGUI();
 		}
+
+		public void OnDestroy()
+		{
+			if (this.Core == null)
+			{
+				return;
+			}
+
+			this.Core.OnDestroy();
+		}
+
+		public void OnApplicationQuit()
+		{
+			if (this.Core == null)
+			{
+				return;
+			}
+
+			this.Core.OnApplicationQuit();
+		}
     }
 }
 

--- a/VOID_Core.cs
+++ b/VOID_Core.cs
@@ -180,6 +180,12 @@
 		internal ApplicationLauncherButton AppLauncherButton;
 
 		/*
+		 * Events
+		 * */
+		public delegate void VOIDEventHandler(object sender);
+		public event VOIDEventHandler onApplicationQuit;
+
+		/*
 		 * Properties
 		 * */
 		public bool factoryReset
@@ -625,6 +631,11 @@
 			}
 		}
 
+		public void OnApplicationQuit()
+		{
+			this.onApplicationQuit(this);
+		}
+
 		public void ResetGUI()
 		{
 			this.StopGUI();

--- a/VOID_DataLogger.cs
+++ b/VOID_DataLogger.cs
@@ -54,6 +54,7 @@
 
 		protected List<byte> csvBytes;
 
+		protected string _fileName;
 		protected FileStream _outputFile;
 
 		protected uint outstandingWrites;
@@ -97,15 +98,20 @@
 		{
 			get
 			{
-				return KSP.IO.IOUtils.GetFilePathFor(
-					typeof(VOID_Core),
-					string.Format(
-						"{0}_{1}",
-						this.vessel.vesselName,
-						"data.csv"
-					),
-					null
-				);
+				if (this._fileName == null || this._fileName == string.Empty)
+				{
+					this._fileName = KSP.IO.IOUtils.GetFilePathFor(
+						typeof(VOID_Core),
+						string.Format(
+							"{0}_{1}",
+							this.vessel.vesselName,
+							"data.csv"
+						),
+						null
+					);
+				}
+
+				return this._fileName;
 			}
 		}
 
@@ -145,10 +151,13 @@
 						byte[] byteOrderMark = utf8Encoding.GetPreamble();
 
 						logger.Append(" and writing preamble");
-						outputFile.Write(byteOrderMark, 0, byteOrderMark.Length);
+						this._outputFile.Write(byteOrderMark, 0, byteOrderMark.Length);
 					}
 
 					logger.Append('.');
+
+					logger.AppendFormat("  File is {0}opened asynchronously.", this._outputFile.IsAsync ? "" : "not ");
+
 					logger.Print();
 				}
 
@@ -211,7 +220,7 @@
 			this.CloseFileIfOpen();
 
 			logger.Append(" Done.");
-			logger.Print();
+			logger.Print(false);
 		}
 
 		#endregion
@@ -412,13 +421,20 @@
 
 		private void CloseFileIfOpen()
 		{
+			Tools.DebugLogger logger = Tools.DebugLogger.New(this);
+
+			logger.AppendFormat("Cleaning up file {0}...", this.fileName);
+
 			if (this.csvBytes.Count > 0)
 			{
+				logger.Append(" Writing remaining data...");
 				this.AsyncWriteData();
 			}
 
+			logger.Append(" Waiting for writes to finish.");
 			while (this.outstandingWrites > 0)
 			{
+				logger.Append('.');
 				System.Threading.Thread.Sleep(10);
 			}
 
@@ -426,8 +442,12 @@
 			{
 				this._outputFile.Close();
 				this._outputFile = null;
-			}
-		}
+				logger.Append(" File closed.");
+			}
+
+			logger.Print(false);
+		}
+
 		#endregion
 
 		#region Constructors & Destructors
@@ -446,6 +466,11 @@
 
 			this.WindowPos.x = Screen.width - 520f;
 			this.WindowPos.y = 85f;
+
+			this.core.onApplicationQuit += delegate(object sender)
+			{
+				this.CloseFileIfOpen();
+			};
 		}
 
 		~VOID_DataLogger()

--- a/VOID_Tools.cs
+++ b/VOID_Tools.cs
@@ -335,7 +335,7 @@
 						func(id);
 					}
 					#if DEBUG
-					catch (ArgumentException ex)
+					catch (ArgumentException)
 					#else
 					catch (ArgumentException)
 					#endif