From 8317a66ea5c4224a2a6ccfb2389f3b5fe7efff13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 8 Apr 2018 11:57:36 +0200 Subject: NandPaths: Return paths that are relative to Wii NAND Since all FS access will go through the new FS interface (PR #6421) in order to keep track of metadata properly, there is no need to return absolute paths anymore. In fact, returning host paths is a roadblock to using the FS interface. This starts the migration work by adding a way to get paths that are relative to the Wii NAND instead of always getting absolute paths on the host FS. To prepare for future changes, this commit also makes returned paths canonical by removing the trailing slash when it's unneeded. Eventually, once everything has been migrated to the new interface, we can remove the "from" parameter. --- Source/Core/Common/NandPaths.cpp | 27 ++++++++++++++++----------- Source/Core/Common/NandPaths.h | 20 +++++++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) (limited to 'Source/Core/Common') 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 from) +{ + return from ? RootUserPath(*from) : ""; +} + +std::string GetImportTitlePath(u64 title_id, std::optional from) { return RootUserPath(from) + StringFromFormat("/import/%08x/%08x", static_cast(title_id >> 32), static_cast(title_id)); } -std::string GetTicketFileName(u64 title_id, FromWhichRoot from) +std::string GetTicketFileName(u64 title_id, std::optional from) { return StringFromFormat("%s/ticket/%08x/%08x.tik", RootUserPath(from).c_str(), static_cast(title_id >> 32), static_cast(title_id)); } -std::string GetTitlePath(u64 title_id, FromWhichRoot from) +std::string GetTitlePath(u64 title_id, std::optional from) { - return StringFromFormat("%s/title/%08x/%08x/", RootUserPath(from).c_str(), + return StringFromFormat("%s/title/%08x/%08x", RootUserPath(from).c_str(), static_cast(title_id >> 32), static_cast(title_id)); } -std::string GetTitleDataPath(u64 title_id, FromWhichRoot from) +std::string GetTitleDataPath(u64 title_id, std::optional 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 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 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 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 #include #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 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 from = {}); +std::string GetTitlePath(u64 title_id, std::optional from = {}); +std::string GetTitleDataPath(u64 title_id, std::optional from = {}); +std::string GetTitleContentPath(u64 title_id, std::optional from = {}); +std::string GetTMDFileName(u64 title_id, std::optional 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 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); -- cgit v1.2.3