-
Notifications
You must be signed in to change notification settings - Fork 24
/
NewInstallerUserInterface.cs
135 lines (121 loc) · 4.62 KB
/
NewInstallerUserInterface.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using SixLabors.ImageSharp;
using System.IO;
using System.Management.Automation;
namespace PSMSI
{
[Cmdlet(VerbsCommon.New, "InstallerUserInterface")]
public class NewInstallerUserInterface : PSCmdlet
{
[Parameter]
public string Eula { get; set; }
[Parameter]
public string TopBanner { get; set; }
[Parameter]
public string WelcomeAndCompletionBackground { get; set; }
[Parameter]
public string ExclamationIcon { get; set; }
[Parameter]
public string InformationIcon { get; set; }
[Parameter]
public string NewIcon { get; set; }
[Parameter]
public string UpIcon { get; set; }
[Parameter]
public string ExitDialogText { get; set; }
protected override void ProcessRecord()
{
if (Eula != null)
{
Eula = GetUnresolvedProviderPathFromPSPath(Eula);
if (!File.Exists(Eula))
{
WriteWarning("-EULA specified but the file does not exist.");
}
}
if (TopBanner != null)
{
TopBanner = GetUnresolvedProviderPathFromPSPath(TopBanner);
if (!File.Exists(TopBanner))
{
WriteWarning("-TopBanner specified but the file does not exist.");
}
}
if (WelcomeAndCompletionBackground != null)
{
WelcomeAndCompletionBackground = GetUnresolvedProviderPathFromPSPath(WelcomeAndCompletionBackground);
if (!File.Exists(WelcomeAndCompletionBackground))
{
WriteWarning("-WelcomeAndCompletionBackground specified but the file does not exist.");
}
}
if (ExclamationIcon != null)
{
ExclamationIcon = GetUnresolvedProviderPathFromPSPath(ExclamationIcon);
if (!File.Exists(ExclamationIcon))
{
WriteWarning("-ExclamationIcon specified but the file does not exist.");
}
}
if (InformationIcon != null)
{
InformationIcon = GetUnresolvedProviderPathFromPSPath(InformationIcon);
if (!File.Exists(InformationIcon))
{
WriteWarning("-InformationIcon specified but the file does not exist.");
}
}
if (NewIcon != null)
{
NewIcon = GetUnresolvedProviderPathFromPSPath(NewIcon);
if (!File.Exists(NewIcon))
{
WriteWarning("-NewIcon specified but the file does not exist.");
}
}
if (UpIcon != null)
{
UpIcon = GetUnresolvedProviderPathFromPSPath(UpIcon);
if (!File.Exists(UpIcon))
{
WriteWarning("-UpIcon specified but the file does not exist.");
}
}
TestImageSize(TopBanner, nameof(TopBanner), 58, 493);
TestImageSize(WelcomeAndCompletionBackground, nameof(WelcomeAndCompletionBackground), 312, 493);
TestImageSize(ExclamationIcon, nameof(ExclamationIcon), 32, 32);
TestImageSize(InformationIcon, nameof(InformationIcon), 32, 32);
TestImageSize(NewIcon, nameof(NewIcon), 16, 16);
TestImageSize(UpIcon, nameof(UpIcon), 16, 16);
WriteObject(new Models.UserInterface
{
Eula = Eula,
TopBanner = TopBanner,
WelcomeAndCompletionBackground = WelcomeAndCompletionBackground,
ExclamationIcon = ExclamationIcon,
InformationIcon = InformationIcon,
NewIcon = NewIcon,
UpIcon = UpIcon,
ExitDialogText = ExitDialogText
});
}
private void TestImageSize(string file, string name, int height, int width)
{
if (file == null) return;
try
{
var image = Image.Load(file);
if (image.Height != height)
{
WriteWarning($"The {name} image's recommended height is {height} pixels but the image specified is {image.Height}.");
}
if (image.Width != width)
{
WriteWarning($"The {name} image's recommended width is {width} pixels but the image specified is {image.Width}.");
}
}
catch
{
}
}
}
}