diff --git a/Common/File/Path.cpp b/Common/File/Path.cpp index 132aed3c8d..452c85703d 100644 --- a/Common/File/Path.cpp +++ b/Common/File/Path.cpp @@ -513,8 +513,7 @@ bool FixPathCase(const Path &realBasePath, std::string &path, FixPathCaseBehavio if (len == 0) return true; - if (path[len - 1] == '/') - { + if (path[len - 1] == '/') { len--; if (len == 0) @@ -526,14 +525,12 @@ bool FixPathCase(const Path &realBasePath, std::string &path, FixPathCaseBehavio fullPath.append(basePath); size_t start = 0; - while (start < len) - { + while (start < len) { size_t i = path.find('/', start); if (i == std::string::npos) i = len; - if (i > start) - { + if (i > start) { std::string component = path.substr(start, i - start); // Fix case and stop on nonexistant path component diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index d8832457a4..3206476267 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -90,12 +90,12 @@ DirectoryFileSystem::~DirectoryFileSystem() { // TODO(scoped): Merge the two below functions somehow. -Path DirectoryFileHandle::GetLocalPath(const Path &basePath, std::string localPath) const { +Path DirectoryFileHandle::GetLocalPath(const Path &basePath, std::string_view localPath) const { if (localPath.empty()) return basePath; if (localPath[0] == '/') - localPath.erase(0, 1); + localPath = localPath.substr(1); if (fileSystemFlags_ & FileSystemFlags::STRIP_PSP) { if (localPath == "PSP") { @@ -108,12 +108,12 @@ Path DirectoryFileHandle::GetLocalPath(const Path &basePath, std::string localPa return basePath / localPath; } -Path DirectoryFileSystem::GetLocalPath(std::string internalPath) const { +Path DirectoryFileSystem::GetLocalPath(std::string_view internalPath) const { if (internalPath.empty()) return basePath; if (internalPath[0] == '/') - internalPath.erase(0, 1); + internalPath = internalPath.substr(1); if (flags & FileSystemFlags::STRIP_PSP) { if (internalPath == "PSP") { @@ -1053,8 +1053,8 @@ VFSFileSystem::~VFSFileSystem() { entries.clear(); } -std::string VFSFileSystem::GetLocalPath(const std::string &localPath) const { - return basePath + localPath; +std::string VFSFileSystem::GetLocalPath(std::string_view localPath) const { + return join(basePath, localPath); } bool VFSFileSystem::MkDir(const std::string &dirname) { diff --git a/Core/FileSystems/DirectoryFileSystem.h b/Core/FileSystems/DirectoryFileSystem.h index 083b15635c..ffac242911 100644 --- a/Core/FileSystems/DirectoryFileSystem.h +++ b/Core/FileSystems/DirectoryFileSystem.h @@ -51,7 +51,7 @@ struct DirectoryFileHandle { DirectoryFileHandle(Flags flags, FileSystemFlags fileSystemFlags) : replay_(flags != SKIP_REPLAY), fileSystemFlags_(fileSystemFlags) {} - Path GetLocalPath(const Path &basePath, std::string localpath) const; + Path GetLocalPath(const Path &basePath, std::string_view localPath) const; bool Open(const Path &basePath, std::string &fileName, FileAccess access, u32 &err); size_t Read(u8* pointer, s64 size); size_t Write(const u8* pointer, s64 size); @@ -104,7 +104,7 @@ private: IHandleAllocator *hAlloc; FileSystemFlags flags; - Path GetLocalPath(std::string internalPath) const; + Path GetLocalPath(std::string_view internalPath) const; }; // VFSFileSystem: Ability to map in Android APK paths as well! Does not support all features, only meant for fonts. @@ -151,5 +151,5 @@ private: std::string basePath; IHandleAllocator *hAlloc; - std::string GetLocalPath(const std::string &localpath) const; + std::string GetLocalPath(std::string_view localpath) const; }; diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index f4c498d16b..4e2af27703 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -255,7 +255,7 @@ void ISOFileSystem::ReadDirectory(TreeEntry *root) const { root->valid = true; } -const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(const std::string &path, bool catchError) { +const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(std::string_view path, bool catchError) { const size_t pathLength = path.length(); if (pathLength == 0) { @@ -288,9 +288,9 @@ const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(const std::string &pa if (nextSlashIndex == std::string::npos) nextSlashIndex = pathLength; - const std::string firstPathComponent = path.substr(pathIndex, nextSlashIndex - pathIndex); + const std::string_view firstPathComponent = path.substr(pathIndex, nextSlashIndex - pathIndex); for (size_t i = 0; i < entry->children.size(); i++) { - const std::string &n = entry->children[i]->name; + const std::string_view n = entry->children[i]->name; if (firstPathComponent == n) { //yay we got it nextEntry = entry->children[i]; @@ -302,8 +302,9 @@ const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(const std::string &pa if (nextEntry) { entry = nextEntry; - if (!entry->valid) + if (!entry->valid) { ReadDirectory(entry); + } pathIndex += name.length(); if (pathIndex < pathLength && path[pathIndex] == '/') ++pathIndex; @@ -311,9 +312,9 @@ const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(const std::string &pa if (pathLength <= pathIndex) return entry; } else { - if (catchError) - ERROR_LOG(Log::FileSystem, "File '%s' not found", path.c_str()); - + if (catchError) { + ERROR_LOG(Log::FileSystem, "File '%.*s' not found", STR_VIEW(path)); + } return 0; } } diff --git a/Core/FileSystems/ISOFileSystem.h b/Core/FileSystems/ISOFileSystem.h index 615b788631..c07a5616af 100644 --- a/Core/FileSystems/ISOFileSystem.h +++ b/Core/FileSystems/ISOFileSystem.h @@ -98,7 +98,7 @@ private: TreeEntry entireISO; void ReadDirectory(TreeEntry *root) const; - const TreeEntry *GetFromPath(const std::string &path, bool catchError = true); + const TreeEntry *GetFromPath(std::string_view path, bool catchError = true); std::string EntryFullPath(const TreeEntry *e); }; diff --git a/Core/FileSystems/VirtualDiscFileSystem.cpp b/Core/FileSystems/VirtualDiscFileSystem.cpp index af5a21e80c..35e4164523 100644 --- a/Core/FileSystems/VirtualDiscFileSystem.cpp +++ b/Core/FileSystems/VirtualDiscFileSystem.cpp @@ -236,19 +236,12 @@ void VirtualDiscFileSystem::DoState(PointerWrap &p) // We don't savestate handlers (loaded on fs load), but if they change, it may not load properly. } -Path VirtualDiscFileSystem::GetLocalPath(std::string localpath) const { +Path VirtualDiscFileSystem::GetLocalPath(std::string_view localpath) const { if (localpath.empty()) return basePath; if (localpath[0] == '/') - localpath.erase(0,1); - //Convert slashes -#ifdef _WIN32 - for (size_t i = 0; i < localpath.size(); i++) { - if (localpath[i] == '/') - localpath[i] = '\\'; - } -#endif + localpath.remove_prefix(1); return basePath / localpath; } diff --git a/Core/FileSystems/VirtualDiscFileSystem.h b/Core/FileSystems/VirtualDiscFileSystem.h index bfcbe3014d..987ea01ffa 100644 --- a/Core/FileSystems/VirtualDiscFileSystem.h +++ b/Core/FileSystems/VirtualDiscFileSystem.h @@ -64,7 +64,7 @@ private: // Warning: modifies input string. int getFileListIndex(std::string &fileName); int getFileListIndex(u32 accessBlock, u32 accessSize, bool blockMode = false) const; - Path GetLocalPath(std::string localpath) const; + Path GetLocalPath(std::string_view localpath) const; typedef void *HandlerLibrary; typedef int HandlerHandle;