Skip to content

Commit d8f9a3c

Browse files
committed
Automatically select the "Zero" background when using a custom background image
1 parent 5b51376 commit d8f9a3c

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

ZuneModCore/Mods/BackgroundImageMod.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ public class BackgroundImageModFactory : DIModFactoryBase<BackgroundImageMod>
1717
private const string Author = "Joshua \"Yoshi\" Askharoun";
1818

1919
public override ModMetadata Metadata => new(nameof(BackgroundImageMod), "Background Image",
20-
Description, Author, new(1, 0));
20+
Description, Author, new(1, 1));
2121
}
2222

2323
public class BackgroundImageMod(ModMetadata metadata, IModCoreConfig modConfig) : Mod(metadata)
2424
{
25+
private const string FRAMEBACKGROUND_NAME = "FRAMEBACKGROUND06.PNG";
26+
2527
public string ZuneInstallDir => modConfig.ZuneInstallDir;
2628

2729
public override AbstractUICollection? GetDefaultOptionsUI()
@@ -90,7 +92,7 @@ public class BackgroundImageMod(ModMetadata metadata, IModCoreConfig modConfig)
9092
// Locate the image resource
9193
// TODO: Allow users to specify which background they want to replace
9294
List<Resource> RCDATA = vi.Resources[resId];
93-
int idx = RCDATA.FindIndex(r => r.Name.Name == "FRAMEBACKGROUND06.PNG");
95+
int idx = RCDATA.FindIndex(r => r.Name.Name == FRAMEBACKGROUND_NAME);
9496
if (idx < 0)
9597
return $"Failed to locate background image resource in Zune software.";
9698
GenericResource ogRes = (GenericResource)RCDATA[idx];
@@ -105,6 +107,10 @@ public class BackgroundImageMod(ModMetadata metadata, IModCoreConfig modConfig)
105107
}
106108
File.Copy(zsrDllTempPath, zsrDllInfo.FullName, true);
107109

110+
// Configure Zune to use the "Zero" background
111+
var resourceUri = $"res://ZuneShellResources.dll!{FRAMEBACKGROUND_NAME}";
112+
RegEdit.CurrentUserSetStringValue(RegEdit.ZUNE_REG_PATH + "Shell", "BackgroundImage", resourceUri);
113+
108114
return null;
109115
}
110116
catch (IOException)

ZuneModCore/Win32/RegEdit.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@ public class RegEdit
66
{
77
public const string ZUNE_REG_PATH = @"SOFTWARE\Microsoft\Zune\";
88

9+
public static bool CurrentUserSetStringValue(string key, string name, string value)
10+
{
11+
RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
12+
regKey ??= Registry.CurrentUser.CreateSubKey(key, true);
13+
14+
regKey.SetValue(name, value, RegistryValueKind.String);
15+
regKey.Close();
16+
regKey.Dispose();
17+
18+
// Read the key to make sure it was set properly
19+
return CurrentUserGetStringValue(key, name) == value;
20+
}
21+
22+
public static string? CurrentUserGetStringValue(string key, string name)
23+
{
24+
using RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
25+
if (regKey == null)
26+
return null;
27+
28+
// Return null if a string value couldn't be read from the key
29+
if (regKey.GetValue(name, false) is string value)
30+
return value;
31+
return null;
32+
}
33+
934
public static bool CurrentUserSetBoolValue(string key, string name, bool value)
1035
{
1136
RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
@@ -16,9 +41,7 @@ public static bool CurrentUserSetBoolValue(string key, string name, bool value)
1641
regKey.Dispose();
1742

1843
// Read the key to make sure it was set properly
19-
if (CurrentUserGetBoolValue(key, name) == null)
20-
return false;
21-
return true;
44+
return CurrentUserGetBoolValue(key, name) == value;
2245
}
2346

2447
public static bool? CurrentUserGetBoolValue(string key, string name)

0 commit comments

Comments
 (0)