Skip to content

Commit

Permalink
fix freespace util for linux
Browse files Browse the repository at this point in the history
fr this time
  • Loading branch information
wootguy committed Nov 10, 2024
1 parent 3e4f48a commit 1597d7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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
3 changes: 2 additions & 1 deletion dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 1597d7a

Please sign in to comment.