mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-05 14:26:06 +02:00
Custom save locations for prints & stickers (#1041)
This commit is contained in:
+96
-18
@@ -6,6 +6,9 @@ using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Microsoft.Win32;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VRCX
|
||||
{
|
||||
@@ -34,7 +37,7 @@ namespace VRCX
|
||||
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat";
|
||||
}
|
||||
|
||||
|
||||
public string GetVRChatPhotosLocation()
|
||||
{
|
||||
var json = ReadConfigFile();
|
||||
@@ -50,10 +53,37 @@ namespace VRCX
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "VRChat");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the folder the user has selected for User-Generated content such as prints / stickers from the JS side.
|
||||
/// If there is no override on the folder, it returns the default VRChat Photos path.
|
||||
/// </summary>
|
||||
/// <returns>The UGC Photo Location.</returns>
|
||||
public string GetUGCPhotoLocation(string path = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return GetVRChatPhotosLocation();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
return GetVRChatPhotosLocation();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetSteamUserdataPathFromRegistry()
|
||||
{
|
||||
string steamUserdataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Steam\userdata");
|
||||
@@ -85,20 +115,20 @@ namespace VRCX
|
||||
var steamUserdataPath = GetSteamUserdataPathFromRegistry();
|
||||
var screenshotPath = string.Empty;
|
||||
var latestWriteTime = DateTime.MinValue;
|
||||
if (!Directory.Exists(steamUserdataPath))
|
||||
if (!Directory.Exists(steamUserdataPath))
|
||||
return screenshotPath;
|
||||
|
||||
|
||||
var steamUserDirs = Directory.GetDirectories(steamUserdataPath);
|
||||
foreach (var steamUserDir in steamUserDirs)
|
||||
{
|
||||
var screenshotDir = Path.Combine(steamUserDir, @"760\remote\438100\screenshots");
|
||||
if (!Directory.Exists(screenshotDir))
|
||||
continue;
|
||||
|
||||
|
||||
var lastWriteTime = File.GetLastWriteTime(screenshotDir);
|
||||
if (lastWriteTime <= latestWriteTime)
|
||||
continue;
|
||||
|
||||
|
||||
latestWriteTime = lastWriteTime;
|
||||
screenshotPath = screenshotDir;
|
||||
}
|
||||
@@ -114,13 +144,13 @@ namespace VRCX
|
||||
{
|
||||
return Path.Combine(GetVRChatAppDataLocation(), "Cache-WindowsPlayer");
|
||||
}
|
||||
|
||||
|
||||
public bool OpenVrcxAppDataFolder()
|
||||
{
|
||||
var path = Program.AppDataDirectory;
|
||||
if (!Directory.Exists(path))
|
||||
return false;
|
||||
|
||||
|
||||
OpenFolderAndSelectItem(path, true);
|
||||
return true;
|
||||
}
|
||||
@@ -130,27 +160,37 @@ namespace VRCX
|
||||
var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\VRChat\VRChat";
|
||||
if (!Directory.Exists(path))
|
||||
return false;
|
||||
|
||||
|
||||
OpenFolderAndSelectItem(path, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool OpenVrcPhotosFolder()
|
||||
{
|
||||
var path = GetVRChatPhotosLocation();
|
||||
if (!Directory.Exists(path))
|
||||
return false;
|
||||
|
||||
|
||||
OpenFolderAndSelectItem(path, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public bool OpenUGCPhotosFolder(string ugcPath = "")
|
||||
{
|
||||
var path = GetUGCPhotoLocation(ugcPath);
|
||||
if (!Directory.Exists(path))
|
||||
return false;
|
||||
|
||||
OpenFolderAndSelectItem(path, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool OpenVrcScreenshotsFolder()
|
||||
{
|
||||
var path = GetVRChatScreenshotsLocation();
|
||||
if (!Directory.Exists(path))
|
||||
return false;
|
||||
|
||||
|
||||
OpenFolderAndSelectItem(path, true);
|
||||
return true;
|
||||
}
|
||||
@@ -160,7 +200,7 @@ namespace VRCX
|
||||
var path = Path.Combine(Path.GetTempPath(), "VRChat", "VRChat", "Crashes");
|
||||
if (!Directory.Exists(path))
|
||||
return false;
|
||||
|
||||
|
||||
OpenFolderAndSelectItem(path, true);
|
||||
return true;
|
||||
}
|
||||
@@ -231,7 +271,7 @@ namespace VRCX
|
||||
Marshal.FreeCoTaskMem(pidlFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OpenFolderAndSelectItemFallback(string path)
|
||||
{
|
||||
if (!File.Exists(path) && !Directory.Exists(path))
|
||||
@@ -247,7 +287,45 @@ namespace VRCX
|
||||
Process.Start("explorer.exe", $"/select,\"{path}\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Opens a folder dialog to select a folder and pass it back to the JS side.
|
||||
/// </summary>
|
||||
/// <param name="defaultPath">The default path for the folder picker.</param>
|
||||
public async Task<string> OpenFolderSelectorDialog(string defaultPath = "")
|
||||
{
|
||||
var tcs = new TaskCompletionSource<string>();
|
||||
var staThread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var openFolderDialog = new FolderBrowserDialog())
|
||||
{
|
||||
openFolderDialog.InitialDirectory = Directory.Exists(defaultPath) ? defaultPath : GetVRChatPhotosLocation();
|
||||
|
||||
var dialogResult = openFolderDialog.ShowDialog(MainForm.nativeWindow);
|
||||
if (dialogResult == DialogResult.OK)
|
||||
{
|
||||
tcs.SetResult(openFolderDialog.SelectedPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
tcs.SetResult(defaultPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.SetException(ex);
|
||||
}
|
||||
});
|
||||
|
||||
staThread.SetApartmentState(ApartmentState.STA);
|
||||
staThread.Start();
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
|
||||
private static readonly Regex _folderRegex = new Regex(string.Format(@"([{0}]*\.+$)|([{0}]+)",
|
||||
Regex.Escape(new string(Path.GetInvalidPathChars()))));
|
||||
|
||||
@@ -260,7 +338,7 @@ namespace VRCX
|
||||
name = name.Replace("\\", "");
|
||||
name = _folderRegex.Replace(name, "");
|
||||
name = _fileRegex.Replace(name, "");
|
||||
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user