mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2024-11-30 20:54:30 +01:00
UI: Conditionally enable install/uninstall file types buttons based on whether they're installed already
This commit is contained in:
parent
eb6ce7bcb3
commit
617b81e209
@ -4,6 +4,7 @@ using Ryujinx.Common.Logging;
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
@ -24,6 +25,26 @@ namespace Ryujinx.UI.Common.Helper
|
|||||||
|
|
||||||
public static bool IsTypeAssociationSupported => (OperatingSystem.IsLinux() || OperatingSystem.IsWindows()) && !ReleaseInformation.IsFlatHubBuild;
|
public static bool IsTypeAssociationSupported => (OperatingSystem.IsLinux() || OperatingSystem.IsWindows()) && !ReleaseInformation.IsFlatHubBuild;
|
||||||
|
|
||||||
|
public static bool AreMimeTypesRegistered
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (OperatingSystem.IsLinux())
|
||||||
|
{
|
||||||
|
return AreMimeTypesRegisteredLinux();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OperatingSystem.IsWindows())
|
||||||
|
{
|
||||||
|
return AreMimeTypesRegisteredWindows();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Add macOS support.
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("linux")]
|
[SupportedOSPlatform("linux")]
|
||||||
private static bool AreMimeTypesRegisteredLinux() => File.Exists(Path.Combine(_mimeDbPath, "packages", "Ryujinx.xml"));
|
private static bool AreMimeTypesRegisteredLinux() => File.Exists(Path.Combine(_mimeDbPath, "packages", "Ryujinx.xml"));
|
||||||
|
|
||||||
@ -72,6 +93,10 @@ namespace Ryujinx.UI.Common.Helper
|
|||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
private static bool AreMimeTypesRegisteredWindows()
|
private static bool AreMimeTypesRegisteredWindows()
|
||||||
{
|
{
|
||||||
|
return _fileExtensions.Aggregate(false,
|
||||||
|
(current, ext) => current | CheckRegistering(ext)
|
||||||
|
);
|
||||||
|
|
||||||
static bool CheckRegistering(string ext)
|
static bool CheckRegistering(string ext)
|
||||||
{
|
{
|
||||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(@$"Software\Classes\{ext}");
|
RegistryKey key = Registry.CurrentUser.OpenSubKey(@$"Software\Classes\{ext}");
|
||||||
@ -87,20 +112,20 @@ namespace Ryujinx.UI.Common.Helper
|
|||||||
|
|
||||||
return keyValue is not null && (keyValue.Contains("Ryujinx") || keyValue.Contains(AppDomain.CurrentDomain.FriendlyName));
|
return keyValue is not null && (keyValue.Contains("Ryujinx") || keyValue.Contains(AppDomain.CurrentDomain.FriendlyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool registered = false;
|
|
||||||
|
|
||||||
foreach (string ext in _fileExtensions)
|
|
||||||
{
|
|
||||||
registered |= CheckRegistering(ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
return registered;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
private static bool InstallWindowsMimeTypes(bool uninstall = false)
|
private static bool InstallWindowsMimeTypes(bool uninstall = false)
|
||||||
{
|
{
|
||||||
|
bool registered = _fileExtensions.Aggregate(false,
|
||||||
|
(current, ext) => current | RegisterExtension(ext, uninstall)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Notify Explorer the file association has been changed.
|
||||||
|
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, nint.Zero, nint.Zero);
|
||||||
|
|
||||||
|
return registered;
|
||||||
|
|
||||||
static bool RegisterExtension(string ext, bool uninstall = false)
|
static bool RegisterExtension(string ext, bool uninstall = false)
|
||||||
{
|
{
|
||||||
string keyString = @$"Software\Classes\{ext}";
|
string keyString = @$"Software\Classes\{ext}";
|
||||||
@ -134,35 +159,6 @@ namespace Ryujinx.UI.Common.Helper
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool registered = false;
|
|
||||||
|
|
||||||
foreach (string ext in _fileExtensions)
|
|
||||||
{
|
|
||||||
registered |= RegisterExtension(ext, uninstall);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify Explorer the file association has been changed.
|
|
||||||
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, nint.Zero, nint.Zero);
|
|
||||||
|
|
||||||
return registered;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool AreMimeTypesRegistered()
|
|
||||||
{
|
|
||||||
if (OperatingSystem.IsLinux())
|
|
||||||
{
|
|
||||||
return AreMimeTypesRegisteredLinux();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OperatingSystem.IsWindows())
|
|
||||||
{
|
|
||||||
return AreMimeTypesRegisteredWindows();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Add macOS support.
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Install()
|
public static bool Install()
|
||||||
|
@ -803,6 +803,11 @@ namespace Ryujinx.Ava.UI.ViewModels
|
|||||||
get => FileAssociationHelper.IsTypeAssociationSupported;
|
get => FileAssociationHelper.IsTypeAssociationSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AreMimeTypesRegistered
|
||||||
|
{
|
||||||
|
get => FileAssociationHelper.AreMimeTypesRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
public ObservableCollectionExtended<ApplicationData> Applications
|
public ObservableCollectionExtended<ApplicationData> Applications
|
||||||
{
|
{
|
||||||
get => _applications;
|
get => _applications;
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:ext="clr-namespace:Ryujinx.Ava.Common.Markup"
|
xmlns:ext="clr-namespace:Ryujinx.Ava.Common.Markup"
|
||||||
|
xmlns:uih="clr-namespace:Ryujinx.UI.Common.Helper"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels"
|
xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels"
|
||||||
|
xmlns:helper="clr-namespace:Ryujinx.UI.Common.Helper;assembly=Ryujinx.UI.Common"
|
||||||
x:DataType="viewModels:MainWindowViewModel"
|
x:DataType="viewModels:MainWindowViewModel"
|
||||||
x:Class="Ryujinx.Ava.UI.Views.Main.MainMenuBarView">
|
x:Class="Ryujinx.Ava.UI.Views.Main.MainMenuBarView">
|
||||||
<Design.DataContext>
|
<Design.DataContext>
|
||||||
@ -265,8 +267,8 @@
|
|||||||
<MenuItem Command="{Binding InstallFirmwareFromFolder}" Header="{ext:Locale MenuBarFileToolsInstallFirmwareFromDirectory}" Icon="{ext:Icon mdi-folder-cog}" />
|
<MenuItem Command="{Binding InstallFirmwareFromFolder}" Header="{ext:Locale MenuBarFileToolsInstallFirmwareFromDirectory}" Icon="{ext:Icon mdi-folder-cog}" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="{ext:Locale MenuBarToolsManageFileTypes}" IsVisible="{Binding ManageFileTypesVisible}">
|
<MenuItem Header="{ext:Locale MenuBarToolsManageFileTypes}" IsVisible="{Binding ManageFileTypesVisible}">
|
||||||
<MenuItem Header="{ext:Locale MenuBarToolsInstallFileTypes}" Click="InstallFileTypes_Click"/>
|
<MenuItem Header="{ext:Locale MenuBarToolsInstallFileTypes}" Click="InstallFileTypes_Click" IsEnabled="{Binding AreMimeTypesRegistered, Converter={x:Static BoolConverters.Not}}" />
|
||||||
<MenuItem Header="{ext:Locale MenuBarToolsUninstallFileTypes}" Click="UninstallFileTypes_Click"/>
|
<MenuItem Header="{ext:Locale MenuBarToolsUninstallFileTypes}" Click="UninstallFileTypes_Click" IsEnabled="{Binding AreMimeTypesRegistered}" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<Separator />
|
<Separator />
|
||||||
<MenuItem Header="{ext:Locale MenuBarToolsXCITrimmer}" IsEnabled="{Binding EnableNonGameRunningControls}" Click="OpenXCITrimmerWindow" Icon="{ext:Icon fa-solid fa-scissors}" />
|
<MenuItem Header="{ext:Locale MenuBarToolsXCITrimmer}" IsEnabled="{Binding EnableNonGameRunningControls}" Click="OpenXCITrimmerWindow" Icon="{ext:Icon fa-solid fa-scissors}" />
|
||||||
|
Loading…
Reference in New Issue
Block a user