From beee8543cf78c5c13e02900bcf2a9eae128da861 Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Tue, 2 Sep 2025 00:26:45 -0700 Subject: [PATCH] Remove ZuneInstallDir property from base Mod --- ZuneModCore/Mod.cs | 4 ---- ZuneModCore/Mods/BackgroundImageMod.cs | 5 ++++- ZuneModCore/Mods/VideoSyncMod.cs | 5 ++++- ZuneModCore/Mods/WebservicesMod.cs | 4 +++- ZuneModdingHelper/Pages/ModsPage.xaml.cs | 24 +++++++++++++----------- ZuneModdingHelper/Services/Settings.cs | 19 ++++++++++++++++++- 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/ZuneModCore/Mod.cs b/ZuneModCore/Mod.cs index 395a2e0..ae22290 100644 --- a/ZuneModCore/Mod.cs +++ b/ZuneModCore/Mod.cs @@ -8,12 +8,8 @@ namespace ZuneModCore; public abstract class Mod(ModMetadata metadata) { - public static string DefaultZuneInstallDir { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Zune"); - public ModMetadata Metadata { get; } = metadata; - public string ZuneInstallDir { get; set; } = DefaultZuneInstallDir; - public virtual AbstractUICollection? GetDefaultOptionsUI() => null; public abstract Task Apply(); diff --git a/ZuneModCore/Mods/BackgroundImageMod.cs b/ZuneModCore/Mods/BackgroundImageMod.cs index 7783463..9510ba4 100644 --- a/ZuneModCore/Mods/BackgroundImageMod.cs +++ b/ZuneModCore/Mods/BackgroundImageMod.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.IO; using System.Threading.Tasks; using Vestris.ResourceLib; +using ZuneModCore.Services; using ZuneModCore.Win32; namespace ZuneModCore.Mods; @@ -19,8 +20,10 @@ public class BackgroundImageModFactory : DIModFactoryBase Description, Author, new(1, 0)); } -public class BackgroundImageMod(ModMetadata metadata) : Mod(metadata) +public class BackgroundImageMod(ModMetadata metadata, IModCoreConfig modConfig) : Mod(metadata) { + public string ZuneInstallDir => modConfig.ZuneInstallDir; + public override AbstractUICollection? GetDefaultOptionsUI() { AbstractUICollection optionsUi = new(nameof(BackgroundImageMod)) diff --git a/ZuneModCore/Mods/VideoSyncMod.cs b/ZuneModCore/Mods/VideoSyncMod.cs index be9d47d..4392c69 100644 --- a/ZuneModCore/Mods/VideoSyncMod.cs +++ b/ZuneModCore/Mods/VideoSyncMod.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Threading.Tasks; +using ZuneModCore.Services; namespace ZuneModCore.Mods; @@ -17,8 +18,10 @@ public class VideoSyncModFactory : DIModFactoryBase Description, Author, new(2, 0)); } -public class VideoSyncMod(ModMetadata metadata) : Mod(metadata) +public class VideoSyncMod(ModMetadata metadata, IModCoreConfig modConfig) : Mod(metadata) { + public string ZuneInstallDir => modConfig.ZuneInstallDir; + private const int ZUNEENCENG_WMVCORA_OFFSET = 0x161E; public override async Task Apply() diff --git a/ZuneModCore/Mods/WebservicesMod.cs b/ZuneModCore/Mods/WebservicesMod.cs index 8e7c0fe..0d3f4d3 100644 --- a/ZuneModCore/Mods/WebservicesMod.cs +++ b/ZuneModCore/Mods/WebservicesMod.cs @@ -28,7 +28,7 @@ public class WebservicesModFactory : DIModFactoryBase Description, Author, new(1, 1)); } -public partial class WebservicesMod(ModMetadata metadata) : Mod(metadata), IAsyncInit +public partial class WebservicesMod(ModMetadata metadata, IModCoreConfig modConfig) : Mod(metadata), IAsyncInit { private const int ZUNESERVICES_ENDPOINTS_BLOCK_OFFSET = 0x14D60; private const int ZUNESERVICES_ENDPOINTS_BLOCK_LENGTH = 0x884; @@ -68,6 +68,8 @@ public partial class WebservicesMod(ModMetadata metadata) : Mod(metadata), IAsyn private CancellationTokenSource _cts = new(); private string _methodFile; + public string ZuneInstallDir => modConfig.ZuneInstallDir; + public override AbstractUICollection? GetDefaultOptionsUI() { AbstractUICollection optionsUi = new(nameof(FeaturesOverrideMod)) diff --git a/ZuneModdingHelper/Pages/ModsPage.xaml.cs b/ZuneModdingHelper/Pages/ModsPage.xaml.cs index da49e73..068d20b 100644 --- a/ZuneModdingHelper/Pages/ModsPage.xaml.cs +++ b/ZuneModdingHelper/Pages/ModsPage.xaml.cs @@ -21,12 +21,10 @@ namespace ZuneModdingHelper.Pages { private const string MOD_MANAGER_TITLE = "MOD MANAGER"; - private readonly IModCoreConfig _modConfig; private readonly Settings _settings; - public ModsPage(IModCoreConfig modConfig, Settings settings) + public ModsPage(Settings settings) { - _modConfig = modConfig; _settings = settings; InitializeComponent(); @@ -50,10 +48,7 @@ namespace ZuneModdingHelper.Pages WeakReferenceMessenger.Default.Send(new ShowDialogMessage(progDialog)); // Stage 0: Initialize mod - var mod = modFactory.Create(Ioc.Default); - mod.ZuneInstallDir = _modConfig.ZuneInstallDir; - if (mod is IAsyncInit initMod) - await initMod.InitAsync(); + var mod = await CreateModInstance(modFactory); ++progDialog.Progress; // Stage 1: Display AbstractUI for options @@ -115,10 +110,7 @@ namespace ZuneModdingHelper.Pages }; WeakReferenceMessenger.Default.Send(new ShowDialogMessage(progDialog)); - var mod = modFactory.Create(Ioc.Default); - mod.ZuneInstallDir = _modConfig.ZuneInstallDir; - if (mod is IAsyncInit initMod) - await initMod.InitAsync(); + var mod = await CreateModInstance(modFactory); ++progDialog.Progress; // TODO: Implement AbstractUI display for reset options @@ -161,6 +153,16 @@ namespace ZuneModdingHelper.Pages return modFactory is not null; } + private static async Task CreateModInstance(IModFactory modFactory) + { + var mod = modFactory.Create(Ioc.Default); + + if (mod is IAsyncInit initMod) + await initMod.InitAsync(); + + return mod; + } + private async Task ShowDonationRequestDialog(bool _) { // Close success dialog diff --git a/ZuneModdingHelper/Services/Settings.cs b/ZuneModdingHelper/Services/Settings.cs index 52d0b5e..bb5cf06 100644 --- a/ZuneModdingHelper/Services/Settings.cs +++ b/ZuneModdingHelper/Services/Settings.cs @@ -4,6 +4,7 @@ using System.IO; using System; using ZuneModCore; using ZuneModCore.Services; +using System.Collections.Generic; namespace ZuneModdingHelper.Services; @@ -22,7 +23,7 @@ public class Settings(IModifiableFolder folder) : SettingsBase(folder, SystemTex public string ZuneInstallDir { - get => GetSetting(() => Mod.DefaultZuneInstallDir); + get => GetSetting(GetDefaultZuneInstallDir); set => SetSetting(value); } @@ -37,6 +38,22 @@ public class Settings(IModifiableFolder folder) : SettingsBase(folder, SystemTex get => GetSetting(() => DonationRequestInterval.OneMonth); set => SetSetting(value); } + + private static string GetDefaultZuneInstallDir() + { + // Check common install locations for Zune + string[] commonPaths = [ + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Zune"), + @"C:\Program Files\Zune", + @"C:\Program Files (x86)\Zune", + ]; + + foreach (var path in commonPaths) + if (Directory.Exists(path)) + return path; + + return commonPaths[0]; + } } public enum DonationRequestInterval