diff --git a/ZuneModCore/Mod.cs b/ZuneModCore/Mod.cs index d8630cf..f83cf97 100644 --- a/ZuneModCore/Mod.cs +++ b/ZuneModCore/Mod.cs @@ -27,32 +27,24 @@ public abstract class Mod public string ZuneInstallDir { get; set; } = DefaultZuneInstallDir; private static List? _mods; - public static IReadOnlyList AvailableMods + public static IReadOnlyList GetAvailableMods() { - get + if (_mods is null) { - if (_mods is null) + _mods = new(AvailableModTypes.Count); + var services = CommunityToolkit.Mvvm.DependencyInjection.Ioc.Default; + foreach (var modType in AvailableModTypes) { - _mods = new(AvailableModTypes.Count); - var services = CommunityToolkit.Mvvm.DependencyInjection.Ioc.Default; - foreach (var modType in AvailableModTypes) - { - var instance = ActivatorUtilities.CreateInstance(services, modType); - if (instance is Mod mod) - _mods.Add(mod); - } + var instance = ActivatorUtilities.CreateInstance(services, modType); + if (instance is Mod mod) + _mods.Add(mod); } - return _mods; } + + return _mods; } - public abstract string Id { get; } - - public abstract string Title { get; } - - public abstract string Description { get; } - - public abstract string Author { get; } + public abstract ModMetadata Metadata { get; } public virtual AbstractUICollection? GetDefaultOptionsUI() => null; @@ -74,7 +66,7 @@ public abstract class Mod { get { - string dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ZuneModCore", Id); + string dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ZuneModCore", Metadata.Id); // Create the directory just in case the consumer assumes the folder exists already Directory.CreateDirectory(dir); return dir; diff --git a/ZuneModCore/ModMetadata.cs b/ZuneModCore/ModMetadata.cs new file mode 100644 index 0000000..815ba43 --- /dev/null +++ b/ZuneModCore/ModMetadata.cs @@ -0,0 +1,3 @@ +namespace ZuneModCore; + +public record ModMetadata(string Id, string Title, string Description, string Author); diff --git a/ZuneModCore/Mods/BackgroundImageMod.cs b/ZuneModCore/Mods/BackgroundImageMod.cs index 804c384..eb9845a 100644 --- a/ZuneModCore/Mods/BackgroundImageMod.cs +++ b/ZuneModCore/Mods/BackgroundImageMod.cs @@ -11,13 +11,11 @@ namespace ZuneModCore.Mods; public class BackgroundImageMod : Mod { - public override string Id => nameof(BackgroundImageMod); + private const string Description = "Replaces the \"Zero\" background with an image of your choice."; - public override string Title => "Background Image"; + private const string Author = "Joshua \"Yoshi\" Askharoun"; - public override string Description => "Replaces the \"Zero\" background with an image of your choice."; - - public override string Author => "Joshua \"Yoshi\" Askharoun"; + public override ModMetadata Metadata => new(nameof(BackgroundImageMod), "Background Image", Description, Author); public override AbstractUICollection? GetDefaultOptionsUI() { diff --git a/ZuneModCore/Mods/FeaturesOverrideMod.cs b/ZuneModCore/Mods/FeaturesOverrideMod.cs index be9a30a..5a7d279 100644 --- a/ZuneModCore/Mods/FeaturesOverrideMod.cs +++ b/ZuneModCore/Mods/FeaturesOverrideMod.cs @@ -12,20 +12,17 @@ public class FeaturesOverrideMod : Mod, IAsyncInit { private const string ZUNE_FEATURESOVERRIDE_REGKEY = RegEdit.ZUNE_REG_PATH + "FeaturesOverride"; - public override string Id => nameof(FeaturesOverrideMod); - - public override string Title => "Features Override"; - - public override string Description => "Re-enables access to some features disabled by Microsoft, such as the Social and Marketplace tabs.\r\n" + + private const string Description = "Re-enables access to some features disabled by Microsoft, such as the Social and Marketplace tabs.\r\n" + "Does not restore functionality of those features, but shows them in the software."; - public override string Author => "Rafael Rivera"; + private const string Author = "Rafael Rivera"; + + public override ModMetadata Metadata => new(nameof(FeaturesOverrideMod), "Features Override", Description, Author); public override AbstractUICollection? GetDefaultOptionsUI() { AbstractUICollection optionsUi = new(nameof(FeaturesOverrideMod)) { - // We don't know what some of these overrides do exactly, so hide them from the user. // The ID is the name of the registry key, the label is the display name new AbstractBoolean("Apps", "Apps"), diff --git a/ZuneModCore/Mods/MbidLocatorMod.cs b/ZuneModCore/Mods/MbidLocatorMod.cs index 02db4df..c312133 100644 --- a/ZuneModCore/Mods/MbidLocatorMod.cs +++ b/ZuneModCore/Mods/MbidLocatorMod.cs @@ -16,15 +16,13 @@ public class MbidLocatorMod : Mod private static readonly string[] KNOWN_EXTS = [".mp3", ".mp4", ".m4a", ".wav"]; - public override string Id => nameof(MbidLocatorMod); - - public override string Title => "MusicBrainz ID Locator"; - - public override string Description => "Puts MusicBrainz IDs added by MusicBrainz Picard where the Zune " + + private const string Description = "Puts MusicBrainz IDs added by MusicBrainz Picard where the Zune " + "software can use it to show additional information provided by Community Webservices.\r\n" + "Note that this will only have an effect if you have used MusicBrainz Picard on your music library."; - public override string Author => "Joshua \"Yoshi\" Askharoun"; + private const string Author = "Joshua \"Yoshi\" Askharoun"; + + public override ModMetadata Metadata => new(nameof(MbidLocatorMod), "MusicBrainz ID Locator", Description, Author); public override AbstractUICollection? GetDefaultOptionsUI() { diff --git a/ZuneModCore/Mods/VideoSyncMod.cs b/ZuneModCore/Mods/VideoSyncMod.cs index d302577..c227b11 100644 --- a/ZuneModCore/Mods/VideoSyncMod.cs +++ b/ZuneModCore/Mods/VideoSyncMod.cs @@ -10,14 +10,12 @@ public class VideoSyncMod : Mod { private const int ZUNEENCENG_WMVCORA_OFFSET = 0x161E; - public override string Title => "Fix Video Sync"; - - public override string Description => + private const string Description = "Resolves \"Error C00D11CD\" when attempting to sync video to a Zune device using Windows 10 1607 (Anniversary Update) or newer"; - public override string Author => "sylvathemoth"; + private const string Author = "sylvathemoth"; - public override string Id => nameof(VideoSyncMod); + public override ModMetadata Metadata => new(nameof(VideoSyncMod), "Fix Video Sync", Description, Author); public override async Task Apply() { diff --git a/ZuneModCore/Mods/WebservicesMod.cs b/ZuneModCore/Mods/WebservicesMod.cs index fca2bb1..3d86c1f 100644 --- a/ZuneModCore/Mods/WebservicesMod.cs +++ b/ZuneModCore/Mods/WebservicesMod.cs @@ -34,14 +34,12 @@ public class WebservicesMod : Mod, IAsyncInit private HttpClient _client; private CancellationTokenSource _cts = new(); - public override string Id => nameof(WebservicesMod); - - public override string Title => "Community Webservices"; - - public override string Description => "Partially restores online features such as the Marketplace by patching the Zune desktop software " + + private const string Description = "Partially restores online features such as the Marketplace by patching the Zune desktop software " + "to use the community's recreation of Microsoft's Zune servers at zunes.me (instead of zune.net)."; - public override string Author => "Joshua \"Yoshi\" Askharoun"; + private const string Author = "Joshua \"Yoshi\" Askharoun"; + + public override ModMetadata Metadata => new(nameof(WebservicesMod), "Community Webservices", Description, Author); public override AbstractUICollection? GetDefaultOptionsUI() { diff --git a/ZuneModdingHelper/Pages/ModsPage.xaml b/ZuneModdingHelper/Pages/ModsPage.xaml index afdec65..9fa7e8e 100644 --- a/ZuneModdingHelper/Pages/ModsPage.xaml +++ b/ZuneModdingHelper/Pages/ModsPage.xaml @@ -23,8 +23,8 @@ - - + @@ -41,7 +41,7 @@ Style="{StaticResource ActionButtonStyle}"/> - diff --git a/ZuneModdingHelper/Pages/ModsPage.xaml.cs b/ZuneModdingHelper/Pages/ModsPage.xaml.cs index 793f891..6075354 100644 --- a/ZuneModdingHelper/Pages/ModsPage.xaml.cs +++ b/ZuneModdingHelper/Pages/ModsPage.xaml.cs @@ -31,10 +31,11 @@ namespace ZuneModdingHelper.Pages if (!TryGetModFromControl(sender, out var mod)) return; + var modTitle = mod.Metadata.Title; ProgressDialogViewModel progDialog = new() { Title = MOD_MANAGER_TITLE, - Description = $"Preparing to apply '{mod.Title}'...", + Description = $"Preparing to apply '{modTitle}'...", ShowAffirmativeButton = false, IsIndeterminate = true, Maximum = 3, @@ -49,11 +50,11 @@ namespace ZuneModdingHelper.Pages ++progDialog.Progress; // Stage 1: Display AbstractUI for options - progDialog.Description = $"Awaiting options for '{mod.Title}'..."; + progDialog.Description = $"Awaiting options for '{modTitle}'..."; if (mod.OptionsUI != null) { var optionsDialog = new AbstractUIGroupDialog(mod.OptionsUI); - optionsDialog.Title = optionsDialog.Title + " | " + mod.Title; + optionsDialog.Title = optionsDialog.Title + " | " + modTitle; bool? optionsResult = optionsDialog.ShowDialog(); if (!(optionsResult.HasValue && optionsResult.Value)) { @@ -65,7 +66,7 @@ namespace ZuneModdingHelper.Pages ++progDialog.Progress; // Stage 2: Apply mod - progDialog.Description = $"Applying '{mod.Title}'..."; + progDialog.Description = $"Applying '{modTitle}'..."; string applyResult = await mod.Apply(); if (applyResult != null) { @@ -74,7 +75,7 @@ namespace ZuneModdingHelper.Pages DialogViewModel errorDialog = new() { Title = MOD_MANAGER_TITLE, - Description = $"Failed to apply '{mod.Title}'.\r\n{applyResult}", + Description = $"Failed to apply '{modTitle}'.\r\n{applyResult}", }; WeakReferenceMessenger.Default.Send(new ShowDialogMessage(errorDialog)); @@ -86,7 +87,7 @@ namespace ZuneModdingHelper.Pages WeakReferenceMessenger.Default.Send(new ShowDialogMessage(new() { Title = MOD_MANAGER_TITLE, - Description = $"Successfully applied '{mod.Title}'", + Description = $"Successfully applied '{modTitle}'", })); } @@ -95,10 +96,11 @@ namespace ZuneModdingHelper.Pages if (!TryGetModFromControl(sender, out var mod)) return; + var modTitle = mod.Metadata.Title; ProgressDialogViewModel progDialog = new() { Title = MOD_MANAGER_TITLE, - Description = $"Preparing to reset '{mod.Title}'...", + Description = $"Preparing to reset '{modTitle}'...", ShowAffirmativeButton = false, IsIndeterminate = true, Maximum = 2, @@ -119,7 +121,7 @@ namespace ZuneModdingHelper.Pages // optionsDialog.ShowDialog(); //} - progDialog.Description = $"Resetting '{mod.Title}'..."; + progDialog.Description = $"Resetting '{modTitle}'..."; string resetResult = await mod.Reset(); if (resetResult != null) { @@ -128,7 +130,7 @@ namespace ZuneModdingHelper.Pages DialogViewModel errorDialog = new() { Title = MOD_MANAGER_TITLE, - Description = $"Failed to reset '{mod.Title}'.\r\n{resetResult}", + Description = $"Failed to reset '{modTitle}'.\r\n{resetResult}", }; WeakReferenceMessenger.Default.Send(new ShowDialogMessage(errorDialog)); @@ -141,7 +143,7 @@ namespace ZuneModdingHelper.Pages WeakReferenceMessenger.Default.Send(new ShowDialogMessage(new() { Title = MOD_MANAGER_TITLE, - Description = $"Successfully reset '{mod.Title}'", + Description = $"Successfully reset '{modTitle}'", })); }