diff --git a/src/ChromaControl.SDK.OpenRGB/Extensions/JsonNodeExtensions.cs b/src/ChromaControl.SDK.OpenRGB/Extensions/JsonNodeExtensions.cs new file mode 100644 index 0000000..38b6f00 --- /dev/null +++ b/src/ChromaControl.SDK.OpenRGB/Extensions/JsonNodeExtensions.cs @@ -0,0 +1,42 @@ +// Licensed to the Chroma Control Contributors under one or more agreements. +// The Chroma Control Contributors licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json; +using System.Text.Json.Nodes; + +namespace ChromaControl.SDK.OpenRGB.Extensions; + +internal static class JsonNodeExtensions +{ + public static void Merge(this JsonNode current, JsonNode merge) + { + var mergeObject = merge.AsObject(); + + foreach (var mergeNode in mergeObject) + { + if (mergeNode.Value is null) + { + current[mergeNode.Key] = null; + } + else + { + if (current[mergeNode.Key] is null) + { + current[mergeNode.Key] = mergeNode.Value.DeepClone(); + } + else + { + if (mergeNode.Value.GetValueKind() is JsonValueKind.Object) + { + current[mergeNode.Key]!.Merge(mergeNode.Value); + } + else + { + current[mergeNode.Key] = mergeNode.Value.DeepClone(); + } + } + } + } + } +} diff --git a/src/ChromaControl.SDK.OpenRGB/Internal/OpenRGBConstants.cs b/src/ChromaControl.SDK.OpenRGB/Internal/OpenRGBConstants.cs new file mode 100644 index 0000000..5d2e6ea --- /dev/null +++ b/src/ChromaControl.SDK.OpenRGB/Internal/OpenRGBConstants.cs @@ -0,0 +1,184 @@ +// Licensed to the Chroma Control Contributors under one or more agreements. +// The Chroma Control Contributors licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Immutable; + +namespace ChromaControl.SDK.OpenRGB.Internal; + +internal sealed class OpenRGBConstants +{ + public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ChromaControl"); + public static readonly string ConfigPath = Path.Combine(DataPath, "config"); + + public static readonly ImmutableList DisabledDetectors = + [ + "Lian Li O11 Dynamic - Razer Edition", + "Razer Abyssus Elite D.Va Edition", + "Razer Abyssus Essential", + "Razer Base Station Chroma", + "Razer Base Station V2 Chroma", + "Razer Basilisk", + "Razer Basilisk Essential", + "Razer Basilisk Ultimate (Wired)", + "Razer Basilisk Ultimate (Wireless)", + "Razer Basilisk V2", + "Razer Basilisk V3", + "Razer Basilisk V3 Pro (Wired)", + "Razer Basilisk V3 Pro (Wireless)", + "Razer Basilisk V3 X HyperSpeed", + "Razer Blackwidow 2019", + "Razer Blackwidow Chroma", + "Razer Blackwidow Chroma Tournament Edition", + "Razer Blackwidow Chroma V2", + "Razer Blackwidow Elite", + "Razer Blackwidow Overwatch", + "Razer Blackwidow V3", + "Razer Blackwidow V3 Mini (Wired)", + "Razer Blackwidow V3 Mini (Wireless)", + "Razer Blackwidow V3 Pro (Wired)", + "Razer Blackwidow V3 Pro (Wireless)", + "Razer Blackwidow V3 TKL", + "Razer Blackwidow V4", + "Razer Blackwidow V4 Pro", + "Razer Blackwidow V4 X", + "Razer Blackwidow X Chroma", + "Razer Blackwidow X Chroma Tournament Edition", + "Razer Blade (2016)", + "Razer Blade (Late 2016)", + "Razer Blade 14 (2021)", + "Razer Blade 14 (2022)", + "Razer Blade 14 (2023)", + "Razer Blade 15 (2018 Advanced)", + "Razer Blade 15 (2018 Base)", + "Razer Blade 15 (2018 Mercury)", + "Razer Blade 15 (2019 Advanced)", + "Razer Blade 15 (2019 Base)", + "Razer Blade 15 (2019 Mercury)", + "Razer Blade 15 (2019 Studio)", + "Razer Blade 15 (2020 Advanced)", + "Razer Blade 15 (2020 Base)", + "Razer Blade 15 (2021 Advanced)", + "Razer Blade 15 (2021 Base)", + "Razer Blade 15 (2022)", + "Razer Blade 15 (Late 2020)", + "Razer Blade 15 (Late 2021 Advanced)", + "Razer Blade Pro (2016)", + "Razer Blade Pro (2017 FullHD)", + "Razer Blade Pro (2017)", + "Razer Blade Pro (2019)", + "Razer Blade Pro (Late 2019)", + "Razer Blade Pro 17 (2020)", + "Razer Blade Pro 17 (2021)", + "Razer Blade Stealth (2016)", + "Razer Blade Stealth (2017)", + "Razer Blade Stealth (2019)", + "Razer Blade Stealth (2020)", + "Razer Blade Stealth (Late 2016)", + "Razer Blade Stealth (Late 2017)", + "Razer Blade Stealth (Late 2019)", + "Razer Blade Stealth (Late 2020)", + "Razer Book 13 (2020)", + "Razer Charging Pad Chroma", + "Razer Chroma Addressable RGB Controller", + "Razer Chroma HDK", + "Razer Chroma Mug Holder", + "Razer Chroma PC Case Lighting Kit", + "Razer Cobra", + "Razer Core", + "Razer Core X", + "Razer Cynosa Chroma", + "Razer Cynosa Chroma V2", + "Razer Cynosa Lite", + "Razer Deathadder Chroma", + "Razer Deathadder Elite", + "Razer Deathadder Essential", + "Razer Deathadder Essential V2", + "Razer Deathadder Essential White Edition", + "Razer Deathadder V2", + "Razer Deathadder V2 Mini", + "Razer Deathadder V2 Pro (Wired)", + "Razer Deathadder V2 Pro (Wireless)", + "Razer Deathstalker Chroma", + "Razer Deathstalker V2", + "Razer Deathstalker V2 Pro (Wired)", + "Razer Deathstalker V2 Pro (Wireless)", + "Razer Deathstalker V2 Pro TKL (Wired)", + "Razer Deathstalker V2 Pro TKL (Wireless)", + "Razer Diamondback", + "Razer Firefly", + "Razer Firefly Hyperflux", + "Razer Firefly V2", + "Razer Goliathus", + "Razer Goliathus Chroma 3XL", + "Razer Goliathus Extended", + "Razer Huntsman", + "Razer Huntsman Elite", + "Razer Huntsman Mini", + "Razer Huntsman Mini Analog", + "Razer Huntsman Tournament Edition", + "Razer Huntsman V2", + "Razer Huntsman V2 Analog", + "Razer Huntsman V2 TKL", + "Razer Kraken 7.1", + "Razer Kraken 7.1 Chroma", + "Razer Kraken 7.1 V2", + "Razer Kraken Kitty Black Edition", + "Razer Kraken Kitty Black Edition V2", + "Razer Kraken Kitty Edition", + "Razer Kraken Ultimate", + "Razer Lancehead 2017 (Wired)", + "Razer Lancehead 2017 (Wireless)", + "Razer Lancehead 2019 (Wired)", + "Razer Lancehead 2019 (Wireless)", + "Razer Lancehead Tournament Edition", + "Razer Laptop Stand Chroma", + "Razer Laptop Stand Chroma V2", + "Razer Leviathan V2", + "Razer Leviathan V2 X", + "Razer Mamba 2012 (Wired)", + "Razer Mamba 2012 (Wireless)", + "Razer Mamba 2015 (Wired)", + "Razer Mamba 2015 (Wireless)", + "Razer Mamba 2018 (Wired)", + "Razer Mamba 2018 (Wireless)", + "Razer Mamba Elite", + "Razer Mamba Hyperflux (Wired)", + "Razer Mamba Tournament Edition", + "Razer Mouse Bungee V3 Chroma", + "Razer Mouse Dock Chroma", + "Razer Mouse Dock Pro", + "Razer Naga Chroma", + "Razer Naga Classic", + "Razer Naga Epic Chroma", + "Razer Naga Hex V2", + "Razer Naga Left Handed", + "Razer Naga Pro (Wired)", + "Razer Naga Pro (Wireless)", + "Razer Naga Pro V2 (Wired)", + "Razer Naga Pro V2 (Wireless)", + "Razer Naga Trinity", + "Razer Nommo Chroma", + "Razer Nommo Pro", + "Razer Orbweaver Chroma", + "Razer Ornata Chroma", + "Razer Ornata Chroma V2", + "Razer Ornata V3", + "Razer Ornata V3 Rev2", + "Razer Ornata V3 TKL", + "Razer Ornata V3 X", + "Razer Ornata V3 X Rev2", + "Razer Seiren Emote", + "Razer Strider Chroma", + "Razer Tartarus Chroma", + "Razer Tartarus Pro", + "Razer Tartarus V2", + "Razer Thunderbolt 4 Dock Chroma", + "Razer Tiamat 7.1 V2", + "Razer Viper", + "Razer Viper 8kHz", + "Razer Viper Mini", + "Razer Viper Ultimate (Wired)", + "Razer Viper Ultimate (Wireless)", + ]; +} diff --git a/src/ChromaControl.SDK.OpenRGB/Internal/OpenRGBManager.cs b/src/ChromaControl.SDK.OpenRGB/Internal/OpenRGBManager.cs index 13a3aeb..aff0187 100644 --- a/src/ChromaControl.SDK.OpenRGB/Internal/OpenRGBManager.cs +++ b/src/ChromaControl.SDK.OpenRGB/Internal/OpenRGBManager.cs @@ -2,7 +2,10 @@ // The Chroma Control Contributors licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using ChromaControl.SDK.OpenRGB.Extensions; using System.Diagnostics; +using System.Text.Json; +using System.Text.Json.Nodes; namespace ChromaControl.SDK.OpenRGB.Internal; @@ -20,7 +23,10 @@ public OpenRGBManager() public void Start() { + UpdateConfigFile(); + _job.AssignProcess(Process.GetCurrentProcess()); + _process.Start(); } @@ -39,14 +45,78 @@ public void Dispose() GC.SuppressFinalize(this); } + private static void UpdateConfigFile() + { + var configFilePath = Path.Combine(OpenRGBConstants.ConfigPath, "OpenRGB.json"); + + JsonNode? document; + + if (File.Exists(configFilePath)) + { + var json = File.ReadAllText(configFilePath); + document = JsonNode.Parse(json)!; + } + else + { + document = JsonNode.Parse("{\"Detectors\":{\"detectors\":{}}}")!; + } + + foreach (var detector in OpenRGBConstants.DisabledDetectors) + { + document["Detectors"]!["detectors"]![detector] = false; + } + + try + { + var mergeConfigFilePath = Path.Combine(OpenRGBConstants.ConfigPath, "OpenRGB.Merge.json"); + + if (File.Exists(mergeConfigFilePath)) + { + var json = File.ReadAllText(mergeConfigFilePath); + var mergeDocument = JsonNode.Parse(json); + + if (mergeDocument is not null) + { + document.Merge(mergeDocument); + } + } + } + catch { } + + var newJson = document.ToJsonString(new JsonSerializerOptions + { + WriteIndented = true + }); + + File.WriteAllText(configFilePath, newJson); + } + private static Process CreateProcess() { var process = new Process(); + var configPath = OpenRGBConstants.ConfigPath; + + if (!Directory.Exists(configPath)) + { + Directory.CreateDirectory(configPath); + } + + configPath = $"{configPath}"; + + var arguments = new string[] + { + "--server", + "--server-host 127.0.0.1", + "--server-port 6744", + "--noautoconnect", + $"--config \"{configPath}\"" + }; + process.StartInfo.FileName = "cmd.exe"; process.StartInfo.UseShellExecute = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - process.StartInfo.Arguments = $"/C \"{FindExecutablePath()}\" --noautoconnect --server"; + process.StartInfo.Arguments = $"/C \"\"{FindExecutablePath()}\" {string.Join(' ', arguments)}\""; return process; }