Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up windows association manager code #31450

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

peppy
Copy link
Member

@peppy peppy commented Jan 8, 2025

I'm supposed to be working on this logic to add support to stable, but I couldn't work with this class so I spent 10 minutes fixing it up.

  • No records for anything that isn't a barebones model
  • Removing weird null calls to setup defaults. The localisation flow is now completely isolated and not required to be called until we want to support it.

@@ -189,14 +190,16 @@ public void Install()
// register a program id for the given extension
using (var programKey = classes.CreateSubKey(programId))
{
programKey.SetValue(null, description);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default that was previously written in UpdateDescription(null) is now written here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that this is passing LocalisableString to SetValue() directly is unsettling me. Looking at dotnet/runtime source it should do what we'd want here but the API is very magic-typed so I'd prefer an explicit .ToString() here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triggers an inspection unfortunately :(

JetBrains Rider 2025-01-08 at 10 50 17

Would this work for you?

diff --git a/osu.Desktop/Windows/WindowsAssociationManager.cs b/osu.Desktop/Windows/WindowsAssociationManager.cs
index 98e77b1ff6..d30fd7878b 100644
--- a/osu.Desktop/Windows/WindowsAssociationManager.cs
+++ b/osu.Desktop/Windows/WindowsAssociationManager.cs
@@ -217,7 +217,10 @@ public void LocaliseDescription(LocalisationManager localisationManager)
                 if (classes == null) return;
 
                 using (var programKey = classes.OpenSubKey(programId, true))
-                    programKey?.SetValue(null, localisationManager.GetLocalisedString(description));
+                {
+                    string localisedString = localisationManager.GetLocalisedString(description);
+                    programKey?.SetValue(null, localisedString);
+                }
             }
 
             /// <summary>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhhh that's the wrong call that you're trying to do this on no? Your patch seems to be touching line 220, this is line 193.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed.

{
protocolKey.SetValue(URL_PROTOCOL, string.Empty);
protocolKey.SetValue(null, $@"URL:{description}");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default that was previously written in UpdateDescription(null) is now written here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with the URL: prefix in the string? That looks new?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that is hidden away, I completely failed to spot it...... Sure yeah.

Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good to me

@peppy peppy merged commit 2e10f83 into ppy:master Jan 8, 2025
10 checks passed
@peppy peppy deleted the association-manager-cleanup branch January 14, 2025 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants