From 9b0577351fde7ac334bec33ab603cc38b69196dd Mon Sep 17 00:00:00 2001 From: Bashar Astifan Date: Tue, 2 May 2023 00:09:22 +0400 Subject: [PATCH] Review's changes, more fixes and better structure --- Common/File/DirListing.cpp | 8 +- Common/File/DiskFree.cpp | 12 ++ Common/File/Path.cpp | 12 ++ Common/File/Path.h | 1 + Common/File/PathBrowser.cpp | 2 +- Core/PSPLoaders.cpp | 2 +- Core/System.cpp | 3 +- UI/CwCheatScreen.cpp | 9 -- UI/DevScreens.cpp | 18 +-- UI/GameScreen.cpp | 2 +- UI/GameSettingsScreen.cpp | 19 +-- UI/MainScreen.cpp | 3 - UI/MemStickScreen.cpp | 61 +++----- UI/NativeApp.cpp | 28 +--- UWP/App.cpp | 13 +- UWP/PPSSPP_UWPMain.cpp | 39 +++-- UWP/UWPHelpers/LaunchItem.h | 18 ++- UWP/UWPHelpers/StorageAccess.cpp | 23 ++- UWP/UWPHelpers/StorageAccess.h | 21 ++- UWP/UWPHelpers/StorageAsync.cpp | 6 - UWP/UWPHelpers/StorageAsync.h | 6 - UWP/UWPHelpers/StorageManager.cpp | 179 +++++++++++++++-------- UWP/UWPHelpers/StorageManager.h | 25 +++- UWP/UWPHelpers/StoragePickers.cpp | 20 ++- UWP/UWPHelpers/StoragePickers.h | 20 ++- ext/libzip/zip_source_file_win32_utf16.c | 11 +- 26 files changed, 309 insertions(+), 252 deletions(-) diff --git a/Common/File/DirListing.cpp b/Common/File/DirListing.cpp index 7eac82dbbf..009c9b9448 100644 --- a/Common/File/DirListing.cpp +++ b/Common/File/DirListing.cpp @@ -221,12 +221,12 @@ bool GetFilesInDir(const Path &directory, std::vector *files, const ch HANDLE hFind = FindFirstFileEx((directory.ToWString() + L"\\*").c_str(), FindExInfoStandard, &ffd, FindExSearchNameMatch, NULL, 0); #endif if (hFind == INVALID_HANDLE_VALUE) { -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) +#if PPSSPP_PLATFORM(UWP) // This step just to avoid empty results by adding fake folders - // It will help also to navigate back between selected folder - if(GetFakeFolders(directory, files, filter, filters)){ + // it will help also to navigate back between selected folder + // we must ignore this function for any request other than UI navigation + if (GetFakeFolders(directory, files, filter, filters)) return true; - } #endif return false; } diff --git a/Common/File/DiskFree.cpp b/Common/File/DiskFree.cpp index 34a5ba520a..929eabf8fe 100644 --- a/Common/File/DiskFree.cpp +++ b/Common/File/DiskFree.cpp @@ -19,13 +19,25 @@ #include #include "Common/Log.h" +#include "Core/Config.h" #include "Common/File/Path.h" #include "Common/File/AndroidStorage.h" #include "Common/Data/Encoding/Utf8.h" +#if PPSSPP_PLATFORM(UWP) +#include +#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(); + } + 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/Common/File/Path.cpp b/Common/File/Path.cpp index 815593016a..855c5a2980 100644 --- a/Common/File/Path.cpp +++ b/Common/File/Path.cpp @@ -12,6 +12,10 @@ #include "android/jni/app-android.h" #include "android/jni/AndroidContentURI.h" +#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) +#include "UWP/UWPHelpers/StorageManager.h" +#endif + #if HOST_IS_CASE_SENSITIVE #include #include @@ -294,6 +298,14 @@ std::string Path::ToVisualString(const char *relativeRoot) const { } } +std::string Path::ToShortFriendlyPath() const { +#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) + return GetPreviewPath(path_); +#else + return path_.ToVisualString(); +#endif +} + bool Path::CanNavigateUp() const { if (type_ == PathType::CONTENT_URI) { return AndroidContentURI(path_).CanNavigateUp(); diff --git a/Common/File/Path.h b/Common/File/Path.h index ac93f9a9b8..f9a217e75d 100644 --- a/Common/File/Path.h +++ b/Common/File/Path.h @@ -94,6 +94,7 @@ public: // Pass in a relative root to turn the path into a relative path - if it is one! std::string ToVisualString(const char *relativeRoot = nullptr) const; + std::string ToShortFriendlyPath() const; bool CanNavigateUp() const; Path NavigateUp() const; diff --git a/Common/File/PathBrowser.cpp b/Common/File/PathBrowser.cpp index f5ab1a33be..d9f71e9644 100644 --- a/Common/File/PathBrowser.cpp +++ b/Common/File/PathBrowser.cpp @@ -193,7 +193,7 @@ bool PathBrowser::IsListingReady() { } std::string PathBrowser::GetFriendlyPath() const { - std::string str = GetPath().ToVisualString(); + std::string str = GetPath().ToShortFriendlyPath(); // Show relative to memstick root if there. if (startsWith(str, aliasMatch_)) { return aliasDisplay_ + str.substr(aliasMatch_.size()); diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index 8e0439b828..5fc79c28d3 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -418,7 +418,7 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) { std::string homebrewName = PSP_CoreParameter().fileToStart.ToVisualString(); std::size_t lslash = homebrewName.find_last_of("/"); -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) +#if PPSSPP_PLATFORM(UWP) if (lslash == homebrewName.npos) { lslash = homebrewName.find_last_of("\\"); } diff --git a/Core/System.cpp b/Core/System.cpp index 471bf936b4..6e5a6aa2c7 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -767,9 +767,8 @@ void InitSysDirectories() { File::CreateDir(GetSysDirectory(DIRECTORY_SAVEDATA)); File::CreateDir(GetSysDirectory(DIRECTORY_SAVESTATE)); File::CreateDir(GetSysDirectory(DIRECTORY_SYSTEM)); -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) File::CreateDir(GetSysDirectory(DIRECTORY_TEXTURES)); -#endif + File::CreateDir(GetSysDirectory(DIRECTORY_CHEATS)); if (g_Config.currentDirectory.empty()) { g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME); diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index 7cbca449c1..1b63895c95 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -188,16 +188,7 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams ¶ms) { MIPSComp::jit->ClearCache(); } if (engine_) { -#if PPSSPP_PLATFORM(UWP) -#if !defined(__LIBRETRO__) - // UWP storage manager will attempt to launch the file File::OpenFileInEditor(engine_->CheatFilename()); -#else - System_LaunchUrl(LaunchUrlType::BROWSER_URL, engine_->CheatFilename().c_str()); -#endif -#else - File::OpenFileInEditor(engine_->CheatFilename()); -#endif } return UI::EVENT_DONE; } diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 7587be8dac..5f702df126 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -656,19 +656,11 @@ void SystemInfoScreen::CreateViews() { storage->Add(new ItemHeader(si->T("Directories"))); // Intentionally non-translated -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - // If location set to local folder the path will be too long to view - // it's better to show simplified text like 'LocalState' using 'GetPreviewPath' - storage->Add(new InfoItem("MemStickDirectory", GetPreviewPath(g_Config.memStickDirectory.ToVisualString()))); - storage->Add(new InfoItem("InternalDataDirectory", GetPreviewPath(g_Config.internalDataDirectory.ToVisualString()))); - storage->Add(new InfoItem("AppCacheDir", GetPreviewPath(g_Config.appCacheDirectory.ToVisualString()))); - storage->Add(new InfoItem("DefaultCurrentDir", GetPreviewPath(g_Config.defaultCurrentDirectory.ToVisualString()))); -#else - storage->Add(new InfoItem("MemStickDirectory", g_Config.memStickDirectory.ToVisualString())); - storage->Add(new InfoItem("InternalDataDirectory", g_Config.internalDataDirectory.ToVisualString())); - storage->Add(new InfoItem("AppCacheDir", g_Config.appCacheDirectory.ToVisualString())); - storage->Add(new InfoItem("DefaultCurrentDir", g_Config.defaultCurrentDirectory.ToVisualString())); -#endif + storage->Add(new InfoItem("MemStickDirectory", g_Config.memStickDirectory.ToShortFriendlyPath())); + storage->Add(new InfoItem("InternalDataDirectory", g_Config.internalDataDirectory.ToShortFriendlyPath())); + storage->Add(new InfoItem("AppCacheDir", g_Config.appCacheDirectory.ToShortFriendlyPath())); + storage->Add(new InfoItem("DefaultCurrentDir", g_Config.defaultCurrentDirectory.ToShortFriendlyPath())); + #if PPSSPP_PLATFORM(ANDROID) storage->Add(new InfoItem("ExtFilesDir", g_extFilesDir)); bool scoped = System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE); diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index 5460dd5ae3..eb163fc419 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -115,7 +115,7 @@ void GameScreen::CreateViews() { tvID_ = infoLayout->Add(new TextView("", ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); tvID_->SetShadow(true); // This one doesn't need to be updated. - infoLayout->Add(new TextView(gamePath_.ToVisualString(), ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetShadow(true); + infoLayout->Add(new TextView(gamePath_.ToShortFriendlyPath(), ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetShadow(true); tvGameSize_ = infoLayout->Add(new TextView("...", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); tvGameSize_->SetShadow(true); tvSaveDataSize_ = infoLayout->Add(new TextView("...", ALIGN_LEFT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 2d2fb2498f..137349d2f4 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -94,7 +94,7 @@ extern AndroidAudioState *g_audioState; #endif -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) +#if PPSSPP_PLATFORM(UWP) #include "UWP/UWPHelpers/StorageManager.h" #endif @@ -977,12 +977,13 @@ void GameSettingsScreen::CreateSystemSettings(UI::ViewGroup *systemSettings) { systemSettings->Add(new Choice(sy->T("Set Memory Stick folder")))->OnClick.Handle(this, &GameSettingsScreen::OnChangeMemStickDir); #endif -#if PPSSPP_PLATFORM(ANDROID) - memstickDisplay_ = g_Config.memStickDirectory.ToVisualString(); +#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(UWP) + memstickDisplay_ = g_Config.memStickDirectory.ToShortFriendlyPath(); auto memstickPath = systemSettings->Add(new ChoiceWithValueDisplay(&memstickDisplay_, sy->T("Memory Stick folder", "Memory Stick folder"), I18NCat::NONE)); memstickPath->SetEnabled(!PSP_IsInited()); memstickPath->OnClick.Handle(this, &GameSettingsScreen::OnChangeMemStickDir); +#if PPSSPP_PLATFORM(ANDROID) // Display USB path for convenience. std::string usbPath; if (PathToVisualUsbPath(g_Config.memStickDirectory, usbPath)) { @@ -992,11 +993,7 @@ void GameSettingsScreen::CreateSystemSettings(UI::ViewGroup *systemSettings) { } systemSettings->Add(new InfoItem(sy->T("USB"), usbPath))->SetChoiceStyle(true); } -#elif PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - memstickDisplay_ = GetPreviewPath(g_Config.memStickDirectory.ToString()); - auto memstickPath = systemSettings->Add(new ChoiceWithValueDisplay(&memstickDisplay_, sy->T("Memory Stick folder", "Memory Stick folder"), I18NCat::NONE)); - memstickPath->SetEnabled(!PSP_IsInited()); - memstickPath->OnClick.Handle(this, &GameSettingsScreen::OnChangeMemStickDir); +#endif #elif defined(_WIN32) && !PPSSPP_PLATFORM(UWP) SavePathInMyDocumentChoice = systemSettings->Add(new CheckBox(&installed_, sy->T("Save path in My Documents", "Save path in My Documents"))); SavePathInMyDocumentChoice->SetEnabled(!PSP_IsInited()); @@ -1892,12 +1889,6 @@ UI::EventReturn GameSettingsScreen::OnRestoreDefaultSettings(UI::EventParams &e) UI::EventReturn DeveloperToolsScreen::OnLoggingChanged(UI::EventParams &e) { System_Notify(SystemNotification::TOGGLE_DEBUG_CONSOLE); -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - if (g_Config.bEnableLogging) { - // Create log file incase log was off, to avoid restart - LogManager::GetInstance()->ChangeFileLog(GetLogFile().c_str()); - } -#endif return UI::EVENT_DONE; } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 2bdbddb101..cd9e360641 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1167,11 +1167,8 @@ void MainScreen::CreateViews() { } } -//#if !PPSSPP_PLATFORM(UWP) - // Having an exit button is against UWP guidelines?. rightColumnChoices->Add(new Spacer(25.0)); rightColumnChoices->Add(new Choice(mm->T("Exit")))->OnClick.Handle(this, &MainScreen::OnExit); -//#endif if (vertical) { root_ = new LinearLayout(ORIENT_VERTICAL); diff --git a/UI/MemStickScreen.cpp b/UI/MemStickScreen.cpp index 7942f558a9..485a679be6 100644 --- a/UI/MemStickScreen.cpp +++ b/UI/MemStickScreen.cpp @@ -48,7 +48,7 @@ #include "UI/MainScreen.h" #include "UI/MiscScreens.h" -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) +#if PPSSPP_PLATFORM(UWP) #include "UWP/UWPHelpers/StorageManager.h" #endif @@ -82,9 +82,9 @@ static bool SwitchMemstickFolderTo(Path newMemstickFolder) { } Path memStickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt"; -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) +#if PPSSPP_PLATFORM(UWP) File::Delete(memStickDirFile); - if (newMemstickFolder != Path(GetLocalFolder())) { + if (newMemstickFolder != g_Config.internalDataDirectory) { #endif std::string str = newMemstickFolder.ToString(); @@ -93,7 +93,7 @@ static bool SwitchMemstickFolderTo(Path newMemstickFolder) { // Not sure what to do if this file can't be written. Disk full? } -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) +#if PPSSPP_PLATFORM(UWP) } #endif @@ -137,8 +137,8 @@ MemStickScreen::MemStickScreen(bool initialSetup) } } else { // Detect the current choice, so it's preselected in the UI. -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - if (g_Config.memStickDirectory == Path(GetLocalFolder())) { +#if PPSSPP_PLATFORM(UWP) + if (g_Config.memStickDirectory == g_Config.internalDataDirectory) { #else if (g_Config.memStickDirectory == Path(g_extFilesDir)) { #endif @@ -271,19 +271,13 @@ void MemStickScreen::CreateViews() { if (choice_ == CHOICE_BROWSE_FOLDER || choice_ == CHOICE_SET_MANUAL) { UI::View *extraView = nullptr; if (!g_Config.memStickDirectory.empty()) { -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - extraView = new TextView(StringFromFormat(" %s: %s", iz->T("Current"), GetPreviewPath(g_Config.memStickDirectory.ToString()).c_str()), ALIGN_LEFT, false); -#else - extraView = new TextView(StringFromFormat(" %s: %s", iz->T("Current"), g_Config.memStickDirectory.ToVisualString().c_str()), ALIGN_LEFT, false); -#endif + extraView = new TextView(StringFromFormat(" %s: %s", iz->T("Current"), g_Config.memStickDirectory.ToShortFriendlyPath().c_str()), ALIGN_LEFT, false); } AddExplanation(leftColumn, (MemStickScreen::Choice)choice_, extraView); } -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - std::string privateString = iz->T("Use App Local Data"); -#else + std::string privateString = iz->T("Use App Private Data"); -#endif + if (initialSetup_) { privateString = StringFromFormat("%s (%s)", iz->T("Skip for now"), privateString.c_str()); } @@ -305,11 +299,7 @@ void MemStickScreen::CreateViews() { case CHOICE_PRIVATE_DIRECTORY: if (initialSetup_) { confirmButtonText = di->T("Skip"); -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - confirmButtonImage = ImageID("I_ARROW_RIGHT"); -#else confirmButtonImage = ImageID("I_WARNING"); -#endif } else { confirmButtonText = di->T("OK"); } @@ -431,8 +421,8 @@ UI::EventReturn MemStickScreen::SetFolderManually(UI::EventParams ¶ms) { } UI::EventReturn MemStickScreen::UseInternalStorage(UI::EventParams ¶ms) { -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - Path pendingMemStickFolder = Path(GetLocalFolder()); +#if PPSSPP_PLATFORM(UWP) + Path pendingMemStickFolder = g_Config.internalDataDirectory; #else Path pendingMemStickFolder = Path(g_extFilesDir); #endif @@ -598,11 +588,7 @@ void ConfirmMemstickMoveScreen::CreateViews() { if (!initialSetup_) { leftColumn->Add(new TextView(iz->T("PPSSPP will restart after the change"), ALIGN_LEFT, false)); } -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - leftColumn->Add(new TextView(GetPreviewPath(newMemstickFolder_.ToString()), ALIGN_LEFT, false)); -#else - leftColumn->Add(new TextView(newMemstickFolder_.ToVisualString(), ALIGN_LEFT, false)); -#endif + leftColumn->Add(new TextView(newMemstickFolder_.ToShortFriendlyPath(), ALIGN_LEFT, false)); std::string newFreeSpaceText = std::string(iz->T("Free space")) + ": " + FormatSpaceString(freeSpaceNew); leftColumn->Add(new TextView(newFreeSpaceText, ALIGN_LEFT, false)); if (existingFilesInNewFolder_) { @@ -619,11 +605,7 @@ void ConfirmMemstickMoveScreen::CreateViews() { std::string oldFreeSpaceText = std::string(iz->T("Free space")) + ": " + FormatSpaceString(freeSpaceOld); rightColumn->Add(new TextView(std::string(iz->T("Current")) + ":", ALIGN_LEFT, false)); -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - rightColumn->Add(new TextView(GetPreviewPath(oldMemstickFolder.ToString()), ALIGN_LEFT, false)); -#else - rightColumn->Add(new TextView(oldMemstickFolder.ToVisualString(), ALIGN_LEFT, false)); -#endif + rightColumn->Add(new TextView(oldMemstickFolder.ToShortFriendlyPath(), ALIGN_LEFT, false)); rightColumn->Add(new TextView(oldFreeSpaceText, ALIGN_LEFT, false)); } @@ -678,8 +660,6 @@ void ConfirmMemstickMoveScreen::update() { } UI::EventReturn ConfirmMemstickMoveScreen::OnConfirm(UI::EventParams ¶ms) { - auto sy = GetI18NCategory(I18NCat::SYSTEM); - auto iz = GetI18NCategory(I18NCat::MEMSTICK); // Transfer all the files in /PSP from the original directory. // Should probably be done on a background thread so we can show some UI. @@ -687,9 +667,10 @@ UI::EventReturn ConfirmMemstickMoveScreen::OnConfirm(UI::EventParams ¶ms) { // If the directory itself is called PSP, don't go below. if (moveData_) { - progressReporter_.Set(iz->T("Starting move...")); + progressReporter_.Set(T(I18NCat::MEMSTICK, "Starting move...")); moveDataTask_ = Promise::Spawn(&g_threadManager, [&]() -> MoveResult * { + auto ms = GetI18NCategory(I18NCat::MEMSTICK); Path moveSrc = g_Config.memStickDirectory; Path moveDest = newMemstickFolder_; if (moveSrc.GetFilename() != "PSP") { @@ -711,11 +692,7 @@ UI::EventReturn ConfirmMemstickMoveScreen::OnConfirm(UI::EventParams ¶ms) { // TODO: Handle failure listing files. std::string error = "Failed to read old directory"; INFO_LOG(SYSTEM, "%s", error.c_str()); -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - progressReporter_.Set(error.c_str()); // it's throwing exception with 'iz->T' -#else - progressReporter_.Set(iz->T(error.c_str())); -#endif + progressReporter_.Set(ms->T(error.c_str())); return new MoveResult{ false, error }; } @@ -806,12 +783,12 @@ UI::EventReturn ConfirmMemstickMoveScreen::OnConfirm(UI::EventParams ¶ms) { } void ConfirmMemstickMoveScreen::FinishFolderMove() { - auto iz = GetI18NCategory(I18NCat::MEMSTICK); + auto ms = GetI18NCategory(I18NCat::MEMSTICK); // Successful so far, switch the memstick folder. if (!SwitchMemstickFolderTo(newMemstickFolder_)) { // TODO: More precise errors. - error_ = iz->T("That folder doesn't work as a memstick folder."); + error_ = ms->T("That folder doesn't work as a memstick folder."); return; } @@ -828,7 +805,7 @@ void ConfirmMemstickMoveScreen::FinishFolderMove() { // TriggerFinish(DialogResult::DR_OK); screenManager()->switchScreen(new MainScreen()); } else { - error_ = iz->T("Failed to save config"); + error_ = ms->T("Failed to save config"); RecreateViews(); } } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 0c3d28a309..939f1394df 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -146,10 +146,6 @@ #include -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) -#include "UWP/UWPHelpers/StorageManager.h" -#endif - ScreenManager *g_screenManager; std::string config_filename; @@ -450,7 +446,9 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch g_VFS.Register("", new DirectoryReader(Path(savegame_dir))); g_Config.defaultCurrentDirectory = Path("/"); +#if !PPSSPP_PLATFORM(UWP) g_Config.internalDataDirectory = Path(savegame_dir); +#endif #if PPSSPP_PLATFORM(ANDROID) // In Android 12 with scoped storage, due to the above, the external directory @@ -497,30 +495,24 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch } #elif PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) Path memstickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt"; - auto pathResolved = Path(ResolvePathUWP(memstickDirFile.ToString())); - if (File::Exists(pathResolved)) { - INFO_LOG(SYSTEM, "Reading '%s' to find memstick dir.", pathResolved.c_str()); + if (File::Exists(memstickDirFile)) { + INFO_LOG(SYSTEM, "Reading '%s' to find memstick dir.", memstickDirFile.c_str()); std::string memstickDir; - if (File::ReadFileToString(true, pathResolved, memstickDir)) { + if (File::ReadFileToString(true, memstickDirFile, memstickDir)) { Path memstickPath(memstickDir); if (!memstickPath.empty() && File::Exists(memstickPath)) { g_Config.memStickDirectory = memstickPath; g_Config.SetSearchPath(GetSysDirectory(DIRECTORY_SYSTEM)); g_Config.Reload(); INFO_LOG(SYSTEM, "Memstick Directory from memstick_dir.txt: '%s'", g_Config.memStickDirectory.c_str()); - } - else { + } else { ERROR_LOG(SYSTEM, "Couldn't read directory '%s' specified by memstick_dir.txt.", memstickDir.c_str()); - if (System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) { - // Ask the user to configure a memstick directory. - INFO_LOG(SYSTEM, "Asking the user."); - g_Config.memStickDirectory.clear(); - } + g_Config.memStickDirectory.clear(); } } } else { - INFO_LOG(SYSTEM, "No memstick directory file found (tried to open '%s')", pathResolved.c_str()); + INFO_LOG(SYSTEM, "No memstick directory file found (tried to open '%s')", memstickDirFile.c_str()); } #elif PPSSPP_PLATFORM(IOS) g_Config.defaultCurrentDirectory = g_Config.internalDataDirectory; @@ -786,11 +778,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch DEBUG_LOG(SYSTEM, "ScreenManager!"); g_screenManager = new ScreenManager(); -#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) - if (g_Config.memStickDirectory.empty() || (g_Config.bFirstRun && isLocalState(g_Config.memStickDirectory.ToString()))) { -#else if (g_Config.memStickDirectory.empty()) { -#endif INFO_LOG(SYSTEM, "No memstick directory! Asking for one to be configured."); g_screenManager->switchScreen(new LogoScreen(AfterLogoScreen::MEMSTICK_SCREEN_INITIAL_SETUP)); } else if (gotoGameSettings) { diff --git a/UWP/App.cpp b/UWP/App.cpp index c0dd8d2ee9..4c91dd20e6 100644 --- a/UWP/App.cpp +++ b/UWP/App.cpp @@ -14,7 +14,7 @@ #include -#include +#include "UWPHelpers/LaunchItem.h" #include using namespace UWP; @@ -237,7 +237,6 @@ void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ } if (args->Kind == ActivationKind::Protocol) { - unsigned i; ProtocolActivatedEventArgs^ protocolArgs = dynamic_cast(args); launchItem = LaunchItem(protocolArgs); } @@ -255,7 +254,7 @@ void App::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) { g_Config.Save("App::OnSuspending"); app->m_deviceResources->Trim(); deferral->Complete(); - }); + }); } void App::OnResuming(Platform::Object^ sender, Platform::Object^ args) { @@ -290,14 +289,6 @@ void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ ar } void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) { - - if (args->Visible == false) { - // MainScreen::OnExit and even App::OnWindowClosed - // doesn't seem to be called when closing the window - // Try to save the config here - // OnSuspending should now do the job - //g_Config.Save("App::OnVisibilityChanged"); - } m_windowVisible = args->Visible; } diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index b85cf7bdc5..0273454a3f 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -40,7 +40,7 @@ // UWP Storage helper includes #include "UWPHelpers/StorageManager.h" #include "UWPHelpers/StorageAsync.h" -#include +#include "UWPHelpers/LaunchItem.h" using namespace UWP; @@ -104,8 +104,9 @@ PPSSPP_UWPMain::PPSSPP_UWPMain(App ^app, const std::shared_ptrLocalFolder->Path->Data(); - g_Config.memStickDirectory = Path(memstickFolderW); + std::wstring internalDataFolderW = ApplicationData::Current->LocalFolder->Path->Data(); + g_Config.internalDataDirectory = Path(internalDataFolderW); + g_Config.memStickDirectory = g_Config.internalDataDirectory; // On Win32 it makes more sense to initialize the system directories here // because the next place it was called was in the EmuThread, and it's too late by then. @@ -118,6 +119,10 @@ PPSSPP_UWPMain::PPSSPP_UWPMain(App ^app, const std::shared_ptr System_GetPropertyStringVec(SystemProperty prop) { // Need to resize off the null terminator either way. tempPath.resize(sz); result.push_back(ConvertWStringToUTF8(tempPath)); - - // As per below 'getenv' isn't supported - // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/getenv-wgetenv?view=msvc-170 - /*if (getenv("TMPDIR") && strlen(getenv("TMPDIR")) != 0) - result.push_back(getenv("TMPDIR")); - if (getenv("TMP") && strlen(getenv("TMP")) != 0) - result.push_back(getenv("TMP")); - if (getenv("TEMP") && strlen(getenv("TEMP")) != 0) - result.push_back(getenv("TEMP"));*/ - return result; } @@ -459,7 +454,10 @@ void System_Toast(const char *str) {} bool System_GetPropertyBool(SystemProperty prop) { switch (prop) { case SYSPROP_HAS_OPEN_DIRECTORY: - return true; + { + auto ver = Windows::System::Profile::AnalyticsInfo::VersionInfo; + return ver->DeviceFamily != "Windows.Xbox"; + } case SYSPROP_HAS_FILE_BROWSER: return true; case SYSPROP_HAS_FOLDER_BROWSER: @@ -538,7 +536,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string } case SystemRequestType::BROWSE_FOR_FILE: { - std::vector supportedExtensions = { ".cso", ".bin", ".iso", ".elf", ".zip" }; + std::vector supportedExtensions = { ".cso", ".bin", ".iso", ".elf", ".pbp", ".zip"}; switch ((BrowseFileType)param3) { case BrowseFileType::INI: supportedExtensions = { ".ini" }; @@ -549,6 +547,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string case BrowseFileType::ANY: supportedExtensions = {}; break; + default: + ERROR_LOG(FILESYS, "Unexpected BrowseFileType: %d", param3); + return false; } //Call file picker @@ -614,13 +615,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string } void System_ShowFileInFolder(const char *path) { - auto ver = Windows::System::Profile::AnalyticsInfo::VersionInfo; - if (ver->DeviceFamily == "Windows.Xbox") { - // Unsupported - } - else { - OpenFolder(std::string(path)); - } + OpenFolder(std::string(path)); } void System_LaunchUrl(LaunchUrlType urlType, const char *url) { diff --git a/UWP/UWPHelpers/LaunchItem.h b/UWP/UWPHelpers/LaunchItem.h index e351879056..22084fdc41 100644 --- a/UWP/UWPHelpers/LaunchItem.h +++ b/UWP/UWPHelpers/LaunchItem.h @@ -1,5 +1,19 @@ -// UWP STORAGE MANAGER -// GitHub: https://github.com/basharast/UWP2Win32 +// Copyright (c) 2023- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #pragma once diff --git a/UWP/UWPHelpers/StorageAccess.cpp b/UWP/UWPHelpers/StorageAccess.cpp index ba6eff3d6d..99d4b535cd 100644 --- a/UWP/UWPHelpers/StorageAccess.cpp +++ b/UWP/UWPHelpers/StorageAccess.cpp @@ -1,13 +1,24 @@ -// UWP STORAGE MANAGER -// Copyright (c) 2023 Bashar Astifan. -// Email: bashar@astifan.online -// Telegram: @basharastifan -// GitHub: https://github.com/basharast/UWP2Win32 +// Copyright (c) 2023- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include "StorageAsync.h" #include "StorageAccess.h" #include "UWPUtil.h" -#include +#include "Common/File/Path.h" using namespace Platform; using namespace Windows::Storage; diff --git a/UWP/UWPHelpers/StorageAccess.h b/UWP/UWPHelpers/StorageAccess.h index 248227338b..e7ad863eae 100644 --- a/UWP/UWPHelpers/StorageAccess.h +++ b/UWP/UWPHelpers/StorageAccess.h @@ -1,8 +1,19 @@ -// UWP STORAGE MANAGER -// Copyright (c) 2023 Bashar Astifan. -// Email: bashar@astifan.online -// Telegram: @basharastifan -// GitHub: https://github.com/basharast/UWP2Win32 +// Copyright (c) 2023- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #pragma once diff --git a/UWP/UWPHelpers/StorageAsync.cpp b/UWP/UWPHelpers/StorageAsync.cpp index 70c9891f1e..e79152fe9c 100644 --- a/UWP/UWPHelpers/StorageAsync.cpp +++ b/UWP/UWPHelpers/StorageAsync.cpp @@ -1,9 +1,3 @@ -// UWP STORAGE MANAGER -// Copyright (c) 2023 Bashar Astifan. -// Email: bashar@astifan.online -// Telegram: @basharastifan -// GitHub: https://github.com/basharast/UWP2Win32 - // Thanks to RetroArch/Libretro team for this idea // This is improved version of the original idea diff --git a/UWP/UWPHelpers/StorageAsync.h b/UWP/UWPHelpers/StorageAsync.h index b023715e35..3f57a2457a 100644 --- a/UWP/UWPHelpers/StorageAsync.h +++ b/UWP/UWPHelpers/StorageAsync.h @@ -1,9 +1,3 @@ -// UWP STORAGE MANAGER -// Copyright (c) 2023 Bashar Astifan. -// Email: bashar@astifan.online -// Telegram: @basharastifan -// GitHub: https://github.com/basharast/UWP2Win32 - // Thanks to RetroArch/Libretro team for this idea // This is improved version of the original idea diff --git a/UWP/UWPHelpers/StorageManager.cpp b/UWP/UWPHelpers/StorageManager.cpp index 500bf45f6c..55aaf2a93b 100644 --- a/UWP/UWPHelpers/StorageManager.cpp +++ b/UWP/UWPHelpers/StorageManager.cpp @@ -1,13 +1,24 @@ -// UWP STORAGE MANAGER -// Copyright (c) 2023 Bashar Astifan. -// Email: bashar@astifan.online -// Telegram: @basharastifan -// GitHub: https://github.com/basharast/UWP2Win32 +// Copyright (c) 2023- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include "pch.h" #include #include - +#include #include "Common/Log.h" #include "Core/Config.h" @@ -27,9 +38,9 @@ using namespace Windows::ApplicationModel; #pragma region Locations -std::string GetWorkingFolder() { +std::string GetPSPFolder() { if (g_Config.memStickDirectory.empty()) { - return GetLocalFolder(); + return g_Config.internalDataDirectory.ToString(); } else { return g_Config.memStickDirectory.ToString(); @@ -76,6 +87,9 @@ std::string GetMusicFolder() { std::string GetPreviewPath(std::string path) { std::string pathView = path; + if (Path(GetLocalFolder()) == Path(path + "\\LocalState")) { + return "AppData"; + } pathView = ReplaceAll(pathView, "/", "\\"); pathView = ReplaceAll(pathView, GetLocalFolder(), "LocalState"); pathView = ReplaceAll(pathView, GetTempFolder(), "TempState"); @@ -142,37 +156,66 @@ bool CheckDriveAccess(std::string driveName) { return state; } -bool isWriteMode(const char* mode) { - return (!strcmp(mode, "w") || !strcmp(mode, "wb") || !strcmp(mode, "wt") || !strcmp(mode, "at") || !strcmp(mode, "a")); -} -bool isAppendMode(const char* mode) { - return (!strcmp(mode, "at") || !strcmp(mode, "a")); -} - FILE* GetFileStreamFromApp(std::string path, const char* mode) { FILE* file{}; auto pathResolved = Path(ResolvePathUWP(path)); HANDLE handle; - auto access = GENERIC_READ; - auto share = FILE_SHARE_READ; - auto creation = OPEN_EXISTING; - bool isWrite = isWriteMode(mode); - bool isAppend = isAppendMode(mode); - if (isWrite) { - access = GENERIC_WRITE; - share = FILE_SHARE_WRITE; - creation = isAppend ? OPEN_ALWAYS : CREATE_ALWAYS; + DWORD dwDesiredAccess = GENERIC_READ; + DWORD dwShareMode = FILE_SHARE_READ; + DWORD dwCreationDisposition = OPEN_EXISTING; + int flags = 0; + + if (!strcmp(mode, "r") || !strcmp(mode, "rb") || !strcmp(mode, "rt")) + { + dwDesiredAccess = GENERIC_READ; + dwShareMode = FILE_SHARE_READ; + dwCreationDisposition = OPEN_EXISTING; + flags = _O_RDONLY; } - handle = CreateFile2FromAppW(pathResolved.ToWString().c_str(), access, share, creation, nullptr); + else if (!strcmp(mode, "r+") || !strcmp(mode, "rb+") || !strcmp(mode, "r+b") || !strcmp(mode, "rt+") || !strcmp(mode, "r+t")) + { + dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; + dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + dwCreationDisposition = OPEN_EXISTING; + flags = _O_RDWR; + } + else if (!strcmp(mode, "a") || !strcmp(mode, "ab") || !strcmp(mode, "at")) { + dwDesiredAccess = GENERIC_WRITE; + dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + dwCreationDisposition = CREATE_ALWAYS; + flags = _O_APPEND | _O_WRONLY | _O_CREAT; + } + else if (!strcmp(mode, "a+") || !strcmp(mode, "ab+") || !strcmp(mode, "a+b") || !strcmp(mode, "at+") || !strcmp(mode, "a+t")) { + dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; + dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + dwCreationDisposition = CREATE_ALWAYS; + flags = _O_APPEND | _O_RDWR | _O_CREAT; + } + else if (!strcmp(mode, "w") || !strcmp(mode, "wb") || !strcmp(mode, "wt")) + { + dwDesiredAccess = GENERIC_WRITE; + dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + dwCreationDisposition = CREATE_ALWAYS; + flags = _O_WRONLY | _O_CREAT | _O_TRUNC; + } + else if (!strcmp(mode, "w+") || !strcmp(mode, "wb+") || !strcmp(mode, "w+b") || !strcmp(mode, "wt+") || !strcmp(mode, "w+t")) + { + dwDesiredAccess = GENERIC_READ | GENERIC_WRITE; + dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + dwCreationDisposition = CREATE_ALWAYS; + flags = _O_RDWR | _O_CREAT | _O_TRUNC; + } + + if (strpbrk(mode, "t") != nullptr) { + flags |= _O_TEXT; + } + + handle = CreateFile2FromAppW(pathResolved.ToWString().c_str(), dwDesiredAccess, dwShareMode, dwCreationDisposition, nullptr); if (handle != INVALID_HANDLE_VALUE) { - int flags = _O_RDONLY; - if (isWrite) { - flags = _O_RDWR; - } file = _fdopen(_open_osfhandle((intptr_t)handle, flags), mode); } @@ -243,35 +286,18 @@ bool GetFakeFolders(Path path, std::vector* files, const char* f if (!subRoot.empty()) { for each (auto sItem in subRoot) { auto folderPath = Path(sItem); - auto attributes = FILE_ATTRIBUTE_DIRECTORY; File::FileInfo info; info.name = folderPath.GetFilename(); info.fullName = folderPath; info.exists = true; info.size = 1; info.isDirectory = true; - info.isWritable = (attributes & FILE_ATTRIBUTE_READONLY) == 0; + info.isWritable = 0; info.atime = 1000; info.mtime = 1000; info.ctime = 1000; - if (attributes & FILE_ATTRIBUTE_READONLY) { - info.access = 0444; // Read - } - else { - info.access = 0666; // Read/Write - } - if (attributes & FILE_ATTRIBUTE_DIRECTORY) { - info.access |= 0111; // Execute - } - if (!info.isDirectory) { - std::string ext = info.fullName.GetFileExtension(); - if (!ext.empty()) { - ext = ext.substr(1); // Remove the dot. - if (filter && filters.find(ext) == filters.end()) { - continue; - } - } - } + info.access = 0111; + files->push_back(info); state = true; } @@ -285,15 +311,15 @@ bool GetFakeFolders(Path path, std::vector* files, const char* f #pragma region Helpers bool OpenFile(std::string path) { bool state = false; - path = ReplaceAll(path, "/", "\\"); + Platform::String^ wString = ref new Platform::String(Path(path).ToWString().c_str()); StorageFile^ storageItem; - ExecuteTask(storageItem, StorageFile::GetFileFromPathAsync(ToPlatformString(path))); + ExecuteTask(storageItem, StorageFile::GetFileFromPathAsync(wString)); if (storageItem != nullptr) { ExecuteTask(state, Windows::System::Launcher::LaunchFileAsync(storageItem), false); } else { - auto uri = ref new Windows::Foundation::Uri(ToPlatformString(path)); + auto uri = ref new Windows::Foundation::Uri(wString); ExecuteTask(state, Windows::System::Launcher::LaunchUriAsync(uri), false); } return state; @@ -301,31 +327,58 @@ bool OpenFile(std::string path) { bool OpenFolder(std::string path) { bool state = false; - path = ReplaceAll(path, "/", "\\"); - + Path itemPath(path); + Platform::String^ wString = ref new Platform::String(itemPath.ToWString().c_str()); StorageFolder^ storageItem; - ExecuteTask(storageItem, StorageFolder::GetFolderFromPathAsync(ToPlatformString(path))); + ExecuteTask(storageItem, StorageFolder::GetFolderFromPathAsync(wString)); if (storageItem != nullptr) { ExecuteTask(state, Windows::System::Launcher::LaunchFolderAsync(storageItem), false); } + else { + // Try as it's file + Path parent = Path(itemPath.GetDirectory()); + Platform::String^ wParentString = ref new Platform::String(parent.ToWString().c_str()); + + ExecuteTask(storageItem, StorageFolder::GetFolderFromPathAsync(wParentString)); + if (storageItem != nullptr) { + ExecuteTask(state, Windows::System::Launcher::LaunchFolderAsync(storageItem), false); + } + } return state; } -bool IsFirstStart() { - auto firstrun = GetDataFromLocalSettings("first_run"); - AddDataToLocalSettings("first_run", "done", true); - return firstrun.empty(); +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 (...) { + + } + } + return remainingSize; } #pragma endregion #pragma region Logs std::string GetLogFile() { - Path logFilePath = Path(GetWorkingFolder() + "\\PSP\\ppsspp.txt"); + std::string logFile; + Path logFilePath = Path(GetPSPFolder() + "\\PSP\\ppsspp.txt"); HANDLE h = CreateFile2FromAppW(logFilePath.ToWString().c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, CREATE_ALWAYS, nullptr); - if (h == INVALID_HANDLE_VALUE) { - return std::string(); + if (h != INVALID_HANDLE_VALUE) { + logFile = logFilePath.ToString(); + CloseHandle(h); } - return logFilePath.ToString(); + return logFile; } #pragma endregion diff --git a/UWP/UWPHelpers/StorageManager.h b/UWP/UWPHelpers/StorageManager.h index 5930547891..5da161111a 100644 --- a/UWP/UWPHelpers/StorageManager.h +++ b/UWP/UWPHelpers/StorageManager.h @@ -1,8 +1,19 @@ -// UWP STORAGE MANAGER -// Copyright (c) 2023 Bashar Astifan. -// Email: bashar@astifan.online -// Telegram: @basharastifan -// GitHub: https://github.com/basharast/UWP2Win32 +// Copyright (c) 2023- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #pragma once @@ -15,7 +26,7 @@ #include "StoragePickers.h" // Locations -std::string GetWorkingFolder(); // Where main data is, default is app data +std::string GetPSPFolder(); // Where main data is, default is app data std::string GetInstallationFolder(); std::string GetLocalFolder(); std::string GetTempFolder(); @@ -39,8 +50,8 @@ bool IsRootForAccessibleItems(std::string path); // Helpers bool OpenFile(std::string path); bool OpenFolder(std::string path); -bool IsFirstStart(); std::string ResolvePathUWP(std::string path); +int64_t GetLocalFreeSpace(); // Log helpers std::string GetLogFile(); diff --git a/UWP/UWPHelpers/StoragePickers.cpp b/UWP/UWPHelpers/StoragePickers.cpp index e61808c180..bd29125acf 100644 --- a/UWP/UWPHelpers/StoragePickers.cpp +++ b/UWP/UWPHelpers/StoragePickers.cpp @@ -1,7 +1,19 @@ -// UWP STORAGE MANAGER -// Copyright (c) 2023 Bashar Astifan. -// Email: bashar@astifan.online -// Telegram: @basharastifan +// Copyright (c) 2023- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include "pch.h" diff --git a/UWP/UWPHelpers/StoragePickers.h b/UWP/UWPHelpers/StoragePickers.h index 9b22c01e4b..8d845e6798 100644 --- a/UWP/UWPHelpers/StoragePickers.h +++ b/UWP/UWPHelpers/StoragePickers.h @@ -1,7 +1,19 @@ -// UWP STORAGE MANAGER -// Copyright (c) 2023 Bashar Astifan. -// Email: bashar@astifan.online -// Telegram: @basharastifan +// Copyright (c) 2023- PPSSPP Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0 or later versions. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official git repository and contact information can be found at +// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #pragma once diff --git a/ext/libzip/zip_source_file_win32_utf16.c b/ext/libzip/zip_source_file_win32_utf16.c index 8a179cd78b..e77da80960 100644 --- a/ext/libzip/zip_source_file_win32_utf16.c +++ b/ext/libzip/zip_source_file_win32_utf16.c @@ -41,7 +41,7 @@ static HANDLE __stdcall utf16_create_file(const char *name, DWORD access, DWORD static void utf16_make_tempname(char *buf, size_t len, const char *name, zip_uint32_t i); static char *utf16_strdup(const char *string); -#ifdef MS_UWP && !defined(__LIBRETRO__) +#ifdef MS_UWP static BOOL __stdcall GetFileAttr(const void* name, GET_FILEEX_INFO_LEVELS info_level, void* lpFileInformation) { BOOL state = GetFileAttributesExFromAppW(name, info_level, lpFileInformation); return state; @@ -54,10 +54,10 @@ static BOOL __stdcall DelFile(const void* name) { zip_win32_file_operations_t ops_utf16 = { utf16_allocate_tempname, - utf16_create_file, // Will invoke UWP Storage manager (If needed) - DelFile, // Will invoke UWP Storage manager + utf16_create_file, + DelFile, GetFileAttributesW, - GetFileAttr, // Will invoke UWP Storage manager + GetFileAttr, utf16_make_tempname, MoveFileExW, SetFileAttributesW, @@ -119,8 +119,7 @@ utf16_create_file(const char *name, DWORD access, DWORD share_mode, PSECURITY_AT return CreateFile2((const wchar_t *)name, access, share_mode, creation_disposition, &extParams); #else - HANDLE h = CreateFile2FromAppW((const wchar_t *)name, access, share_mode, creation_disposition, NULL); - return h; + return CreateFile2FromAppW((const wchar_t *)name, access, share_mode, creation_disposition, NULL); #endif #else return CreateFileW((const wchar_t *)name, access, share_mode, security_attributes, creation_disposition, file_attributes, template_file);