1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:47:24 +08:00

Make WindowsAssociationManager static

Usages/localisation logic TBD
This commit is contained in:
Susko3 2024-02-07 21:45:36 +01:00
parent 57d5717e6a
commit eeba937686
2 changed files with 19 additions and 40 deletions

View File

@ -181,7 +181,7 @@ namespace osu.Desktop
{ {
tools.RemoveShortcutForThisExe(); tools.RemoveShortcutForThisExe();
tools.RemoveUninstallerRegistryEntry(); tools.RemoveUninstallerRegistryEntry();
WindowsAssociationManager.UninstallAssociations(@"osu"); WindowsAssociationManager.UninstallAssociations();
}, onEveryRun: (_, _, _) => }, onEveryRun: (_, _, _) =>
{ {
// While setting the `ProcessAppUserModelId` fixes duplicate icons/shortcuts on the taskbar, it currently // While setting the `ProcessAppUserModelId` fixes duplicate icons/shortcuts on the taskbar, it currently

View File

@ -6,9 +6,6 @@ using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using Microsoft.Win32; using Microsoft.Win32;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Game.Localisation; using osu.Game.Localisation;
@ -16,7 +13,7 @@ using osu.Game.Localisation;
namespace osu.Desktop.Windows namespace osu.Desktop.Windows
{ {
[SupportedOSPlatform("windows")] [SupportedOSPlatform("windows")]
public partial class WindowsAssociationManager : Component public static class WindowsAssociationManager
{ {
public const string SOFTWARE_CLASSES = @"Software\Classes"; public const string SOFTWARE_CLASSES = @"Software\Classes";
@ -54,25 +51,7 @@ namespace osu.Desktop.Windows
new UriAssociation(@"osump", WindowsAssociationManagerStrings.OsuMultiplayer, Icons.Lazer), new UriAssociation(@"osump", WindowsAssociationManagerStrings.OsuMultiplayer, Icons.Lazer),
}; };
[Resolved] public static void InstallAssociations(LocalisationManager? localisation)
private LocalisationManager localisation { get; set; } = null!;
private IBindable<LocalisationParameters> localisationParameters = null!;
[BackgroundDependencyLoader]
private void load()
{
localisationParameters = localisation.CurrentParameters.GetBoundCopy();
InstallAssociations();
}
protected override void LoadComplete()
{
base.LoadComplete();
localisationParameters.ValueChanged += _ => updateDescriptions();
}
public void InstallAssociations()
{ {
try try
{ {
@ -88,7 +67,7 @@ namespace osu.Desktop.Windows
association.Install(classes, EXE_PATH); association.Install(classes, EXE_PATH);
} }
updateDescriptions(); updateDescriptions(localisation);
} }
catch (Exception e) catch (Exception e)
{ {
@ -96,7 +75,7 @@ namespace osu.Desktop.Windows
} }
} }
private void updateDescriptions() private static void updateDescriptions(LocalisationManager? localisation)
{ {
try try
{ {
@ -105,18 +84,10 @@ namespace osu.Desktop.Windows
return; return;
foreach (var association in file_associations) foreach (var association in file_associations)
{ association.UpdateDescription(classes, PROGRAM_ID_PREFIX, getLocalisedString(association.Description));
var b = localisation.GetLocalisedBindableString(association.Description);
association.UpdateDescription(classes, PROGRAM_ID_PREFIX, b.Value);
b.UnbindAll();
}
foreach (var association in uri_associations) foreach (var association in uri_associations)
{ association.UpdateDescription(classes, getLocalisedString(association.Description));
var b = localisation.GetLocalisedBindableString(association.Description);
association.UpdateDescription(classes, b.Value);
b.UnbindAll();
}
NotifyShellUpdate(); NotifyShellUpdate();
} }
@ -124,11 +95,19 @@ namespace osu.Desktop.Windows
{ {
Logger.Log($@"Failed to update file and URI associations: {e.Message}"); Logger.Log($@"Failed to update file and URI associations: {e.Message}");
} }
string getLocalisedString(LocalisableString s)
{
if (localisation == null)
return s.ToString();
var b = localisation.GetLocalisedBindableString(s);
b.UnbindAll();
return b.Value;
}
} }
public void UninstallAssociations() => UninstallAssociations(PROGRAM_ID_PREFIX); public static void UninstallAssociations()
public static void UninstallAssociations(string programIdPrefix)
{ {
try try
{ {
@ -137,7 +116,7 @@ namespace osu.Desktop.Windows
return; return;
foreach (var association in file_associations) foreach (var association in file_associations)
association.Uninstall(classes, programIdPrefix); association.Uninstall(classes, PROGRAM_ID_PREFIX);
foreach (var association in uri_associations) foreach (var association in uri_associations)
association.Uninstall(classes); association.Uninstall(classes);