medfall

A super great game engine
Log | Files | Refs

commit b475cb89361fe0a7074ae42deb512ccdd7ca2fb3
parent ab105fd09d5c21cef49140725a688a1bc0ea2a3b
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Jul 15 23:08:43 +0300

Write the game version/size to the registry after an update

Diffstat:
launcher/main.cc | 45++++++++++++++++++++++++++++++++++++++++++++-
scripts/gen_makefile.lua | 3+--
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/launcher/main.cc b/launcher/main.cc @@ -6,6 +6,7 @@ #include <set> #include "intrinsics.h" +#include "int_conversions.h" #include "game.h" #include "log.h" #include "gl.h" @@ -300,6 +301,7 @@ struct Updater { std::vector< std::string > files_to_remove; u64 update_size = 0; + u64 game_size = 0; }; #define DOWNLOAD_THREADS 16 @@ -407,6 +409,7 @@ static WORK_QUEUE_CALLBACK( download_manifest ) { updater->files_to_update.push_back( FileUpdate( kv.first ) ); updater->update_size += kv.second.file_size; } + updater->game_size += kv.second.file_size; } updater->state = UPDATER_NEED_UPDATE; @@ -469,6 +472,38 @@ static WORK_QUEUE_CALLBACK( download_file ) { glfwPostEmptyEvent(); } +#if PLATFORM_WINDOWS +void set_registry_key( HKEY hkey, const char * path, const char * value, const char * data ) { + HKEY key; + LONG ok_open = RegOpenKeyExA( hkey, path, 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &key ); + if( ok_open != ERROR_SUCCESS ) { + WARN( "couldn't open registry key {} {} ({})", path, value, ok_open ); + return; + } + SCOPE_EXIT( RegCloseKey( key ) ); + + LONG ok_set = RegSetValueExA( key, value, 0, REG_SZ, ( const BYTE * ) data, checked_cast< DWORD >( strlen( data ) + 1 ) ); + if( ok_set != ERROR_SUCCESS ) { + WARN( "couldn't write registry key ({})", ok_set ); + } +} + +void set_registry_key( HKEY hkey, const char * path, const char * value, u32 data ) { + HKEY key; + LONG ok_open = RegOpenKeyExA( hkey, path, 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &key ); + if( ok_open != ERROR_SUCCESS ) { + WARN( "couldn't open registry key {} {} ({})", path, value, ok_open ); + return; + } + SCOPE_EXIT( RegCloseKey( key ) ); + + LONG ok_set = RegSetValueExA( key, value, 0, REG_DWORD, ( const BYTE * ) &data, sizeof( data ) ); + if( ok_set != ERROR_SUCCESS ) { + WARN( "couldn't write registry key ({})", ok_set ); + } +} +#endif + static WORK_QUEUE_CALLBACK( install_update ) { std::vector< std::string > updated_files; Version version; @@ -504,8 +539,10 @@ static WORK_QUEUE_CALLBACK( install_update ) { // TODO: remove update directory tree // TODO: remove game files that are no longer needed + str< 64 > version_str( "{}.{}.{}.{}", version.a, version.b, version.c, version.d ); + FILE * version_txt = fopen( "version.txt", "w" ); - ggprint_to_file( version_txt, "{}.{}.{}.{}\n", version.a, version.b, version.c, version.d ); + ggprint_to_file( version_txt, "{}\n", version_str ); fclose( version_txt ); FILE * manifest_txt = fopen( "manifest.txt", "w" ); @@ -515,6 +552,12 @@ static WORK_QUEUE_CALLBACK( install_update ) { fclose( manifest_txt ); Updater * updater = SCOPED_ACQUIRE( locked_updater ); + +#if PLATFORM_WINDOWS + set_registry_key( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Medfall", "DisplayVersion", version_str.c_str() ); + set_registry_key( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Medfall", "EstimatedSize", clamp_u32( updater->game_size / 1024 ) ); +#endif + updater->state = UPDATER_READY; glfwPostEmptyEvent(); diff --git a/scripts/gen_makefile.lua b/scripts/gen_makefile.lua @@ -15,8 +15,7 @@ local configs = { toolchain = "msvc", cxxflags = "/I . /c /Oi /Gm- /GR- /EHa- /EHsc /nologo /DNOMINMAX /D_USE_MATH_DEFINES /DWIN32_LEAN_AND_MEAN", - -- ldflags = "user32.lib shell32.lib opengl32.lib gdi32.lib Ws2_32.lib", - ldflags = "user32.lib shell32.lib dbghelp.lib /nologo", + ldflags = "user32.lib shell32.lib advapi32.lib dbghelp.lib /nologo", warnings = "/W4 /wd4100 /wd4201 /wd4189 /wd4351 /wd4505 /wd4127 /wd4530 /wd4702 /D_CRT_SECURE_NO_WARNINGS", },