mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-02-06 13:38:56 +00:00
Check actual free disk space when games ask.
Windows only for the moment.
This commit is contained in:
parent
763e5c9c4b
commit
2958c575a1
@ -895,34 +895,22 @@ int SavedataParam::BuildHash(unsigned char *output,
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string SavedataParam::GetSpaceText(int size)
|
||||
std::string SavedataParam::GetSpaceText(u64 size)
|
||||
{
|
||||
static const char *suffixes[] = {"B", "KB", "MB", "GB"};
|
||||
char text[50];
|
||||
|
||||
if(size < 1024)
|
||||
for (size_t i = 0; i < ARRAY_SIZE(suffixes); ++i)
|
||||
{
|
||||
sprintf(text,"%d B",size);
|
||||
return std::string(text);
|
||||
if (size < 1024)
|
||||
{
|
||||
snprintf(text, sizeof(text), "%d %s", size, suffixes[i]);
|
||||
return std::string(text);
|
||||
}
|
||||
size /= 1024;
|
||||
}
|
||||
|
||||
size /= 1024;
|
||||
|
||||
if(size < 1024)
|
||||
{
|
||||
sprintf(text,"%d KB",size);
|
||||
return std::string(text);
|
||||
}
|
||||
|
||||
size /= 1024;
|
||||
|
||||
if(size < 1024)
|
||||
{
|
||||
sprintf(text,"%d MB",size);
|
||||
return std::string(text);
|
||||
}
|
||||
|
||||
size /= 1024;
|
||||
sprintf(text,"%d GB",size);
|
||||
snprintf(text, sizeof(text), "%d TB");
|
||||
return std::string(text);
|
||||
}
|
||||
|
||||
@ -936,10 +924,11 @@ int SavedataParam::GetSizes(SceUtilitySavedataParam *param)
|
||||
|
||||
if (param->msFree.IsValid())
|
||||
{
|
||||
const u64 freeBytes = MemoryStick_FreeSpace();
|
||||
param->msFree->clusterSize = (u32)MemoryStick_SectorSize();
|
||||
param->msFree->freeClusters = (u32)(MemoryStick_FreeSpace() / MemoryStick_SectorSize());
|
||||
param->msFree->freeSpaceKB = (u32)(MemoryStick_FreeSpace() / 0x400);
|
||||
const std::string spaceTxt = SavedataParam::GetSpaceText((int)MemoryStick_FreeSpace());
|
||||
param->msFree->freeClusters = (u32)(freeBytes / MemoryStick_SectorSize());
|
||||
param->msFree->freeSpaceKB = (u32)(freeBytes / 0x400);
|
||||
const std::string spaceTxt = SavedataParam::GetSpaceText(freeBytes);
|
||||
memset(param->msFree->freeSpaceStr, 0, sizeof(param->msFree->freeSpaceStr));
|
||||
strncpy(param->msFree->freeSpaceStr, spaceTxt.c_str(), sizeof(param->msFree->freeSpaceStr));
|
||||
}
|
||||
@ -1184,14 +1173,15 @@ bool SavedataParam::GetSize(SceUtilitySavedataParam *param)
|
||||
|
||||
if (param->sizeInfo.IsValid())
|
||||
{
|
||||
const u64 freeBytes = MemoryStick_FreeSpace();
|
||||
// TODO: Read the entries and count up the size vs. existing size?
|
||||
|
||||
param->sizeInfo->sectorSize = (int)MemoryStick_SectorSize();
|
||||
param->sizeInfo->freeSectors = (int)(MemoryStick_FreeSpace() / MemoryStick_SectorSize());
|
||||
param->sizeInfo->freeSectors = (int)(freeBytes / MemoryStick_SectorSize());
|
||||
|
||||
// TODO: Is this after the specified files? Before?
|
||||
param->sizeInfo->freeKB = (int)(MemoryStick_FreeSpace() / 1024);
|
||||
std::string spaceTxt = SavedataParam::GetSpaceText((int)MemoryStick_FreeSpace());
|
||||
param->sizeInfo->freeKB = (int)(freeBytes / 1024);
|
||||
std::string spaceTxt = SavedataParam::GetSpaceText(freeBytes);
|
||||
strncpy(param->sizeInfo->freeString, spaceTxt.c_str(), 8);
|
||||
param->sizeInfo->freeString[7] = '\0';
|
||||
|
||||
|
@ -323,7 +323,7 @@ public:
|
||||
std::string GetKey(const SceUtilitySavedataParam *param) const;
|
||||
bool HasKey(const SceUtilitySavedataParam *param) const;
|
||||
|
||||
static std::string GetSpaceText(int size);
|
||||
static std::string GetSpaceText(u64 size);
|
||||
|
||||
int SetPspParam(SceUtilitySavedataParam* param);
|
||||
SceUtilitySavedataParam *GetPspParam();
|
||||
|
@ -15,6 +15,7 @@
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <limits>
|
||||
#include "ChunkFile.h"
|
||||
#include "FileUtil.h"
|
||||
#include "DirectoryFileSystem.h"
|
||||
@ -721,6 +722,20 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
|
||||
return myVector;
|
||||
}
|
||||
|
||||
u64 DirectoryFileSystem::FreeSpace(const std::string &path) {
|
||||
#ifdef _WIN32
|
||||
const std::wstring w32path = ConvertUTF8ToWString(GetLocalPath(path));
|
||||
ULARGE_INTEGER free;
|
||||
if (GetDiskFreeSpaceExW(w32path.c_str(), &free, nullptr, nullptr))
|
||||
return free.QuadPart;
|
||||
#else
|
||||
// TODO: Implement.
|
||||
#endif
|
||||
|
||||
// Just assume they're swimming in free disk space if we don't know otherwise.
|
||||
return std::numeric_limits<u64>::max();
|
||||
}
|
||||
|
||||
void DirectoryFileSystem::DoState(PointerWrap &p) {
|
||||
auto s = p.Section("DirectoryFileSystem", 0, 2);
|
||||
if (!s)
|
||||
|
@ -109,6 +109,7 @@ public:
|
||||
bool RemoveFile(const std::string &filename);
|
||||
bool GetHostPath(const std::string &inpath, std::string &outpath);
|
||||
int Flags() { return flags; }
|
||||
u64 FreeSpace(const std::string &path) override;
|
||||
|
||||
private:
|
||||
struct OpenFileEntry {
|
||||
@ -151,6 +152,7 @@ public:
|
||||
bool RemoveFile(const std::string &filename);
|
||||
bool GetHostPath(const std::string &inpath, std::string &outpath);
|
||||
int Flags() { return 0; }
|
||||
u64 FreeSpace(const std::string &path) override { return 0; }
|
||||
|
||||
private:
|
||||
struct OpenFileEntry {
|
||||
|
@ -117,6 +117,7 @@ public:
|
||||
virtual int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) = 0;
|
||||
virtual int DevType(u32 handle) = 0;
|
||||
virtual int Flags() = 0;
|
||||
virtual u64 FreeSpace(const std::string &path) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -140,6 +141,7 @@ public:
|
||||
virtual int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) {return SCE_KERNEL_ERROR_ERRNO_FUNCTION_NOT_SUPPORTED; }
|
||||
virtual int DevType(u32 handle) { return 0; }
|
||||
virtual int Flags() { return 0; }
|
||||
virtual u64 FreeSpace(const std::string &path) override { return 0; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
|
||||
int DevType(u32 handle) override;
|
||||
int Flags() override { return 0; }
|
||||
u64 FreeSpace(const std::string &path) override { return 0; }
|
||||
|
||||
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
|
||||
bool GetHostPath(const std::string &inpath, std::string &outpath) {return false;}
|
||||
@ -131,6 +132,7 @@ public:
|
||||
return isoFileSystem_->DevType(handle);
|
||||
}
|
||||
int Flags() override { return isoFileSystem_->Flags(); }
|
||||
u64 FreeSpace(const std::string &path) override { return isoFileSystem_->FreeSpace(path); }
|
||||
|
||||
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override {
|
||||
return isoFileSystem_->WriteFile(handle, pointer, size);
|
||||
|
@ -591,6 +591,17 @@ int MetaFileSystem::ReadEntireFile(const std::string &filename, std::vector<u8>
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 MetaFileSystem::FreeSpace(const std::string &path)
|
||||
{
|
||||
lock_guard guard(lock);
|
||||
std::string of;
|
||||
IFileSystem *system;
|
||||
if (MapFilePath(path, of, &system))
|
||||
return system->FreeSpace(of);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MetaFileSystem::DoState(PointerWrap &p)
|
||||
{
|
||||
lock_guard guard(lock);
|
||||
|
@ -108,6 +108,7 @@ public:
|
||||
virtual int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec);
|
||||
virtual int DevType(u32 handle);
|
||||
virtual int Flags() { return 0; }
|
||||
virtual u64 FreeSpace(const std::string &path) override;
|
||||
|
||||
// Convenience helper - returns < 0 on failure.
|
||||
int ReadEntireFile(const std::string &filename, std::vector<u8> &data);
|
||||
|
@ -41,6 +41,7 @@ public:
|
||||
bool GetHostPath(const std::string &inpath, std::string &outpath);
|
||||
std::vector<PSPFileInfo> GetDirListing(std::string path);
|
||||
int Flags() { return 0; }
|
||||
u64 FreeSpace(const std::string &path) override { return 0; }
|
||||
|
||||
// unsupported operations
|
||||
size_t WriteFile(u32 handle, const u8 *pointer, s64 size);
|
||||
|
@ -438,7 +438,7 @@ void __IoWakeManager() {
|
||||
}
|
||||
|
||||
void __IoInit() {
|
||||
MemoryStick_SetFatState(PSP_FAT_MEMORYSTICK_STATE_ASSIGNED);
|
||||
MemoryStick_Init();
|
||||
|
||||
asyncNotifyEvent = CoreTiming::RegisterEvent("IoAsyncNotify", __IoAsyncNotify);
|
||||
syncNotifyEvent = CoreTiming::RegisterEvent("IoSyncNotify", __IoSyncNotify);
|
||||
|
@ -1,18 +1,26 @@
|
||||
#include "MemoryStick.h"
|
||||
#include "ChunkFile.h"
|
||||
#include "Common/ChunkFile.h"
|
||||
#include "Core/FileSystems/MetaFileSystem.h"
|
||||
#include "Core/HW/MemoryStick.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
// MS and FatMS states.
|
||||
static MemStickState memStickState = PSP_MEMORYSTICK_STATE_DRIVER_READY;
|
||||
static MemStickFatState memStickFatState = PSP_FAT_MEMORYSTICK_STATE_ASSIGNED;
|
||||
static MemStickState memStickState;
|
||||
static MemStickFatState memStickFatState;
|
||||
static u64 memStickSize;
|
||||
|
||||
void MemoryStick_DoState(PointerWrap &p)
|
||||
{
|
||||
auto s = p.Section("MemoryStick", 1);
|
||||
auto s = p.Section("MemoryStick", 1, 2);
|
||||
if (!s)
|
||||
return;
|
||||
|
||||
p.Do(memStickState);
|
||||
p.Do(memStickFatState);
|
||||
if (s >= 2)
|
||||
p.Do(memStickSize);
|
||||
else
|
||||
memStickSize = 1ULL * 1024 * 1024 * 1024;
|
||||
|
||||
}
|
||||
|
||||
MemStickState MemoryStick_State()
|
||||
@ -32,10 +40,20 @@ u64 MemoryStick_SectorSize()
|
||||
|
||||
u64 MemoryStick_FreeSpace()
|
||||
{
|
||||
return 1ULL * 1024 * 1024 * 1024; // 1GB
|
||||
u64 freeSpace = pspFileSystem.FreeSpace("ms0:/");
|
||||
if (freeSpace < memStickSize)
|
||||
return freeSpace;
|
||||
return memStickSize;
|
||||
}
|
||||
|
||||
void MemoryStick_SetFatState(MemStickFatState state)
|
||||
{
|
||||
memStickFatState = state;
|
||||
}
|
||||
|
||||
void MemoryStick_Init()
|
||||
{
|
||||
memStickState = PSP_MEMORYSTICK_STATE_DRIVER_READY;
|
||||
memStickFatState = PSP_FAT_MEMORYSTICK_STATE_ASSIGNED;
|
||||
memStickSize = 8ULL * 1024 * 1024 * 1024; // 8GB
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ enum MemStickFatState {
|
||||
PSP_FAT_MEMORYSTICK_STATE_ASSIGNED = 1,
|
||||
};
|
||||
|
||||
void MemoryStick_Init();
|
||||
void MemoryStick_DoState(PointerWrap &p);
|
||||
MemStickState MemoryStick_State();
|
||||
MemStickFatState MemoryStick_FatState();
|
||||
|
Loading…
x
Reference in New Issue
Block a user