Skip to content

Commit 2136520

Browse files
authored
Sideload UpdateService Download fix (#9254)
1 parent 923706f commit 2136520

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

src/Files.Backend/Services/IUpdateService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public interface IUpdateService : INotifyPropertyChanged
1515
/// </summary>
1616
bool IsUpdating { get; }
1717

18+
uint DownloadPercentage { get; }
19+
1820
Task DownloadUpdates();
1921

2022
Task DownloadMandatoryUpdates();

src/Files.Uwp/App.xaml.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ await Task.WhenAll(
213213
// Check for required updates
214214
var updateService = Ioc.Default.GetRequiredService<IUpdateService>();
215215
await updateService.CheckForUpdates();
216-
#if SIDELOAD
217-
//await updateService.DownloadUpdates();
218-
#else
216+
#if !SIDELOAD
219217
await updateService.DownloadMandatoryUpdates();
220218
#endif
221219

src/Files.Uwp/ServicesImplementation/SideloadUpdateService.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public bool IsUpdating
3838
private set => SetProperty(ref _isUpdating, value);
3939
}
4040

41+
public uint DownloadPercentage { get; private set; }
42+
4143
public async Task DownloadUpdates()
4244
{
4345
if (!IsUpdateAvailable)
@@ -48,18 +50,47 @@ public async Task DownloadUpdates()
4850
IsUpdating = true;
4951

5052
App.Logger.Info($"SIDELOAD: Updating: {DownloadUri.AbsoluteUri}");
53+
5154
PackageManager pm = new PackageManager();
52-
// Use DeploymentOptions.ForceApplicationShutdown to force shutdown.
53-
await pm.UpdatePackageAsync(DownloadUri, null, DeploymentOptions.None);
54-
App.Logger.Info($"SIDELOAD: Finished updating: {DownloadUri.AbsoluteUri}");
55+
DeploymentResult deploymentResult = null;
5556

56-
IsUpdating = false;
57-
IsUpdateAvailable = false;
57+
try
58+
{
59+
var progress = new Progress<DeploymentProgress>(report =>
60+
{
61+
DownloadPercentage = report.percentage;
62+
// UNDONE: Removed as it floods the log files.
63+
// App.Logger.Info($"SIDELOAD: Download State: {report.state}");
64+
// App.Logger.Info($"SIDELOAD: Download Percentage: {report.percentage}%");
65+
66+
if (DownloadPercentage == 100)
67+
{
68+
App.Logger.Info($"SIDELOAD: Finished updating: {DownloadUri.AbsoluteUri}");
69+
}
70+
});
71+
72+
// Have to use ForceTargetAppShutdown flag as the appinstaller won't update while it's being used.
73+
deploymentResult = await pm.RequestAddPackageByAppInstallerFileAsync(
74+
DownloadUri,
75+
AddPackageByAppInstallerOptions.ForceTargetAppShutdown,
76+
pm.GetDefaultPackageVolume()).AsTask(progress);
77+
78+
}
79+
catch (Exception e)
80+
{
81+
App.Logger.Error(e, e.Message);
82+
App.Logger.Info(deploymentResult?.ErrorText ?? "No error message from deploymentResult.");
83+
}
84+
finally
85+
{
86+
IsUpdating = false;
87+
IsUpdateAvailable = false;
88+
}
5889
}
5990

6091
public Task DownloadMandatoryUpdates()
6192
{
62-
throw new NotImplementedException();
93+
throw new NotSupportedException("This method is not supported by this service.");
6394
}
6495

6596
public async Task CheckForUpdates()

src/Files.Uwp/ServicesImplementation/UpdateService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ private set
4242
}
4343
}
4444

45+
// TODO: This needs to be implemented in this service.
46+
public uint DownloadPercentage { get; }
47+
4548
public UpdateService()
4649
{
4750
_updatePackages = new List<StorePackageUpdate>();

0 commit comments

Comments
 (0)