ppsspp/Common/File/DiskFree.cpp
Henrik Rydgård e01ca5b057
Logging API change (refactor) (#19324)
* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
2024-07-14 14:42:59 +02:00

70 lines
1.5 KiB
C++

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <sys/stat.h>
#else
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#if defined(__ANDROID__)
#include <sys/types.h>
#include <sys/vfs.h>
#define statvfs statfs
#else
#include <sys/statvfs.h>
#endif
#include <ctype.h>
#include <fcntl.h>
#endif
#include <cinttypes>
#include "Common/Log.h"
#include "Common/File/Path.h"
#include "Common/File/AndroidStorage.h"
#include "Common/Data/Encoding/Utf8.h"
#if PPSSPP_PLATFORM(UWP)
#include "UWP/UWPHelpers/StorageManager.h"
#endif
bool free_disk_space(const Path &path, int64_t &space) {
#ifdef _WIN32
ULARGE_INTEGER free;
#if PPSSPP_PLATFORM(UWP)
if (GetDriveFreeSpace(path, space)) {
return true;
}
else
#endif
if (GetDiskFreeSpaceExW(path.ToWString().c_str(), &free, nullptr, nullptr)) {
space = free.QuadPart;
return true;
}
#else
if (path.Type() == PathType::CONTENT_URI) {
space = Android_GetFreeSpaceByContentUri(path.ToString());
INFO_LOG(Log::Common, "Free space at '%s': %" PRIu64, path.c_str(), space);
return space >= 0;
}
struct statvfs diskstat;
int res = statvfs(path.c_str(), &diskstat);
if (res == 0) {
// Not sure why we're excluding Android here anyway...
#ifndef __ANDROID__
if (diskstat.f_flag & ST_RDONLY) {
// No space to write.
space = 0;
return true;
}
#endif
space = (uint64_t)diskstat.f_bavail * (uint64_t)diskstat.f_frsize;
return true;
}
#endif
// We can't know how much is free.
return false;
}