Skip to content

Commit

Permalink
Fix import of old files
Browse files Browse the repository at this point in the history
  • Loading branch information
the-paid-actor committed Jan 12, 2024
1 parent 6e25d21 commit 8c31a27
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 38 deletions.
1 change: 1 addition & 0 deletions DTCCodeGenerator/SourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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 ns = "DTC";
var content = configFile.GetText()?.ToString();
if (!string.IsNullOrEmpty(content))
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.0</Version>
<Version>7.0.1</Version>
<Product>DTC for DCS</Product>
<Description>$(Product)</Description>
<ApplicationIcon>Resources\Iconleak-Atrous-Disk.ico</ApplicationIcon>
Expand Down
9 changes: 3 additions & 6 deletions dcs-dtc/New/Presets/V2/Base/V1V2/ConfigV1V2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ public static Configuration Convert(string s, Type type)
{
if (type == typeof(FA18Configuration))
{
var cfg = JsonConvert.DeserializeObject<V1.Aircrafts.FA18.FA18Configuration>(s);
return FA18V1V2Loader.GetV2(cfg);
return FA18V1V2Loader.GetV2(s);
}
else if (type == typeof(F16Configuration))
{
var cfg = JsonConvert.DeserializeObject<V1.Aircrafts.F16.F16Configuration>(s);
return F16V1V2Loader.GetV2(cfg);
return F16V1V2Loader.GetV2(s);
}
else if (type == typeof(F15EConfiguration))
{
var cfg = JsonConvert.DeserializeObject<V1.Aircrafts.F15E.F15EConfiguration>(s);
return F15EV1V2Loader.GetV2(cfg);
return F15EV1V2Loader.GetV2(s);
}
else
{
Expand Down
20 changes: 13 additions & 7 deletions dcs-dtc/New/Presets/V2/Base/V1V2/F15EV1V2Loader.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
using DTC.New.Presets.V2.Aircrafts.F15E.Systems;
using DTC.New.Presets.V2.Base.Systems;
using DTC.Utilities;
using Newtonsoft.Json;
using System.Dynamic;
using F15EConfigurationV1 = DTC.New.Presets.V1.Aircrafts.F15E.F15EConfiguration;
using F15EConfigurationV2 = DTC.New.Presets.V2.Aircrafts.F15E.F15EConfiguration;

namespace DTC.New.Presets.V2.Base.V1V2;

internal class F15EV1V2Loader
{
public static F15EConfigurationV2 GetV2(F15EConfigurationV1 v1)
public static F15EConfigurationV2 GetV2(string json)
{
var v1 = JsonConvert.DeserializeObject<F15EConfigurationV1>(json);
var v2 = new F15EConfigurationV2();

CopyUpload(v1, v2);
CopyWaypoints(v1, v2);
CopyRadios(v1, v2);
CopyDisplays(v1, v2);
CopyMisc(v1, v2);

Cleanup(v1, v2);
Cleanup(v2, json);

return v2;
}

private static void Cleanup(F15EConfigurationV1 v1, F15EConfigurationV2 v2)
private static void Cleanup(F15EConfigurationV2 v2, string json)
{
var originalCfg = JsonConvert.DeserializeObject<ExpandoObject>(json);
var anyNull = false;

if (v1.Waypoints == null)
if (!Util.HasProperty(originalCfg, "Waypoints"))
{
v2.RouteA = null;
v2.RouteB = null;
v2.RouteC = null;
anyNull = true;
}

if (v1.Radios == null) { v2.Radios = null; anyNull = true; }
if (v1.Displays == null) { v2.Displays = null; anyNull = true; }
if (v1.Misc == null) { v2.Misc = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "Radios")) { v2.Radios = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "Displays")) { v2.Displays = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "Misc")) { v2.Misc = null; anyNull = true; }

if (anyNull)
{
Expand Down
25 changes: 15 additions & 10 deletions dcs-dtc/New/Presets/V2/Base/V1V2/F16V1V2Loader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using DTC.New.Presets.V2.Aircrafts.F16.Systems;
using DTC.New.Presets.V2.Base.Systems;
using DTC.Utilities;
using Newtonsoft.Json;
using System.Dynamic;
using System.Globalization;
using F16ConfigurationV1 = DTC.New.Presets.V1.Aircrafts.F16.F16Configuration;
using F16ConfigurationV2 = DTC.New.Presets.V2.Aircrafts.F16.F16Configuration;
Expand All @@ -8,8 +11,9 @@ namespace DTC.New.Presets.V2.Base.V1V2;

internal class F16V1V2Loader
{
public static F16ConfigurationV2 GetV2(F16ConfigurationV1 v1)
public static F16ConfigurationV2 GetV2(string json)
{
var v1 = JsonConvert.DeserializeObject<F16ConfigurationV1>(json);
var v2 = new F16ConfigurationV2();

CopyUpload(v1, v2);
Expand All @@ -21,22 +25,23 @@ public static F16ConfigurationV2 GetV2(F16ConfigurationV1 v1)
CopyHTS(v1, v2);
CopyMisc(v1, v2);

Cleanup(v1, v2);
Cleanup(v2, json);

return v2;
}

private static void Cleanup(F16ConfigurationV1 v1, F16ConfigurationV2 v2)
private static void Cleanup(F16ConfigurationV2 v2, string json)
{
var originalCfg = JsonConvert.DeserializeObject<ExpandoObject>(json);
var anyNull = false;

if (v1.Waypoints == null) { v2.Waypoints = null; anyNull = true; }
if (v1.Radios == null) { v2.Radios = null; anyNull = true; }
if (v1.CMS == null) { v2.CMS = null; anyNull = true; }
if (v1.MFD == null) { v2.MFD = null; anyNull = true; }
if (v1.HARM == null) { v2.HARM = null; anyNull = true; }
if (v1.HTS == null) { v2.HTS = null; anyNull = true; }
if (v1.Misc == null) { v2.Misc = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "Waypoints")) { v2.Waypoints = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "Radios")) { v2.Radios = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "CMS")) { v2.CMS = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "MFD")) { v2.MFD = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "HARM")) { v2.HARM = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "HTS")) { v2.HTS = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "Misc")) { v2.Misc = null; anyNull = true; }

if (anyNull)
{
Expand Down
23 changes: 14 additions & 9 deletions dcs-dtc/New/Presets/V2/Base/V1V2/FA18V1V2Loader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using DTC.New.Presets.V2.Aircrafts.FA18.Systems;
using DTC.New.Presets.V2.Base.Systems;
using DTC.Utilities;
using Newtonsoft.Json;
using System.Dynamic;
using System.Globalization;
using FA18ConfigurationV1 = DTC.New.Presets.V1.Aircrafts.FA18.FA18Configuration;
using FA18ConfigurationV2 = DTC.New.Presets.V2.Aircrafts.FA18.FA18Configuration;
Expand All @@ -9,8 +11,9 @@ namespace DTC.New.Presets.V2.Base.V1V2;

internal class FA18V1V2Loader
{
public static FA18ConfigurationV2 GetV2(FA18ConfigurationV1 v1)
public static FA18ConfigurationV2 GetV2(string json)
{
var v1 = JsonConvert.DeserializeObject<FA18ConfigurationV1>(json);
var v2 = new FA18ConfigurationV2();

CopyUpload(v1, v2);
Expand All @@ -21,20 +24,22 @@ public static FA18ConfigurationV2 GetV2(FA18ConfigurationV1 v1)
CopyCMS(v1, v2);
CopyMisc(v1, v2);

Cleanup(v1, v2);
Cleanup(v2, json);

return v2;
}

private static void Cleanup(FA18ConfigurationV1 v1, FA18ConfigurationV2 v2)
private static void Cleanup(FA18ConfigurationV2 v2, string json)
{
var originalCfg = JsonConvert.DeserializeObject<ExpandoObject>(json);
var anyNull = false;
if (v1.Waypoints == null) { v2.Waypoints = null; anyNull = true; }
if (v1.Sequences == null) { v2.Sequences = null; anyNull = true; }
if (v1.PrePlanned == null) { v2.PrePlanned = null; anyNull = true; }
if (v1.Radios == null) { v2.Radios = null; anyNull = true; }
if (v1.CMS == null) { v2.CMS = null; anyNull = true; }
if (v1.Misc == null) { v2.Misc = null; anyNull = true; }

if (!Util.HasProperty(originalCfg, "Waypoints")) { v2.Waypoints = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "Sequences")) { v2.Sequences = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "PrePlanned")) { v2.PrePlanned = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "Radios")) { v2.Radios = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "CMS")) { v2.CMS = null; anyNull = true; }
if (!Util.HasProperty(originalCfg, "Misc")) { v2.Misc = null; anyNull = true; }

if (anyNull)
{
Expand Down
16 changes: 15 additions & 1 deletion dcs-dtc/Utilities/Util.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
namespace DTC.Utilities
using System.Dynamic;

namespace DTC.Utilities
{
public class Util
{
public static bool HasProperty(dynamic obj, string name)
{
Type objType = obj.GetType();

if (objType == typeof(ExpandoObject))
{
return ((IDictionary<string, object>)obj).ContainsKey(name);
}

return objType.GetProperty(name) != null;
}

public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
Expand Down
8 changes: 4 additions & 4 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:{9777782D-7C32-4A94-9356-B43A0E425A4D}"
"PackageCode" = "8:{79350319-E97B-4B87-9CCF-4B4E371F5CCA}"
"ProductCode" = "8:{05540FEF-A73C-4A34-9F39-36192036DAE7}"
"PackageCode" = "8:{F33CC15C-FD1B-4579-90FE-F6E0F2B04220}"
"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.0"
"ProductVersion" = "8:7.0.1"
"Manufacturer" = "8:The_Paid_Actor"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down Expand Up @@ -734,7 +734,7 @@
{
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_F593CDD77C884A0E97E277F55AAFD180"
{
"SourcePath" = "8:..\\dcs-dtc\\bin\\Release\\net7.0-windows\\win-x64\\publish\\win-x64\\DTC.exe"
"SourcePath" = "8:"
"TargetName" = "8:"
"Tag" = "8:"
"Folder" = "8:_C0338CF17BED4AC190E0B5237AF500E4"
Expand Down

0 comments on commit 8c31a27

Please sign in to comment.