Skip to content

Commit

Permalink
Make WindowsAssociationManager static
Browse files Browse the repository at this point in the history
Usages/localisation logic TBD
  • Loading branch information
Susko3 committed Feb 7, 2024
1 parent 57d5717 commit eeba937
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 40 deletions.
2 changes: 1 addition & 1 deletion osu.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private static void setupSquirrel()
{
tools.RemoveShortcutForThisExe();
tools.RemoveUninstallerRegistryEntry();
WindowsAssociationManager.UninstallAssociations(@"osu");
WindowsAssociationManager.UninstallAssociations();
}, onEveryRun: (_, _, _) =>
{
// While setting the `ProcessAppUserModelId` fixes duplicate icons/shortcuts on the taskbar, it currently
Expand Down
57 changes: 18 additions & 39 deletions osu.Desktop/Windows/WindowsAssociationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Microsoft.Win32;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using osu.Game.Localisation;

namespace osu.Desktop.Windows
{
[SupportedOSPlatform("windows")]
public partial class WindowsAssociationManager : Component
public static class WindowsAssociationManager
{
public const string SOFTWARE_CLASSES = @"Software\Classes";

Expand Down Expand Up @@ -54,25 +51,7 @@ public partial class WindowsAssociationManager : Component
new UriAssociation(@"osump", WindowsAssociationManagerStrings.OsuMultiplayer, Icons.Lazer),
};

[Resolved]
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()
public static void InstallAssociations(LocalisationManager? localisation)
{
try
{
Expand All @@ -88,15 +67,15 @@ public void InstallAssociations()
association.Install(classes, EXE_PATH);
}

updateDescriptions();
updateDescriptions(localisation);
}
catch (Exception e)
{
Logger.Log(@$"Failed to install file and URI associations: {e.Message}");
}
}

private void updateDescriptions()
private static void updateDescriptions(LocalisationManager? localisation)
{
try
{
Expand All @@ -105,30 +84,30 @@ private void updateDescriptions()
return;

foreach (var association in file_associations)
{
var b = localisation.GetLocalisedBindableString(association.Description);
association.UpdateDescription(classes, PROGRAM_ID_PREFIX, b.Value);
b.UnbindAll();
}
association.UpdateDescription(classes, PROGRAM_ID_PREFIX, getLocalisedString(association.Description));

foreach (var association in uri_associations)
{
var b = localisation.GetLocalisedBindableString(association.Description);
association.UpdateDescription(classes, b.Value);
b.UnbindAll();
}
association.UpdateDescription(classes, getLocalisedString(association.Description));

NotifyShellUpdate();
}
catch (Exception e)
{
Logger.Log($@"Failed to update file and URI associations: {e.Message}");
}
}

public void UninstallAssociations() => UninstallAssociations(PROGRAM_ID_PREFIX);
string getLocalisedString(LocalisableString s)
{
if (localisation == null)
return s.ToString();

var b = localisation.GetLocalisedBindableString(s);
b.UnbindAll();
return b.Value;
}
}

public static void UninstallAssociations(string programIdPrefix)
public static void UninstallAssociations()
{
try
{
Expand All @@ -137,7 +116,7 @@ public static void UninstallAssociations(string programIdPrefix)
return;

foreach (var association in file_associations)
association.Uninstall(classes, programIdPrefix);
association.Uninstall(classes, PROGRAM_ID_PREFIX);

foreach (var association in uri_associations)
association.Uninstall(classes);
Expand Down

0 comments on commit eeba937

Please sign in to comment.