From 744eef70cb7eea4b938764d54719a6ec1edc0b83 Mon Sep 17 00:00:00 2001 From: the-paid-actor Date: Sun, 14 Jan 2024 15:43:47 -0300 Subject: [PATCH] Fix crash on uploading empty radios to Strike Eagle --- .../Properties/launchSettings.json | 9 +- DTCCodeGenerator/SourceGenerator.cs | 27 ++++-- dcs-dtc/DTC.csproj | 2 +- .../Uploader/Aircrafts/F15E/Systems/Radios.cs | 88 +++++++++++-------- .../Uploader/Aircrafts/F16/Systems/Radios.cs | 11 +++ .../Uploader/Aircrafts/FA18/Systems/Radios.cs | 9 ++ installer/installer.vdproj | 6 +- 7 files changed, 103 insertions(+), 49 deletions(-) diff --git a/DTCCodeGenerator/Properties/launchSettings.json b/DTCCodeGenerator/Properties/launchSettings.json index 9e26dfe..23ba306 100644 --- a/DTCCodeGenerator/Properties/launchSettings.json +++ b/DTCCodeGenerator/Properties/launchSettings.json @@ -1 +1,8 @@ -{} \ No newline at end of file +{ + "profiles": { + "Profile 1": { + "commandName": "DebugRoslynComponent", + "targetProject": "..\\dcs-dtc\\DTC.csproj" + } + } +} \ No newline at end of file diff --git a/DTCCodeGenerator/SourceGenerator.cs b/DTCCodeGenerator/SourceGenerator.cs index 02db58c..3f277ad 100644 --- a/DTCCodeGenerator/SourceGenerator.cs +++ b/DTCCodeGenerator/SourceGenerator.cs @@ -22,8 +22,7 @@ public void Execute(GeneratorExecutionContext context) foreach (var configFile in context.AdditionalFiles.Where(file => file.Path.EndsWith(".json"))) { - var assembly = "dcs-dtc\\dcs-dtc\\dcs-dtc"; - //var assembly = "dcs-dtc\\dcs-dtc"; + var assembly = "dcs-dtc"; var ns = "DTC"; var content = configFile.GetText()?.ToString(); if (!string.IsNullOrEmpty(content)) @@ -203,12 +202,28 @@ public string Namespace { get { - var rootDir = this.path.Split(new string[] { this.assemblyName }, StringSplitOptions.RemoveEmptyEntries)[1]; + var pathParts = this.path.Split(Path.DirectorySeparatorChar).Where(item => !string.IsNullOrWhiteSpace(item)).ToArray(); + var startIndex = -1; + var endIndex = -1; + for (var i = 0; i < pathParts.Length; i++) + { + if (pathParts[i] == assemblyName && pathParts[i+1] != assemblyName) + { + startIndex = i + 1; + } + } + for (var i = 0; i < pathParts.Length; i++) + { + if (pathParts[i] == Path.GetFileName(this.path)) + { + endIndex = i - 1; + } + } + var namespaceName = string.Empty; - foreach (var item in rootDir.Split(Path.DirectorySeparatorChar).Where(item => !string.IsNullOrWhiteSpace(item))) + for (var i = startIndex; i <= endIndex; i++) { - if (item != Path.GetFileName(this.path)) - namespaceName += $".{item.Trim()}"; + namespaceName += $".{pathParts[i].Trim()}"; } return $"{this.ns}{namespaceName}"; diff --git a/dcs-dtc/DTC.csproj b/dcs-dtc/DTC.csproj index a18979f..7443d3d 100644 --- a/dcs-dtc/DTC.csproj +++ b/dcs-dtc/DTC.csproj @@ -7,7 +7,7 @@ enable true enable - 7.0.1 + 7.0.3 DTC for DCS $(Product) Resources\Iconleak-Atrous-Disk.ico diff --git a/dcs-dtc/New/Uploader/Aircrafts/F15E/Systems/Radios.cs b/dcs-dtc/New/Uploader/Aircrafts/F15E/Systems/Radios.cs index 93eca9d..f13d9fc 100644 --- a/dcs-dtc/New/Uploader/Aircrafts/F15E/Systems/Radios.cs +++ b/dcs-dtc/New/Uploader/Aircrafts/F15E/Systems/Radios.cs @@ -26,40 +26,48 @@ private void BuildRadios() private void BuildRadios(Device d, RadioSystem radios) { - Cmd(d.GetCommand("CLR")); - Cmd(d.GetCommand("CLR")); - Cmd(d.GetCommand("CLR")); - Cmd(d.GetCommand("CLR")); - Cmd(d.GetCommand("MENU")); - BuildRadio(d, radios.Radio1, "PB05"); + BuildRadio(d, radios.Radio2, "PB06"); + Cmd(d.GetCommand("CLR")); Cmd(d.GetCommand("CLR")); Cmd(d.GetCommand("CLR")); Cmd(d.GetCommand("CLR")); Cmd(d.GetCommand("MENU")); + } - BuildRadio(d, radios.Radio2, "PB06"); + private void BuildRadio(Device d, Radio radio, string pb) + { + if (radio == null) return; + + if (!radio.EnableGuard && + (radio.Presets == null || radio.Presets.Count == 0) && + radio.SelectedFrequency == null && + radio.SelectedPreset == null && + radio.Mode == 0) + { + return; + } Cmd(d.GetCommand("CLR")); Cmd(d.GetCommand("CLR")); Cmd(d.GetCommand("CLR")); Cmd(d.GetCommand("CLR")); Cmd(d.GetCommand("MENU")); - } - private void BuildRadio(Device d, Radio radio, string pb) - { var isRadio1 = (pb == "PB05"); - if (radio.Mode == RadioMode.Frequency) - { - If(IsRadioPresetOrFreqSelected(isRadio1 ? "1" : "2", "preset"), d.GetCommand(isRadio1 ? "GCML" : "GCMR")); - } - if (radio.Mode == RadioMode.Preset) + if (radio.Mode != 0) { - If(IsRadioPresetOrFreqSelected(isRadio1 ? "1" : "2", "freq"), d.GetCommand(isRadio1 ? "GCML" : "GCMR")); + if (radio.Mode == RadioMode.Frequency) + { + If(IsRadioPresetOrFreqSelected(isRadio1 ? "1" : "2", "preset"), d.GetCommand(isRadio1 ? "GCML" : "GCMR")); + } + else if (radio.Mode == RadioMode.Preset) + { + If(IsRadioPresetOrFreqSelected(isRadio1 ? "1" : "2", "freq"), d.GetCommand(isRadio1 ? "GCML" : "GCMR")); + } } if (radio.SelectedFrequency != null) @@ -71,29 +79,35 @@ private void BuildRadio(Device d, Radio radio, string pb) Cmd(d.GetCommand(pb)); - BuildRadioPresets(d, radio); - - if (radio.SelectedPreset == "G") + if (radio.Presets != null && radio.Presets.Count > 0) { - Cmd(Digits(d, isRadio1 ? "20" : "40")); - Cmd(d.GetCommand(isRadio1 ? "PRESL" : "PRESR")); - Cmd(d.GetCommand("CLR")); - - Cmd(d.GetCommand(isRadio1 ? "PRESLCCW" : "PRESRCCW")); + BuildRadioPresets(d, radio); } - else if (radio.SelectedPreset == "GV") - { - Cmd(Digits(d, "40")); - Cmd(d.GetCommand("PRESR")); - Cmd(d.GetCommand("CLR")); - Cmd(d.GetCommand("PRESRCCW")); - Cmd(d.GetCommand("PRESRCCW")); - } - else + + if (radio.SelectedPreset != null) { - Cmd(Digits(d, radio.SelectedPreset)); - Cmd(d.GetCommand(isRadio1 ? "PRESL" : "PRESR")); - Cmd(d.GetCommand("CLR")); + if (radio.SelectedPreset == "G") + { + Cmd(Digits(d, isRadio1 ? "20" : "40")); + Cmd(d.GetCommand(isRadio1 ? "PRESL" : "PRESR")); + Cmd(d.GetCommand("CLR")); + + Cmd(d.GetCommand(isRadio1 ? "PRESLCCW" : "PRESRCCW")); + } + else if (radio.SelectedPreset == "GV") + { + Cmd(Digits(d, "40")); + Cmd(d.GetCommand("PRESR")); + Cmd(d.GetCommand("CLR")); + Cmd(d.GetCommand("PRESRCCW")); + Cmd(d.GetCommand("PRESRCCW")); + } + else + { + Cmd(Digits(d, radio.SelectedPreset)); + Cmd(d.GetCommand(isRadio1 ? "PRESL" : "PRESR")); + Cmd(d.GetCommand("CLR")); + } } if (radio.EnableGuard) @@ -128,8 +142,6 @@ private void InputFrequency(Device d, string freq) private void BuildRadioPresets(Device d, Radio radio) { - if (radio.Presets == null) return; - foreach (var preset in radio.Presets) { if (!string.IsNullOrEmpty(preset.Frequency)) diff --git a/dcs-dtc/New/Uploader/Aircrafts/F16/Systems/Radios.cs b/dcs-dtc/New/Uploader/Aircrafts/F16/Systems/Radios.cs index d58a217..4a12fea 100644 --- a/dcs-dtc/New/Uploader/Aircrafts/F16/Systems/Radios.cs +++ b/dcs-dtc/New/Uploader/Aircrafts/F16/Systems/Radios.cs @@ -19,6 +19,17 @@ public void BuildRadios() private void BuildRadios(Command radioCmd, Radio radio) { + if (radio == null) return; + + if (!radio.EnableGuard && + (radio.Presets == null || radio.Presets.Count == 0) && + radio.SelectedFrequency == null && + radio.SelectedPreset == null && + radio.Mode == 0) + { + return; + } + Cmd(radioCmd); if (radio.EnableGuard) diff --git a/dcs-dtc/New/Uploader/Aircrafts/FA18/Systems/Radios.cs b/dcs-dtc/New/Uploader/Aircrafts/FA18/Systems/Radios.cs index 14741d5..521a939 100644 --- a/dcs-dtc/New/Uploader/Aircrafts/FA18/Systems/Radios.cs +++ b/dcs-dtc/New/Uploader/Aircrafts/FA18/Systems/Radios.cs @@ -21,6 +21,15 @@ private void BuildRadio(int radioId, Radio radio, Command toggleRadioCmd, Comman { if (radio == null) return; + if (!radio.EnableGuard && + (radio.Presets == null || radio.Presets.Count == 0) && + radio.SelectedFrequency == null && + radio.SelectedPreset == null && + radio.Mode == 0) + { + return; + } + if (radio.EnableGuard) { Cmd(toggleRadioCmd); diff --git a/installer/installer.vdproj b/installer/installer.vdproj index 8a2ad91..3989629 100644 --- a/installer/installer.vdproj +++ b/installer/installer.vdproj @@ -198,15 +198,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:DTC for DCS" - "ProductCode" = "8:{05540FEF-A73C-4A34-9F39-36192036DAE7}" - "PackageCode" = "8:{F33CC15C-FD1B-4579-90FE-F6E0F2B04220}" + "ProductCode" = "8:{7F16CEE9-94D9-41C0-8D22-E09E19895111}" + "PackageCode" = "8:{2ED64D44-56C9-4514-8C88-CB6B23C8FE32}" "UpgradeCode" = "8:{3D5849D5-76B8-466F-9C16-2B1A020D0784}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:TRUE" - "ProductVersion" = "8:7.0.1" + "ProductVersion" = "8:7.0.3" "Manufacturer" = "8:The_Paid_Actor" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:"