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
+6 -5
View File
@@ -575,14 +575,15 @@ namespace VRCX
return null;
}
public async Task<bool> SavePrintToFile(string url, string fileName)
public async Task<bool> SavePrintToFile(string url, string path, string fileName)
{
var path = Path.Combine(GetVRChatPhotosLocation(), fileName);
Directory.CreateDirectory(Path.GetDirectoryName(path));
if (File.Exists(path))
var folder = Path.Combine(GetVRChatPhotosLocation(), "Prints", MakeValidFileName(path));
Directory.CreateDirectory(folder);
var filePath = Path.Combine(folder, MakeValidFileName(fileName));
if (File.Exists(filePath))
return false;
return await ImageCache.SaveImageToFile(url, path);
return await ImageCache.SaveImageToFile(url, filePath);
}
}
}
+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;
}
}
}