Skip to content

Commit

Permalink
add freespace command for debugging
Browse files Browse the repository at this point in the history
this util still isn't working
  • Loading branch information
wootguy committed Nov 10, 2024
1 parent 3e4f48a commit 706413b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 19 additions & 1 deletion dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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");
Expand Down
10 changes: 10 additions & 0 deletions dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", (uint64_t)stat.f_bsize);
ALERT(at_console, "f_frsize: %llu\n", (uint64_t)stat.f_frsize);
ALERT(at_console, "f_blocks: %llu\n", (uint64_t)stat.f_blocks);
ALERT(at_console, "f_bfree: %llu\n", (uint64_t)stat.f_bfree);
ALERT(at_console, "f_bavail: %llu\n", (uint64_t)stat.f_bavail);
ALERT(at_console, "f_files: %llu\n", (uint64_t)stat.f_files);
ALERT(at_console, "f_ffree: %llu\n", (uint64_t)stat.f_ffree);
ALERT(at_console, "f_favail: %llu\n", (uint64_t)stat.f_favail);
ALERT(at_console, "f_namemax: %llu\n", (uint64_t)stat.f_namemax);

return stat.f_bavail * stat.f_bsize;
#endif
}

0 comments on commit 706413b

Please sign in to comment.