diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2017-08-15 22:40:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-15 22:40:56 +0200 |
| commit | 9b79e0ac728529de850aef2df30d155aba350352 (patch) | |
| tree | ec7829a630f0622755d2d4e9f5c90d427115276f /Source/Core/Common | |
| parent | 8fedd4fa0662daebcff91b82203773000d0b0ae7 (diff) | |
| parent | 40c70469e5cf20124e49f8c41827173e87cbda3f (diff) | |
Merge pull request #5930 from delroth/wfs
Fix Dragon Quest X offline mode on Dolphin
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/NandPaths.cpp | 29 | ||||
| -rw-r--r-- | Source/Core/Common/NandPaths.h | 3 |
2 files changed, 32 insertions, 0 deletions
diff --git a/Source/Core/Common/NandPaths.cpp b/Source/Core/Common/NandPaths.cpp index 1fcbab38be..ec43b38484 100644 --- a/Source/Core/Common/NandPaths.cpp +++ b/Source/Core/Common/NandPaths.cpp @@ -58,6 +58,35 @@ std::string GetTMDFileName(u64 _titleID, FromWhichRoot from) return GetTitleContentPath(_titleID, from) + "title.tmd"; } +bool IsTitlePath(const std::string& path, FromWhichRoot from, u64* title_id) +{ + std::string expected_prefix = RootUserPath(from) + "/title/"; + if (!StringBeginsWith(path, expected_prefix)) + { + return false; + } + + // Try to find a title ID in the remaining path. + std::string subdirectory = path.substr(expected_prefix.size()); + std::vector<std::string> components = SplitString(subdirectory, '/'); + if (components.size() < 2) + { + return false; + } + + u32 title_id_high, title_id_low; + if (!AsciiToHex(components[0], title_id_high) || !AsciiToHex(components[1], title_id_low)) + { + return false; + } + + if (title_id != nullptr) + { + *title_id = (static_cast<u64>(title_id_high) << 32) | title_id_low; + } + return true; +} + std::string EscapeFileName(const std::string& filename) { // Prevent paths from containing special names like ., .., ..., ...., and so on diff --git a/Source/Core/Common/NandPaths.h b/Source/Core/Common/NandPaths.h index 0a7738664c..6ef53a9912 100644 --- a/Source/Core/Common/NandPaths.h +++ b/Source/Core/Common/NandPaths.h @@ -29,6 +29,9 @@ std::string GetTitleDataPath(u64 _titleID, FromWhichRoot from); std::string GetTitleContentPath(u64 _titleID, FromWhichRoot from); std::string GetTMDFileName(u64 _titleID, FromWhichRoot from); +// Returns whether a path is within an installed title's directory. +bool IsTitlePath(const std::string& path, FromWhichRoot from, u64* title_id = nullptr); + // Escapes characters that are invalid or have special meanings in the host file system std::string EscapeFileName(const std::string& filename); // Escapes characters that are invalid or have special meanings in the host file system |
