2023-12-04 14:17:13 +01:00
|
|
|
using Ryujinx.Common.Logging;
|
2021-12-05 00:02:30 +01:00
|
|
|
using System;
|
2020-09-01 11:09:42 +02:00
|
|
|
using System.Diagnostics;
|
2023-01-15 06:11:52 -05:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2020-09-01 11:09:42 +02:00
|
|
|
|
2024-02-11 02:09:18 +00:00
|
|
|
namespace Ryujinx.UI.Common.Helper
|
2020-09-01 11:09:42 +02:00
|
|
|
{
|
2023-01-15 06:11:52 -05:00
|
|
|
public static partial class OpenHelper
|
2020-09-01 11:09:42 +02:00
|
|
|
{
|
2023-01-15 06:11:52 -05:00
|
|
|
[LibraryImport("shell32.dll", SetLastError = true)]
|
2024-10-26 08:46:41 -05:00
|
|
|
private static partial int SHOpenFolderAndSelectItems(nint pidlFolder, uint cidl, nint apidl, uint dwFlags);
|
2023-01-15 06:11:52 -05:00
|
|
|
|
|
|
|
|
[LibraryImport("shell32.dll", SetLastError = true)]
|
2024-10-26 08:46:41 -05:00
|
|
|
private static partial void ILFree(nint pidlList);
|
2023-01-15 06:11:52 -05:00
|
|
|
|
|
|
|
|
[LibraryImport("shell32.dll", SetLastError = true)]
|
2024-10-26 08:46:41 -05:00
|
|
|
private static partial nint ILCreateFromPathW([MarshalAs(UnmanagedType.LPWStr)] string pszPath);
|
2023-01-15 06:11:52 -05:00
|
|
|
|
2021-01-08 09:14:13 +01:00
|
|
|
public static void OpenFolder(string path)
|
|
|
|
|
{
|
2023-01-15 06:11:52 -05:00
|
|
|
if (Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
Process.Start(new ProcessStartInfo
|
|
|
|
|
{
|
2023-06-29 02:39:22 +02:00
|
|
|
FileName = path,
|
2023-01-15 06:11:52 -05:00
|
|
|
UseShellExecute = true,
|
2023-06-29 02:39:22 +02:00
|
|
|
Verb = "open",
|
2023-01-15 06:11:52 -05:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-01-08 09:14:13 +01:00
|
|
|
{
|
2023-01-15 06:11:52 -05:00
|
|
|
Logger.Notice.Print(LogClass.Application, $"Directory \"{path}\" doesn't exist!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LocateFile(string path)
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
|
|
|
{
|
2024-10-26 08:46:41 -05:00
|
|
|
nint pidlList = ILCreateFromPathW(path);
|
|
|
|
|
if (pidlList != nint.Zero)
|
2023-01-15 06:11:52 -05:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-10-26 08:46:41 -05:00
|
|
|
Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, nint.Zero, 0));
|
2023-01-15 06:11:52 -05:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
ILFree(pidlList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (OperatingSystem.IsMacOS())
|
|
|
|
|
{
|
2023-02-08 22:08:15 -05:00
|
|
|
ObjectiveC.NSString nsStringPath = new(path);
|
2023-06-29 02:39:22 +02:00
|
|
|
ObjectiveC.Object nsUrl = new("NSURL");
|
|
|
|
|
var urlPtr = nsUrl.GetFromMessage("fileURLWithPath:", nsStringPath);
|
2023-02-08 22:08:15 -05:00
|
|
|
|
2023-06-29 02:39:22 +02:00
|
|
|
ObjectiveC.Object nsArray = new("NSArray");
|
|
|
|
|
ObjectiveC.Object urlArray = nsArray.GetFromMessage("arrayWithObject:", urlPtr);
|
2023-02-08 22:08:15 -05:00
|
|
|
|
2023-06-29 02:39:22 +02:00
|
|
|
ObjectiveC.Object nsWorkspace = new("NSWorkspace");
|
|
|
|
|
ObjectiveC.Object sharedWorkspace = nsWorkspace.GetFromMessage("sharedWorkspace");
|
2023-02-08 22:08:15 -05:00
|
|
|
|
2023-06-29 02:39:22 +02:00
|
|
|
sharedWorkspace.SendMessage("activateFileViewerSelectingURLs:", urlArray);
|
2023-01-15 06:11:52 -05:00
|
|
|
}
|
|
|
|
|
else if (OperatingSystem.IsLinux())
|
|
|
|
|
{
|
|
|
|
|
Process.Start("dbus-send", $"--session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:\"file://{path}\" string:\"\"");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OpenFolder(Path.GetDirectoryName(path));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"File \"{path}\" doesn't exist!");
|
|
|
|
|
}
|
2021-01-08 09:14:13 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-01 11:09:42 +02:00
|
|
|
public static void OpenUrl(string url)
|
|
|
|
|
{
|
2021-12-05 00:02:30 +01:00
|
|
|
if (OperatingSystem.IsWindows())
|
2020-09-01 11:09:42 +02:00
|
|
|
{
|
|
|
|
|
Process.Start(new ProcessStartInfo("cmd", $"/c start {url.Replace("&", "^&")}"));
|
|
|
|
|
}
|
2021-12-05 00:02:30 +01:00
|
|
|
else if (OperatingSystem.IsLinux())
|
2020-09-01 11:09:42 +02:00
|
|
|
{
|
|
|
|
|
Process.Start("xdg-open", url);
|
|
|
|
|
}
|
2021-12-05 00:02:30 +01:00
|
|
|
else if (OperatingSystem.IsMacOS())
|
2020-09-01 11:09:42 +02:00
|
|
|
{
|
2023-02-08 22:08:15 -05:00
|
|
|
ObjectiveC.NSString nsStringPath = new(url);
|
2023-06-29 02:39:22 +02:00
|
|
|
ObjectiveC.Object nsUrl = new("NSURL");
|
|
|
|
|
var urlPtr = nsUrl.GetFromMessage("URLWithString:", nsStringPath);
|
2023-02-08 22:08:15 -05:00
|
|
|
|
2023-06-29 02:39:22 +02:00
|
|
|
ObjectiveC.Object nsWorkspace = new("NSWorkspace");
|
|
|
|
|
ObjectiveC.Object sharedWorkspace = nsWorkspace.GetFromMessage("sharedWorkspace");
|
2023-02-08 22:08:15 -05:00
|
|
|
|
2023-06-29 02:39:22 +02:00
|
|
|
sharedWorkspace.GetBoolFromMessage("openURL:", urlPtr);
|
2020-09-01 11:09:42 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Cannot open url \"{url}\" on this platform!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-29 02:39:22 +02:00
|
|
|
}
|