Changed: Use new code to determine free disk space

--HG--
branch : develop
hg/feature/material-editor
kervala 9 years ago
parent b11fabe867
commit 68aa20257f

@ -72,9 +72,9 @@ public:
*/ */
static bool isNT(); static bool isNT();
/** Returns the space left on the hard drive that contains the filename /** Returns the space left on the hard drive that contains the filename in bytes
*/ */
static std::string availableHDSpace (const std::string &filename); static uint64 availableHDSpace (const std::string &filename);
/** Returns all the physical memory available on the computer (in bytes) /** Returns all the physical memory available on the computer (in bytes)
*/ */

@ -34,6 +34,11 @@
# include <cpuid.h> # include <cpuid.h>
# define nlcpuid(regs, idx) __cpuid(idx, regs[0], regs[1], regs[2], regs[3]) # define nlcpuid(regs, idx) __cpuid(idx, regs[0], regs[1], regs[2], regs[3])
# endif // NL_CPU_INTEL # endif // NL_CPU_INTEL
# ifdef NL_OS_MAC
# include <sys/mount.h>
# else
# include <sys/vfs.h>
# endif
#endif // NL_OS_WINDOWS #endif // NL_OS_WINDOWS
#include "nel/misc/system_info.h" #include "nel/misc/system_info.h"
@ -1118,49 +1123,24 @@ bool CSystemInfo::isNT()
#endif #endif
} }
string CSystemInfo::availableHDSpace (const string &filename) uint64 CSystemInfo::availableHDSpace (const string &filename)
{ {
#ifdef NL_OS_UNIX std::string path = CFile::getPath(filename);
string cmd = "df ";
if(filename.empty())
cmd += ".";
else
cmd += filename;
cmd += " >/tmp/nelhdfs";
sint error = system (cmd.c_str());
if (error)
nlwarning("'%s' failed with error code %d", cmd.c_str(), error);
int fd = open("/tmp/nelhdfs", O_RDONLY);
if (fd == -1)
{
return 0;
}
else
{
char buffer[4096+1];
int len = read(fd, buffer, sizeof(buffer)-1);
close(fd);
buffer[len] = '\0';
vector<string> splitted;
explode(string(buffer), string("\n"), splitted, true);
if(splitted.size() < 2) #ifdef NL_OS_UNIX
return "NoInfo"; struct stat stst;
struct statfs stfs;
vector<string> sline;
explode(splitted[1], string(" "), sline, true);
if(sline.size() < 5) if (::stat(path.c_str(), &stst) == -1) return 0;
return splitted[1]; if (::statfs(c_str(), &stfs) == -1) return 0;
string space = sline[3] + "000"; return (uint64)(stfs.f_bavail * stst.st_blksize);
return bytesToHumanReadable(space);
}
#else #else
nlunreferenced(filename); ULARGE_INTEGER freeSpace = {0};
return "NoInfo"; BOOL bRes = ::GetDiskFreeSpaceExA(path.c_str(), &freeSpace, NULL, NULL);
if (!bRes) return 0;
return (uint64)freeSpace.QuadPart;
#endif #endif
} }

Loading…
Cancel
Save