mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Remove ZuneInstallDir property from base Mod
This commit is contained in:
@@ -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<string?> Apply();
|
||||
|
||||
@@ -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<BackgroundImageMod>
|
||||
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))
|
||||
|
||||
@@ -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<VideoSyncMod>
|
||||
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<string?> Apply()
|
||||
|
||||
@@ -28,7 +28,7 @@ public class WebservicesModFactory : DIModFactoryBase<WebservicesMod>
|
||||
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))
|
||||
|
||||
@@ -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<Mod> CreateModInstance(IModFactory<Mod> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user