Fix AreUnifiedThresholdsSynced modifying config.

master
Glenn Maynard 5 years ago
parent baf9b47fe9
commit ae25ed327a
  1. 2
      smx-config/ConfigPresets.cs
  2. 15
      smx-config/Helpers.cs
  3. 2
      smx-config/SMX.cs

@ -141,7 +141,7 @@ namespace smx_config
// have no effect.
static public bool AreUnifiedThresholdsSynced(SMX.SMXConfig config)
{
SMX.SMXConfig config2 = config;
SMX.SMXConfig config2 = Helpers.DeepClone(config);
SyncUnifiedThresholds(ref config2);
return SamePreset(config, config2);
}

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows;
using System.Windows.Media;
using System.Windows.Resources;
@ -107,6 +109,19 @@ namespace smx_config
return new System.ComponentModel.Win32Exception(error).Message;
}
// https://stackoverflow.com/a/129395/136829
public static T DeepClone<T>(T obj)
{
using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, obj);
ms.Position = 0;
return (T) formatter.Deserialize(ms);
}
}
// Work around Enumerable.SequenceEqual not checking if the arrays are null.
public static bool SequenceEqual<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
{

@ -27,6 +27,7 @@ namespace SMX
PlatformFlags_FSR = 1 << 1,
};
[Serializable]
public struct PackedSensorSettings {
// Load cell thresholds:
public Byte loadCellLowThreshold;
@ -47,6 +48,7 @@ namespace SMX
};
[StructLayout(LayoutKind.Sequential, Pack=1)]
[Serializable]
public struct SMXConfig {
public Byte masterVersion;
public Byte configVersion;

Loading…
Cancel
Save