all plugins: fixed possible race condition introduced in 4.4

This commit is contained in:
alterNERDtive 2022-06-02 15:28:17 +02:00
parent 35057b3f35
commit 55f10a1117
5 changed files with 143 additions and 131 deletions

View file

@ -1,4 +1,14 @@
# 4.4 (2022-05-31) # devel
### Fixed
* Race condition in all plugins that might lead to commands using command-scoped
variables (`~<name>`) not working as intended. This was introduced in
refactoring work that was done for 4.4.
-----
# 4.4 (2022-05-31)
### Added ### Added

View file

@ -86,8 +86,6 @@ namespace EliteAttack
/// <param name="vaProxy">The VoiceAttack proxy object.</param> /// <param name="vaProxy">The VoiceAttack proxy object.</param>
public static void VA_Invoke1(dynamic vaProxy) public static void VA_Invoke1(dynamic vaProxy)
{ {
VA = vaProxy;
string context = vaProxy.Context.ToLower(); string context = vaProxy.Context.ToLower();
Log.Debug($"Running context '{context}' …"); Log.Debug($"Running context '{context}' …");
try try
@ -95,11 +93,11 @@ namespace EliteAttack
switch (context) switch (context)
{ {
case "startup": case "startup":
Context_Startup(); Context_Startup(vaProxy);
break; break;
case "log.log": case "log.log":
// log // log
Context_Log(); Context_Log(vaProxy);
break; break;
default: default:
// invalid // invalid
@ -140,10 +138,11 @@ namespace EliteAttack
| plugin contexts | | plugin contexts |
\================*/ \================*/
private static void Context_Log() #pragma warning disable IDE0060 // Remove unused parameter
private static void Context_Log(dynamic vaProxy)
{ {
string message = VA!.GetText("~message"); string message = vaProxy.GetText("~message");
string level = VA!.GetText("~level"); string level = vaProxy.GetText("~level");
if (level == null) if (level == null)
{ {
@ -166,10 +165,11 @@ namespace EliteAttack
} }
} }
private static void Context_Startup() private static void Context_Startup(dynamic vaProxy)
{ {
Log.Notice("Starting up …"); Log.Notice("Starting up …");
Log.Notice("Finished startup."); Log.Notice("Finished startup.");
} }
#pragma warning restore IDE0060 // Remove unused parameter
} }
} }

View file

@ -102,8 +102,6 @@ namespace RatAttack
/// <param name="vaProxy">The VoiceAttack proxy object.</param> /// <param name="vaProxy">The VoiceAttack proxy object.</param>
public static void VA_Invoke1(dynamic vaProxy) public static void VA_Invoke1(dynamic vaProxy)
{ {
VA = vaProxy;
string context = vaProxy.Context.ToLower(); string context = vaProxy.Context.ToLower();
Log.Debug($"Running context '{context}' …"); Log.Debug($"Running context '{context}' …");
try try
@ -112,25 +110,25 @@ namespace RatAttack
{ {
case "getcasedata": case "getcasedata":
// plugin methods // plugin methods
Context_GetCaseData(); Context_GetCaseData(vaProxy);
break; break;
case "parseratsignal": case "parseratsignal":
Context_ParseRatsignal(); Context_ParseRatsignal(vaProxy);
break; break;
case "startup": case "startup":
Context_Startup(); Context_Startup(vaProxy);
break; break;
case "edsm.getnearestcmdr": case "edsm.getnearestcmdr":
// EDSM // EDSM
Context_EDSM_GetNearestCMDR(); Context_EDSM_GetNearestCMDR(vaProxy);
break; break;
case "log.log": case "log.log":
// log // log
Context_Log(); Context_Log(vaProxy);
break; break;
default: default:
// invalid // invalid
Log.Error($"Invalid plugin context '{VA!.Context}'."); Log.Error($"Invalid plugin context '{vaProxy.Context}'.");
break; break;
} }
} }
@ -232,10 +230,11 @@ namespace RatAttack
| plugin contexts | | plugin contexts |
\================*/ \================*/
private static void Context_EDSM_GetNearestCMDR() #pragma warning disable IDE0060 // Remove unused parameter
private static void Context_EDSM_GetNearestCMDR(dynamic vaProxy)
{ {
int caseNo = VA!.GetInt("~caseNo") ?? throw new ArgumentNullException("~caseNo"); int caseNo = vaProxy.GetInt("~caseNo") ?? throw new ArgumentNullException("~caseNo");
string cmdrList = VA!.GetText("~cmdrs") ?? throw new ArgumentNullException("~cmdrs"); string cmdrList = vaProxy.GetText("~cmdrs") ?? throw new ArgumentNullException("~cmdrs");
string[] cmdrs = cmdrList.Split(';'); string[] cmdrs = cmdrList.Split(';');
if (cmdrs.Length == 0) if (cmdrs.Length == 0)
{ {
@ -244,7 +243,7 @@ namespace RatAttack
string system = CaseList[caseNo]?.System ?? throw new ArgumentException($"Case #{caseNo} has no system information", "~caseNo"); string system = CaseList[caseNo]?.System ?? throw new ArgumentException($"Case #{caseNo} has no system information", "~caseNo");
string path = $@"{VA!.SessionState["VA_SOUNDS"]}\Scripts\edsm-getnearest.exe"; string path = $@"{vaProxy.SessionState["VA_SOUNDS"]}\Scripts\edsm-getnearest.exe";
string arguments = $@"--short --text --system ""{system}"" ""{string.Join(@""" """, cmdrs)}"""; string arguments = $@"--short --text --system ""{system}"" ""{string.Join(@""" """, cmdrs)}""";
Process p = PythonProxy.SetupPythonScript(path, arguments); Process p = PythonProxy.SetupPythonScript(path, arguments);
@ -279,29 +278,29 @@ namespace RatAttack
break; break;
} }
VA!.SetText("~message", message); vaProxy.SetText("~message", message);
VA!.SetBoolean("~error", error); vaProxy.SetBoolean("~error", error);
VA!.SetText("~errorMessage", errorMessage); vaProxy.SetText("~errorMessage", errorMessage);
VA!.SetInt("~exitCode", p.ExitCode); vaProxy.SetInt("~exitCode", p.ExitCode);
} }
private static void Context_GetCaseData() private static void Context_GetCaseData(dynamic vaProxy)
{ {
int cn = VA!.GetInt("~caseNumber"); int cn = vaProxy.GetInt("~caseNumber");
if (CaseList.ContainsKey(cn)) if (CaseList.ContainsKey(cn))
{ {
RatCase rc = CaseList[cn]; RatCase rc = CaseList[cn];
VA!.SetInt("~~caseNumber", rc.Number); vaProxy.SetInt("~~caseNumber", rc.Number);
VA!.SetText("~~cmdr", rc.Cmdr); vaProxy.SetText("~~cmdr", rc.Cmdr);
VA!.SetText("~~system", rc?.System?.ToLower()); vaProxy.SetText("~~system", rc?.System?.ToLower());
VA!.SetText("~~systemInfo", rc?.SystemInfo); vaProxy.SetText("~~systemInfo", rc?.SystemInfo);
VA!.SetBoolean("~~permitLocked", rc?.PermitLocked); vaProxy.SetBoolean("~~permitLocked", rc?.PermitLocked);
VA!.SetText("~~permitName", rc?.PermitName); vaProxy.SetText("~~permitName", rc?.PermitName);
VA!.SetText("~~platform", rc?.Platform); vaProxy.SetText("~~platform", rc?.Platform);
VA!.SetBoolean("~~odyssey", rc?.Odyssey); vaProxy.SetBoolean("~~odyssey", rc?.Odyssey);
VA!.SetBoolean("~~codeRed", rc?.CodeRed); vaProxy.SetBoolean("~~codeRed", rc?.CodeRed);
} }
else else
{ {
@ -309,10 +308,10 @@ namespace RatAttack
} }
} }
private static void Context_Log() private static void Context_Log(dynamic vaProxy)
{ {
string message = VA!.GetText("~message"); string message = vaProxy.GetText("~message");
string level = VA!.GetText("~level"); string level = vaProxy.GetText("~level");
if (level == null) if (level == null)
{ {
@ -335,18 +334,19 @@ namespace RatAttack
} }
} }
private static void Context_Startup() private static void Context_Startup(dynamic vaProxy)
{ {
Log.Notice("Starting up …"); Log.Notice("Starting up …");
_ = RatsignalPipe.Run(); _ = RatsignalPipe.Run();
Log.Notice("Finished startup."); Log.Notice("Finished startup.");
} }
private static void Context_ParseRatsignal() private static void Context_ParseRatsignal(dynamic vaProxy)
{ {
Log.Warn("Passing a RATSIGNAL to VoiceAttack through the clipboard or a file is DEPRECATED and will no longer be supported in the future."); Log.Warn("Passing a RATSIGNAL to VoiceAttack through the clipboard or a file is DEPRECATED and will no longer be supported in the future.");
On_Ratsignal(new Ratsignal(VA!.GetText("~ratsignal"), VA!.GetBoolean("~announceRatsignal"))); On_Ratsignal(new Ratsignal(vaProxy.GetText("~ratsignal"), vaProxy.GetBoolean("~announceRatsignal")));
} }
#pragma warning restore IDE0060 // Remove unused parameter
/// <summary> /// <summary>
/// Encapsulates a RATSIGNAL for sending between the CLI helper tool and /// Encapsulates a RATSIGNAL for sending between the CLI helper tool and

View file

@ -89,8 +89,6 @@ namespace SpanshAttack
/// <param name="vaProxy">The VoiceAttack proxy object.</param> /// <param name="vaProxy">The VoiceAttack proxy object.</param>
public static void VA_Invoke1(dynamic vaProxy) public static void VA_Invoke1(dynamic vaProxy)
{ {
VA = vaProxy;
string context = vaProxy.Context.ToLower(); string context = vaProxy.Context.ToLower();
Log.Debug($"Running context '{context}' …"); Log.Debug($"Running context '{context}' …");
try try
@ -98,26 +96,26 @@ namespace SpanshAttack
switch (context) switch (context)
{ {
case "startup": case "startup":
Context_Startup(); Context_Startup(vaProxy);
break; break;
case "edts.getcoordinates": case "edts.getcoordinates":
// EDTS // EDTS
Context_EDTS_GetCoordinates(); Context_EDTS_GetCoordinates(vaProxy);
break; break;
case "log.log": case "log.log":
// log // log
Context_Log(); Context_Log(vaProxy);
break; break;
case "spansh.systemexists": case "spansh.systemexists":
// Spansh // Spansh
Context_Spansh_SytemExists(); Context_Spansh_SytemExists(vaProxy);
break; break;
case "spansh.nearestsystem": case "spansh.nearestsystem":
Context_Spansh_Nearestsystem(); Context_Spansh_Nearestsystem(vaProxy);
break; break;
default: default:
// invalid // invalid
Log.Error($"Invalid plugin context '{VA!.Context}'."); Log.Error($"Invalid plugin context '{vaProxy.Context}'.");
break; break;
} }
} }
@ -154,9 +152,10 @@ namespace SpanshAttack
| plugin contexts | | plugin contexts |
\================*/ \================*/
private static void Context_EDTS_GetCoordinates() #pragma warning disable IDE0060 // Remove unused parameter
private static void Context_EDTS_GetCoordinates(dynamic vaProxy)
{ {
string name = VA!.GetText("~system") ?? throw new ArgumentNullException("~system"); string name = vaProxy.GetText("~system") ?? throw new ArgumentNullException("~system");
bool success = false; bool success = false;
string? errorType = null; string? errorType = null;
@ -175,10 +174,10 @@ namespace SpanshAttack
Log.Warn($@"Coordinates with low precision for ""{name}"": ({system.Coords.X}, {system.Coords.Y}, {system.Coords.Z}), precision: {system.Coords.Precision}ly"); Log.Warn($@"Coordinates with low precision for ""{name}"": ({system.Coords.X}, {system.Coords.Y}, {system.Coords.Z}), precision: {system.Coords.Precision}ly");
} }
VA!.SetInt("~x", system.Coords.X); vaProxy.SetInt("~x", system.Coords.X);
VA!.SetInt("~y", system.Coords.Y); vaProxy.SetInt("~y", system.Coords.Y);
VA!.SetInt("~z", system.Coords.Z); vaProxy.SetInt("~z", system.Coords.Z);
VA!.SetInt("~precision", system.Coords.Precision); vaProxy.SetInt("~precision", system.Coords.Precision);
success = true; success = true;
} }
@ -193,19 +192,19 @@ namespace SpanshAttack
errorMessage = e.Message; errorMessage = e.Message;
} }
VA!.SetBoolean("~success", success); vaProxy.SetBoolean("~success", success);
if (!string.IsNullOrWhiteSpace(errorType)) if (!string.IsNullOrWhiteSpace(errorType))
{ {
Log.Error(errorMessage!); Log.Error(errorMessage!);
VA!.SetText("~errorType", errorType); vaProxy.SetText("~errorType", errorType);
VA!.SetText("~errorMessage", errorMessage); vaProxy.SetText("~errorMessage", errorMessage);
} }
} }
private static void Context_Log() private static void Context_Log(dynamic vaProxy)
{ {
string message = VA!.GetText("~message"); string message = vaProxy.GetText("~message");
string level = VA!.GetText("~level"); string level = vaProxy.GetText("~level");
if (level == null) if (level == null)
{ {
@ -228,13 +227,13 @@ namespace SpanshAttack
} }
} }
private static void Context_Spansh_Nearestsystem() private static void Context_Spansh_Nearestsystem(dynamic vaProxy)
{ {
int x = VA!.GetInt("~x") ?? throw new ArgumentNullException("~x"); int x = vaProxy.GetInt("~x") ?? throw new ArgumentNullException("~x");
int y = VA!.GetInt("~y") ?? throw new ArgumentNullException("~y"); int y = vaProxy.GetInt("~y") ?? throw new ArgumentNullException("~y");
int z = VA!.GetInt("~z") ?? throw new ArgumentNullException("~z"); int z = vaProxy.GetInt("~z") ?? throw new ArgumentNullException("~z");
string path = $@"{VA!.SessionState["VA_SOUNDS"]}\Scripts\spansh.exe"; string path = $@"{vaProxy.SessionState["VA_SOUNDS"]}\Scripts\spansh.exe";
string arguments = $@"nearestsystem --parsable {x} {y} {z}"; string arguments = $@"nearestsystem --parsable {x} {y} {z}";
Process p = PythonProxy.SetupPythonScript(path, arguments); Process p = PythonProxy.SetupPythonScript(path, arguments);
@ -273,21 +272,21 @@ namespace SpanshAttack
break; break;
} }
VA!.SetText("~system", system); vaProxy.SetText("~system", system);
VA!.SetDecimal("~x", coords['x']); vaProxy.SetDecimal("~x", coords['x']);
VA!.SetDecimal("~y", coords['y']); vaProxy.SetDecimal("~y", coords['y']);
VA!.SetDecimal("~z", coords['z']); vaProxy.SetDecimal("~z", coords['z']);
VA!.SetDecimal("~distance", distance); vaProxy.SetDecimal("~distance", distance);
VA!.SetBoolean("~error", error); vaProxy.SetBoolean("~error", error);
VA!.SetText("~errorMessage", errorMessage); vaProxy.SetText("~errorMessage", errorMessage);
VA!.SetInt("~exitCode", p.ExitCode); vaProxy.SetInt("~exitCode", p.ExitCode);
} }
private static void Context_Spansh_SytemExists() private static void Context_Spansh_SytemExists(dynamic vaProxy)
{ {
string system = VA!.GetText("~system") ?? throw new ArgumentNullException("~system"); string system = vaProxy.GetText("~system") ?? throw new ArgumentNullException("~system");
string path = $@"{VA!.SessionState["VA_SOUNDS"]}\Scripts\spansh.exe"; string path = $@"{vaProxy.SessionState["VA_SOUNDS"]}\Scripts\spansh.exe";
string arguments = $@"systemexists ""{system}"""; string arguments = $@"systemexists ""{system}""";
Process p = PythonProxy.SetupPythonScript(path, arguments); Process p = PythonProxy.SetupPythonScript(path, arguments);
@ -321,16 +320,17 @@ namespace SpanshAttack
break; break;
} }
VA!.SetBoolean("~systemExists", exists); vaProxy.SetBoolean("~systemExists", exists);
VA!.SetBoolean("~error", error); vaProxy.SetBoolean("~error", error);
VA!.SetText("~errorMessage", errorMessage); vaProxy.SetText("~errorMessage", errorMessage);
VA!.SetInt("~exitCode", p.ExitCode); vaProxy.SetInt("~exitCode", p.ExitCode);
} }
private static void Context_Startup() private static void Context_Startup(dynamic vaProxy)
{ {
Log.Notice("Starting up …"); Log.Notice("Starting up …");
Log.Notice("Finished startup."); Log.Notice("Finished startup.");
} }
#pragma warning restore IDE0060 // Remove unused parameter
} }
} }

View file

@ -328,7 +328,8 @@ namespace alterNERDtive
| plugin contexts | | plugin contexts |
\================*/ \================*/
private static void Context_Config_Dialog() #pragma warning disable IDE0060 // Remove unused parameter
private static void Context_Config_Dialog(dynamic vaProxy)
{ {
Thread dialogThread = new Thread(new ThreadStart(() => Thread dialogThread = new Thread(new ThreadStart(() =>
{ {
@ -348,17 +349,17 @@ namespace alterNERDtive
dialogThread.Start(); dialogThread.Start();
} }
private static void Context_Config_Dump() private static void Context_Config_Dump(dynamic vaProxy)
{ {
Config.DumpConfig(); Config.DumpConfig();
} }
private static void Context_Config_List() private static void Context_Config_List(dynamic vaProxy)
{ {
Config.ListConfig(); Config.ListConfig();
} }
private static void Context_Config_Setup() private static void Context_Config_Setup(dynamic vaProxy)
{ {
Log.Debug("Loading default configuration …"); Log.Debug("Loading default configuration …");
Config.ApplyAllDefaults(); Config.ApplyAllDefaults();
@ -371,14 +372,14 @@ namespace alterNERDtive
Log.Debug("Finished loading configuration."); Log.Debug("Finished loading configuration.");
} }
private static void Context_Config_SetVariables() private static void Context_Config_SetVariables(dynamic vaProxy)
{ {
string trigger = VA!.GetText("~trigger") ?? throw new ArgumentNullException("~trigger"); string trigger = vaProxy.GetText("~trigger") ?? throw new ArgumentNullException("~trigger");
Log.Debug($"Loading variables for trigger '{trigger}' …"); Log.Debug($"Loading variables for trigger '{trigger}' …");
Config.SetVariablesForTrigger(VA!, trigger); Config.SetVariablesForTrigger(vaProxy, trigger);
} }
private static void Context_Config_VersionMigration() private static void Context_Config_VersionMigration(dynamic vaProxy)
{ {
// ============= // =============
// === 4.3.1 === // === 4.3.1 ===
@ -390,7 +391,7 @@ namespace alterNERDtive
string name = $"EliteAttack.{option}s#"; string name = $"EliteAttack.{option}s#";
string oldName = $"EliteAttack.{option}#"; string oldName = $"EliteAttack.{option}#";
Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{oldName}", "boolean" } }); Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{oldName}", "boolean" } });
bool? value = VA!.GetBoolean(oldName); bool? value = vaProxy.GetBoolean(oldName);
if (value != null) if (value != null)
{ {
Log.Info($"Migrating option {oldName} …"); Log.Info($"Migrating option {oldName} …");
@ -404,7 +405,7 @@ namespace alterNERDtive
// =========== // ===========
// SpanshAttack // SpanshAttack
string edtsPath = $@"{VA!.SessionState["VA_SOUNDS"]}\scripts\edts.exe"; string edtsPath = $@"{vaProxy.SessionState["VA_SOUNDS"]}\scripts\edts.exe";
if (File.Exists(edtsPath)) if (File.Exists(edtsPath))
{ {
File.Delete(edtsPath); File.Delete(edtsPath);
@ -422,7 +423,7 @@ namespace alterNERDtive
string name = $"{prefix}.{option}"; string name = $"{prefix}.{option}";
string oldName = $"{oldPrefix}.{option}"; string oldName = $"{oldPrefix}.{option}";
Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{oldName}", "boolean" } }); Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{oldName}", "boolean" } });
bool? value = VA!.GetBoolean(oldName); bool? value = vaProxy.GetBoolean(oldName);
if (value != null) if (value != null)
{ {
Log.Info($"Migrating option {oldName} …"); Log.Info($"Migrating option {oldName} …");
@ -437,7 +438,7 @@ namespace alterNERDtive
{ {
string name = $"{prefix}.{option}"; string name = $"{prefix}.{option}";
Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "boolean" } }); Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "boolean" } });
bool? value = VA!.GetBoolean(name); bool? value = vaProxy.GetBoolean(name);
if (value != null) if (value != null)
{ {
Log.Info($"Migrating option {name} …"); Log.Info($"Migrating option {name} …");
@ -450,7 +451,7 @@ namespace alterNERDtive
{ {
string name = $"{prefix}.{option}"; string name = $"{prefix}.{option}";
Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "text" } }); Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "text" } });
string value = VA!.GetText(name); string value = vaProxy.GetText(name);
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
{ {
Log.Info($"Migrating option {name} …"); Log.Info($"Migrating option {name} …");
@ -465,7 +466,7 @@ namespace alterNERDtive
{ {
string name = $"{prefix}.{option}"; string name = $"{prefix}.{option}";
Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "boolean" } }); Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "boolean" } });
bool? value = VA!.GetBoolean(name); bool? value = vaProxy.GetBoolean(name);
if (value != null) if (value != null)
{ {
Log.Info($"Migrating option {name} …"); Log.Info($"Migrating option {name} …");
@ -478,7 +479,7 @@ namespace alterNERDtive
{ {
string name = $"{prefix}.{option}"; string name = $"{prefix}.{option}";
Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "text" } }); Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "text" } });
string value = VA!.GetText(name); string value = vaProxy.GetText(name);
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
{ {
Log.Info($"Migrating option {name} …"); Log.Info($"Migrating option {name} …");
@ -493,7 +494,7 @@ namespace alterNERDtive
{ {
string name = $"{prefix}.{option}"; string name = $"{prefix}.{option}";
Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "text" } }); Commands.Run("alterNERDtive-base.loadVariableFromProfile", wait: true, parameters: new dynamic[] { new string[] { $"{name}", "text" } });
string value = VA!.GetText(name); string value = vaProxy.GetText(name);
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
{ {
Log.Info($"Migrating option {name} …"); Log.Info($"Migrating option {name} …");
@ -503,19 +504,19 @@ namespace alterNERDtive
} }
} }
private static void Context_Eddi_Event() private static void Context_Eddi_Event(dynamic vaProxy)
{ {
string eddiEvent = VA!.Command.Name(); string eddiEvent = vaProxy.Command.Name();
string command = eddiEvent.Substring(2, eddiEvent.Length - 4); string command = eddiEvent.Substring(2, eddiEvent.Length - 4);
Log.Debug($"Running EDDI event '{command}' …"); Log.Debug($"Running EDDI event '{command}' …");
Commands.RunAll(ActiveProfiles, command, logMissing: false, subcommand: true); // FIXXME: a) triggerAll or something, b) change all profiles to use "((<name>.<event>))" over "<name>.<event>" Commands.RunAll(ActiveProfiles, command, logMissing: false, subcommand: true); // FIXXME: a) triggerAll or something, b) change all profiles to use "((<name>.<event>))" over "<name>.<event>"
} }
private static void Context_EDSM_BodyCount() private static void Context_EDSM_BodyCount(dynamic vaProxy)
{ {
string system = VA!.GetText("~system") ?? throw new ArgumentNullException("~system"); string system = vaProxy.GetText("~system") ?? throw new ArgumentNullException("~system");
string path = $@"{VA!.SessionState["VA_SOUNDS"]}\scripts\explorationtools.exe"; string path = $@"{vaProxy.SessionState["VA_SOUNDS"]}\scripts\explorationtools.exe";
string arguments = $@"bodycount ""{system}"""; string arguments = $@"bodycount ""{system}""";
Process p = PythonProxy.SetupPythonScript(path, arguments); Process p = PythonProxy.SetupPythonScript(path, arguments);
@ -551,19 +552,19 @@ namespace alterNERDtive
break; break;
} }
VA!.SetInt("~bodyCount", bodyCount); vaProxy.SetInt("~bodyCount", bodyCount);
VA!.SetBoolean("~error", error); vaProxy.SetBoolean("~error", error);
VA!.SetText("~errorMessage", errorMessage); vaProxy.SetText("~errorMessage", errorMessage);
VA!.SetInt("~exitCode", p.ExitCode); vaProxy.SetInt("~exitCode", p.ExitCode);
} }
private static void Context_EDSM_DistanceBetween() private static void Context_EDSM_DistanceBetween(dynamic vaProxy)
{ {
string fromSystem = VA!.GetText("~fromSystem") ?? throw new ArgumentNullException("~fromSystem"); string fromSystem = vaProxy.GetText("~fromSystem") ?? throw new ArgumentNullException("~fromSystem");
string toSystem = VA!.GetText("~toSystem") ?? throw new ArgumentNullException("~toSystem"); string toSystem = vaProxy.GetText("~toSystem") ?? throw new ArgumentNullException("~toSystem");
int roundTo = VA!.GetInt("~roundTo") ?? 2; int roundTo = vaProxy.GetInt("~roundTo") ?? 2;
string path = $@"{VA!.SessionState["VA_SOUNDS"]}\Scripts\explorationtools.exe"; string path = $@"{vaProxy.SessionState["VA_SOUNDS"]}\Scripts\explorationtools.exe";
string arguments = $@"distancebetween --roundto {roundTo} ""{fromSystem}"" ""{toSystem}"""; string arguments = $@"distancebetween --roundto {roundTo} ""{fromSystem}"" ""{toSystem}""";
Process p = PythonProxy.SetupPythonScript(path, arguments); Process p = PythonProxy.SetupPythonScript(path, arguments);
@ -595,16 +596,16 @@ namespace alterNERDtive
break; break;
} }
VA!.SetDecimal("~distance", distance); vaProxy.SetDecimal("~distance", distance);
VA!.SetBoolean("~error", error); vaProxy.SetBoolean("~error", error);
VA!.SetText("~errorMessage", errorMessage); vaProxy.SetText("~errorMessage", errorMessage);
VA!.SetInt("~exitCode", p.ExitCode); vaProxy.SetInt("~exitCode", p.ExitCode);
} }
private static void Context_Log() private static void Context_Log(dynamic vaProxy)
{ {
string message = VA!.GetText("~message"); string message = vaProxy.GetText("~message");
string level = VA!.GetText("~level"); string level = vaProxy.GetText("~level");
if (level == null) if (level == null)
{ {
@ -627,12 +628,12 @@ namespace alterNERDtive
} }
} }
private static void Context_Spansh_OutdatedStations() private static void Context_Spansh_OutdatedStations(dynamic vaProxy)
{ {
string system = VA!.GetText("~system") ?? throw new ArgumentNullException("~system"); string system = vaProxy.GetText("~system") ?? throw new ArgumentNullException("~system");
int minage = VA!.GetInt("~minage") ?? throw new ArgumentNullException("~minage"); int minage = vaProxy.GetInt("~minage") ?? throw new ArgumentNullException("~minage");
string path = $@"{VA!.SessionState["VA_SOUNDS"]}\Scripts\spansh.exe"; string path = $@"{vaProxy.SessionState["VA_SOUNDS"]}\Scripts\spansh.exe";
string arguments = $@"oldstations --system ""{system}"" --minage {minage}"; string arguments = $@"oldstations --system ""{system}"" --minage {minage}";
Process p = PythonProxy.SetupPythonScript(path, arguments); Process p = PythonProxy.SetupPythonScript(path, arguments);
@ -667,24 +668,25 @@ namespace alterNERDtive
break; break;
} }
VA!.SetText("~message", message); vaProxy.SetText("~message", message);
VA!.SetBoolean("~error", error); vaProxy.SetBoolean("~error", error);
VA!.SetText("~errorMessage", errorMessage); vaProxy.SetText("~errorMessage", errorMessage);
VA!.SetInt("~exitCode", p.ExitCode); vaProxy.SetInt("~exitCode", p.ExitCode);
} }
private static void Context_Startup() private static void Context_Startup(dynamic vaProxy)
{ {
Log.Notice("Starting up …"); Log.Notice("Starting up …");
CheckProfiles(VA); CheckProfiles(vaProxy);
Log.Notice($"Active profiles: {string.Join(", ", ActiveProfiles)}"); Log.Notice($"Active profiles: {string.Join(", ", ActiveProfiles)}");
Commands.TriggerEventAll(ActiveProfiles, "startup", logMissing: false); Commands.TriggerEventAll(ActiveProfiles, "startup", logMissing: false);
Log.Notice("Finished startup."); Log.Notice("Finished startup.");
} }
private static void Context_Update_Check() private static void Context_Update_Check(dynamic vaProxy)
{ {
UpdateCheck(); UpdateCheck();
} }
#pragma warning restore IDE0060 // Remove unused parameter
} }
} }