mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Consolidate metadata properties into one record
This commit is contained in:
+12
-20
@@ -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;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace ZuneModCore;
|
||||
|
||||
public record ModMetadata(string Id, string Title, string Description, string Author);
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock TextTrimming="CharacterEllipsis">
|
||||
<Run Text="{Binding Title, Mode=OneWay}" FontWeight="SemiBold" FontSize="16"/>
|
||||
<Run Text=" By "/><Run Text="{Binding Author, Mode=OneWay}"
|
||||
<Run Text="{Binding Metadata.Title, Mode=OneWay}" FontWeight="SemiBold" FontSize="16"/>
|
||||
<Run Text=" By "/><Run Text="{Binding Metadata.Author, Mode=OneWay}"
|
||||
Foreground="{StaticResource ZuneMediumTextBrush}"/>
|
||||
</TextBlock>
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
Style="{StaticResource ActionButtonStyle}"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Text="{Binding Description}" Grid.Row="1" Foreground="{StaticResource ZuneLightTextBrush}"
|
||||
<TextBlock Text="{Binding Metadata.Description}" Grid.Row="1" Foreground="{StaticResource ZuneLightTextBrush}"
|
||||
FontSize="14" TextWrapping="Wrap"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
@@ -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}'",
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user