/// <summary> /// Called by Mag-Filter /// </summary> internal static void RecordLaunchResponse(DateTime timestampUtc) { string filepath = FileLocations.GetCurrentLaunchResponseFilePath(); using (var file = new StreamWriter(filepath, append: false)) { int pid = System.Diagnostics.Process.GetCurrentProcess().Id; file.WriteLine("FileVersion:{0}", LaunchResponse.MASTER_FILE_VERSION); file.WriteLine("TimeUtc:" + timestampUtc); file.WriteLine("ProcessId:{0}", pid); file.WriteLine("MagFilterVersion:{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); } }
/// <summary> /// Called by ThwargLauncher /// </summary> public static LaunchResponse GetLaunchResponse(TimeSpan maxLatency) { var info = new LaunchResponse(); try { string filepath = FileLocations.GetCurrentLaunchResponseFilePath(); if (string.IsNullOrEmpty(filepath)) { return(info); } if (!File.Exists(filepath)) { return(info); } var settings = (new SettingsFileLoader()).ReadSettingsFile(filepath); info.FileVersion = SettingHelpers.GetSingleStringValue(settings, "FileVersion"); if (!info.FileVersion.StartsWith(LaunchResponse.MASTER_FILE_VERSION_COMPAT)) { throw new Exception(string.Format( "Incompatible launch response file version: {0}", info.FileVersion)); } info.ResponseTime = SettingHelpers.GetSingleDateTimeValue(settings, "TimeUtc"); if (DateTime.UtcNow - info.ResponseTime >= maxLatency) { return(info); } info.ProcessId = SettingHelpers.GetSingleIntValue(settings, "ProcessId"); info.MagFilterVersion = SettingHelpers.GetSingleStringValue(settings, "MagFilterVersion"); info.IsValid = true; } catch (Exception exc) { log.WriteError("GetLaunchResponse exception: {0}", exc); } return(info); }