From 808ff28aa5daf81fcd652c4977d3926409569e9d Mon Sep 17 00:00:00 2001 From: Bashar Astifan Date: Wed, 3 May 2023 13:04:07 +0400 Subject: [PATCH] Free space and other fixes - Fixed freespace value - added back BOOTABLE case to BROWSE_FOR_FILE - Fixed fake folder info - Fixed some code formating --- Common/File/DiskFree.cpp | 7 ++--- Core/System.cpp | 1 - UWP/App.cpp | 2 +- UWP/PPSSPP_UWPMain.cpp | 7 +++-- UWP/UWP.vcxproj | 1 + UWP/UWPHelpers/StorageManager.cpp | 46 +++++++++++++++++-------------- UWP/UWPHelpers/StorageManager.h | 2 +- UWP/UWPHelpers/StoragePickers.cpp | 20 +++++++------- 8 files changed, 47 insertions(+), 39 deletions(-) diff --git a/Common/File/DiskFree.cpp b/Common/File/DiskFree.cpp index 929eabf8fe..07c92c9d40 100644 --- a/Common/File/DiskFree.cpp +++ b/Common/File/DiskFree.cpp @@ -25,19 +25,18 @@ #include "Common/Data/Encoding/Utf8.h" #if PPSSPP_PLATFORM(UWP) -#include +#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 (path == g_Config.internalDataDirectory) { - space = GetLocalFreeSpace(); + if (GetDriveFreeSpace(path, space)) { + return true; } else #endif - // Is 'GetDiskFreeSpaceExW' returning wrong values in UWP? if (GetDiskFreeSpaceExW(path.ToWString().c_str(), &free, nullptr, nullptr)) { space = free.QuadPart; return true; diff --git a/Core/System.cpp b/Core/System.cpp index 6e5a6aa2c7..74fe4bf0d2 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -768,7 +768,6 @@ void InitSysDirectories() { File::CreateDir(GetSysDirectory(DIRECTORY_SAVESTATE)); File::CreateDir(GetSysDirectory(DIRECTORY_SYSTEM)); File::CreateDir(GetSysDirectory(DIRECTORY_TEXTURES)); - File::CreateDir(GetSysDirectory(DIRECTORY_CHEATS)); if (g_Config.currentDirectory.empty()) { g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME); diff --git a/UWP/App.cpp b/UWP/App.cpp index 4c91dd20e6..0b1afde5ad 100644 --- a/UWP/App.cpp +++ b/UWP/App.cpp @@ -253,7 +253,7 @@ void App::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) { create_task([app, deferral]() { g_Config.Save("App::OnSuspending"); app->m_deviceResources->Trim(); - deferral->Complete(); + deferral->Complete(); }); } diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 0273454a3f..bbef42887f 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -536,8 +536,11 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string } case SystemRequestType::BROWSE_FOR_FILE: { - std::vector supportedExtensions = { ".cso", ".bin", ".iso", ".elf", ".pbp", ".zip"}; + std::vector supportedExtensions = {}; switch ((BrowseFileType)param3) { + case BrowseFileType::BOOTABLE: + supportedExtensions = { ".cso", ".bin", ".iso", ".elf", ".pbp", ".zip" }; + break; case BrowseFileType::INI: supportedExtensions = { ".ini" }; break; @@ -545,7 +548,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string supportedExtensions = { ".db" }; break; case BrowseFileType::ANY: - supportedExtensions = {}; + // 'ChooseFile' will added '*' by default when there are no extensions assigned break; default: ERROR_LOG(FILESYS, "Unexpected BrowseFileType: %d", param3); diff --git a/UWP/UWP.vcxproj b/UWP/UWP.vcxproj index 0b7590b0fe..9a6a2da5f0 100644 --- a/UWP/UWP.vcxproj +++ b/UWP/UWP.vcxproj @@ -89,6 +89,7 @@ True False Never + C8DEB388B9BC89D1DC61324E4E9D9FE6A796B7AA False 0 OnApplicationRun diff --git a/UWP/UWPHelpers/StorageManager.cpp b/UWP/UWPHelpers/StorageManager.cpp index 55aaf2a93b..57d2023515 100644 --- a/UWP/UWPHelpers/StorageManager.cpp +++ b/UWP/UWPHelpers/StorageManager.cpp @@ -292,10 +292,10 @@ bool GetFakeFolders(Path path, std::vector* files, const char* f info.exists = true; info.size = 1; info.isDirectory = true; - info.isWritable = 0; - info.atime = 1000; - info.mtime = 1000; - info.ctime = 1000; + info.isWritable = true; + info.atime = 0; + info.mtime = 0; + info.ctime = 0; info.access = 0111; files->push_back(info); @@ -347,25 +347,31 @@ bool OpenFolder(std::string path) { return state; } -int64_t GetLocalFreeSpace() { - Platform::String^ freeSpaceKey = ref new Platform::String(L"System.FreeSpace"); - Platform::Collections::Vector^ propertiesToRetrieve = ref new Platform::Collections::Vector(); - propertiesToRetrieve->Append(freeSpaceKey); - Windows::Foundation::Collections::IMap^ result; - ExecuteTask(result, ApplicationData::Current->LocalFolder->Properties->RetrievePropertiesAsync(propertiesToRetrieve)); - int64_t remainingSize = 0; - if (result != nullptr && result->Size > 0) { - try { - auto it = result->First(); - auto sizeString = it->Current->Value->ToString(); - const wchar_t* begin = sizeString->Data(); - remainingSize = (int64_t)std::wcstol(begin, nullptr, 10); - } - catch (...) { +bool GetDriveFreeSpace(Path path, int64_t& space) { + bool state = false; + Platform::String^ wString = ref new Platform::String(path.ToWString().c_str()); + StorageFolder^ storageItem; + ExecuteTask(storageItem, StorageFolder::GetFolderFromPathAsync(wString)); + if (storageItem != nullptr) { + Platform::String^ freeSpaceKey = ref new Platform::String(L"System.FreeSpace"); + Platform::Collections::Vector^ propertiesToRetrieve = ref new Platform::Collections::Vector(); + propertiesToRetrieve->Append(freeSpaceKey); + Windows::Foundation::Collections::IMap^ result; + ExecuteTask(result, storageItem->Properties->RetrievePropertiesAsync(propertiesToRetrieve)); + if (result != nullptr && result->Size > 0) { + try { + auto value = result->Lookup(L"System.FreeSpace"); + space = (uint64_t)value; + state = true; + } + catch (...) { + + } } } - return remainingSize; + + return state; } #pragma endregion diff --git a/UWP/UWPHelpers/StorageManager.h b/UWP/UWPHelpers/StorageManager.h index 5da161111a..996b4be739 100644 --- a/UWP/UWPHelpers/StorageManager.h +++ b/UWP/UWPHelpers/StorageManager.h @@ -51,7 +51,7 @@ bool IsRootForAccessibleItems(std::string path); bool OpenFile(std::string path); bool OpenFolder(std::string path); std::string ResolvePathUWP(std::string path); -int64_t GetLocalFreeSpace(); +bool GetDriveFreeSpace(Path path, int64_t& space); // Log helpers std::string GetLogFile(); diff --git a/UWP/UWPHelpers/StoragePickers.cpp b/UWP/UWPHelpers/StoragePickers.cpp index bd29125acf..db725834f7 100644 --- a/UWP/UWPHelpers/StoragePickers.cpp +++ b/UWP/UWPHelpers/StoragePickers.cpp @@ -35,12 +35,12 @@ concurrency::task PickSingleFolder() return concurrency::create_task(folderPicker->PickSingleFolderAsync()).then([](StorageFolder^ folder) { auto path = ref new Platform::String(); - if (folder != nullptr) - { + if (folder != nullptr) + { AddItemToFutureList(folder); - path = folder->Path; - } - return path; + path = folder->Path; + } + return path; }); } @@ -62,12 +62,12 @@ concurrency::task PickSingleFile(std::vector ext } return concurrency::create_task(filePicker->PickSingleFileAsync()).then([](StorageFile^ file) { auto path = ref new Platform::String(); - if (file != nullptr) - { + if (file != nullptr) + { AddItemToFutureList(file); - path = file->Path; - } - return path; + path = file->Path; + } + return path; }); }