From 13b7bdfd228f3c1379f2a37e4249b33b449a74e4 Mon Sep 17 00:00:00 2001 From: wootguy Date: Sun, 10 Nov 2024 06:19:39 -0800 Subject: [PATCH] add freespace command for debugging this util still isn't working --- dlls/game.cpp | 20 +++++++++++++++++++- dlls/util.cpp | 10 ++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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..c5e538da 100644 --- a/dlls/util.cpp +++ b/dlls/util.cpp @@ -3129,6 +3129,16 @@ uint64_t getFreeSpace(const std::string& path) { ALERT(at_console, "Error getting free space.\n"); return 0; } + ALERT(at_console, "f_bsize: %llu\n", stat.f_bsize); + ALERT(at_console, "f_frsize: %llu\n", stat.f_frsize); + ALERT(at_console, "f_blocks: %llu\n", stat.f_blocks); + ALERT(at_console, "f_bfree: %llu\n", stat.f_bfree); + ALERT(at_console, "f_bavail: %llu\n", stat.f_bavail); + ALERT(at_console, "f_files: %llu\n", stat.f_files); + ALERT(at_console, "f_ffree: %llu\n", stat.f_ffree); + ALERT(at_console, "f_favail: %llu\n", stat.f_favail); + ALERT(at_console, "f_namemax: %llu\n", stat.f_namemax); + return stat.f_bavail * stat.f_bsize; #endif }