Skip to content

Commit

Permalink
corrected device save string for devices
Browse files Browse the repository at this point in the history
  • Loading branch information
dooly123 committed Mar 3, 2025
1 parent 7a77942 commit b26def3
Show file tree
Hide file tree
Showing 6 changed files with 3,113 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UnityEngine;

Expand Down Expand Up @@ -91,11 +92,20 @@ public static void SaveDevices(string directoryPath, List<BasisDeviceMatchSettin
continue;
}

string filePath = Path.Combine(directoryPath, device.DeviceID + JsonIdentifier);

string filePath = Path.Combine(directoryPath, MakeDeviceSafeForSave(device.DeviceID) + JsonIdentifier);
Task.Run(() => SaveDeviceAsync(filePath, device));
}
}
public static string MakeDeviceSafeForSave(string fileName)
{
// Define a regex pattern to match invalid filename characters
string invalidChars = new string(Path.GetInvalidFileNameChars()) + "{}";
string pattern = $"[{Regex.Escape(invalidChars)}]";

// Replace invalid characters with an underscore
return Regex.Replace(fileName, pattern, "_");
}
public static void SaveDeviceAsync(string filePath, BasisDeviceMatchSettings device)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Simulate()
{
EventSystem.current.SetSelectedGameObject(null, null);
}

DevicesCount = Inputs.Count;
for (int Index = 0; Index < DevicesCount; Index++)
{
BasisInput input = Inputs[Index];
Expand Down
Loading

0 comments on commit b26def3

Please sign in to comment.