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.
This commit is contained in:
Léo Lam
2018-04-08 11:57:36 +02:00
parent 00de41b583
commit 8317a66ea5
11 changed files with 61 additions and 42 deletions

View File

@ -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))