mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-30 09:43:45 +01:00
Path code cleanup, move some UI code (#21037)
* Move a bunch of path logic into Core/Util/PathUtil.cpp/h . * Move GameImageView out from SaveDataScreen * More cleanup, add a translation string
This commit is contained in:
1 parent
3116eba395
commit
b8fced5b41
72 files changed
+416
-330
No files matched your search
+8
-76
@@ -57,6 +57,7 @@
|
||||
#include "Core/HLE/sceUtility.h"
|
||||
#include "Core/Instance.h"
|
||||
#include "Core/Util/RecentFiles.h"
|
||||
#include "Core/Util/PathUtil.h"
|
||||
|
||||
#include "GPU/Common/FramebufferManagerCommon.h"
|
||||
|
||||
@@ -73,8 +74,6 @@ static const std::string_view logSectionName = "LogDebug";
|
||||
static const std::string_view logSectionName = "Log";
|
||||
#endif
|
||||
|
||||
bool TryUpdateSavedPath(Path *path);
|
||||
|
||||
static const std::vector<std::string_view> defaultProAdhocServerList = {
|
||||
"socom.cc", "psp.gameplayer.club", // TODO: Add some saved recent history too?
|
||||
};
|
||||
@@ -1177,10 +1176,10 @@ void Config::UpdateIniLocation(const char *iniFileName, const char *controllerIn
|
||||
const bool useIniFilename = iniFileName != nullptr && strlen(iniFileName) > 0;
|
||||
const char *ppssppIniFilename = IsVREnabled() ? "ppssppvr.ini" : "ppsspp.ini";
|
||||
bool exists;
|
||||
iniFilename_ = FindConfigFile(useIniFilename ? iniFileName : ppssppIniFilename, &exists);
|
||||
iniFilename_ = FindConfigFile(searchPath_, useIniFilename ? iniFileName : ppssppIniFilename, &exists);
|
||||
const bool useControllerIniFilename = controllerIniFilename != nullptr && strlen(controllerIniFilename) > 0;
|
||||
const char *controlsIniFilename = IsVREnabled() ? "controlsvr.ini" : "controls.ini";
|
||||
controllerIniFilename_ = FindConfigFile(useControllerIniFilename ? controllerIniFilename : controlsIniFilename, &exists);
|
||||
controllerIniFilename_ = FindConfigFile(searchPath_, useControllerIniFilename ? controllerIniFilename : controlsIniFilename, &exists);
|
||||
}
|
||||
|
||||
bool Config::LoadAppendedConfig() {
|
||||
@@ -1538,70 +1537,10 @@ void Config::NotifyUpdatedCpuCore() {
|
||||
}
|
||||
}
|
||||
|
||||
// On iOS, the path to the app documents directory changes on each launch.
|
||||
// Example path:
|
||||
// /var/mobile/Containers/Data/Application/0E0E89DE-8D8E-485A-860C-700D8BC87B86/Documents/PSP/GAME/SuicideBarbie
|
||||
// The GUID part changes on each launch.
|
||||
bool TryUpdateSavedPath(Path *path) {
|
||||
#if PPSSPP_PLATFORM(IOS)
|
||||
// DEBUG_LOG(Log::Loader, "Original path: %s", path->c_str());
|
||||
std::string pathStr = path->ToString();
|
||||
|
||||
const std::string_view applicationRoot = "/var/mobile/Containers/Data/Application/";
|
||||
if (startsWith(pathStr, applicationRoot)) {
|
||||
size_t documentsPos = pathStr.find("/Documents/");
|
||||
if (documentsPos == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
std::string memstick = g_Config.memStickDirectory.ToString();
|
||||
size_t memstickDocumentsPos = memstick.find("/Documents"); // Note: No trailing slash, or we won't find it.
|
||||
*path = Path(memstick.substr(0, memstickDocumentsPos) + pathStr.substr(documentsPos));
|
||||
return true;
|
||||
} else {
|
||||
// Path can't be auto-updated.
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Config::SetSearchPath(const Path &searchPath) {
|
||||
searchPath_ = searchPath;
|
||||
}
|
||||
|
||||
Path Config::FindConfigFile(std::string_view baseFilename, bool *exists) const {
|
||||
// Don't search for an absolute path.
|
||||
if (baseFilename.size() > 1 && baseFilename[0] == '/') {
|
||||
Path path(baseFilename);
|
||||
*exists = File::Exists(path);
|
||||
return path;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
// Handle paths starting with a drive letter.
|
||||
if (baseFilename.size() > 3 && baseFilename[1] == ':' && (baseFilename[2] == '/' || baseFilename[2] == '\\')) {
|
||||
Path path(baseFilename);
|
||||
*exists = File::Exists(path);
|
||||
return path;
|
||||
}
|
||||
#endif
|
||||
|
||||
Path filename = searchPath_ / baseFilename;
|
||||
if (File::Exists(filename)) {
|
||||
*exists = true;
|
||||
return filename;
|
||||
}
|
||||
*exists = false;
|
||||
// Make sure at least the directory it's supposed to be in exists.
|
||||
Path parent = filename.NavigateUp();
|
||||
|
||||
// We try to create the path and ignore if it fails (already exists).
|
||||
if (parent != GetSysDirectory(DIRECTORY_SYSTEM)) {
|
||||
File::CreateFullPath(parent);
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
void Config::RestoreDefaults(RestoreSettingsBits whatToRestore, bool log) {
|
||||
if (IsGameSpecific()) {
|
||||
// TODO: This could be done in a cleaner way.
|
||||
@@ -1636,13 +1575,13 @@ void Config::RestoreDefaults(RestoreSettingsBits whatToRestore, bool log) {
|
||||
|
||||
bool Config::HasGameConfig(std::string_view gameId) {
|
||||
bool exists = false;
|
||||
Path fullIniFilePath = GetGameConfigFilePath(gameId, &exists);
|
||||
Path fullIniFilePath = GetGameConfigFilePath(searchPath_, gameId, &exists);
|
||||
return exists;
|
||||
}
|
||||
|
||||
bool Config::CreateGameConfig(std::string_view gameId) {
|
||||
bool exists;
|
||||
Path fullIniFilePath = GetGameConfigFilePath(gameId, &exists);
|
||||
Path fullIniFilePath = GetGameConfigFilePath(searchPath_, gameId, &exists);
|
||||
|
||||
if (exists) {
|
||||
INFO_LOG(Log::System, "Game config already exists");
|
||||
@@ -1655,7 +1594,7 @@ bool Config::CreateGameConfig(std::string_view gameId) {
|
||||
|
||||
bool Config::DeleteGameConfig(std::string_view gameId) {
|
||||
bool exists = false;
|
||||
Path fullIniFilePath = Path(GetGameConfigFilePath(gameId, &exists));
|
||||
Path fullIniFilePath = GetGameConfigFilePath(searchPath_, gameId, &exists);
|
||||
|
||||
if (exists) {
|
||||
if (System_GetPropertyBool(SYSPROP_HAS_TRASH_BIN)) {
|
||||
@@ -1667,13 +1606,6 @@ bool Config::DeleteGameConfig(std::string_view gameId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Path Config::GetGameConfigFilePath(std::string_view gameId, bool *exists) {
|
||||
std::string_view ppssppIniFilename = IsVREnabled() ? "_ppssppvr.ini" : "_ppsspp.ini";
|
||||
std::string iniFileName = join(gameId, ppssppIniFilename);
|
||||
Path iniFileNameFull = FindConfigFile(iniFileName, exists);
|
||||
return iniFileNameFull;
|
||||
}
|
||||
|
||||
bool Config::SaveGameConfig(const std::string &gameId, std::string_view titleForComment) {
|
||||
if (gameId.empty()) {
|
||||
return false;
|
||||
@@ -1685,7 +1617,7 @@ bool Config::SaveGameConfig(const std::string &gameId, std::string_view titleFor
|
||||
}
|
||||
|
||||
bool exists;
|
||||
Path fullIniFilePath = GetGameConfigFilePath(gameId, &exists);
|
||||
Path fullIniFilePath = GetGameConfigFilePath(searchPath_, gameId, &exists);
|
||||
|
||||
IniFile iniFile;
|
||||
|
||||
@@ -1735,7 +1667,7 @@ bool Config::SaveGameConfig(const std::string &gameId, std::string_view titleFor
|
||||
|
||||
bool Config::LoadGameConfig(const std::string &gameId) {
|
||||
bool exists;
|
||||
Path iniFileNameFull = GetGameConfigFilePath(gameId, &exists);
|
||||
Path iniFileNameFull = GetGameConfigFilePath(searchPath_, gameId, &exists);
|
||||
if (!exists) {
|
||||
// Bail if there's no game-specific config.
|
||||
DEBUG_LOG(Log::Loader, "No game-specific settings found in %s. Using global defaults.", iniFileNameFull.c_str());
|
||||
|
||||
@@ -672,12 +672,10 @@ public:
|
||||
bool SaveGameConfig(const std::string &pGameId, std::string_view titleForComment);
|
||||
void UnloadGameConfig();
|
||||
|
||||
Path GetGameConfigFilePath(std::string_view gameId, bool *exists);
|
||||
bool HasGameConfig(std::string_view gameId);
|
||||
bool IsGameSpecific() const { return !gameId_.empty(); }
|
||||
|
||||
void SetSearchPath(const Path &path);
|
||||
Path FindConfigFile(std::string_view baseFilename, bool *exists) const;
|
||||
|
||||
void UpdateIniLocation(const char *iniFileName = nullptr, const char *controllerIniFilename = nullptr);
|
||||
|
||||
@@ -744,7 +742,6 @@ private:
|
||||
};
|
||||
|
||||
std::string CreateRandMAC();
|
||||
bool TryUpdateSavedPath(Path *path);
|
||||
|
||||
// TODO: Find a better place for this.
|
||||
extern http::RequestManager g_DownloadManager;
|
||||
|
||||
+3
-1
@@ -936,6 +936,7 @@
|
||||
<ClCompile Include="Util\GameDB.cpp" />
|
||||
<ClCompile Include="Util\GameManager.cpp" />
|
||||
<ClCompile Include="Util\MemStick.cpp" />
|
||||
<ClCompile Include="Util\PathUtil.cpp" />
|
||||
<ClCompile Include="Util\PortManager.cpp" />
|
||||
<ClCompile Include="Util\PPGeDraw.cpp" />
|
||||
<ClCompile Include="..\ext\xxhash.c">
|
||||
@@ -1304,6 +1305,7 @@
|
||||
<ClInclude Include="Util\GameDB.h" />
|
||||
<ClInclude Include="Util\GameManager.h" />
|
||||
<ClInclude Include="Util\MemStick.h" />
|
||||
<ClInclude Include="Util\PathUtil.h" />
|
||||
<ClInclude Include="Util\PortManager.h" />
|
||||
<ClInclude Include="Util\PPGeDraw.h" />
|
||||
<ClInclude Include="..\ext\xxhash.h" />
|
||||
@@ -1348,4 +1350,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -1393,6 +1393,9 @@
|
||||
<ClCompile Include="HW\GranularMixer.cpp">
|
||||
<Filter>HW</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Util\PathUtil.cpp">
|
||||
<Filter>Util</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ELF\ElfReader.h">
|
||||
@@ -2250,6 +2253,9 @@
|
||||
<ClInclude Include="HW\GranularMixer.h">
|
||||
<Filter>HW</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Util\PathUtil.h">
|
||||
<Filter>Util</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\LICENSE.TXT" />
|
||||
@@ -2278,4 +2284,4 @@
|
||||
<Filter>Ext</Filter>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -774,105 +774,6 @@ void PSP_RunLoopFor(int cycles) {
|
||||
Core_RunLoopUntil(CoreTiming::GetTicks() + cycles);
|
||||
}
|
||||
|
||||
Path GetSysDirectory(PSPDirectories directoryType) {
|
||||
const Path &memStickDirectory = g_Config.memStickDirectory;
|
||||
Path pspDirectory;
|
||||
if (!strcasecmp(memStickDirectory.GetFilename().c_str(), "PSP")) {
|
||||
// Let's strip this off, to easily allow choosing a root directory named "PSP" on Android.
|
||||
pspDirectory = memStickDirectory;
|
||||
} else {
|
||||
pspDirectory = memStickDirectory / "PSP";
|
||||
}
|
||||
|
||||
switch (directoryType) {
|
||||
case DIRECTORY_PSP:
|
||||
return pspDirectory;
|
||||
case DIRECTORY_CHEATS:
|
||||
return pspDirectory / "Cheats";
|
||||
case DIRECTORY_GAME:
|
||||
return pspDirectory / "GAME";
|
||||
case DIRECTORY_SAVEDATA:
|
||||
return pspDirectory / "SAVEDATA";
|
||||
case DIRECTORY_SCREENSHOT:
|
||||
return pspDirectory / "SCREENSHOT";
|
||||
case DIRECTORY_SYSTEM:
|
||||
return pspDirectory / "SYSTEM";
|
||||
case DIRECTORY_PAUTH:
|
||||
return memStickDirectory / "PAUTH"; // This one's at the root...
|
||||
case DIRECTORY_EXDATA:
|
||||
return memStickDirectory / "EXDATA"; // This one's traditionally at the root...
|
||||
case DIRECTORY_DUMP:
|
||||
return pspDirectory / "SYSTEM/DUMP";
|
||||
case DIRECTORY_SAVESTATE:
|
||||
return pspDirectory / "PPSSPP_STATE";
|
||||
case DIRECTORY_CACHE:
|
||||
return pspDirectory / "SYSTEM/CACHE";
|
||||
case DIRECTORY_TEXTURES:
|
||||
return pspDirectory / "TEXTURES";
|
||||
case DIRECTORY_PLUGINS:
|
||||
return pspDirectory / "PLUGINS";
|
||||
case DIRECTORY_APP_CACHE:
|
||||
if (!g_Config.appCacheDirectory.empty()) {
|
||||
return g_Config.appCacheDirectory;
|
||||
}
|
||||
return pspDirectory / "SYSTEM/CACHE";
|
||||
case DIRECTORY_VIDEO:
|
||||
return pspDirectory / "VIDEO";
|
||||
case DIRECTORY_AUDIO:
|
||||
return pspDirectory / "AUDIO";
|
||||
case DIRECTORY_CUSTOM_SHADERS:
|
||||
return pspDirectory / "shaders";
|
||||
case DIRECTORY_CUSTOM_THEMES:
|
||||
return pspDirectory / "themes";
|
||||
|
||||
case DIRECTORY_MEMSTICK_ROOT:
|
||||
return g_Config.memStickDirectory;
|
||||
// Just return the memory stick root if we run into some sort of problem.
|
||||
default:
|
||||
ERROR_LOG(Log::FileSystem, "Unknown directory type.");
|
||||
return g_Config.memStickDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
bool CreateSysDirectories() {
|
||||
#if PPSSPP_PLATFORM(ANDROID)
|
||||
const bool createNoMedia = true;
|
||||
#else
|
||||
const bool createNoMedia = false;
|
||||
#endif
|
||||
|
||||
Path pspDir = GetSysDirectory(DIRECTORY_PSP);
|
||||
INFO_LOG(Log::IO, "Creating '%s' and subdirs:", pspDir.c_str());
|
||||
File::CreateFullPath(pspDir);
|
||||
if (!File::Exists(pspDir)) {
|
||||
INFO_LOG(Log::IO, "Not a workable memstick directory. Giving up");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the default directories that a real PSP creates. Good for homebrew so they can
|
||||
// expect a standard environment. Skipping THEME though, that's pointless.
|
||||
static const PSPDirectories sysDirs[] = {
|
||||
DIRECTORY_CHEATS,
|
||||
DIRECTORY_SAVEDATA,
|
||||
DIRECTORY_SAVESTATE,
|
||||
DIRECTORY_GAME,
|
||||
DIRECTORY_SYSTEM,
|
||||
DIRECTORY_TEXTURES,
|
||||
DIRECTORY_PLUGINS,
|
||||
DIRECTORY_CACHE,
|
||||
};
|
||||
|
||||
for (auto dir : sysDirs) {
|
||||
Path path = GetSysDirectory(dir);
|
||||
File::CreateFullPath(path);
|
||||
if (createNoMedia) {
|
||||
// Create a nomedia file in each specified subdirectory.
|
||||
File::CreateEmptyFile(path / ".nomedia");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *DumpFileTypeToString(DumpFileType type) {
|
||||
switch (type) {
|
||||
case DumpFileType::EBOOT: return "EBOOT";
|
||||
|
||||
+1
-24
@@ -22,6 +22,7 @@
|
||||
#include "Common/File/Path.h"
|
||||
#include "Core/CoreParameter.h"
|
||||
#include "Core/ConfigValues.h"
|
||||
#include "Core/Util/PathUtil.h"
|
||||
|
||||
class MetaFileSystem;
|
||||
class ParamSFOData;
|
||||
@@ -39,30 +40,6 @@ enum GlobalUIState {
|
||||
UISTATE_EXCEPTION,
|
||||
};
|
||||
|
||||
// Use these in conjunction with GetSysDirectory.
|
||||
enum PSPDirectories {
|
||||
DIRECTORY_PSP,
|
||||
DIRECTORY_CHEATS,
|
||||
DIRECTORY_SCREENSHOT,
|
||||
DIRECTORY_SYSTEM,
|
||||
DIRECTORY_GAME,
|
||||
DIRECTORY_SAVEDATA,
|
||||
DIRECTORY_PAUTH,
|
||||
DIRECTORY_DUMP,
|
||||
DIRECTORY_SAVESTATE,
|
||||
DIRECTORY_CACHE,
|
||||
DIRECTORY_TEXTURES,
|
||||
DIRECTORY_PLUGINS,
|
||||
DIRECTORY_APP_CACHE, // Use the OS app cache if available
|
||||
DIRECTORY_VIDEO,
|
||||
DIRECTORY_AUDIO,
|
||||
DIRECTORY_MEMSTICK_ROOT,
|
||||
DIRECTORY_EXDATA,
|
||||
DIRECTORY_CUSTOM_SHADERS,
|
||||
DIRECTORY_CUSTOM_THEMES,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
class GraphicsContext;
|
||||
enum class GPUBackend;
|
||||
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
#include <string_view>
|
||||
|
||||
#include "Common/File/Path.h"
|
||||
#include "Common/File/FileUtil.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/System/System.h"
|
||||
#include "Common/Log.h"
|
||||
#include "Core/Util/PathUtil.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Common/VR/PPSSPPVR.h"
|
||||
|
||||
Path FindConfigFile(const Path &searchPath, std::string_view baseFilename, bool *exists) {
|
||||
// Don't search for an absolute path.
|
||||
if (baseFilename.size() > 1 && baseFilename[0] == '/') {
|
||||
Path path(baseFilename);
|
||||
*exists = File::Exists(path);
|
||||
return path;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
// Handle paths starting with a drive letter.
|
||||
if (baseFilename.size() > 3 && baseFilename[1] == ':' && (baseFilename[2] == '/' || baseFilename[2] == '\\')) {
|
||||
Path path(baseFilename);
|
||||
*exists = File::Exists(path);
|
||||
return path;
|
||||
}
|
||||
#endif
|
||||
|
||||
Path filename = searchPath / baseFilename;
|
||||
if (File::Exists(filename)) {
|
||||
*exists = true;
|
||||
return filename;
|
||||
}
|
||||
*exists = false;
|
||||
// Make sure at least the directory it's supposed to be in exists.
|
||||
Path parent = filename.NavigateUp();
|
||||
|
||||
// We try to create the path and ignore if it fails (already exists).
|
||||
if (parent != GetSysDirectory(DIRECTORY_SYSTEM)) {
|
||||
File::CreateFullPath(parent);
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
Path GetSysDirectory(PSPDirectories directoryType) {
|
||||
const Path &memStickDirectory = g_Config.memStickDirectory;
|
||||
Path pspDirectory;
|
||||
if (!strcasecmp(memStickDirectory.GetFilename().c_str(), "PSP")) {
|
||||
// Let's strip this off, to easily allow choosing a root directory named "PSP" on Android.
|
||||
pspDirectory = memStickDirectory;
|
||||
} else {
|
||||
pspDirectory = memStickDirectory / "PSP";
|
||||
}
|
||||
|
||||
switch (directoryType) {
|
||||
case DIRECTORY_PSP:
|
||||
return pspDirectory;
|
||||
case DIRECTORY_CHEATS:
|
||||
return pspDirectory / "Cheats";
|
||||
case DIRECTORY_GAME:
|
||||
return pspDirectory / "GAME";
|
||||
case DIRECTORY_SAVEDATA:
|
||||
return pspDirectory / "SAVEDATA";
|
||||
case DIRECTORY_SCREENSHOT:
|
||||
return pspDirectory / "SCREENSHOT";
|
||||
case DIRECTORY_SYSTEM:
|
||||
return pspDirectory / "SYSTEM";
|
||||
case DIRECTORY_PAUTH:
|
||||
return memStickDirectory / "PAUTH"; // This one's at the root...
|
||||
case DIRECTORY_EXDATA:
|
||||
return memStickDirectory / "EXDATA"; // This one's traditionally at the root...
|
||||
case DIRECTORY_DUMP:
|
||||
return pspDirectory / "SYSTEM/DUMP";
|
||||
case DIRECTORY_SAVESTATE:
|
||||
return pspDirectory / "PPSSPP_STATE";
|
||||
case DIRECTORY_CACHE:
|
||||
return pspDirectory / "SYSTEM/CACHE";
|
||||
case DIRECTORY_TEXTURES:
|
||||
return pspDirectory / "TEXTURES";
|
||||
case DIRECTORY_PLUGINS:
|
||||
return pspDirectory / "PLUGINS";
|
||||
case DIRECTORY_APP_CACHE:
|
||||
if (!g_Config.appCacheDirectory.empty()) {
|
||||
return g_Config.appCacheDirectory;
|
||||
}
|
||||
return pspDirectory / "SYSTEM/CACHE";
|
||||
case DIRECTORY_VIDEO:
|
||||
return pspDirectory / "VIDEO";
|
||||
case DIRECTORY_AUDIO:
|
||||
return pspDirectory / "AUDIO";
|
||||
case DIRECTORY_CUSTOM_SHADERS:
|
||||
return pspDirectory / "shaders";
|
||||
case DIRECTORY_CUSTOM_THEMES:
|
||||
return pspDirectory / "themes";
|
||||
|
||||
case DIRECTORY_MEMSTICK_ROOT:
|
||||
return g_Config.memStickDirectory;
|
||||
// Just return the memory stick root if we run into some sort of problem.
|
||||
default:
|
||||
ERROR_LOG(Log::FileSystem, "Unknown directory type.");
|
||||
return g_Config.memStickDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
bool CreateSysDirectories() {
|
||||
#if PPSSPP_PLATFORM(ANDROID)
|
||||
const bool createNoMedia = true;
|
||||
#else
|
||||
const bool createNoMedia = false;
|
||||
#endif
|
||||
|
||||
Path pspDir = GetSysDirectory(DIRECTORY_PSP);
|
||||
INFO_LOG(Log::IO, "Creating '%s' and subdirs:", pspDir.c_str());
|
||||
File::CreateFullPath(pspDir);
|
||||
if (!File::Exists(pspDir)) {
|
||||
INFO_LOG(Log::IO, "Not a workable memstick directory. Giving up");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the default directories that a real PSP creates. Good for homebrew so they can
|
||||
// expect a standard environment. Skipping THEME though, that's pointless.
|
||||
static const PSPDirectories sysDirs[] = {
|
||||
DIRECTORY_CHEATS,
|
||||
DIRECTORY_SAVEDATA,
|
||||
DIRECTORY_SAVESTATE,
|
||||
DIRECTORY_GAME,
|
||||
DIRECTORY_SYSTEM,
|
||||
DIRECTORY_TEXTURES,
|
||||
DIRECTORY_PLUGINS,
|
||||
DIRECTORY_CACHE,
|
||||
};
|
||||
|
||||
for (auto dir : sysDirs) {
|
||||
Path path = GetSysDirectory(dir);
|
||||
File::CreateFullPath(path);
|
||||
if (createNoMedia) {
|
||||
// Create a nomedia file in each specified subdirectory.
|
||||
File::CreateEmptyFile(path / ".nomedia");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Path GetGameConfigFilePath(const Path &searchPath, std::string_view gameId, bool *exists) {
|
||||
std::string_view ppssppIniFilename = IsVREnabled() ? "_ppssppvr.ini" : "_ppsspp.ini";
|
||||
std::string iniFileName = join(gameId, ppssppIniFilename);
|
||||
Path iniFileNameFull = FindConfigFile(searchPath, iniFileName, exists);
|
||||
return iniFileNameFull;
|
||||
}
|
||||
|
||||
// On iOS, the path to the app documents directory changes on each launch.
|
||||
// Example path:
|
||||
// /var/mobile/Containers/Data/Application/0E0E89DE-8D8E-485A-860C-700D8BC87B86/Documents/PSP/GAME/SuicideBarbie
|
||||
// The GUID part changes on each launch.
|
||||
bool TryUpdateSavedPath(Path *path) {
|
||||
#if PPSSPP_PLATFORM(IOS)
|
||||
// DEBUG_LOG(Log::Loader, "Original path: %s", path->c_str());
|
||||
std::string pathStr = path->ToString();
|
||||
|
||||
const std::string_view applicationRoot = "/var/mobile/Containers/Data/Application/";
|
||||
if (startsWith(pathStr, applicationRoot)) {
|
||||
size_t documentsPos = pathStr.find("/Documents/");
|
||||
if (documentsPos == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
std::string memstick = g_Config.memStickDirectory.ToString();
|
||||
size_t memstickDocumentsPos = memstick.find("/Documents"); // Note: No trailing slash, or we won't find it.
|
||||
*path = Path(memstick.substr(0, memstickDocumentsPos) + pathStr.substr(documentsPos));
|
||||
return true;
|
||||
} else {
|
||||
// Path can't be auto-updated.
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
Path GetFailedBackendsDir() {
|
||||
Path failedBackendsDir;
|
||||
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
||||
failedBackendsDir = GetSysDirectory(DIRECTORY_APP_CACHE);
|
||||
} else {
|
||||
failedBackendsDir = GetSysDirectory(DIRECTORY_SYSTEM);
|
||||
}
|
||||
return failedBackendsDir;
|
||||
}
|
||||
|
||||
std::string GetFriendlyPath(Path path, Path aliasMatch, std::string_view aliasDisplay) {
|
||||
// Show relative to memstick root if there.
|
||||
if (path.StartsWith(aliasMatch)) {
|
||||
std::string p;
|
||||
if (aliasMatch.ComputePathTo(path, p)) {
|
||||
return join(aliasDisplay, p);
|
||||
}
|
||||
std::string str = path.ToString();
|
||||
if (aliasMatch.size() < str.length()) {
|
||||
return join(aliasDisplay, str.substr(aliasMatch.size()));
|
||||
} else {
|
||||
return std::string(aliasDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
std::string str = path.ToString();
|
||||
#if !PPSSPP_PLATFORM(ANDROID) && (PPSSPP_PLATFORM(LINUX) || PPSSPP_PLATFORM(MAC))
|
||||
char *home = getenv("HOME");
|
||||
if (home != nullptr && !strncmp(str.c_str(), home, strlen(home))) {
|
||||
return std::string("~") + str.substr(strlen(home));
|
||||
}
|
||||
#endif
|
||||
return path.ToVisualString();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "Common/File/Path.h"
|
||||
|
||||
// Use these in conjunction with GetSysDirectory.
|
||||
enum PSPDirectories {
|
||||
DIRECTORY_PSP,
|
||||
DIRECTORY_CHEATS,
|
||||
DIRECTORY_SCREENSHOT,
|
||||
DIRECTORY_SYSTEM,
|
||||
DIRECTORY_GAME,
|
||||
DIRECTORY_SAVEDATA,
|
||||
DIRECTORY_PAUTH,
|
||||
DIRECTORY_DUMP,
|
||||
DIRECTORY_SAVESTATE,
|
||||
DIRECTORY_CACHE,
|
||||
DIRECTORY_TEXTURES,
|
||||
DIRECTORY_PLUGINS,
|
||||
DIRECTORY_APP_CACHE, // Use the OS app cache if available
|
||||
DIRECTORY_VIDEO,
|
||||
DIRECTORY_AUDIO,
|
||||
DIRECTORY_MEMSTICK_ROOT,
|
||||
DIRECTORY_EXDATA,
|
||||
DIRECTORY_CUSTOM_SHADERS,
|
||||
DIRECTORY_CUSTOM_THEMES,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
Path FindConfigFile(const Path &searchPath, std::string_view baseFilename, bool *exists);
|
||||
Path GetSysDirectory(PSPDirectories directoryType);
|
||||
bool CreateSysDirectories();
|
||||
Path GetGameConfigFilePath(const Path &searchPath, std::string_view gameId, bool *exists);
|
||||
bool TryUpdateSavedPath(Path *path);
|
||||
Path GetFailedBackendsDir();
|
||||
std::string GetFriendlyPath(Path path, Path aliasMatch, std::string_view aliasDisplay);
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Common/TimeUtil.h"
|
||||
#include "Core/Loaders.h"
|
||||
#include "Core/Util/RecentFiles.h"
|
||||
#include "Core/Util/PathUtil.h"
|
||||
#include "Core/Config.h"
|
||||
|
||||
RecentFilesManager g_recentFiles;
|
||||
|
||||
Reference in new issue
Block a user