From 316e3e6f74a3c08b4454e2a1e4d5c6ef77f0c856 Mon Sep 17 00:00:00 2001 From: Cameron Beeley Date: Fri, 10 Jul 2026 23:38:33 +0100 Subject: [PATCH] Fix legacy Green/Blue lightbar channels parsing from the Red element In PostProcessXml's legacy per-channel colour path, the green and blue channels both parsed RedColorString instead of their own GreenColorString / BlueColorString, so a profile using the old separate // elements loaded with all three channels set to the red value and the lightbar showed the wrong colour. Parse each channel from its own element, and add a regression test that deserializes a legacy per-channel profile and asserts the mapped DS4Color channels individually. --- DS4Windows/DS4Control/DTOXml/ProfileDTO.cs | 4 ++-- DS4WindowsTests/ProfileTests.cs | 27 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/DS4Windows/DS4Control/DTOXml/ProfileDTO.cs b/DS4Windows/DS4Control/DTOXml/ProfileDTO.cs index 6e2c8da..bb4304a 100644 --- a/DS4Windows/DS4Control/DTOXml/ProfileDTO.cs +++ b/DS4Windows/DS4Control/DTOXml/ProfileDTO.cs @@ -2769,12 +2769,12 @@ public void PostProcessXml() if (!string.IsNullOrEmpty(GreenColorString)) { - byte.TryParse(RedColorString, out _ledColor.green); + byte.TryParse(GreenColorString, out _ledColor.green); } if (!string.IsNullOrEmpty(BlueColorString)) { - byte.TryParse(RedColorString, out _ledColor.blue); + byte.TryParse(BlueColorString, out _ledColor.blue); } } diff --git a/DS4WindowsTests/ProfileTests.cs b/DS4WindowsTests/ProfileTests.cs index e606de7..2dd7436 100644 --- a/DS4WindowsTests/ProfileTests.cs +++ b/DS4WindowsTests/ProfileTests.cs @@ -524,5 +524,32 @@ public void CheckWriteProfile() Assert.AreEqual(OutContType.ViiperX360, roundTripStore.outputDevType[0]); } + + [TestMethod] + public void CheckLegacyPerChannelColorRead() + { + // Old profiles store the lightbar colour as separate // + // elements rather than a combined . Each channel must be parsed + // from its own element. + string legacyColorProfileXml = @" + + 10 + 20 + 30 +"; + + XmlSerializer serializer = new XmlSerializer(typeof(ProfileDTO), + ProfileDTO.GetAttributeOverrides()); + using StringReader sr = new StringReader(legacyColorProfileXml); + ProfileDTO dto = serializer.Deserialize(sr) as ProfileDTO; + dto.DeviceIndex = 0; + BackingStore tempStore = new BackingStore(); + dto.MapTo(tempStore); + + DS4Color led = tempStore.lightbarSettingInfo[0].ds4winSettings.m_Led; + Assert.AreEqual((byte)10, led.red); + Assert.AreEqual((byte)20, led.green); + Assert.AreEqual((byte)30, led.blue); + } } }