From 1fea62da115b5ec3dcfa537fc00effe215926929 Mon Sep 17 00:00:00 2001 From: Miepee <38186597+Miepee@users.noreply.github.com> Date: Fri, 29 Oct 2021 10:42:04 +0200 Subject: [PATCH] when creating the APK, select it too --- .../AM2RLauncher/CrossPlatformOperations.cs | 25 +++++++++++++++++-- .../AM2RLauncher/MainForm/MainForm.Methods.cs | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs index 3737ae0..37ad89d 100644 --- a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs +++ b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs @@ -202,11 +202,32 @@ namespace AM2RLauncher if (!Directory.Exists(realPath)) Directory.CreateDirectory(realPath); + //needs quotes otherwise paths with space wont open if (currentPlatform.IsWinForms) // And we're using explorer.exe to prevent people from stuffing system commands in here wholesale. That would be bad. - Process.Start("explorer.exe", realPath); + Process.Start("explorer.exe", $"/select \"{realPath}\""); + // linux only opens the directory bc opening and selecting a file is pain else if (currentPlatform.IsGtk) - Process.Start("xdg-open", $"\"{realPath}\""); //needs quotes otherwise paths with space wont open + Process.Start("xdg-open", $"\"{realPath}\""); + } + + /// + /// Opens and selects it in a file explorer. + /// + /// Path to open. + public static void OpenFolderAndSelectFile(string path) + { + // We have to replace forward slashes with backslashes here on windows because explorer.exe is picky... + string realPath = currentPlatform.IsWinForms ? Environment.ExpandEnvironmentVariables(path).Replace("/", "\\") : path.Replace("~", Environment.GetEnvironmentVariable("HOME")); + if (!File.Exists(realPath)) + return; + + //needs quotes otherwise paths with spaces wont open + if (currentPlatform.IsWinForms) + // And we're using explorer.exe to prevent people from stuffing system commands in here wholesale. That would be bad. + Process.Start("explorer.exe", $"/select, \"{realPath}\""); + else if (currentPlatform.IsGtk) + Process.Start("xdg-open", $"\"{Path.GetDirectoryName(realPath)}\""); } /// diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs index 4707c65..fd1c9c4 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs @@ -623,7 +623,7 @@ namespace AM2RLauncher HelperMethods.DeleteDirectory(tempDir); - CrossPlatformOperations.OpenFolder(CrossPlatformOperations.CURRENTPATH); + CrossPlatformOperations.OpenFolderAndSelectFile(CrossPlatformOperations.CURRENTPATH + "/" + profile.Name + ".apk"); log.Info("Successfully created Android APK for profile " + profile.Name + "."); }