medfall

A super great game engine
Log | Files | Refs

commit 3cebd5f6f4e1e38aab47842ad84d97cb5d4aa142
parent 05a9ee7282295d3b0fded4a69e963b791b50e68c
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu Jul  6 21:47:55 +0300

Let the launcher update itself

Diffstat:
launcher/main.cc | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/launcher/main.cc b/launcher/main.cc @@ -34,6 +34,8 @@ #include "libs/monocypher/monocypher.h" +#include "libs/whereami/whereami.h" + #if PLATFORM_WINDOWS #define GAME_BINARY "medfall.exe" #else @@ -483,11 +485,22 @@ static WORK_QUEUE_CALLBACK( install_update ) { manifest = updater->remote_manifest; } + char launcher_path[ 1024 ]; + int dirname_length; + int path_length = wai_getExecutablePath( launcher_path, sizeof( launcher_path ), &dirname_length ); + launcher_path[ path_length ] = '\0'; + const char * launcher_exe = launcher_path + dirname_length + 1; + for( const std::string & file_name : updated_files ) { + if( file_name == launcher_exe ) { + str< 1024 > old( "{}.old", launcher_path ); + rename( launcher_path, old.c_str() ); + } recursive_mkdir( NULL, file_name.c_str() ); rename( ( "update/" + file_name ).c_str(), file_name.c_str() ); } + // TODO: remove update directory tree // TODO: remove game files that are no longer needed