|
1 | 1 | // Copyright (c) Files Community |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | | -using CommunityToolkit.WinUI.Helpers; |
5 | 4 | using Microsoft.Extensions.Logging; |
6 | 5 | using System.IO; |
7 | 6 | using System.Net.Http; |
@@ -123,34 +122,45 @@ public async Task CheckForUpdatesAsync() |
123 | 122 |
|
124 | 123 | public async Task CheckAndUpdateFilesLauncherAsync() |
125 | 124 | { |
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 |
130 | 126 | { |
| 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 | + |
131 | 133 | 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); |
133 | 136 | var destHashFilePath = Path.Combine(destFolderPath, "Files.App.Launcher.exe.sha256"); |
134 | 137 |
|
135 | 138 | if (File.Exists(destHashFilePath)) |
136 | 139 | { |
137 | | - await using var srcStream = (await srcHashFile.OpenReadAsync()).AsStream(); |
| 140 | + await using var srcStream = (await srcHashFile.OpenReadAsync().AsTask().ConfigureAwait(false)).AsStream(); |
138 | 141 | await using var destStream = File.OpenRead(destHashFilePath); |
139 | | - |
140 | 142 | hashEqual = HashEqual(srcStream, destStream); |
141 | 143 | } |
142 | 144 |
|
143 | 145 | if (!hashEqual) |
144 | 146 | { |
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); |
147 | 150 |
|
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); |
150 | 155 |
|
151 | 156 | Logger?.LogInformation("Files.App.Launcher updated."); |
152 | 157 | } |
153 | 158 | } |
| 159 | + catch (Exception ex) |
| 160 | + { |
| 161 | + Logger?.LogError(ex, ex.Message); |
| 162 | + return; |
| 163 | + } |
154 | 164 |
|
155 | 165 | bool HashEqual(Stream a, Stream b) |
156 | 166 | { |
|
0 commit comments