From 0345d6aed40b5b7d22aae3448b1eeb02b6265582 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Thu, 13 Apr 2017 00:01:04 -0400 Subject: [PATCH] make sure version.nfo is saved-to and read-from a safe place --- src/globalincs/version.cpp | 9 +++++---- src/network/multi_update.cpp | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/globalincs/version.cpp b/src/globalincs/version.cpp index b2c3bb8..52cfece 100644 --- a/src/globalincs/version.cpp +++ b/src/globalincs/version.cpp @@ -44,6 +44,7 @@ #include "version.h" #include "osregistry.h" #include "pstypes.h" +#include "cfile.h" // ---------------------------------------------------------------------------------------------------------------- // VERSION DEFINES/VARS @@ -70,7 +71,7 @@ int version_compare(const char *filename, int *u_major, int *u_minor, int *u_bui int latest_major, latest_minor, latest_build; // open file and try backup, if needed - FILE *f = fopen(filename, "rt"); + CFILE *f = cfopen(filename, "rt", CFILE_NORMAL, CF_TYPE_DATA); if (f == NULL) { return -1; } @@ -80,9 +81,9 @@ int version_compare(const char *filename, int *u_major, int *u_minor, int *u_bui SDL_strlcpy(verbuffer, "", SDL_arraysize(verbuffer)); SDL_strlcpy(buffer, "", SDL_arraysize(buffer)); - while ( !feof(f) ) { + while ( !cfeof(f) ) { // Read the line into a temporary buffer - if ( fgets(buffer, MAX_LINE_LENGTH, f) == NULL ) { + if ( cfgets(buffer, MAX_LINE_LENGTH, f) == NULL ) { break; } @@ -99,7 +100,7 @@ int version_compare(const char *filename, int *u_major, int *u_minor, int *u_bui // Line is a good one, so save it... SDL_strlcpy(verbuffer, buffer, SDL_arraysize(verbuffer)); } - fclose(f); + cfclose(f); // Make sure a version line was found if (strlen(verbuffer) == 0) { diff --git a/src/network/multi_update.cpp b/src/network/multi_update.cpp index 66b5639..b537fbd 100644 --- a/src/network/multi_update.cpp +++ b/src/network/multi_update.cpp @@ -126,6 +126,7 @@ #include "version.h" #include "inetgetfile.h" #include "cfile.h" +#include "cfilesystem.h" // ------------------------------------------------------------------------------------------------------------------- // MULTI UPDATE DEFINES/VARS @@ -148,13 +149,13 @@ char Multi_update_error_string[512]; int multi_update_http_init() { char url_file[512] = ""; - char local_file[512] = ""; + char local_file[MAX_PATH_LEN] = ""; // url SDL_strlcpy(url_file, VERSION_URL, SDL_arraysize(url_file)); // local file - SDL_snprintf(local_file, SDL_arraysize(local_file), "%s%s%s", Cfile_root_dir, DIR_SEPARATOR_STR, VERSION_LOC_FNAME); + cf_create_default_path_string(local_file, CF_TYPE_DATA, VERSION_LOC_FNAME); // new file Multi_update_get = new InetGetFile(url_file, local_file); -- 2.39.2