diff options
Diffstat (limited to 'Source/Core/Common')
| -rw-r--r-- | Source/Core/Common/NandPaths.cpp | 27 | ||||
| -rw-r--r-- | Source/Core/Common/NandPaths.h | 20 |
2 files changed, 29 insertions, 18 deletions
diff --git a/Source/Core/Common/NandPaths.cpp b/Source/Core/Common/NandPaths.cpp index b670be635d..336c1bb7bb 100644 --- a/Source/Core/Common/NandPaths.cpp +++ b/Source/Core/Common/NandPaths.cpp @@ -21,41 +21,46 @@ std::string RootUserPath(FromWhichRoot from) return File::GetUserPath(idx); } -std::string GetImportTitlePath(u64 title_id, FromWhichRoot from) +static std::string RootUserPath(std::optional<FromWhichRoot> from) +{ + return from ? RootUserPath(*from) : ""; +} + +std::string GetImportTitlePath(u64 title_id, std::optional<FromWhichRoot> from) { return RootUserPath(from) + StringFromFormat("/import/%08x/%08x", static_cast<u32>(title_id >> 32), static_cast<u32>(title_id)); } -std::string GetTicketFileName(u64 title_id, FromWhichRoot from) +std::string GetTicketFileName(u64 title_id, std::optional<FromWhichRoot> from) { return StringFromFormat("%s/ticket/%08x/%08x.tik", RootUserPath(from).c_str(), static_cast<u32>(title_id >> 32), static_cast<u32>(title_id)); } -std::string GetTitlePath(u64 title_id, FromWhichRoot from) +std::string GetTitlePath(u64 title_id, std::optional<FromWhichRoot> from) { - return StringFromFormat("%s/title/%08x/%08x/", RootUserPath(from).c_str(), + return StringFromFormat("%s/title/%08x/%08x", RootUserPath(from).c_str(), static_cast<u32>(title_id >> 32), static_cast<u32>(title_id)); } -std::string GetTitleDataPath(u64 title_id, FromWhichRoot from) +std::string GetTitleDataPath(u64 title_id, std::optional<FromWhichRoot> from) { - return GetTitlePath(title_id, from) + "data/"; + return GetTitlePath(title_id, from) + "/data"; } -std::string GetTitleContentPath(u64 title_id, FromWhichRoot from) +std::string GetTitleContentPath(u64 title_id, std::optional<FromWhichRoot> from) { - return GetTitlePath(title_id, from) + "content/"; + return GetTitlePath(title_id, from) + "/content"; } -std::string GetTMDFileName(u64 title_id, FromWhichRoot from) +std::string GetTMDFileName(u64 title_id, std::optional<FromWhichRoot> from) { - return GetTitleContentPath(title_id, from) + "title.tmd"; + return GetTitleContentPath(title_id, from) + "/title.tmd"; } -bool IsTitlePath(const std::string& path, FromWhichRoot from, u64* title_id) +bool IsTitlePath(const std::string& path, std::optional<FromWhichRoot> from, u64* title_id) { std::string expected_prefix = RootUserPath(from) + "/title/"; if (!StringBeginsWith(path, expected_prefix)) diff --git a/Source/Core/Common/NandPaths.h b/Source/Core/Common/NandPaths.h index 5a1dcffce4..068a240f43 100644 --- a/Source/Core/Common/NandPaths.h +++ b/Source/Core/Common/NandPaths.h @@ -4,6 +4,7 @@ #pragma once +#include <optional> #include <string> #include "Common/CommonTypes.h" @@ -18,17 +19,22 @@ enum FromWhichRoot std::string RootUserPath(FromWhichRoot from); +// The following functions return paths relative to the NAND root. +// If a FromWhichRoot is passed, the NAND root on the host filesystem will be prepended to the path. +// TODO: remove the from parameter after all code is migrated off direct FS access. + // Returns /import/%08x/%08x. Intended for use by ES. -std::string GetImportTitlePath(u64 title_id, FromWhichRoot from = FROM_SESSION_ROOT); +std::string GetImportTitlePath(u64 title_id, std::optional<FromWhichRoot> from = {}); -std::string GetTicketFileName(u64 title_id, FromWhichRoot from); -std::string GetTitlePath(u64 title_id, FromWhichRoot from); -std::string GetTitleDataPath(u64 title_id, FromWhichRoot from); -std::string GetTitleContentPath(u64 title_id, FromWhichRoot from); -std::string GetTMDFileName(u64 title_id, FromWhichRoot from); +std::string GetTicketFileName(u64 title_id, std::optional<FromWhichRoot> from = {}); +std::string GetTitlePath(u64 title_id, std::optional<FromWhichRoot> from = {}); +std::string GetTitleDataPath(u64 title_id, std::optional<FromWhichRoot> from = {}); +std::string GetTitleContentPath(u64 title_id, std::optional<FromWhichRoot> from = {}); +std::string GetTMDFileName(u64 title_id, std::optional<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); +bool IsTitlePath(const std::string& path, std::optional<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); |
