Skip to content

Commit

Permalink
Fix crash on uploading empty radios to Strike Eagle
Browse files Browse the repository at this point in the history
  • Loading branch information
the-paid-actor committed Jan 14, 2024
1 parent f32a565 commit 744eef7
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 49 deletions.
9 changes: 8 additions & 1 deletion DTCCodeGenerator/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{}
{
"profiles": {
"Profile 1": {
"commandName": "DebugRoslynComponent",
"targetProject": "..\\dcs-dtc\\DTC.csproj"
}
}
}
27 changes: 21 additions & 6 deletions DTCCodeGenerator/SourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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}";
Expand Down
2 changes: 1 addition & 1 deletion dcs-dtc/DTC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Version>7.0.1</Version>
<Version>7.0.3</Version>
<Product>DTC for DCS</Product>
<Description>$(Product)</Description>
<ApplicationIcon>Resources\Iconleak-Atrous-Disk.ico</ApplicationIcon>
Expand Down
88 changes: 50 additions & 38 deletions dcs-dtc/New/Uploader/Aircrafts/F15E/Systems/Radios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 11 additions & 0 deletions dcs-dtc/New/Uploader/Aircrafts/F16/Systems/Radios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions dcs-dtc/New/Uploader/Aircrafts/FA18/Systems/Radios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions installer/installer.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down

0 comments on commit 744eef7

Please sign in to comment.