Skip to content

Commit d69b850

Browse files
authored
Fix: Fixed crash that would sometimes occur when updating (#16976)
1 parent e993f5e commit d69b850

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/Files.App/Services/App/AppUpdateSideloadService.cs

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using CommunityToolkit.WinUI.Helpers;
54
using Microsoft.Extensions.Logging;
65
using System.IO;
76
using System.Net.Http;
@@ -123,34 +122,45 @@ public async Task CheckForUpdatesAsync()
123122

124123
public async Task CheckAndUpdateFilesLauncherAsync()
125124
{
126-
var destFolderPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, "Files");
127-
var destExeFilePath = Path.Combine(destFolderPath, "Files.App.Launcher.exe");
128-
129-
if (File.Exists(destExeFilePath))
125+
try
130126
{
127+
var destFolderPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, "Files");
128+
var destExeFilePath = Path.Combine(destFolderPath, "Files.App.Launcher.exe");
129+
130+
if (!File.Exists(destExeFilePath))
131+
return;
132+
131133
var hashEqual = false;
132-
var srcHashFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/Files.App.Launcher.exe.sha256"));
134+
var srcHashFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/Files.App.Launcher.exe.sha256"))
135+
.AsTask().ConfigureAwait(false);
133136
var destHashFilePath = Path.Combine(destFolderPath, "Files.App.Launcher.exe.sha256");
134137

135138
if (File.Exists(destHashFilePath))
136139
{
137-
await using var srcStream = (await srcHashFile.OpenReadAsync()).AsStream();
140+
await using var srcStream = (await srcHashFile.OpenReadAsync().AsTask().ConfigureAwait(false)).AsStream();
138141
await using var destStream = File.OpenRead(destHashFilePath);
139-
140142
hashEqual = HashEqual(srcStream, destStream);
141143
}
142144

143145
if (!hashEqual)
144146
{
145-
var srcExeFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/Files.App.Launcher.exe"));
146-
var destFolder = await StorageFolder.GetFolderFromPathAsync(destFolderPath);
147+
var srcExeFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/FilesOpenDialog/Files.App.Launcher.exe"))
148+
.AsTask().ConfigureAwait(false);
149+
var destFolder = await StorageFolder.GetFolderFromPathAsync(destFolderPath).AsTask().ConfigureAwait(false);
147150

148-
await srcExeFile.CopyAsync(destFolder, "Files.App.Launcher.exe", NameCollisionOption.ReplaceExisting);
149-
await srcHashFile.CopyAsync(destFolder, "Files.App.Launcher.exe.sha256", NameCollisionOption.ReplaceExisting);
151+
await srcExeFile.CopyAsync(destFolder, "Files.App.Launcher.exe", NameCollisionOption.ReplaceExisting)
152+
.AsTask().ConfigureAwait(false);
153+
await srcHashFile.CopyAsync(destFolder, "Files.App.Launcher.exe.sha256", NameCollisionOption.ReplaceExisting)
154+
.AsTask().ConfigureAwait(false);
150155

151156
Logger?.LogInformation("Files.App.Launcher updated.");
152157
}
153158
}
159+
catch (Exception ex)
160+
{
161+
Logger?.LogError(ex, ex.Message);
162+
return;
163+
}
154164

155165
bool HashEqual(Stream a, Stream b)
156166
{

0 commit comments

Comments
 (0)