Automatically select the "Zero" background when using a custom background image

This commit is contained in:
Yoshi Askharoun
2025-09-02 11:53:42 -07:00
parent 5b5137678a
commit d8f9a3cf44
2 changed files with 34 additions and 5 deletions
+8 -2
View File
@@ -17,11 +17,13 @@ public class BackgroundImageModFactory : DIModFactoryBase<BackgroundImageMod>
private const string Author = "Joshua \"Yoshi\" Askharoun";
public override ModMetadata Metadata => new(nameof(BackgroundImageMod), "Background Image",
Description, Author, new(1, 0));
Description, Author, new(1, 1));
}
public class BackgroundImageMod(ModMetadata metadata, IModCoreConfig modConfig) : Mod(metadata)
{
private const string FRAMEBACKGROUND_NAME = "FRAMEBACKGROUND06.PNG";
public string ZuneInstallDir => modConfig.ZuneInstallDir;
public override AbstractUICollection? GetDefaultOptionsUI()
@@ -90,7 +92,7 @@ public class BackgroundImageMod(ModMetadata metadata, IModCoreConfig modConfig)
// Locate the image resource
// TODO: Allow users to specify which background they want to replace
List<Resource> RCDATA = vi.Resources[resId];
int idx = RCDATA.FindIndex(r => r.Name.Name == "FRAMEBACKGROUND06.PNG");
int idx = RCDATA.FindIndex(r => r.Name.Name == FRAMEBACKGROUND_NAME);
if (idx < 0)
return $"Failed to locate background image resource in Zune software.";
GenericResource ogRes = (GenericResource)RCDATA[idx];
@@ -105,6 +107,10 @@ public class BackgroundImageMod(ModMetadata metadata, IModCoreConfig modConfig)
}
File.Copy(zsrDllTempPath, zsrDllInfo.FullName, true);
// Configure Zune to use the "Zero" background
var resourceUri = $"res://ZuneShellResources.dll!{FRAMEBACKGROUND_NAME}";
RegEdit.CurrentUserSetStringValue(RegEdit.ZUNE_REG_PATH + "Shell", "BackgroundImage", resourceUri);
return null;
}
catch (IOException)
+26 -3
View File
@@ -6,6 +6,31 @@ public class RegEdit
{
public const string ZUNE_REG_PATH = @"SOFTWARE\Microsoft\Zune\";
public static bool CurrentUserSetStringValue(string key, string name, string value)
{
RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
regKey ??= Registry.CurrentUser.CreateSubKey(key, true);
regKey.SetValue(name, value, RegistryValueKind.String);
regKey.Close();
regKey.Dispose();
// Read the key to make sure it was set properly
return CurrentUserGetStringValue(key, name) == value;
}
public static string? CurrentUserGetStringValue(string key, string name)
{
using RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
if (regKey == null)
return null;
// Return null if a string value couldn't be read from the key
if (regKey.GetValue(name, false) is string value)
return value;
return null;
}
public static bool CurrentUserSetBoolValue(string key, string name, bool value)
{
RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
@@ -16,9 +41,7 @@ public class RegEdit
regKey.Dispose();
// Read the key to make sure it was set properly
if (CurrentUserGetBoolValue(key, name) == null)
return false;
return true;
return CurrentUserGetBoolValue(key, name) == value;
}
public static bool? CurrentUserGetBoolValue(string key, string name)