improved error handling when uploading tapes to server
authorHolger Schemel <info@artsoft.org>
Tue, 12 Oct 2021 09:12:59 +0000 (11:12 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 12 Oct 2021 09:12:59 +0000 (11:12 +0200)
src/screens.c
src/tape.c

index fb6b4e76976952219a1015710389d65fe6dbb38a..339b8b6c593cc3dfe4bef7c7c64affc9a91bcf5a 100644 (file)
@@ -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)
index 68eeaccf0cd1267159d239005ce76870d7b1e6a6..38bc0166394f487ef64a31a979ad25e4e89b316c 100644 (file)
@@ -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);
   }