Made Sys_GetFreeDiskSpace, because it'll probably need to get reused eventually anyway.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5450 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2019-04-17 19:57:26 +00:00
parent cb346bc1db
commit 15390a908f
10 changed files with 129 additions and 34 deletions

View File

@ -4245,11 +4245,16 @@ void CL_FTP_f(void)
//fixme: make a cvar
void CL_Fog_f(void)
{
int ftype = Q_strcasecmp(Cmd_Argv(0), "fog");
int ftype;
if (!Q_strcasecmp(Cmd_Argv(0), "waterfog"))
ftype = 1;
else //fog
ftype = 0;
if ((cl.fog_locked && !Cmd_FromGamecode() && !cls.allow_cheats) || Cmd_Argc() <= 1)
{
static const char *fognames[]={"fog","waterfog"};
if (Cmd_ExecLevel != RESTRICT_INSECURE)
Con_Printf("Current fog %f (r:%f g:%f b:%f, a:%f bias:%f)\n", cl.fog[ftype].density, cl.fog[ftype].colour[0], cl.fog[ftype].colour[1], cl.fog[ftype].colour[2], cl.fog[ftype].alpha, cl.fog[ftype].depthbias);
Con_Printf("Current %s %f (r:%f g:%f b:%f, a:%f bias:%f)\n", fognames[ftype], cl.fog[ftype].density, cl.fog[ftype].colour[0], cl.fog[ftype].colour[1], cl.fog[ftype].colour[2], cl.fog[ftype].alpha, cl.fog[ftype].depthbias);
}
else
{
@ -4298,6 +4303,29 @@ void CL_Fog_f(void)
}
}
#ifdef _DEBUG
void CL_FreeSpace_f(void)
{
quint64_t freespace;
const char *freepath = Cmd_Argv(1);
if (Sys_GetFreeDiskSpace(freepath, &freespace))
{
if (freespace > 512.0*1024*1024*1024)
Con_Printf("%s: %g tb available\n", freepath, freespace/(1024.0*1024*1024*1024));
else if (freespace > 512.0*1024*1024)
Con_Printf("%s: %g gb available\n", freepath, freespace/(1024.0*1024*1024));
else if (freespace > 512.0*1024)
Con_Printf("%s: %g mb available\n", freepath, freespace/(1024.0*1024));
else if (freespace > 512.0)
Con_Printf("%s: %g kb available\n", freepath, freespace/1024.0);
else
Con_Printf("%s: %"PRIu64" bytes available\n", freepath, freespace);
}
else
Con_Printf("%s: disk free not queryable\n", freepath);
}
#endif
void CL_CrashMeEndgame_f(void)
{
Host_EndGame("crashme! %s", Cmd_Args());
@ -4663,6 +4691,9 @@ void CL_Init (void)
Cmd_AddCommandD ("demo_jump", CL_DemoJump_f, "Jump to a specified time in a demo. Prefix with a + or - for a relative offset. Seeking backwards will restart the demo and the fast forward, which can take some time in long demos.");
Cmd_AddCommandD ("demo_nudge", CL_DemoNudge_f, "Nudge the demo by one frame. Argument should be +1 or -1. Nudging backwards is limited.");
Cmd_AddCommandAD ("timedemo", CL_TimeDemo_f, CL_DemoList_c, NULL);
#ifdef _DEBUG
Cmd_AddCommand ("freespace", CL_FreeSpace_f);
#endif
Cmd_AddCommand ("crashme_endgame", CL_CrashMeEndgame_f);
Cmd_AddCommand ("crashme_error", CL_CrashMeError_f);

View File

@ -21,17 +21,6 @@
#define HAVE_API_VFW
#endif
#ifdef HAVE_MEDIA_ENCODER
#if defined(__linux__) && !defined(ANDROID)
//should really include posix 2001 systems in general
#define HAVE_STATVFS
#endif
#ifdef HAVE_STATVFS
#include <sys/statvfs.h>
#endif
#endif
#ifdef _WIN32
#include "winquake.h"
#endif
@ -2999,27 +2988,16 @@ static void QDECL capture_raw_video (void *vctx, int frame, void *data, int stri
{
char base[MAX_QPATH];
Q_strncpyz(base, ctx->videonameprefix, sizeof(base));
*COM_SkipPath(base) = 0;
if (FS_NativePath(base, ctx->fsroot, filename, sizeof(filename)))
{
#ifdef HAVE_STATVFS
//posix 2001
struct statvfs inf;
if(0==statvfs(filename, &inf))
{
if (inf.f_frsize*(double)inf.f_blocks < (1024.*1024)*capturethrottlesize.value)
Sys_Sleep(1);
}
#elif defined(_WIN32) && !defined(FTE_SDL)
wchar_t ffs[MAX_OSPATH];
ULARGE_INTEGER freebytes;
if (GetDiskFreeSpaceExW(widen(ffs, sizeof(ffs), filename), &freebytes, NULL, NULL))
if (freebytes.QuadPart < (ULONGLONG)(1024*1024)*capturethrottlesize.value)
Sys_Sleep(1);
#else
Con_Printf("capturethrottlesize is unsupported in this build\n");
capturethrottlesize.ival = 0;
#endif
quint64_t diskfree = 0;
if (Sys_GetFreeDiskSpace(filename, &diskfree) && diskfree < (quint64_t)1024*1024*capturethrottlesize.value)
Sys_Sleep(1); //throttle
else
{
Con_Printf("%s: unable to query free disk space. Disabling\n", capturethrottlesize.name);
capturethrottlesize.ival = capturethrottlesize.value = 0;
}
}
}
}

View File

@ -860,6 +860,24 @@ qboolean Sys_Rename (const char *oldfname, const char *newfname)
{
return !rename(oldfname, newfname);
}
#if _POSIX_C_SOURCE >= 200112L
#include <sys/statvfs.h>
#endif
qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace)
{
#if _POSIX_C_SOURCE >= 200112L
//posix 2001
struct statvfs inf;
if(0==statvfs(path, &inf))
{
*freespace = inf.f_bsize*(quint64_t)inf.f_bavail;
return true;
}
#endif
return false;
}
void Sys_SendKeyEvents(void)
{
}

View File

@ -480,6 +480,22 @@ qboolean Sys_Rename (const char *oldfname, const char *newfname)
{
return !rename(oldfname, newfname);
}
#if _POSIX_C_SOURCE >= 200112L
#include <sys/statvfs.h>
#endif
qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace)
{
#if _POSIX_C_SOURCE >= 200112L
//posix 2001
struct statvfs inf;
if(0==statvfs(path, &inf))
{
*freespace = inf.f_bsize*(quint64_t)inf.f_bavail; //grab the quota-free value rather than the actual free space
return true;
}
#endif
return false;
}
int Sys_DebugLog(char *file, char *fmt, ...)
{

View File

@ -287,6 +287,23 @@ qboolean Sys_Rename (const char *oldfname, const char *newfname)
return !rename(oldfname, newfname);
}
#if _POSIX_C_SOURCE >= 200112L
#include <sys/statvfs.h>
#endif
qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace)
{
#if _POSIX_C_SOURCE >= 200112L
//posix 2001
struct statvfs inf;
if(0==statvfs(path, &inf))
{
*freespace = inf.f_bsize*(quint64_t)inf.f_bavail;
return true;
}
#endif
return false;
}
//someone used the 'quit' command
void Sys_Quit (void)
{

View File

@ -682,3 +682,17 @@ searchpathfuncs_t *QDECL VFSW32_OpenPath(vfsfile_t *mustbenull, searchpathfuncs_
return &np->pub;
}
#endif
qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace)
{ //symlinks means the path needs to be fairly full. it may also be a file, and relative to the working directory.
wchar_t ffs[MAX_OSPATH];
ULARGE_INTEGER freebytes;
if (GetDiskFreeSpaceExW(widen(ffs, sizeof(ffs), path), &freebytes, NULL, NULL))
{
*freespace = freebytes.QuadPart;
return true;
}
return false;
}

View File

@ -28,6 +28,7 @@ void Sys_mkdir (const char *path); //not all pre-unix systems have directories (
qboolean Sys_rmdir (const char *path);
qboolean Sys_remove (const char *path);
qboolean Sys_Rename (const char *oldfname, const char *newfname);
qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace); //false for not-implemented or other error. path will be a system path, but may be relative (if basedir isn't properly known). path MAY be a file, or may be a slash-terminated directory.
qboolean Sys_FindGameData(const char *poshname, const char *gamename, char *basepath, int basepathlen, qboolean allowprompts);
//

View File

@ -1907,7 +1907,7 @@ qboolean VID_AttachGL (rendererstate_t *info)
Con_SafePrintf("WGL_EXTENSIONS: %s\n", wgl_extensions?wgl_extensions:"NONE");
qwglCreateContextAttribsARB = getglfunc("wglCreateContextAttribsARB");
#if 1//def _DEBUG
//attempt to promote that to opengl3.
if (qwglCreateContextAttribsARB)
{
@ -2020,7 +2020,6 @@ qboolean VID_AttachGL (rendererstate_t *info)
}
}
}
#endif
qwglChoosePixelFormatARB = getglfunc("wglChoosePixelFormatARB");
qwglGetPixelFormatAttribfvARB = getglfunc("wglGetPixelFormatAttribfvARB");

View File

@ -111,6 +111,24 @@ qboolean Sys_Rename (const char *oldfname, const char *newfname)
return !rename(oldfname, newfname);
}
#if _POSIX_C_SOURCE >= 200112L
#include <sys/statvfs.h>
#endif
qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace)
{
#if _POSIX_C_SOURCE >= 200112L
//posix 2001
struct statvfs inf;
if(0==statvfs(path, &inf))
{
*freespace = inf.f_bsize*(quint64_t)inf.f_bavail;
return true;
}
#endif
return false;
}
int Sys_DebugLog(char *file, char *fmt, ...)
{
va_list argptr;

View File

@ -103,6 +103,9 @@ qboolean Sys_remove (const char *path)
qboolean Sys_Rename (const char *oldfname, const char *newfname)
{
return emscriptenfte_buf_rename(oldfname, newfname);
}
qboolean Sys_GetFreeDiskSpace(const char *path, quint64_t *freespace)
{ //not implemented. we could try querying local storage quotas, but our filesystem is otherwise purely ram so doesn't have much of a limit in 64bit browsers. hurrah for swap space.
return false;
}