Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit d763ffd

Browse files
committed
Show the reason downloading file failed in the error message that's displayed on message box
1 parent e21ad7b commit d763ffd

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

ClientUpdater/Updater.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ private static async Task PerformUpdateAsync()
11761176
{
11771177
currentFilename = info.Archived ? info.Filename + ARCHIVE_FILE_EXTENSION : info.Filename;
11781178
currentFileSize = info.Archived ? info.ArchiveSize : info.Size;
1179-
bool flag = await DownloadFileAsync(info).ConfigureAwait(false);
1179+
string errorMessage = await DownloadFileAsync(info).ConfigureAwait(false);
11801180

11811181
if (terminateUpdate)
11821182
{
@@ -1187,7 +1187,7 @@ private static async Task PerformUpdateAsync()
11871187
return;
11881188
}
11891189

1190-
if (flag)
1190+
if (errorMessage == null)
11911191
{
11921192
totalDownloadedKbs += info.Archived ? info.ArchiveSize : info.Size;
11931193
break;
@@ -1200,8 +1200,13 @@ private static async Task PerformUpdateAsync()
12001200
Logger.Log("Updater: Too many retries for downloading file " +
12011201
(info.Archived ? info.Filename + ARCHIVE_FILE_EXTENSION : info.Filename) + ". Update halted.");
12021202

1203+
string extraMsg = string.Empty;
1204+
1205+
if (errorMessage != null)
1206+
extraMsg = Environment.NewLine + Environment.NewLine + "Download error message: " + errorMessage;
1207+
12031208
throw new("Too many retries for downloading file " +
1204-
(info.Archived ? info.Filename + ARCHIVE_FILE_EXTENSION : info.Filename));
1209+
(info.Archived ? info.Filename + ARCHIVE_FILE_EXTENSION : info.Filename) + extraMsg);
12051210
}
12061211
}
12071212
}
@@ -1324,8 +1329,8 @@ private static async Task PerformUpdateAsync()
13241329
/// Downloads and handles individual file.
13251330
/// </summary>
13261331
/// <param name="fileInfo">File info for the file.</param>
1327-
/// <returns>True if successful, otherwise false.</returns>
1328-
private static async ValueTask<bool> DownloadFileAsync(UpdaterFileInfo fileInfo)
1332+
/// <returns>Error message if something went wrong, otherwise null.</returns>
1333+
private static async ValueTask<string> DownloadFileAsync(UpdaterFileInfo fileInfo)
13291334
{
13301335
Logger.Log("Updater: Initializing download of file " + fileInfo.Filename);
13311336

@@ -1388,20 +1393,21 @@ private static async ValueTask<bool> DownloadFileAsync(UpdaterFileInfo fileInfo)
13881393
}
13891394
else
13901395
{
1391-
Logger.Log("Updater: Downloaded archive " + filename + extraExtension + " has a non-matching identifier: " + archiveIdentifier + " against " + fileInfo.ArchiveIdentifier);
1396+
string errorMsg = "Downloaded archive " + filename + extraExtension + " has a non-matching identifier: " + archiveIdentifier + " against " + fileInfo.ArchiveIdentifier;
1397+
Logger.Log("Updater: " + errorMsg);
13921398
DeleteFileAndWait(downloadFile.FullName);
13931399

1394-
return false;
1400+
return errorMsg;
13951401
}
13961402
}
13971403

13981404
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && downloadFile.Extension.Equals(".sh", StringComparison.OrdinalIgnoreCase))
13991405
{
1400-
Logger.Log($"Updater: File {downloadFile.Name} is a script, adding execute permission.");
1406+
Logger.Log($"Updater: File {downloadFile.Name} is a script, adding execute permission. Current permission flags: " + downloadFile.UnixFileMode);
14011407

14021408
downloadFile.UnixFileMode |= UnixFileMode.UserExecute;
14031409

1404-
Logger.Log($"Updater: File {downloadFile.Name} execute permission added.");
1410+
Logger.Log($"Updater: File {downloadFile.Name} execute permission added. Current permission flags: " + downloadFile.UnixFileMode);
14051411
}
14061412
}
14071413

@@ -1410,20 +1416,21 @@ private static async ValueTask<bool> DownloadFileAsync(UpdaterFileInfo fileInfo)
14101416
{
14111417
Logger.Log("Updater: File " + filename + " is intact.");
14121418

1413-
return true;
1419+
return null;
14141420
}
14151421

1416-
Logger.Log("Updater: Downloaded file " + filename + " has a non-matching identifier: " + fileIdentifier + " against " + fileInfo.Identifier);
1422+
string msg = "Downloaded file " + filename + " has a non-matching identifier: " + fileIdentifier + " against " + fileInfo.Identifier;
1423+
Logger.Log("Updater: " + msg);
14171424
DeleteFileAndWait(decompressedFile.FullName);
14181425

1419-
return false;
1426+
return msg;
14201427
}
14211428
catch (Exception exception)
14221429
{
14231430
Logger.Log("Updater: An error occurred while downloading file " + filename + ": " + exception.Message);
14241431
DeleteFileAndWait(decompressedFile.FullName);
14251432

1426-
return false;
1433+
return exception.Message;
14271434
}
14281435
}
14291436

0 commit comments

Comments
 (0)