@@ -12,8 +12,8 @@ public record class SolidWallpaperSettings(
12
12
Color Color
13
13
) : IWallpaperSettings ;
14
14
15
- public record class ImageWallpaperSettings (
16
- byte [ ] Image
15
+ public record class ScriptWallpaperSettings (
16
+ string Script
17
17
) : IWallpaperSettings ;
18
18
19
19
public interface IColorSettings ;
@@ -66,25 +66,29 @@ void WriteWallpaperScript(Action<StringWriter> after)
66
66
67
67
switch ( Configuration . WallpaperSettings )
68
68
{
69
- case ImageWallpaperSettings settings :
69
+ case ScriptWallpaperSettings settings :
70
+ string imageFile = @"C:\Windows\Setup\Scripts\Wallpaper" ;
71
+ string getterFile = AddTextFile ( "GetWallpaper.ps1" , settings . Script ) ;
72
+ SpecializeScript . Append ( $$ """
73
+ try {
74
+ $bytes = Get-Content -LiteralPath '{{ getterFile }} ' -Raw | Invoke-Expression;
75
+ [System.IO.File]::WriteAllBytes( '{{ imageFile }} ', $bytes );
76
+ } catch {
77
+ $_;
78
+ }
79
+ """ ) ;
80
+ WriteWallpaperScript ( writer =>
70
81
{
71
- string file = @"C:\Windows\Setup\Scripts\Wallpaper" ;
72
- AddBinaryFile ( settings . Image , file ) ;
73
- WriteWallpaperScript ( writer =>
74
- {
75
- writer . WriteLine ( @$ "Set-WallpaperImage -LiteralPath '{ file } ';") ;
76
- } ) ;
77
- break ;
78
- }
82
+ writer . WriteLine ( @$ "Set-WallpaperImage -LiteralPath '{ imageFile } ';") ;
83
+ } ) ;
84
+ break ;
79
85
80
86
case SolidWallpaperSettings settings :
87
+ WriteWallpaperScript ( writer =>
81
88
{
82
- WriteWallpaperScript ( writer =>
83
- {
84
- writer . WriteLine ( $ "Set-WallpaperColor -HtmlColor '{ ColorTranslator . ToHtml ( settings . Color ) } ';") ;
85
- } ) ;
86
- break ;
87
- }
89
+ writer . WriteLine ( $ "Set-WallpaperColor -HtmlColor '{ ColorTranslator . ToHtml ( settings . Color ) } ';") ;
90
+ } ) ;
91
+ break ;
88
92
}
89
93
}
90
94
}
0 commit comments