Skip to content

Commit

Permalink
Finalized AppInstallerUpdateHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Weatherlights committed Oct 17, 2024
1 parent bc826e5 commit ab41979
Show file tree
Hide file tree
Showing 20 changed files with 355 additions and 307 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Source/.vs/wcommsixwrap/v17/.suo
Binary file not shown.
270 changes: 133 additions & 137 deletions Source/.vs/wcommsixwrap/v17/DocumentLayout.backup.json

Large diffs are not rendered by default.

252 changes: 123 additions & 129 deletions Source/.vs/wcommsixwrap/v17/DocumentLayout.json

Large diffs are not rendered by default.

42 changes: 24 additions & 18 deletions Source/wcommsixwrap/AppInstallerUpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal class AppInstallerUpdateHandler
public bool WaitForUpdateSearchToFinish = true;
public bool mandatoryInstallationFailure = false;
private bool restartOnMandatoryUpdate = true;
private bool treatAvailableUpdateAsMandatory = false;
public bool hasMandatoryUpdates { get; set; }
public Uri AppInstallerUri { get; set; }

Expand Down Expand Up @@ -95,6 +96,11 @@ public void processXml(XmlReader reader)
if (reader.Value.Equals("false"))
restartOnMandatoryUpdate = false;
break;
case "TreatAvailableUpdateAsMandatory":
reader.Read();
if (reader.Value.Equals("true"))
treatAvailableUpdateAsMandatory = true;
break;
case "AppInstallerUri":
reader.Read();
AppInstallerUri = new Uri(reader.Value);
Expand Down Expand Up @@ -203,14 +209,21 @@ public async void InstallOnStart()
IAsyncOperation<PackageUpdateAvailabilityResult> searchOperation = package.CheckUpdateAvailabilityAsync();

searchOperation.AsTask().Wait();

updateresult = await searchOperation.AsTask();

switch (updateresult.Availability)
{
case PackageUpdateAvailability.Available:
myLogWriter.LogWrite("Found available updates.");
hasMandatoryUpdates = true;
if (treatAvailableUpdateAsMandatory)
{
hasMandatoryUpdates = true;
myLogWriter.LogWrite("treatAvailableUpdateAsMandatory is set. Will treat available update as mandatory.");
} else
{
installOnExit = true;
myLogWriter.LogWrite("treatAvailableUpdateAsMandatory is not set. Will install update on exit.");
}
break;
case PackageUpdateAvailability.Required:
//Queue up the update and close the current instance
Expand All @@ -225,17 +238,10 @@ public async void InstallOnStart()
case PackageUpdateAvailability.Unknown:
default:
// Log and ignore error.
myLogWriter.LogWrite("Failed to process updates.");
myLogWriter.LogWrite("Failed to process updates.",3);
break;
}

//MessageBox.Show("Updates found", "Searching", MessageBoxButton.OK, MessageBoxImage.Information);






executeUpdateProcedure = true;
if (executeUpdateProcedure)
{
Expand Down Expand Up @@ -286,12 +292,12 @@ public async void InstallOnStart()
myLogWriter.LogWrite("Mandatory updates need to be installed and will now be enforced.");
UpdateHandlerWindow updateHandlerWindow = new UpdateHandlerWindow(packageManager, AppInstallerUri, caption, message, captionFailRequired, messageFailRequired);
myLogWriter.LogWrite("Window has been initialized.");
updateHandlerWindow.ShowDialog();
myLogWriter.LogWrite("InstallUpdate has finished execution.");
if (!updateHandlerWindow.failure)
{
updateHandlerWindow.ShowDialog();


myLogWriter.LogWrite("InstallUpdate has finished execution.");
if (!updateHandlerWindow.failure)
{
myLogWriter.LogWrite("App has been scheduled for a restart.");
}
// await InstallUpdate(updates);
Expand Down Expand Up @@ -350,13 +356,13 @@ private async Task InstallUpdate()
myLogWriter.LogWrite("Status: " + installOperation.Status.ToString());
//updateHandlerForm.ShowDialog();

myLogWriter.LogWrite("Showing Update Dialog");


installOperation.AsTask().Wait();


var installResult = await installOperation;
//updateHandlerForm.Close();
myLogWriter.LogWrite("Closed Update dialog");
myLogWriter.LogWrite("Finished update");
//StorePackageUpdateResult downloadResult =
// await context.TrySilentDownloadAndInstallStorePackageUpdatesAsync(storePackageUpdates);
bool success = true;
Expand Down
4 changes: 2 additions & 2 deletions Source/wcommsixwrap/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void Main(string[] args)
// 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");

LogWriter myLogWriter = new LogWriter("Main");
myLogWriter.LogWrite("WCOMMSIXWRAP started.");
myLogWriter.LogWrite("MSIX Powerwrapper started.");

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

Expand Down Expand Up @@ -146,7 +146,7 @@ static void Main(string[] args)

if (myAppInstallerUpdateHandler != null)
{
myLogWriter.LogWrite("Executing myUpdateHandler.Execute();");
myLogWriter.LogWrite("Executing myAppInstallerUpdateHandler.Execute();");

myAppInstallerUpdateHandler.Execute();
if (myAppInstallerUpdateHandler.hasMandatoryUpdates && myAppInstallerUpdateHandler.WaitForUpdateSearchToFinish)
Expand Down
2 changes: 2 additions & 0 deletions Source/wcommsixwrap/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ public async void InstallOnStart() {
UpdateHandlerWindow updateHandlerWindow = new UpdateHandlerWindow(context, updates, caption, message, captionFailRequired, messageFailRequired);
myLogWriter.LogWrite("Window has been initialized.");
updateHandlerWindow.ShowDialog();


myLogWriter.LogWrite("InstallUpdate has finished execution.");
if ( !updateHandlerWindow.failure )
{
Expand Down
2 changes: 1 addition & 1 deletion Source/wcommsixwrap/UpdateHandlerWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Name="winUpdateHandler" Height="450" Width="500" ResizeMode="CanMinimize" Title="App is updating" Visibility="Visible" WindowStyle="ThreeDBorderWindow" WindowStartupLocation="CenterScreen" Activated="winUpdateHandler_Activated" Loaded="winUpdateHandler_Loaded" Topmost="True" Icon="pack://application:,,,/wcommsixwrap;component/download1.ico">
<Grid>

<ProgressBar Name="prgProgress" HorizontalAlignment="Center" Height="19" Margin="0,230,0,0" VerticalAlignment="Top" Width="400" Maximum="1" />
<ProgressBar Name="prgProgress" HorizontalAlignment="Center" Height="19" Margin="0,230,0,0" VerticalAlignment="Top" Width="400" Maximum="1" Loaded="prgProgress_Loaded_1" />
<Label Name="lblHeading" Content="App is updating..." HorizontalAlignment="Center" Margin="0,94,0,0" VerticalAlignment="Top" FontSize="16" FontWeight="Bold" Width="400"/>
<TextBlock Name="lblMessage" TextWrapping="Wrap" Text="You may start the app once we are done." HorizontalAlignment="Left" Height="55" Margin="50,130,0,0" VerticalAlignment="Top" Width="400" IsEnabled="False" TextAlignment="Left"/>

Expand Down
74 changes: 56 additions & 18 deletions Source/wcommsixwrap/UpdateHandlerWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Windows.ApplicationModel;
using Windows.Foundation;
using Windows.Management.Deployment;
using Windows.Services.Store;
Expand Down Expand Up @@ -49,6 +52,7 @@ public UpdateHandlerWindow(PackageManager myPackageManager, Uri myAppInstallerUr
this.AppInstallerUri = myAppInstallerUri;
this.updateFailureCaption = myUpdateFailureCaption;
this.updateFailureMessage = myUpdateFailureMessage;

myLogWriter.LogWrite("Calling InitializeComponent().");
InitializeComponent();
this.lblHeading.Content = heading;
Expand All @@ -70,12 +74,11 @@ private void winUpdateHandler_Activated(object sender, EventArgs e)
private void winUpdateHandler_Loaded(object sender, RoutedEventArgs e)
{
myLogWriter.LogWrite("Form has loaded. Will now begin download task.");

DownloadAndInstallAllUpdatesAsync();


}



public async Task DownloadAndInstallAllUpdatesAsync()
{
myLogWriter.LogWrite("Installation will now start.");
Expand All @@ -84,7 +87,7 @@ public async Task DownloadAndInstallAllUpdatesAsync()
try
{
bool failure = false;

if (context != null)
{
IAsyncOperationWithProgress<StorePackageUpdateResult, StorePackageUpdateStatus> downloadOperation = null;
Expand Down Expand Up @@ -134,37 +137,57 @@ await this.Dispatcher.InvokeAsync(
}
if (failure)
MessageBox.Show(updateFailureMessage, updateFailureCaption, MessageBoxButton.OK, MessageBoxImage.Error);
} else if (packageManager != null )
}
else if (packageManager != null)
{
IAsyncOperationWithProgress<Windows.Management.Deployment.DeploymentResult, Windows.Management.Deployment.DeploymentProgress> downloadOperation = null;
downloadOperation = packageManager.AddPackageByAppInstallerFileAsync(AppInstallerUri, AddPackageByAppInstallerOptions.ForceTargetAppShutdown, packageManager.GetDefaultPackageVolume());
downloadOperation.Progress = async (asyncInfo, progress) =>
IAsyncOperationWithProgress<Windows.Management.Deployment.DeploymentResult, Windows.Management.Deployment.DeploymentProgress> deploymentOperation = null;

PackageCatalog packageCatalog = PackageCatalog.OpenForCurrentUser();
packageCatalog.PackageStaging += async (asyncInfo, progress) =>
{
await this.Dispatcher.InvokeAsync(
() =>
{
TaskbarItemInfo.ProgressValue = progress.Progress/100;
prgProgress.Value = progress.Progress/100;
});
};

deploymentOperation = packageManager.AddPackageByAppInstallerFileAsync(AppInstallerUri, AddPackageByAppInstallerOptions.ForceTargetAppShutdown, packageManager.GetDefaultPackageVolume());
myLogWriter.LogWrite("Download Operation initialized.");

/*deploymentOperation.Progress = async (asyncInfo, progress) =>
{
await this.Dispatcher.InvokeAsync(
() =>
{
TaskbarItemInfo.ProgressValue = progress.percentage;
prgProgress.Value = progress.percentage;
});
};
};*/
myLogWriter.LogWrite("Displaying Progress.");

var result = await downloadOperation;
var result = await deploymentOperation;

if (result.ExtendedErrorCode != null)
{
failure = true;
myLogWriter.LogWrite("Update failed with: result." + result.ExtendedErrorCode, 3);
}
}
myLogWriter.LogWrite("Displaying Progress.");
// The Progress async method is called one time for each step in the download
// and installation process for each package in this request.



prgProgress.IsIndeterminate = true;






// The Progress async method is called one time for each step in the download
// and installation process for each package in this request.



prgProgress.IsIndeterminate = true;

}


}
Expand All @@ -175,5 +198,20 @@ await this.Dispatcher.InvokeAsync(
}
this.Close();
}


private void prgProgress_Loaded_1(object sender, RoutedEventArgs e)
{
if (this.context == null) {
this.TaskbarItemInfo = new System.Windows.Shell.TaskbarItemInfo() { ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal };

//packageCatalog.PackageUpdating += OnPackageUpdating;
//packageCatalog.PackageStaging += OnPackageStaging;


}

DownloadAndInstallAllUpdatesAsync();
}
}
}
Binary file modified Source/wcommsixwrap/bin/x64/Release/wcommsixwrap.pdb
Binary file not shown.
Binary file modified Source/wcommsixwrap/bin/x64/Release/xbsy-ost.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 7 additions & 1 deletion Source/wcommsixwrap/obj/x64/Release/UpdateHandlerWindow.g.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\..\UpdateHandlerWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "8F973213131AB30CAC636B0AE0FB797D1B1C5D6A27F204BA9F24C85AD9837146"
#pragma checksum "..\..\..\UpdateHandlerWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "9764F5258F5797831E89C93AC8F3A01203F44BBC39DC945A7B0071D8D19B227C"
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
Expand Down Expand Up @@ -119,6 +119,12 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
return;
case 2:
this.prgProgress = ((System.Windows.Controls.ProgressBar)(target));

#line 11 "..\..\..\UpdateHandlerWindow.xaml"
this.prgProgress.Loaded += new System.Windows.RoutedEventHandler(this.prgProgress_Loaded_1);

#line default
#line hidden
return;
case 3:
this.lblHeading = ((System.Windows.Controls.Label)(target));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\..\UpdateHandlerWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "8F973213131AB30CAC636B0AE0FB797D1B1C5D6A27F204BA9F24C85AD9837146"
#pragma checksum "..\..\..\UpdateHandlerWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "9764F5258F5797831E89C93AC8F3A01203F44BBC39DC945A7B0071D8D19B227C"
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
Expand Down Expand Up @@ -119,6 +119,12 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
return;
case 2:
this.prgProgress = ((System.Windows.Controls.ProgressBar)(target));

#line 11 "..\..\..\UpdateHandlerWindow.xaml"
this.prgProgress.Loaded += new System.Windows.RoutedEventHandler(this.prgProgress_Loaded_1);

#line default
#line hidden
return;
case 3:
this.lblHeading = ((System.Windows.Controls.Label)(target));
Expand Down
Binary file modified Source/wcommsixwrap/obj/x64/Release/wcommsixwrap.exe
Binary file not shown.
Binary file modified Source/wcommsixwrap/obj/x64/Release/wcommsixwrap.pdb
Binary file not shown.

0 comments on commit ab41979

Please sign in to comment.