diff --git a/dlls/game.cpp b/dlls/game.cpp index c330f308..26d6b103 100644 --- a/dlls/game.cpp +++ b/dlls/game.cpp @@ -251,7 +251,24 @@ void update_plugins() { } } +void freespace_command() { + std::string path = CMD_ARGC() > 1 ? CMD_ARGS() : ""; + + if (path.empty()) { + static char gameDir[MAX_PATH]; + GET_GAME_DIR(gameDir); + + path = gameDir; + } + + uint64_t bytes = getFreeSpace(path); + uint32_t gb = bytes / (1024ULL * 1024ULL * 1024ULL); + + ALERT(at_console, "Free space at %s is %.2f GB\n", path.c_str(), (float)gb); +} + void test_command() { + } void cfg_exec_finished() { @@ -273,8 +290,9 @@ void GameDLLInit( void ) g_engfuncs.pfnAddServerCommand("reloadplugin", reload_plugin); g_engfuncs.pfnAddServerCommand("updateplugin", update_plugin); g_engfuncs.pfnAddServerCommand("updateplugins", update_plugins); + g_engfuncs.pfnAddServerCommand("freespace", freespace_command); + // Register cvars here: - g_psv_gravity = CVAR_GET_POINTER( "sv_gravity" ); g_psv_aim = CVAR_GET_POINTER( "sv_aim" ); g_psv_allow_autoaim = CVAR_GET_POINTER("sv_allow_autoaim"); diff --git a/dlls/util.cpp b/dlls/util.cpp index 7e3f12f0..197af0c9 100644 --- a/dlls/util.cpp +++ b/dlls/util.cpp @@ -3129,6 +3129,7 @@ uint64_t getFreeSpace(const std::string& path) { ALERT(at_console, "Error getting free space.\n"); return 0; } - return stat.f_bavail * stat.f_bsize; + + return (uint64_t)stat.f_bavail * (uint64_t)stat.f_bsize; #endif }