From d868aa2ee98e2ceaceebf31ea7f371d538da954a Mon Sep 17 00:00:00 2001 From: JAJames Date: Thu, 3 Mar 2016 05:14:29 -0500 Subject: [PATCH] Added case handling for when a leaving_level_movie already exists, and a file is in the default movie's pending position. This case may occur when overwriting an existing installation (using a patcher or otherwise). --- Rx_SetStartupMovie/Rx_SetStartupMovie.c | 36 ++++++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/Rx_SetStartupMovie/Rx_SetStartupMovie.c b/Rx_SetStartupMovie/Rx_SetStartupMovie.c index 9ab183d..4881e6a 100644 --- a/Rx_SetStartupMovie/Rx_SetStartupMovie.c +++ b/Rx_SetStartupMovie/Rx_SetStartupMovie.c @@ -145,11 +145,21 @@ __declspec(dllexport) void SetStartupMovie(wchar_t *in_leaving_level, wchar_t *i { fclose(file); - // A level-specific movie is currently in position; move it strcpy(leaving_level_movie_filename, movie_prefix); strcpy(leaving_level_movie_filename + sizeof(movie_prefix) / sizeof(char) - 1, leaving_level); strcpy(leaving_level_movie_filename + sizeof(movie_prefix) / sizeof(char) - 1 + leaving_level_length, movie_file_extension); - rename(movie_filename, leaving_level_movie_filename); + + // Check if leaving_level_movie already exists + file = fopen(leaving_level_movie_filename, "rb"); + if (file != NULL) + { + fclose(file); + + // Assume the loaded movie is default (as would be the case after an update/reinstall); remove old default movie + remove(movie_prefix); + } + else // A level-specific movie is currently in position; move it + rename(movie_filename, leaving_level_movie_filename); } else // The default movie is currently in position; move it. rename(movie_filename, movie_prefix); @@ -165,14 +175,26 @@ __declspec(dllexport) void SetStartupMovie(wchar_t *in_leaving_level, wchar_t *i { fclose(file); - // A level-specific movie is currently in position; move it strcpy(leaving_level_movie_filename, movie_prefix); strcpy(leaving_level_movie_filename + sizeof(movie_prefix) / sizeof(char) - 1, leaving_level); strcpy(leaving_level_movie_filename + sizeof(movie_prefix) / sizeof(char) - 1 + leaving_level_length, movie_file_extension); - rename(movie_filename, leaving_level_movie_filename); - - // Move the default movie into position - rename(movie_prefix, movie_filename); + + // Check if leaving_level_movie already exists + file = fopen(leaving_level_movie_filename, "rb"); + if (file != NULL) + { + fclose(file); + + // Assume the loaded movie is default (as would be the case after an update/reinstall); remove old default movie + remove(movie_prefix); + } + else // A level-specific movie is currently in position; move it + { + rename(movie_filename, leaving_level_movie_filename); + + // Move the default movie into position + rename(movie_prefix, movie_filename); + } } // else // Default movie is already in position; nothing to do }