mirror of
https://github.com/ppy/osu.git
synced 2025-01-18 11:52:54 +08:00
Change association localisation flow to make logical sense
This commit is contained in:
parent
d04947d400
commit
b628880214
@ -56,14 +56,13 @@ namespace osu.Desktop.Windows
|
|||||||
/// Installs file and URI associations.
|
/// Installs file and URI associations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Call <see cref="UpdateDescriptions"/> in a timely fashion to keep descriptions up-to-date and localised.
|
/// Call <see cref="LocaliseDescriptions"/> in a timely fashion to keep descriptions up-to-date and localised.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static void InstallAssociations()
|
public static void InstallAssociations()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
updateAssociations();
|
updateAssociations();
|
||||||
updateDescriptions(null); // write default descriptions in case `UpdateDescriptions()` is not called.
|
|
||||||
NotifyShellUpdate();
|
NotifyShellUpdate();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -76,17 +75,13 @@ namespace osu.Desktop.Windows
|
|||||||
/// Updates associations with latest definitions.
|
/// Updates associations with latest definitions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Call <see cref="UpdateDescriptions"/> in a timely fashion to keep descriptions up-to-date and localised.
|
/// Call <see cref="LocaliseDescriptions"/> in a timely fashion to keep descriptions up-to-date and localised.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static void UpdateAssociations()
|
public static void UpdateAssociations()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
updateAssociations();
|
updateAssociations();
|
||||||
|
|
||||||
// TODO: Remove once UpdateDescriptions() is called as specified in the xmldoc.
|
|
||||||
updateDescriptions(null); // always write default descriptions, in case of updating from an older version in which file associations were not implemented/installed
|
|
||||||
|
|
||||||
NotifyShellUpdate();
|
NotifyShellUpdate();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -95,11 +90,17 @@ namespace osu.Desktop.Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateDescriptions(LocalisationManager localisationManager)
|
// TODO: call this sometime.
|
||||||
|
public static void LocaliseDescriptions(LocalisationManager localisationManager)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
updateDescriptions(localisationManager);
|
foreach (var association in file_associations)
|
||||||
|
association.LocaliseDescription(localisationManager);
|
||||||
|
|
||||||
|
foreach (var association in uri_associations)
|
||||||
|
association.LocaliseDescription(localisationManager);
|
||||||
|
|
||||||
NotifyShellUpdate();
|
NotifyShellUpdate();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -140,17 +141,6 @@ namespace osu.Desktop.Windows
|
|||||||
association.Install();
|
association.Install();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateDescriptions(LocalisationManager? localisation)
|
|
||||||
{
|
|
||||||
foreach (var association in file_associations)
|
|
||||||
association.UpdateDescription(getLocalisedString(association.Description));
|
|
||||||
|
|
||||||
foreach (var association in uri_associations)
|
|
||||||
association.UpdateDescription(getLocalisedString(association.Description));
|
|
||||||
|
|
||||||
string getLocalisedString(LocalisableString s) => localisation?.GetLocalisedString(s) ?? s.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Native interop
|
#region Native interop
|
||||||
|
|
||||||
[DllImport("Shell32.dll")]
|
[DllImport("Shell32.dll")]
|
||||||
@ -200,6 +190,8 @@ namespace osu.Desktop.Windows
|
|||||||
// register a program id for the given extension
|
// register a program id for the given extension
|
||||||
using (var programKey = classes.CreateSubKey(programId))
|
using (var programKey = classes.CreateSubKey(programId))
|
||||||
{
|
{
|
||||||
|
programKey.SetValue(null, description);
|
||||||
|
|
||||||
using (var defaultIconKey = programKey.CreateSubKey(default_icon))
|
using (var defaultIconKey = programKey.CreateSubKey(default_icon))
|
||||||
defaultIconKey.SetValue(null, iconPath);
|
defaultIconKey.SetValue(null, iconPath);
|
||||||
|
|
||||||
@ -219,13 +211,13 @@ namespace osu.Desktop.Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDescription(string description)
|
public void LocaliseDescription(LocalisationManager localisationManager)
|
||||||
{
|
{
|
||||||
using var classes = Registry.CurrentUser.OpenSubKey(software_classes, true);
|
using var classes = Registry.CurrentUser.OpenSubKey(software_classes, true);
|
||||||
if (classes == null) return;
|
if (classes == null) return;
|
||||||
|
|
||||||
using (var programKey = classes.OpenSubKey(programId, true))
|
using (var programKey = classes.OpenSubKey(programId, true))
|
||||||
programKey?.SetValue(null, description);
|
programKey?.SetValue(null, localisationManager.GetLocalisedString(description));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -280,6 +272,7 @@ namespace osu.Desktop.Windows
|
|||||||
|
|
||||||
using (var protocolKey = classes.CreateSubKey(protocol))
|
using (var protocolKey = classes.CreateSubKey(protocol))
|
||||||
{
|
{
|
||||||
|
protocolKey.SetValue(null, $@"URL:{description}");
|
||||||
protocolKey.SetValue(url_protocol, string.Empty);
|
protocolKey.SetValue(url_protocol, string.Empty);
|
||||||
|
|
||||||
using (var defaultIconKey = protocolKey.CreateSubKey(default_icon))
|
using (var defaultIconKey = protocolKey.CreateSubKey(default_icon))
|
||||||
@ -290,13 +283,13 @@ namespace osu.Desktop.Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDescription(string description)
|
public void LocaliseDescription(LocalisationManager localisationManager)
|
||||||
{
|
{
|
||||||
using var classes = Registry.CurrentUser.OpenSubKey(software_classes, true);
|
using var classes = Registry.CurrentUser.OpenSubKey(software_classes, true);
|
||||||
if (classes == null) return;
|
if (classes == null) return;
|
||||||
|
|
||||||
using (var protocolKey = classes.OpenSubKey(protocol, true))
|
using (var protocolKey = classes.OpenSubKey(protocol, true))
|
||||||
protocolKey?.SetValue(null, $@"URL:{description}");
|
protocolKey?.SetValue(null, $@"URL:{localisationManager.GetLocalisedString(description)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Uninstall()
|
public void Uninstall()
|
||||||
|
Loading…
Reference in New Issue
Block a user