2022-03-01 14:14:11 -06:00
|
|
|
using CommunityToolkit.Diagnostics;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using ZuneModCore.Mods;
|
|
|
|
|
|
|
|
|
|
namespace ZuneModCore
|
|
|
|
|
{
|
|
|
|
|
public static class ModManager
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A list of all available mods.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly IReadOnlyList<Mod> AvailableMods = new List<Mod>
|
|
|
|
|
{
|
|
|
|
|
new VideoSyncMod(),
|
2023-08-01 02:04:32 -05:00
|
|
|
#if DEBUG
|
2022-08-16 12:27:48 -05:00
|
|
|
new Win11DriverMod(),
|
2023-08-01 02:04:32 -05:00
|
|
|
#endif
|
2022-08-16 12:27:48 -05:00
|
|
|
new FeaturesOverrideMod(),
|
2022-03-01 14:14:11 -06:00
|
|
|
new WebservicesMod(),
|
|
|
|
|
new BackgroundImageMod(),
|
|
|
|
|
new MbidLocatorMod(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static string ZuneInstallDir { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Zune");
|
|
|
|
|
|
|
|
|
|
public static readonly ReleaseVersion CurrentVersion = new(2021, 12, 30, 0, Phase.Alpha);
|
|
|
|
|
|
|
|
|
|
internal static readonly string CoreStorageDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ZuneModCore");
|
|
|
|
|
|
|
|
|
|
private static readonly string CoreStatusFile = Path.Combine(CoreStorageDir, "ModStatus.json");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Marks the specified mod as applied in the status file.
|
|
|
|
|
/// </summary>
|
2022-03-03 14:26:05 -06:00
|
|
|
internal static void MarkApplied(string modId) => MarkStatus(modId, true);
|
2022-03-01 14:14:11 -06:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Marks the specified mod as reset in the status file.
|
|
|
|
|
/// </summary>
|
2022-03-03 14:26:05 -06:00
|
|
|
internal static void MarkReset(string modId) => MarkStatus(modId, false);
|
2022-03-01 14:14:11 -06:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the status of the specified mod in the status file.
|
|
|
|
|
/// </summary>
|
2022-03-03 14:26:05 -06:00
|
|
|
private static void MarkStatus(string modId, bool status)
|
2022-03-01 14:14:11 -06:00
|
|
|
{
|
2022-03-03 14:26:05 -06:00
|
|
|
var model = GetOrCreateStatusModel();
|
2022-03-01 14:14:11 -06:00
|
|
|
|
|
|
|
|
bool curStatus = model.InstalledMods.ContainsKey(modId);
|
|
|
|
|
if (curStatus && !status)
|
|
|
|
|
{
|
|
|
|
|
model.InstalledMods.Remove(modId);
|
|
|
|
|
}
|
|
|
|
|
else if (!curStatus && status)
|
|
|
|
|
{
|
|
|
|
|
model.InstalledMods.Add(modId, CurrentVersion);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 14:26:05 -06:00
|
|
|
string json = JsonSerializer.Serialize(model);
|
|
|
|
|
File.WriteAllText(CoreStatusFile, json);
|
2022-03-01 14:14:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the status of the specified mod from the status file.
|
|
|
|
|
/// </summary>
|
2022-03-03 14:26:05 -06:00
|
|
|
internal static bool CheckStatus(string modId)
|
2022-03-01 14:14:11 -06:00
|
|
|
{
|
2022-03-03 14:26:05 -06:00
|
|
|
var model = GetOrCreateStatusModel();
|
2022-03-01 14:14:11 -06:00
|
|
|
return model.InstalledMods.ContainsKey(modId);
|
|
|
|
|
}
|
2022-03-03 14:26:05 -06:00
|
|
|
|
|
|
|
|
private static StatusModel GetOrCreateStatusModel()
|
|
|
|
|
{
|
|
|
|
|
StatusModel? model = null;
|
|
|
|
|
if (File.Exists(CoreStatusFile))
|
|
|
|
|
{
|
|
|
|
|
string json = File.ReadAllText(CoreStatusFile);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(json))
|
|
|
|
|
model = JsonSerializer.Deserialize<StatusModel>(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model ??= new()
|
|
|
|
|
{
|
|
|
|
|
Version = CurrentVersion,
|
|
|
|
|
InstalledMods = new()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Guard.IsNotNull(model, nameof(model));
|
|
|
|
|
return model;
|
|
|
|
|
}
|
2022-03-01 14:14:11 -06:00
|
|
|
}
|
|
|
|
|
}
|