Edit saved print names

This commit is contained in:
Natsumi
2024-11-18 10:39:22 +13:00
parent 9bcd58d776
commit 78dc8ea42d
5 changed files with 47 additions and 17 deletions
+17
View File
@@ -2,6 +2,7 @@ using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.Win32;
@@ -246,5 +247,21 @@ namespace VRCX
Process.Start("explorer.exe", $"/select,\"{path}\"");
}
}
private static readonly Regex _folderRegex = new Regex(string.Format(@"([{0}]*\.+$)|([{0}]+)",
Regex.Escape(new string(Path.GetInvalidPathChars()))));
private static readonly Regex _fileRegex = new Regex(string.Format(@"([{0}]*\.+$)|([{0}]+)",
Regex.Escape(new string(Path.GetInvalidFileNameChars()))));
public static string MakeValidFileName(string name)
{
name = name.Replace("/", "");
name = name.Replace("\\", "");
name = _folderRegex.Replace(name, "");
name = _fileRegex.Replace(name, "");
return name;
}
}
}