2015-11-15 21:57:35 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2024-12-08 12:12:02 +01:00
|
|
|
#include "Common/CommonWindows.h"
|
2015-11-15 21:57:35 -08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/stat.h>
|
2016-10-12 11:13:16 +02:00
|
|
|
#if defined(__ANDROID__)
|
2015-11-15 21:57:35 -08:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
|
#define statvfs statfs
|
|
|
|
|
#else
|
|
|
|
|
#include <sys/statvfs.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#endif
|
2022-06-17 22:58:30 -07:00
|
|
|
#include <cinttypes>
|
2015-11-15 21:57:35 -08:00
|
|
|
|
2021-07-19 09:38:04 +02:00
|
|
|
#include "Common/Log.h"
|
|
|
|
|
#include "Common/File/Path.h"
|
|
|
|
|
#include "Common/File/AndroidStorage.h"
|
2020-10-01 13:05:04 +02:00
|
|
|
#include "Common/Data/Encoding/Utf8.h"
|
2015-11-15 21:57:35 -08:00
|
|
|
|
2023-05-02 00:09:22 +04:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2023-05-03 13:04:07 +04:00
|
|
|
#include "UWP/UWPHelpers/StorageManager.h"
|
2023-05-02 00:09:22 +04:00
|
|
|
#endif
|
|
|
|
|
|
2021-07-25 00:16:30 +02:00
|
|
|
bool free_disk_space(const Path &path, int64_t &space) {
|
2015-11-15 21:57:35 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
ULARGE_INTEGER free;
|
2023-05-02 00:09:22 +04:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2023-05-03 13:04:07 +04:00
|
|
|
if (GetDriveFreeSpace(path, space)) {
|
|
|
|
|
return true;
|
2023-05-02 00:09:22 +04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
2021-07-19 09:38:04 +02:00
|
|
|
if (GetDiskFreeSpaceExW(path.ToWString().c_str(), &free, nullptr, nullptr)) {
|
2015-11-15 21:57:35 -08:00
|
|
|
space = free.QuadPart;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#else
|
2021-07-19 09:38:04 +02:00
|
|
|
if (path.Type() == PathType::CONTENT_URI) {
|
|
|
|
|
space = Android_GetFreeSpaceByContentUri(path.ToString());
|
2024-07-14 14:42:59 +02:00
|
|
|
INFO_LOG(Log::Common, "Free space at '%s': %" PRIu64, path.c_str(), space);
|
2021-07-19 09:38:04 +02:00
|
|
|
return space >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-15 21:57:35 -08:00
|
|
|
struct statvfs diskstat;
|
2021-07-19 09:38:04 +02:00
|
|
|
int res = statvfs(path.c_str(), &diskstat);
|
2015-11-15 21:57:35 -08:00
|
|
|
|
|
|
|
|
if (res == 0) {
|
2021-07-26 22:11:07 +02:00
|
|
|
// Not sure why we're excluding Android here anyway...
|
2016-10-12 11:13:16 +02:00
|
|
|
#ifndef __ANDROID__
|
2015-11-15 21:57:35 -08:00
|
|
|
if (diskstat.f_flag & ST_RDONLY) {
|
2021-07-26 22:11:07 +02:00
|
|
|
// No space to write.
|
|
|
|
|
space = 0;
|
2015-11-15 21:57:35 -08:00
|
|
|
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;
|
2016-10-11 18:48:49 +02:00
|
|
|
}
|