Consolidate metadata properties into one record

This commit is contained in:
Yoshi Askharoun
2024-05-21 20:14:57 -05:00
parent 249681c7bd
commit d357711b91
9 changed files with 48 additions and 62 deletions
+12 -20
View File
@@ -27,32 +27,24 @@ public abstract class Mod
public string ZuneInstallDir { get; set; } = DefaultZuneInstallDir;
private static List<Mod>? _mods;
public static IReadOnlyList<Mod> AvailableMods
public static IReadOnlyList<Mod> 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;
+3
View File
@@ -0,0 +1,3 @@
namespace ZuneModCore;
public record ModMetadata(string Id, string Title, string Description, string Author);
+3 -5
View File
@@ -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()
{
+4 -7
View File
@@ -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"),
+4 -6
View File
@@ -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()
{
+3 -5
View File
@@ -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<string?> Apply()
{
+4 -6
View File
@@ -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()
{