Skip to content

Commit

Permalink
Let user provide PowerShell script to load a desktop wallpaper image
Browse files Browse the repository at this point in the history
  • Loading branch information
cschneegans committed Dec 3, 2024
1 parent 5ef51a5 commit 36ab095
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions modifier/Personalization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public record class SolidWallpaperSettings(
Color Color
) : IWallpaperSettings;

public record class ImageWallpaperSettings(
byte[] Image
public record class ScriptWallpaperSettings(
string Script
) : IWallpaperSettings;

public interface IColorSettings;
Expand Down Expand Up @@ -66,25 +66,29 @@ void WriteWallpaperScript(Action<StringWriter> after)

switch (Configuration.WallpaperSettings)
{
case ImageWallpaperSettings settings:
case ScriptWallpaperSettings settings:
string imageFile = @"C:\Windows\Setup\Scripts\Wallpaper";
string getterFile = AddTextFile("GetWallpaper.ps1", settings.Script);
SpecializeScript.Append($$"""
try {
$bytes = Get-Content -LiteralPath '{{getterFile}}' -Raw | Invoke-Expression;
[System.IO.File]::WriteAllBytes( '{{imageFile}}', $bytes );
} catch {
$_;
}
""");
WriteWallpaperScript(writer =>
{
string file = @"C:\Windows\Setup\Scripts\Wallpaper";
AddBinaryFile(settings.Image, file);
WriteWallpaperScript(writer =>
{
writer.WriteLine(@$"Set-WallpaperImage -LiteralPath '{file}';");
});
break;
}
writer.WriteLine(@$"Set-WallpaperImage -LiteralPath '{imageFile}';");
});
break;

case SolidWallpaperSettings settings:
WriteWallpaperScript(writer =>
{
WriteWallpaperScript(writer =>
{
writer.WriteLine($"Set-WallpaperColor -HtmlColor '{ColorTranslator.ToHtml(settings.Color)}';");
});
break;
}
writer.WriteLine($"Set-WallpaperColor -HtmlColor '{ColorTranslator.ToHtml(settings.Color)}';");
});
break;
}
}
}
Expand Down

0 comments on commit 36ab095

Please sign in to comment.