From: Holger Schemel Date: Tue, 12 Oct 2021 09:12:59 +0000 (+0200) Subject: improved error handling when uploading tapes to server X-Git-Tag: 4.3.0.0~20 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=eca47918b9fe7fa90a5983c09cef9c492a449ec4;p=rocksndiamonds.git improved error handling when uploading tapes to server --- diff --git a/src/screens.c b/src/screens.c index fb6b4e76..339b8b6c 100644 --- a/src/screens.c +++ b/src/screens.c @@ -9987,7 +9987,19 @@ static boolean OfferUploadTapes(void) int num_tapes_uploaded = UploadTapes(); char message[100]; - sprintf(message, "%d tapes uploaded!", num_tapes_uploaded); + if (num_tapes_uploaded < 0) + { + Request("Cannot upload tapes to score server!", REQ_CONFIRM); + + return FALSE; + } + + if (num_tapes_uploaded == 0) + sprintf(message, "No tapes uploaded!"); + else if (num_tapes_uploaded == 1) + sprintf(message, "1 tape uploaded!"); + else + sprintf(message, "%d tapes uploaded!", num_tapes_uploaded); Request(message, REQ_CONFIRM); @@ -9996,7 +10008,7 @@ static boolean OfferUploadTapes(void) SaveSetup(); - return (num_tapes_uploaded > 0); + return TRUE; } void CheckUploadTapes(void) diff --git a/src/tape.c b/src/tape.c index 68eeaccf..38bc0166 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1400,7 +1400,7 @@ static void AutoPlayTapes_SetScoreEntry(int score, int time) server_scores.uploaded = FALSE; } -static void AutoPlayTapes_WaitForUpload(void) +static boolean AutoPlayTapes_WaitForUpload(void) { unsigned int upload_delay = 0; unsigned int upload_delay_value = 10000; @@ -1415,7 +1415,10 @@ static void AutoPlayTapes_WaitForUpload(void) PrintNoLog("\r"); Print("- uploading score tape to score server - TIMEOUT.\n"); - Fail("cannot upload score tape to score server"); + if (program.headless) + Fail("cannot upload score tape to score server"); + + return FALSE; } UPDATE_BUSY_STATE(); @@ -1425,6 +1428,8 @@ static void AutoPlayTapes_WaitForUpload(void) PrintNoLog("\r"); Print("- uploading score tape to score server - uploaded.\n"); + + return TRUE; } static int AutoPlayTapesExt(boolean initialize) @@ -1829,7 +1834,7 @@ static int AutoPlayTapesExt(boolean initialize) SaveServerScoreFromFile(level_nr, autoplay.tape_filename); - AutoPlayTapes_WaitForUpload(); + boolean success = AutoPlayTapes_WaitForUpload(); if (use_temporary_tape_file) unlink(autoplay.tape_filename); @@ -1837,6 +1842,13 @@ static int AutoPlayTapesExt(boolean initialize) // required for uploading multiple tapes autoplay.tape_filename = NULL; + if (!success) + { + num_tapes = -1; + + break; + } + continue; } @@ -1857,7 +1869,12 @@ static int AutoPlayTapesExt(boolean initialize) { Print("\n"); PrintLine("=", 79); - Print("SUMMARY: %d tapes uploaded.\n", num_tapes); + + if (num_tapes >= 0) + Print("SUMMARY: %d tapes uploaded.\n", num_tapes); + else + Print("SUMMARY: Uploading tapes failed.\n"); + PrintLine("=", 79); }