Skip to content

Commit

Permalink
exe name try 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Mar 14, 2024
1 parent 0b63019 commit 4c48c41
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using AuroraRgb.Settings;
using AuroraRgb.Settings.Layers;
using Common.Utils;
using Newtonsoft.Json;

namespace AuroraRgb.Profiles.Chroma;

[JsonObject(ItemTypeNameHandling = TypeNameHandling.None)]
public class RazerChromaProfile : ApplicationProfile
{
[OnDeserialized]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Project-Aurora/Project-Aurora/Settings/ObjectSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AuroraRgb.Settings;

[JsonObject(ItemTypeNameHandling = TypeNameHandling.None)]
public class ObjectSettings<T>
{
protected string SettingsSavePath { get; set; }
Expand Down Expand Up @@ -42,7 +43,7 @@ protected virtual void LoadSettings(Type settingsType)
{
try
{
Settings = (T)JsonConvert.DeserializeObject(File.ReadAllText(SettingsSavePath), settingsType, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All });
Settings = (T)JsonConvert.DeserializeObject(File.ReadAllText(SettingsSavePath), settingsType, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None });
if (Settings == null)
{
SaveSettings(settingsType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public BooleanOr(IEnumerable<Evaluatable<bool>> subconditions) {
SubConditions = new ObservableCollection<Evaluatable<bool>>(subconditions);
}

[JsonProperty]
public ObservableCollection<Evaluatable<bool>> SubConditions { get; set; } = new ObservableCollection<Evaluatable<bool>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None)]
public ObservableCollection<Evaluatable<bool>> SubConditions { get; set; } = [];

public override Visual GetControl() => new Control_SubconditionHolder(this, "Or");

Expand All @@ -47,9 +47,8 @@ public BooleanAnd() { }
public BooleanAnd(IEnumerable<Evaluatable<bool>> subconditions) {
SubConditions = new ObservableCollection<Evaluatable<bool>>(subconditions);
}

[JsonProperty]
public ObservableCollection<Evaluatable<bool>> SubConditions { get; set; } = new ObservableCollection<Evaluatable<bool>>();
[JsonProperty(TypeNameHandling = TypeNameHandling.None)]
public ObservableCollection<Evaluatable<bool>> SubConditions { get; set; } = [];

public override Visual GetControl() => new Control_SubconditionHolder(this, "And");

Expand Down
17 changes: 16 additions & 1 deletion Project-Aurora/Project-Aurora/Utils/JSONUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;
using AuroraRgb.Profiles.Chroma;
using AuroraRgb.Profiles.Dota_2.Layers;
using AuroraRgb.Profiles.Generic;
using AuroraRgb.Profiles.GTA5.Layers;
Expand Down Expand Up @@ -51,6 +52,12 @@ public override Type BindToType(string? assemblyName, string typeName)

// Use the Regex.Replace method with a MatchEvaluator delegate
var convertedTypeName = TypeAndAssemblyRegex().Replace(typeName, ReplaceGroups);
if (convertedTypeName.Contains("Aurora]"))
{
convertedTypeName = convertedTypeName
.Replace("Aurora]", "AuroraRgb]")
.Replace("[Aurora.", "[AuroraRgb.");
}

var boundType = convertedTypeName switch
{
Expand Down Expand Up @@ -107,6 +114,10 @@ public override Type BindToType(string? assemblyName, string typeName)
typeof(VariableRegistry),
"Aurora.Settings.VariableRegistryItem" =>
typeof(VariableRegistryItem),
"Aurora.Profiles.RazerChromaProfile" =>
typeof(RazerChromaProfile),
"Aurora.Profiles.WrapperProfile" =>
typeof(WrapperProfile),
_ => base.BindToType(assemblyName, ConvertedTypeName(convertedTypeName)),
};
typeMap[typeName] = boundType;
Expand All @@ -129,7 +140,7 @@ private static string ConvertedTypeName(string convertedTypeName)
{
if (!convertedTypeName.StartsWith("Aurora.")) return convertedTypeName;

var regex = new Regex(Regex.Escape("Aurora."));
var regex = OldAuroraNamespace();
return regex.Replace(convertedTypeName, "AuroraRgb.", 1);
}

Expand All @@ -146,6 +157,10 @@ private string ReplaceGroups(Match match)

[GeneratedRegex(@"\[([^\s,^\[]*), ([^\s,^\]]*)]")]
private static partial Regex TypeAndAssemblyRegex();
[GeneratedRegex(@"Aurora\.")]
private static partial Regex OldAuroraNamespace();
[GeneratedRegex(@", Aurora$")]
private static partial Regex EndsWithAurora();
}

public class EnumConverter : JsonConverter
Expand Down

0 comments on commit 4c48c41

Please sign in to comment.