Files
ZuneModdingHelper/ZuneModCore/Mods/FeaturesOverrideMod.cs
T

123 lines
5.4 KiB
C#
Raw Normal View History

2021-04-25 22:59:36 -05:00
using OwlCore.AbstractUI.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
2021-05-26 11:26:08 -05:00
using ZuneModCore.Win32;
2021-04-25 22:59:36 -05:00
namespace ZuneModCore.Mods
{
public class FeaturesOverrideMod : Mod
{
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" +
"Does not restore functionality of those features, but shows them in the software.";
2021-04-26 18:13:55 -05:00
public override string Author => "Rafael Rivera";
2021-04-26 18:05:19 -05:00
2021-08-05 20:45:26 -05:00
public override AbstractUIElementGroup? GetDefaultOptionsUI()
2021-04-25 22:59:36 -05:00
{
2021-08-05 20:45:26 -05:00
return new(nameof(FeaturesOverrideMod))
2021-04-25 22:59:36 -05:00
{
2021-08-05 20:45:26 -05:00
Title = "Select features:",
Items =
{
// 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
2021-04-25 22:59:36 -05:00
2021-08-05 20:45:26 -05:00
new AbstractBooleanUIElement("Apps", "Apps"),
new AbstractBooleanUIElement("Art", "Art"),
new AbstractBooleanUIElement("Channels", "Channels"),
new AbstractBooleanUIElement("FirstLaunchIntroVideo", "First Launch Intro Video"),
new AbstractBooleanUIElement("Games", "Games"),
new AbstractBooleanUIElement("Marketplace", "Marketplace"),
new AbstractBooleanUIElement("MBRPreview", "[Marketplace] Media Preview"),
new AbstractBooleanUIElement("MBRPurchase", "[Marketplace] Media Purchase"),
new AbstractBooleanUIElement("MBRRental", "[Marketplace] Media Rental"),
new AbstractBooleanUIElement("Music", "Music"),
new AbstractBooleanUIElement("MusicVideos", "Music Videos"),
new AbstractBooleanUIElement("Nowplaying", "Now Playing"),
new AbstractBooleanUIElement("NowplayingArt", "Now Playing Art"),
new AbstractBooleanUIElement("Picks", "Picks"),
new AbstractBooleanUIElement("Podcasts", "Podcasts"),
new AbstractBooleanUIElement("QuickMixLocal", "Quick Mix (Local)"),
new AbstractBooleanUIElement("QuickMixZMP", "Quick Mix (ZMP)"),
new AbstractBooleanUIElement("Quickplay", "Quickplay"),
new AbstractBooleanUIElement("Sign In Available", "Sign In"),
new AbstractBooleanUIElement("Social", "Social"),
new AbstractBooleanUIElement("SocialMarketplace", "Social Marketplace"),
new AbstractBooleanUIElement("SubscriptionFreeTracks", "Subscription Free Tracks"),
new AbstractBooleanUIElement("Videos", "Videos"),
}
};
}
2021-04-25 22:59:36 -05:00
public override IReadOnlyList<Type>? DependentMods => null;
public override Task Init()
{
foreach (AbstractUIElement uiElem in OptionsUI.Items)
{
2021-04-25 22:59:36 -05:00
if (uiElem is AbstractBooleanUIElement boolElem)
{
bool? featureOverride = GetFeatureOverride(boolElem.Id);
boolElem.ChangeState(featureOverride ?? false);
}
}
2021-04-25 22:59:36 -05:00
return Task.CompletedTask;
}
public override async Task<string?> Apply() => await Apply(false);
public async Task<string?> Apply(bool applyAll = false)
2021-04-25 22:59:36 -05:00
{
// Use user choices from AbstractUI
2021-04-25 22:59:36 -05:00
foreach (AbstractUIElement uiElem in OptionsUI.Items)
{
if (uiElem is AbstractBooleanUIElement boolElem && (boolElem.State || applyAll))
{
bool isSuccess = SetFeatureOverride(boolElem.Id, true);
if (!isSuccess)
{
string? resetStatus = await Reset();
if (resetStatus != null)
{
// The reset failed as well, return both errors
return "Failed to set registry keys. Unable to clean up partial overrides:\r\n" + resetStatus;
}
else
{
return "Failed to set registry keys. Automatically cleaned up partial changes.";
}
}
}
}
2021-04-25 22:59:36 -05:00
return null;
2021-04-25 22:59:36 -05:00
}
public override async Task<string?> Reset()
2021-04-25 22:59:36 -05:00
{
foreach (AbstractUIElement uiElem in OptionsUI.Items)
if (uiElem is AbstractBooleanUIElement boolElem)
ResetFeatureOverride(boolElem.Id);
return null;
2021-04-25 22:59:36 -05:00
}
public static bool SetFeatureOverride(string feature, bool value) =>
2021-04-25 22:59:36 -05:00
RegEdit.CurrentUserSetBoolValue(ZUNE_FEATURESOVERRIDE_REGKEY, feature, value);
public static bool? GetFeatureOverride(string feature) =>
2021-04-25 22:59:36 -05:00
RegEdit.CurrentUserGetBoolValue(ZUNE_FEATURESOVERRIDE_REGKEY, feature);
public static void ResetFeatureOverride(string feature) =>
RegEdit.CurrentUserDeleteValue(RegEdit.ZUNE_REG_PATH + "FeaturesOverride", feature);
}
}