lr: Cleanup lr_redirection

This commit is contained in:
Adubbz 2019-08-13 23:38:24 +10:00
parent 742e474f68
commit f62174abfd
2 changed files with 44 additions and 37 deletions

View file

@ -18,54 +18,75 @@
namespace sts::lr::impl {
class LocationRedirection : public util::IntrusiveListBaseNode<LocationRedirection> {
NON_COPYABLE(LocationRedirection);
NON_MOVEABLE(LocationRedirection);
private:
ncm::TitleId title_id;
Path path;
u32 flags;
public:
LocationRedirection(ncm::TitleId title_id, const Path& path, u32 flags) :
title_id(title_id), path(path), flags(flags) { /* ... */ }
ncm::TitleId GetTitleId() const {
return this->title_id;
}
void GetPath(Path *out) const {
*out = this->path;
}
u32 GetFlags() const {
return this->flags;
}
void SetFlags(u32 flags) {
this->flags = flags;
}
};
bool LocationRedirector::FindRedirection(Path *out, ncm::TitleId title_id) {
if (this->redirection_list.empty()) {
return false;
}
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end(); it++) {
if (it->title_id == title_id) {
*out = it->path;
for (const auto &redirection : this->redirection_list) {
if (redirection.GetTitleId() == title_id) {
redirection.GetPath(out);
return true;
}
}
return false;
}
void LocationRedirector::SetRedirection(ncm::TitleId title_id, const Path &path, u32 flags) {
this->EraseRedirection(title_id);
auto redirection = new LocationRedirection(title_id, path, flags);
this->redirection_list.push_back(*redirection);
this->redirection_list.push_back(*(new LocationRedirection(title_id, path, flags)));
}
void LocationRedirector::SetRedirectionFlags(ncm::TitleId title_id, u32 flags) {
if (!this->redirection_list.empty()) {
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end(); it++) {
if (it->title_id == title_id) {
it->flags = flags;
break;
}
for (auto &redirection : this->redirection_list) {
if (redirection.GetTitleId() == title_id) {
redirection.SetFlags(flags);
break;
}
}
}
void LocationRedirector::EraseRedirection(ncm::TitleId title_id) {
if (!this->redirection_list.empty()) {
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end(); it++) {
if (it->title_id == title_id) {
auto old = it;
this->redirection_list.erase(old);
delete &(*old);
break;
}
for (auto &redirection : this->redirection_list) {
if (redirection.GetTitleId() == title_id) {
this->redirection_list.erase(this->redirection_list.iterator_to(redirection));
delete &redirection;
break;
}
}
}
void LocationRedirector::ClearRedirections(u32 flags) {
for (auto it = this->redirection_list.begin(); it != this->redirection_list.end();) {
if ((it->flags & flags) == flags) {
if ((it->GetFlags() & flags) == flags) {
auto old = it;
it = this->redirection_list.erase(it);
delete &(*old);
@ -75,6 +96,4 @@ namespace sts::lr::impl {
}
}
}

View file

@ -27,19 +27,7 @@ namespace sts::lr::impl {
RedirectionFlags_Application = (1 << 0),
};
class LocationRedirection : public util::IntrusiveListBaseNode<LocationRedirection> {
NON_COPYABLE(LocationRedirection);
NON_MOVEABLE(LocationRedirection);
public:
ncm::TitleId title_id;
Path path;
u32 flags;
LocationRedirection(ncm::TitleId title_id, const Path& path, u32 flags) :
title_id(title_id), path(path), flags(flags) {
}
};
class LocationRedirection;
class LocationRedirector {
NON_COPYABLE(LocationRedirector);
@ -47,7 +35,7 @@ namespace sts::lr::impl {
private:
sts::util::IntrusiveListBaseTraits<LocationRedirection>::ListType redirection_list;
public:
LocationRedirector() {}
LocationRedirector() { /* ... */ }
bool FindRedirection(Path *out, ncm::TitleId title_id);
void SetRedirection(ncm::TitleId title_id, const Path &path, u32 flags = RedirectionFlags_None);