2020-09-01 09:09:42 +00:00
|
|
|
|
using Ryujinx.Common.Logging;
|
2021-12-04 23:02:30 +00:00
|
|
|
|
using System;
|
2020-09-01 09:09:42 +00:00
|
|
|
|
using System.Diagnostics;
|
2023-01-15 11:11:52 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2020-09-01 09:09:42 +00:00
|
|
|
|
|
2022-05-15 11:30:15 +00:00
|
|
|
|
namespace Ryujinx.Ui.Common.Helper
|
2020-09-01 09:09:42 +00:00
|
|
|
|
{
|
2023-01-15 11:11:52 +00:00
|
|
|
|
public static partial class OpenHelper
|
2020-09-01 09:09:42 +00:00
|
|
|
|
{
|
2023-01-15 11:11:52 +00:00
|
|
|
|
[LibraryImport("shell32.dll", SetLastError = true)]
|
|
|
|
|
public static partial int SHOpenFolderAndSelectItems(IntPtr pidlFolder, uint cidl, IntPtr apidl, uint dwFlags);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("shell32.dll", SetLastError = true)]
|
|
|
|
|
public static partial void ILFree(IntPtr pidlList);
|
|
|
|
|
|
|
|
|
|
[LibraryImport("shell32.dll", SetLastError = true)]
|
|
|
|
|
public static partial IntPtr ILCreateFromPathW([MarshalAs(UnmanagedType.LPWStr)] string pszPath);
|
|
|
|
|
|
2021-01-08 08:14:13 +00:00
|
|
|
|
public static void OpenFolder(string path)
|
|
|
|
|
{
|
2023-01-15 11:11:52 +00:00
|
|
|
|
if (Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
Process.Start(new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = path,
|
|
|
|
|
UseShellExecute = true,
|
|
|
|
|
Verb = "open"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-01-08 08:14:13 +00:00
|
|
|
|
{
|
2023-01-15 11:11:52 +00:00
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Directory \"{path}\" doesn't exist!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LocateFile(string path)
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
if (OperatingSystem.IsWindows())
|
|
|
|
|
{
|
|
|
|
|
IntPtr pidlList = ILCreateFromPathW(path);
|
|
|
|
|
if (pidlList != IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0));
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
ILFree(pidlList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (OperatingSystem.IsMacOS())
|
|
|
|
|
{
|
2023-02-09 03:08:15 +00:00
|
|
|
|
ObjectiveC.NSString nsStringPath = new(path);
|
|
|
|
|
IntPtr nsUrl = ObjectiveC.objc_getClass("NSURL");
|
|
|
|
|
var urlPtr = ObjectiveC.IntPtr_objc_msgSend(nsUrl, "fileURLWithPath:", nsStringPath);
|
|
|
|
|
|
|
|
|
|
IntPtr nsArray = ObjectiveC.objc_getClass("NSArray");
|
|
|
|
|
IntPtr urlArray = ObjectiveC.IntPtr_objc_msgSend(nsArray, "arrayWithObject:", urlPtr);
|
|
|
|
|
|
|
|
|
|
IntPtr nsWorkspace = ObjectiveC.objc_getClass("NSWorkspace");
|
|
|
|
|
IntPtr sharedWorkspace = ObjectiveC.IntPtr_objc_msgSend(nsWorkspace, "sharedWorkspace");
|
|
|
|
|
|
|
|
|
|
ObjectiveC.objc_msgSend(sharedWorkspace, "activateFileViewerSelectingURLs:", urlArray);
|
2023-01-15 11:11:52 +00: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 08:14:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-01 09:09:42 +00:00
|
|
|
|
public static void OpenUrl(string url)
|
|
|
|
|
{
|
2021-12-04 23:02:30 +00:00
|
|
|
|
if (OperatingSystem.IsWindows())
|
2020-09-01 09:09:42 +00:00
|
|
|
|
{
|
|
|
|
|
Process.Start(new ProcessStartInfo("cmd", $"/c start {url.Replace("&", "^&")}"));
|
|
|
|
|
}
|
2021-12-04 23:02:30 +00:00
|
|
|
|
else if (OperatingSystem.IsLinux())
|
2020-09-01 09:09:42 +00:00
|
|
|
|
{
|
|
|
|
|
Process.Start("xdg-open", url);
|
|
|
|
|
}
|
2021-12-04 23:02:30 +00:00
|
|
|
|
else if (OperatingSystem.IsMacOS())
|
2020-09-01 09:09:42 +00:00
|
|
|
|
{
|
2023-02-09 03:08:15 +00:00
|
|
|
|
ObjectiveC.NSString nsStringPath = new(url);
|
|
|
|
|
IntPtr nsUrl = ObjectiveC.objc_getClass("NSURL");
|
|
|
|
|
var urlPtr = ObjectiveC.IntPtr_objc_msgSend(nsUrl, "URLWithString:", nsStringPath);
|
|
|
|
|
|
|
|
|
|
IntPtr nsWorkspace = ObjectiveC.objc_getClass("NSWorkspace");
|
|
|
|
|
IntPtr sharedWorkspace = ObjectiveC.IntPtr_objc_msgSend(nsWorkspace, "sharedWorkspace");
|
|
|
|
|
|
|
|
|
|
ObjectiveC.bool_objc_msgSend(sharedWorkspace, "openURL:", urlPtr);
|
2020-09-01 09:09:42 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Cannot open url \"{url}\" on this platform!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-08 08:14:13 +00:00
|
|
|
|
}
|