Skip to content

Commit ab41979

Browse files
committed
Finalized AppInstallerUpdateHandler
1 parent bc826e5 commit ab41979

20 files changed

Lines changed: 355 additions & 307 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Source/.vs/wcommsixwrap/v17/.suo

3.5 KB
Binary file not shown.

Source/.vs/wcommsixwrap/v17/DocumentLayout.backup.json

Lines changed: 133 additions & 137 deletions
Large diffs are not rendered by default.

Source/.vs/wcommsixwrap/v17/DocumentLayout.json

Lines changed: 123 additions & 129 deletions
Large diffs are not rendered by default.

Source/wcommsixwrap/AppInstallerUpdateHandler.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal class AppInstallerUpdateHandler
3333
public bool WaitForUpdateSearchToFinish = true;
3434
public bool mandatoryInstallationFailure = false;
3535
private bool restartOnMandatoryUpdate = true;
36+
private bool treatAvailableUpdateAsMandatory = false;
3637
public bool hasMandatoryUpdates { get; set; }
3738
public Uri AppInstallerUri { get; set; }
3839

@@ -95,6 +96,11 @@ public void processXml(XmlReader reader)
9596
if (reader.Value.Equals("false"))
9697
restartOnMandatoryUpdate = false;
9798
break;
99+
case "TreatAvailableUpdateAsMandatory":
100+
reader.Read();
101+
if (reader.Value.Equals("true"))
102+
treatAvailableUpdateAsMandatory = true;
103+
break;
98104
case "AppInstallerUri":
99105
reader.Read();
100106
AppInstallerUri = new Uri(reader.Value);
@@ -203,14 +209,21 @@ public async void InstallOnStart()
203209
IAsyncOperation<PackageUpdateAvailabilityResult> searchOperation = package.CheckUpdateAvailabilityAsync();
204210

205211
searchOperation.AsTask().Wait();
206-
212+
207213
updateresult = await searchOperation.AsTask();
208-
209214
switch (updateresult.Availability)
210215
{
211216
case PackageUpdateAvailability.Available:
212217
myLogWriter.LogWrite("Found available updates.");
213-
hasMandatoryUpdates = true;
218+
if (treatAvailableUpdateAsMandatory)
219+
{
220+
hasMandatoryUpdates = true;
221+
myLogWriter.LogWrite("treatAvailableUpdateAsMandatory is set. Will treat available update as mandatory.");
222+
} else
223+
{
224+
installOnExit = true;
225+
myLogWriter.LogWrite("treatAvailableUpdateAsMandatory is not set. Will install update on exit.");
226+
}
214227
break;
215228
case PackageUpdateAvailability.Required:
216229
//Queue up the update and close the current instance
@@ -225,17 +238,10 @@ public async void InstallOnStart()
225238
case PackageUpdateAvailability.Unknown:
226239
default:
227240
// Log and ignore error.
228-
myLogWriter.LogWrite("Failed to process updates.");
241+
myLogWriter.LogWrite("Failed to process updates.",3);
229242
break;
230243
}
231244

232-
//MessageBox.Show("Updates found", "Searching", MessageBoxButton.OK, MessageBoxImage.Information);
233-
234-
235-
236-
237-
238-
239245
executeUpdateProcedure = true;
240246
if (executeUpdateProcedure)
241247
{
@@ -286,12 +292,12 @@ public async void InstallOnStart()
286292
myLogWriter.LogWrite("Mandatory updates need to be installed and will now be enforced.");
287293
UpdateHandlerWindow updateHandlerWindow = new UpdateHandlerWindow(packageManager, AppInstallerUri, caption, message, captionFailRequired, messageFailRequired);
288294
myLogWriter.LogWrite("Window has been initialized.");
289-
updateHandlerWindow.ShowDialog();
290-
myLogWriter.LogWrite("InstallUpdate has finished execution.");
291-
if (!updateHandlerWindow.failure)
292-
{
295+
updateHandlerWindow.ShowDialog();
293296

294297

298+
myLogWriter.LogWrite("InstallUpdate has finished execution.");
299+
if (!updateHandlerWindow.failure)
300+
{
295301
myLogWriter.LogWrite("App has been scheduled for a restart.");
296302
}
297303
// await InstallUpdate(updates);
@@ -350,13 +356,13 @@ private async Task InstallUpdate()
350356
myLogWriter.LogWrite("Status: " + installOperation.Status.ToString());
351357
//updateHandlerForm.ShowDialog();
352358

353-
myLogWriter.LogWrite("Showing Update Dialog");
359+
354360

355-
installOperation.AsTask().Wait();
361+
356362

357363
var installResult = await installOperation;
358364
//updateHandlerForm.Close();
359-
myLogWriter.LogWrite("Closed Update dialog");
365+
myLogWriter.LogWrite("Finished update");
360366
//StorePackageUpdateResult downloadResult =
361367
// await context.TrySilentDownloadAndInstallStorePackageUpdatesAsync(storePackageUpdates);
362368
bool success = true;

Source/wcommsixwrap/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void Main(string[] args)
3838
// bool test2 = configReader.validateFileAgainstHash("C:\\Users\\hauke\\GitHub\\Winget-AutoUpdate-Intune\\WinGet-AutoUpdate-Configurator\\wcommsixconfig.cat", "C:\\Users\\hauke\\GitHub\\Winget-AutoUpdate-Intune\\WinGet-AutoUpdate-Configurator\\Winget-AutoUpdate-x64.exe.wrunconfig");
3939

4040
LogWriter myLogWriter = new LogWriter("Main");
41-
myLogWriter.LogWrite("WCOMMSIXWRAP started.");
41+
myLogWriter.LogWrite("MSIX Powerwrapper started.");
4242

4343
myLogWriter.LogWrite("Configuration location is " + configlocation);
4444

@@ -146,7 +146,7 @@ static void Main(string[] args)
146146

147147
if (myAppInstallerUpdateHandler != null)
148148
{
149-
myLogWriter.LogWrite("Executing myUpdateHandler.Execute();");
149+
myLogWriter.LogWrite("Executing myAppInstallerUpdateHandler.Execute();");
150150

151151
myAppInstallerUpdateHandler.Execute();
152152
if (myAppInstallerUpdateHandler.hasMandatoryUpdates && myAppInstallerUpdateHandler.WaitForUpdateSearchToFinish)

Source/wcommsixwrap/UpdateHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ public async void InstallOnStart() {
259259
UpdateHandlerWindow updateHandlerWindow = new UpdateHandlerWindow(context, updates, caption, message, captionFailRequired, messageFailRequired);
260260
myLogWriter.LogWrite("Window has been initialized.");
261261
updateHandlerWindow.ShowDialog();
262+
263+
262264
myLogWriter.LogWrite("InstallUpdate has finished execution.");
263265
if ( !updateHandlerWindow.failure )
264266
{

0 commit comments

Comments
 (0)