split function to save tape
authorHolger Schemel <info@artsoft.org>
Thu, 10 Sep 2020 18:35:15 +0000 (20:35 +0200)
committerHolger Schemel <info@artsoft.org>
Thu, 10 Sep 2020 18:35:15 +0000 (20:35 +0200)
src/files.c
src/files.h

index 283ebf0f795a7ef15aff44521301d28d88036005..32fbf32b9ee3618c0a154dfc80ab781dd1a48c6a 100644 (file)
@@ -8144,16 +8144,12 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape)
   }
 }
 
-void SaveTape(int nr)
+void SaveTapeToFilename(char *filename)
 {
-  char *filename = getTapeFilename(nr);
   FILE *file;
   int tape_pos_size;
   int info_chunk_size;
   int body_chunk_size;
-  int i;
-
-  InitTapeDirectory(leveldir_current->subdir);
 
   if (!(file = fopen(filename, MODE_WRITE)))
   {
@@ -8161,16 +8157,6 @@ void SaveTape(int nr)
     return;
   }
 
-  tape.file_version = FILE_VERSION_ACTUAL;
-  tape.game_version = GAME_VERSION_ACTUAL;
-
-  tape.num_participating_players = 0;
-
-  // count number of participating players
-  for (i = 0; i < MAX_PLAYERS; i++)
-    if (tape.player_participates[i])
-      tape.num_participating_players++;
-
   tape_pos_size = getTapePosSize(&tape);
 
   info_chunk_size = 2 + (strlen(tape.level_identifier) + 1) + 2;
@@ -8194,6 +8180,26 @@ void SaveTape(int nr)
   fclose(file);
 
   SetFilePermissions(filename, PERMS_PRIVATE);
+}
+
+void SaveTape(int nr)
+{
+  char *filename = getTapeFilename(nr);
+  int i;
+
+  InitTapeDirectory(leveldir_current->subdir);
+
+  tape.file_version = FILE_VERSION_ACTUAL;
+  tape.game_version = GAME_VERSION_ACTUAL;
+
+  tape.num_participating_players = 0;
+
+  // count number of participating players
+  for (i = 0; i < MAX_PLAYERS; i++)
+    if (tape.player_participates[i])
+      tape.num_participating_players++;
+
+  SaveTapeToFilename(filename);
 
   tape.changed = FALSE;
 }
index fd55786c1fbca4688124558bead2570d13d12912..ca331ad70e3b089a92244b918df666bdca5e7d82 100644 (file)
@@ -50,6 +50,7 @@ void CopyNativeLevel_Native_to_RND(struct LevelInfo *);
 void LoadTapeFromFilename(char *);
 void LoadTape(int);
 void LoadSolutionTape(int);
+void SaveTapeToFilename(char *);
 void SaveTape(int);
 void DumpTape(struct TapeInfo *);
 boolean SaveTapeChecked(int);