mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-01 20:53:45 +02:00
Edit saved print names
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user