mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-05 14:26:06 +02:00
Refactored FilePicker (#1045)
This commit is contained in:
@@ -326,6 +326,50 @@ namespace VRCX
|
|||||||
return await tcs.Task;
|
return await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens a folder dialog to select a file and pass the path back to the JS side.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="defaultPath">The default path for the file picker.</param>
|
||||||
|
public async Task<string> OpenFileSelectorDialog(string defaultPath = "", string defaultExt = "", string defaultFilter = "All files (*.*)|*.*")
|
||||||
|
{
|
||||||
|
var tcs = new TaskCompletionSource<string>();
|
||||||
|
var staThread = new Thread(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var openFileDialog = new System.Windows.Forms.OpenFileDialog())
|
||||||
|
{
|
||||||
|
if (Directory.Exists(defaultPath))
|
||||||
|
{
|
||||||
|
openFileDialog.InitialDirectory = defaultPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
openFileDialog.DefaultExt = defaultExt;
|
||||||
|
openFileDialog.Filter = defaultFilter;
|
||||||
|
|
||||||
|
var dialogResult = openFileDialog.ShowDialog(MainForm.nativeWindow);
|
||||||
|
if (dialogResult == DialogResult.OK && !string.IsNullOrEmpty(openFileDialog.FileName))
|
||||||
|
{
|
||||||
|
tcs.SetResult(openFileDialog.FileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tcs.SetResult("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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}]+)",
|
private static readonly Regex _folderRegex = new Regex(string.Format(@"([{0}]*\.+$)|([{0}]+)",
|
||||||
Regex.Escape(new string(Path.GetInvalidPathChars()))));
|
Regex.Escape(new string(Path.GetInvalidPathChars()))));
|
||||||
|
|
||||||
|
|||||||
@@ -272,43 +272,16 @@ namespace VRCX
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Opens a file dialog to select a VRChat registry backup JSON file.
|
public string ReadVrcRegJsonFile(string filepath)
|
||||||
/// </summary>
|
|
||||||
public void OpenVrcRegJsonFileDialog()
|
|
||||||
{
|
{
|
||||||
if (dialogOpen) return;
|
if (!File.Exists(filepath))
|
||||||
dialogOpen = true;
|
|
||||||
|
|
||||||
var thread = new Thread(() =>
|
|
||||||
{
|
{
|
||||||
using (var openFileDialog = new System.Windows.Forms.OpenFileDialog())
|
return "";
|
||||||
{
|
}
|
||||||
openFileDialog.DefaultExt = ".json";
|
|
||||||
openFileDialog.Filter = "JSON Files (*.json)|*.json";
|
|
||||||
openFileDialog.FilterIndex = 1;
|
|
||||||
openFileDialog.RestoreDirectory = true;
|
|
||||||
|
|
||||||
if (openFileDialog.ShowDialog() != DialogResult.OK)
|
var json = File.ReadAllText(filepath);
|
||||||
{
|
return json;
|
||||||
dialogOpen = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dialogOpen = false;
|
|
||||||
|
|
||||||
var path = openFileDialog.FileName;
|
|
||||||
if (string.IsNullOrEmpty(path))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// return file contents
|
|
||||||
var json = File.ReadAllText(path);
|
|
||||||
ExecuteAppFunction("restoreVrcRegistryFromFile", json);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
thread.SetApartmentState(ApartmentState.STA);
|
|
||||||
thread.Start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,6 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
public partial class AppApi
|
public partial class AppApi
|
||||||
{
|
{
|
||||||
private static bool dialogOpen;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds metadata to a PNG screenshot file and optionally renames the file to include the specified world ID.
|
/// Adds metadata to a PNG screenshot file and optionally renames the file to include the specified world ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,51 +37,6 @@ namespace VRCX
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Opens a file dialog to select a PNG screenshot file.
|
|
||||||
/// The resulting file path is passed to <see cref="GetScreenshotMetadata(string)"/>.
|
|
||||||
/// </summary>
|
|
||||||
public void OpenScreenshotFileDialog()
|
|
||||||
{
|
|
||||||
if (dialogOpen) return;
|
|
||||||
dialogOpen = true;
|
|
||||||
|
|
||||||
var thread = new Thread(() =>
|
|
||||||
{
|
|
||||||
using (var openFileDialog = new OpenFileDialog())
|
|
||||||
{
|
|
||||||
openFileDialog.DefaultExt = ".png";
|
|
||||||
openFileDialog.Filter = "PNG Files (*.png)|*.png";
|
|
||||||
openFileDialog.FilterIndex = 1;
|
|
||||||
openFileDialog.RestoreDirectory = true;
|
|
||||||
|
|
||||||
var initialPath = GetVRChatPhotosLocation();
|
|
||||||
if (Directory.Exists(initialPath))
|
|
||||||
{
|
|
||||||
openFileDialog.InitialDirectory = initialPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (openFileDialog.ShowDialog() != DialogResult.OK)
|
|
||||||
{
|
|
||||||
dialogOpen = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dialogOpen = false;
|
|
||||||
|
|
||||||
var path = openFileDialog.FileName;
|
|
||||||
if (string.IsNullOrEmpty(path))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ExecuteAppFunction("screenshotMetadataResetSearch", null);
|
|
||||||
ExecuteAppFunction("getAndDisplayScreenshot", path);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
thread.SetApartmentState(ApartmentState.STA);
|
|
||||||
thread.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetExtraScreenshotData(string path, bool carouselCache)
|
public string GetExtraScreenshotData(string path, bool carouselCache)
|
||||||
{
|
{
|
||||||
var fileName = Path.GetFileNameWithoutExtension(path);
|
var fileName = Path.GetFileNameWithoutExtension(path);
|
||||||
@@ -131,7 +84,6 @@ namespace VRCX
|
|||||||
if (string.IsNullOrEmpty(path))
|
if (string.IsNullOrEmpty(path))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
||||||
var metadata = ScreenshotHelper.GetScreenshotMetadata(path);
|
var metadata = ScreenshotHelper.GetScreenshotMetadata(path);
|
||||||
|
|
||||||
if (metadata == null)
|
if (metadata == null)
|
||||||
|
|||||||
@@ -16344,6 +16344,16 @@ speechSynthesis.getVoices();
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$app.methods.getAndDisplayScreenshotFromFile = async function () {
|
||||||
|
var filePath = await AppApi.OpenFileSelectorDialog(await AppApi.GetVRChatPhotosLocation(), ".png", "PNG Files (*.png)|*.png");
|
||||||
|
if (filePath === "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.screenshotMetadataResetSearch();
|
||||||
|
this.getAndDisplayScreenshot(filePath);
|
||||||
|
};
|
||||||
|
|
||||||
$app.methods.getAndDisplayScreenshot = function (
|
$app.methods.getAndDisplayScreenshot = function (
|
||||||
path,
|
path,
|
||||||
needsCarouselFiles = true
|
needsCarouselFiles = true
|
||||||
|
|||||||
@@ -133,7 +133,14 @@ export default class extends baseClass {
|
|||||||
this.downloadAndSaveJson(row.name, row.data);
|
this.downloadAndSaveJson(row.name, row.data);
|
||||||
},
|
},
|
||||||
|
|
||||||
restoreVrcRegistryFromFile(json) {
|
async restoreVrcRegistryFromFile() {
|
||||||
|
var filePath = await AppApi.OpenFileSelectorDialog(null, ".json", "JSON Files (*.json)|*.json");
|
||||||
|
if (filePath === "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var json = await AppApi.ReadVrcRegJsonFile(filePath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var data = JSON.parse(json);
|
var data = JSON.parse(json);
|
||||||
if (!data || typeof data !== 'object') {
|
if (!data || typeof data !== 'object') {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ mixin screenshotMetadata()
|
|||||||
span(style="margin-left:5px;color:#909399;font-family:monospace") {{ $t('dialog.screenshot_metadata.drag') }}
|
span(style="margin-left:5px;color:#909399;font-family:monospace") {{ $t('dialog.screenshot_metadata.drag') }}
|
||||||
br
|
br
|
||||||
br
|
br
|
||||||
el-button(size="small" icon="el-icon-folder-opened" @click="AppApi.OpenScreenshotFileDialog()") {{ $t('dialog.screenshot_metadata.browse') }}
|
el-button(size="small" icon="el-icon-folder-opened" @click="getAndDisplayScreenshotFromFile()") {{ $t('dialog.screenshot_metadata.browse') }}
|
||||||
el-button(size="small" icon="el-icon-picture-outline" @click="getAndDisplayLastScreenshot()") {{ $t('dialog.screenshot_metadata.last_screenshot') }}
|
el-button(size="small" icon="el-icon-picture-outline" @click="getAndDisplayLastScreenshot()") {{ $t('dialog.screenshot_metadata.last_screenshot') }}
|
||||||
el-button(size="small" icon="el-icon-copy-document" @click="copyImageToClipboard(screenshotMetadataDialog.metadata.filePath)") {{ $t('dialog.screenshot_metadata.copy_image') }}
|
el-button(size="small" icon="el-icon-copy-document" @click="copyImageToClipboard(screenshotMetadataDialog.metadata.filePath)") {{ $t('dialog.screenshot_metadata.copy_image') }}
|
||||||
el-button(size="small" icon="el-icon-folder" @click="openImageFolder(screenshotMetadataDialog.metadata.filePath)") {{ $t('dialog.screenshot_metadata.open_folder') }}
|
el-button(size="small" icon="el-icon-folder" @click="openImageFolder(screenshotMetadataDialog.metadata.filePath)") {{ $t('dialog.screenshot_metadata.open_folder') }}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ mixin settings()
|
|||||||
el-button(type="danger" @click="deleteVrcRegistry" size="small") {{ $t('dialog.registry_backup.reset') }}
|
el-button(type="danger" @click="deleteVrcRegistry" size="small") {{ $t('dialog.registry_backup.reset') }}
|
||||||
div
|
div
|
||||||
el-button(@click="promptVrcRegistryBackupName" size="small") {{ $t('dialog.registry_backup.backup') }}
|
el-button(@click="promptVrcRegistryBackupName" size="small") {{ $t('dialog.registry_backup.backup') }}
|
||||||
el-button(@click="AppApi.OpenVrcRegJsonFileDialog()" size="small") {{ $t('dialog.registry_backup.restore_from_file') }}
|
el-button(@click="restoreVrcRegistryFromFile" size="small") {{ $t('dialog.registry_backup.restore_from_file') }}
|
||||||
|
|
||||||
|
|
||||||
//- dialog: Enable primary password
|
//- dialog: Enable primary password
|
||||||
|
|||||||
Reference in New Issue
Block a user