1515// https://github.com/marcinotorowski/msix-hero/blob/develop/LICENSE.md
1616
1717using System ;
18+ using System . Collections . Generic ;
1819using System . IO ;
1920using System . Linq ;
2021using System . Threading ;
@@ -41,13 +42,19 @@ public WingetInstallerViewModel(YamlUtils yamlUtils, IInteractionService interac
4142 this . interactionService = interactionService ;
4243 this . AddChildren (
4344 this . Architecture = new ChangeableProperty < YamlArchitecture > ( ) ,
44- this . SystemAppId = new ValidatedChangeableProperty < string > ( "System AppId" ) ,
45+ this . PlatformUwp = new ChangeableProperty < bool > ( this . Model ? . Platform ? . Contains ( YamlPlatform . WindowsUniversal ) == true ) ,
46+ this . PlatformWin32 = new ChangeableProperty < bool > ( this . Model ? . Platform ? . Contains ( YamlPlatform . WindowsDesktop ) == true ) ,
47+ this . ProductCode = new ValidatedChangeableProperty < string > ( "Product code" , ValidatorFactory . ValidateGuid ( false ) ) ,
48+ this . PackageFamilyName = new ValidatedChangeableProperty < string > ( "Package family name" , WingetValidators . GetPackageFamilyNameError ) ,
4549 this . SignatureSha256 = new ValidatedChangeableProperty < string > ( "Signature hash" , ValidatorFactory . ValidateSha256 ( false ) ) ,
4650 this . Scope = new ChangeableProperty < YamlScope > ( ) ,
47- this . SilentCommand = new ChangeableProperty < string > ( ) ,
48- this . CustomCommand = new ChangeableProperty < string > ( ) ,
49- this . InstallerType = new ValidatedChangeableProperty < YamlInstallerType > ( "Installer type" , ValidateInstallerType ) ,
50- this . SilentCommandWithProgress = new ChangeableProperty < string > ( )
51+ this . SilentCommand = new ValidatedChangeableProperty < string > ( "Silent command" , WingetValidators . GetInstallerSwitchesError ) ,
52+ this . InteractiveCommand = new ValidatedChangeableProperty < string > ( "Interactive command" , WingetValidators . GetInstallerSwitchesError ) ,
53+ this . LogCommand = new ValidatedChangeableProperty < string > ( "Log command" , WingetValidators . GetInstallerSwitchesError ) ,
54+ this . UpgradeCommand = new ValidatedChangeableProperty < string > ( "Upgrade command" , WingetValidators . GetInstallerSwitchesError ) ,
55+ this . CustomCommand = new ValidatedChangeableProperty < string > ( "Custom command" , WingetValidators . GetCustomInstallerSwitchesError ) ,
56+ this . SilentCommandWithProgress = new ValidatedChangeableProperty < string > ( "Silent command with progress" , WingetValidators . GetInstallerSwitchesError ) ,
57+ this . InstallerType = new ValidatedChangeableProperty < YamlInstallerType > ( "Installer type" , ValidateInstallerType )
5158 ) ;
5259
5360 this . InstallerType . ValueChanged += InstallerTypeOnValueChanged ;
@@ -57,14 +64,25 @@ public void SetData(YamlInstaller installer, bool useNullValues = true)
5764 {
5865 this . Model = installer ;
5966
60- if ( useNullValues || installer . Arch != default )
67+ if ( useNullValues || installer . Architecture != default )
6168 {
62- this . Architecture . CurrentValue = installer ? . Arch ?? YamlArchitecture . none ;
69+ this . Architecture . CurrentValue = installer ? . Architecture ?? YamlArchitecture . None ;
6370 }
6471
65- if ( useNullValues || installer . SystemAppId != null )
72+ if ( useNullValues || installer . Platform != default )
6673 {
67- this . SystemAppId . CurrentValue = installer ? . SystemAppId ;
74+ this . PlatformUwp . CurrentValue = installer ? . Platform ? . Contains ( YamlPlatform . WindowsUniversal ) == true ;
75+ this . PlatformWin32 . CurrentValue = installer ? . Platform ? . Contains ( YamlPlatform . WindowsDesktop ) == true ;
76+ }
77+
78+ if ( useNullValues || installer . ProductCode != null )
79+ {
80+ this . ProductCode . CurrentValue = installer ? . ProductCode ;
81+ }
82+
83+ if ( useNullValues || installer . PackageFamilyName != null )
84+ {
85+ this . PackageFamilyName . CurrentValue = installer ? . PackageFamilyName ;
6886 }
6987
7088 if ( useNullValues || installer . SignatureSha256 != null )
@@ -74,43 +92,70 @@ public void SetData(YamlInstaller installer, bool useNullValues = true)
7492
7593 if ( useNullValues || installer . Scope != default )
7694 {
77- this . Scope . CurrentValue = installer ? . Scope ?? YamlScope . none ;
95+ this . Scope . CurrentValue = installer ? . Scope ?? YamlScope . None ;
7896 }
7997
80- if ( useNullValues || installer . Switches ? . Silent != null )
98+ if ( useNullValues || installer . InstallerSwitches ? . Silent != null )
99+ {
100+ this . SilentCommand . CurrentValue = installer ? . InstallerSwitches ? . Silent ;
101+ }
102+
103+ if ( useNullValues || installer . InstallerSwitches ? . Custom != null )
81104 {
82- this . SilentCommand . CurrentValue = installer ? . Switches ? . Silent ;
105+ this . CustomCommand . CurrentValue = installer ? . InstallerSwitches ? . Custom ;
83106 }
84107
85- if ( useNullValues || installer . Switches ? . Custom != null )
108+ if ( useNullValues || installer . InstallerSwitches ? . SilentWithProgress != default )
86109 {
87- this . CustomCommand . CurrentValue = installer ? . Switches ? . Custom ;
110+ this . SilentCommandWithProgress . CurrentValue = installer ? . InstallerSwitches ? . SilentWithProgress ;
111+ }
112+
113+ if ( useNullValues || installer . InstallerSwitches ? . Interactive != default )
114+ {
115+ this . InteractiveCommand . CurrentValue = installer ? . InstallerSwitches ? . Interactive ;
88116 }
89117
90- if ( useNullValues || installer . InstallerType != default )
118+ if ( useNullValues || installer . InstallerSwitches ? . Upgrade != default )
119+ {
120+ this . UpgradeCommand . CurrentValue = installer ? . InstallerSwitches ? . Upgrade ;
121+ }
122+
123+ if ( useNullValues || installer . InstallerSwitches ? . Log != default )
91124 {
92- this . InstallerType . CurrentValue = installer ? . InstallerType ?? YamlInstallerType . none ;
125+ this . LogCommand . CurrentValue = installer ? . InstallerSwitches ? . Log ;
93126 }
94127
95- if ( useNullValues || installer . Arch != default )
128+ if ( useNullValues || installer . InstallerType != default )
96129 {
97- this . SilentCommandWithProgress . CurrentValue = installer ? . Switches ? . SilentWithProgress ;
130+ this . InstallerType . CurrentValue = installer ? . InstallerType ?? YamlInstallerType . None ;
98131 }
99132
100133 this . Commit ( ) ;
101134 }
102135
103136 public ChangeableProperty < YamlArchitecture > Architecture { get ; }
137+
138+ public ChangeableProperty < bool > PlatformUwp { get ; }
139+
140+ public ChangeableProperty < bool > PlatformWin32 { get ; }
104141
105142 public ChangeableProperty < YamlInstallerType > InstallerType { get ; }
106143
107144 public ChangeableProperty < YamlScope > Scope { get ; }
108145
109- public ChangeableProperty < string > SystemAppId { get ; }
146+ public ChangeableProperty < string > ProductCode { get ; }
147+
148+ public ChangeableProperty < string > PackageFamilyName { get ; }
110149
111150 public ValidatedChangeableProperty < string > SignatureSha256 { get ; }
112151
113152 public ChangeableProperty < string > SilentCommand { get ; }
153+
154+ public ChangeableProperty < string > InteractiveCommand { get ; }
155+
156+ public ChangeableProperty < string > LogCommand { get ; }
157+
158+ public ChangeableProperty < string > UpgradeCommand { get ; }
114159
115160 public ChangeableProperty < string > CustomCommand { get ; }
116161
@@ -120,16 +165,16 @@ public void SetData(YamlInstaller installer, bool useNullValues = true)
120165
121166 public string Url { get ; set ; }
122167
123- public bool IsMsix => this . InstallerType . CurrentValue == YamlInstallerType . msix || this . InstallerType . CurrentValue == YamlInstallerType . appx ;
168+ public bool IsMsix => this . InstallerType . CurrentValue == YamlInstallerType . Msix || this . InstallerType . CurrentValue == YamlInstallerType . Appx ;
124169
125170 public bool IsCommand
126171 {
127172 get
128173 {
129174 switch ( this . InstallerType . CurrentValue )
130175 {
131- case YamlInstallerType . none :
132- case YamlInstallerType . exe :
176+ case YamlInstallerType . None :
177+ case YamlInstallerType . Exe :
133178 return true ;
134179 default :
135180 return false ;
@@ -229,43 +274,57 @@ public override void Commit()
229274 {
230275 base . Commit ( ) ;
231276
232- this . Model . SystemAppId = this . SystemAppId . CurrentValue ;
233-
234- if ( this . Architecture . CurrentValue == YamlArchitecture . none )
235- {
236- this . Model . Arch = 0 ;
237- }
238- else
239- {
240- this . Model . Arch = this . Architecture . CurrentValue ;
241- }
242-
243- if ( this . Scope . CurrentValue == YamlScope . none )
277+ this . Model . PackageFamilyName = this . PackageFamilyName . CurrentValue ;
278+ this . Model . ProductCode = this . ProductCode . CurrentValue ;
279+ this . Model . Architecture = this . Architecture . CurrentValue ;
280+
281+ if ( ! this . PlatformUwp . CurrentValue && ! this . PlatformWin32 . CurrentValue )
244282 {
245- this . Model . Scope = default ;
283+ this . Model . Platform = null ;
246284 }
247285 else
248286 {
249- this . Model . Scope = this . Scope . CurrentValue ;
287+ this . Model . Platform = new List < YamlPlatform > ( ) ;
288+ if ( this . PlatformWin32 . CurrentValue )
289+ {
290+ this . Model . Platform . Add ( YamlPlatform . WindowsDesktop ) ;
291+ }
292+
293+ if ( this . PlatformUwp . CurrentValue )
294+ {
295+ this . Model . Platform . Add ( YamlPlatform . WindowsUniversal ) ;
296+ }
250297 }
251-
252- if ( string . IsNullOrEmpty ( this . SilentCommandWithProgress . CurrentValue ) && string . IsNullOrEmpty ( this . SilentCommand . CurrentValue ) )
298+
299+ this . Model . Scope = this . Scope . CurrentValue ;
300+
301+ if (
302+ string . IsNullOrWhiteSpace ( this . SilentCommandWithProgress . CurrentValue ) &&
303+ string . IsNullOrWhiteSpace ( this . SilentCommand . CurrentValue ) &&
304+ string . IsNullOrWhiteSpace ( this . UpgradeCommand . CurrentValue ) &&
305+ string . IsNullOrWhiteSpace ( this . LogCommand . CurrentValue ) &&
306+ string . IsNullOrWhiteSpace ( this . InteractiveCommand . CurrentValue ) &&
307+ string . IsNullOrWhiteSpace ( this . CustomCommand . CurrentValue ) )
253308 {
254- this . Model . Switches = null ;
309+ this . Model . InstallerSwitches = null ;
255310 }
256- else if ( this . Model . Switches == null )
311+ else if ( this . Model . InstallerSwitches == null )
257312 {
258- this . Model . Switches = new YamlSwitches ( ) ;
313+ this . Model . InstallerSwitches = new YamlInstallerSwitches ( ) ;
259314 }
260315
261- if ( this . Model . Switches != null )
316+ if ( this . Model . InstallerSwitches != null )
262317 {
263- this . Model . Switches . SilentWithProgress = this . SilentCommandWithProgress . CurrentValue ;
264- this . Model . Switches . Silent = this . SilentCommand . CurrentValue ;
265- this . Model . Switches . Custom = this . CustomCommand . CurrentValue ;
318+ this . Model . InstallerSwitches . SilentWithProgress = this . SilentCommandWithProgress . CurrentValue ;
319+ this . Model . InstallerSwitches . Silent = this . SilentCommand . CurrentValue ;
320+ this . Model . InstallerSwitches . Custom = this . CustomCommand . CurrentValue ;
321+ this . Model . InstallerSwitches . Interactive = this . InteractiveCommand . CurrentValue ;
322+ this . Model . InstallerSwitches . Log = this . LogCommand . CurrentValue ;
323+ this . Model . InstallerSwitches . Upgrade = this . UpgradeCommand . CurrentValue ;
266324 }
267325
268- this . Model . SystemAppId = this . SystemAppId . CurrentValue ;
326+ this . Model . ProductCode = this . ProductCode . CurrentValue ;
327+ this . Model . PackageFamilyName = this . PackageFamilyName . CurrentValue ;
269328 this . Model . SignatureSha256 = this . SignatureSha256 . CurrentValue ;
270329 }
271330
@@ -277,7 +336,7 @@ private void InstallerTypeOnValueChanged(object sender, ValueChangedEventArgs e)
277336
278337 private string ValidateInstallerType ( YamlInstallerType value )
279338 {
280- if ( value == YamlInstallerType . none )
339+ if ( value == YamlInstallerType . None )
281340 {
282341 return "The installation type must be selected." ;
283342 }
0 commit comments