mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-11-27 10:54:13 +01:00
registered_cache: Deduplicate results of ListEntry and ListEntryFilter
Prevents a Entry from appearing in the list twice if the user has it installed in two places (e.g. User NAND and SDMC)
This commit is contained in:
parent
780c21ab2d
commit
59044862a9
@ -2,6 +2,7 @@
|
|||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <mbedtls/sha256.h>
|
#include <mbedtls/sha256.h>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
@ -30,6 +31,10 @@ bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs)
|
|||||||
return (lhs.title_id < rhs.title_id) || (lhs.title_id == rhs.title_id && lhs.type < rhs.type);
|
return (lhs.title_id < rhs.title_id) || (lhs.title_id == rhs.title_id && lhs.type < rhs.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) {
|
||||||
|
return std::tie(lhs.title_id, lhs.type) == std::tie(rhs.title_id, rhs.type);
|
||||||
|
}
|
||||||
|
|
||||||
static bool FollowsTwoDigitDirFormat(std::string_view name) {
|
static bool FollowsTwoDigitDirFormat(std::string_view name) {
|
||||||
static const std::regex two_digit_regex("000000[0-9A-F]{2}", std::regex_constants::ECMAScript |
|
static const std::regex two_digit_regex("000000[0-9A-F]{2}", std::regex_constants::ECMAScript |
|
||||||
std::regex_constants::icase);
|
std::regex_constants::icase);
|
||||||
@ -593,6 +598,9 @@ std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntries() const {
|
|||||||
},
|
},
|
||||||
[](const CNMT& c, const ContentRecord& r) { return true; });
|
[](const CNMT& c, const ContentRecord& r) { return true; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::sort(out.begin(), out.end());
|
||||||
|
out.erase(std::unique(out.begin(), out.end()), out.end());
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -616,6 +624,9 @@ std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntriesFilter(
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::sort(out.begin(), out.end());
|
||||||
|
out.erase(std::unique(out.begin(), out.end()), out.end());
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
@ -50,6 +50,9 @@ constexpr u64 GetUpdateTitleID(u64 base_title_id) {
|
|||||||
// boost flat_map requires operator< for O(log(n)) lookups.
|
// boost flat_map requires operator< for O(log(n)) lookups.
|
||||||
bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs);
|
bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs);
|
||||||
|
|
||||||
|
// std unique requires operator== to identify duplicates.
|
||||||
|
bool operator==(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A class that catalogues NCAs in the registered directory structure.
|
* A class that catalogues NCAs in the registered directory structure.
|
||||||
* Nintendo's registered format follows this structure:
|
* Nintendo's registered format follows this structure:
|
||||||
@ -60,8 +63,8 @@ bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs)
|
|||||||
* | 00
|
* | 00
|
||||||
* | 01 <- Actual content split along 4GB boundaries. (optional)
|
* | 01 <- Actual content split along 4GB boundaries. (optional)
|
||||||
*
|
*
|
||||||
* (This impl also supports substituting the nca dir for an nca file, as that's more convenient when
|
* (This impl also supports substituting the nca dir for an nca file, as that's more convenient
|
||||||
* 4GB splitting can be ignored.)
|
* when 4GB splitting can be ignored.)
|
||||||
*/
|
*/
|
||||||
class RegisteredCache {
|
class RegisteredCache {
|
||||||
friend class RegisteredCacheUnion;
|
friend class RegisteredCacheUnion;
|
||||||
|
Loading…
Reference in New Issue
Block a user