bktr: Fix missing includes and optimize style

This commit is contained in:
Zach Hilman 2018-08-26 10:53:31 -04:00
parent f92b3512e0
commit 9664ce255d
12 changed files with 108 additions and 102 deletions

View file

@ -8,24 +8,19 @@
namespace FileSys {
union TitleVersion {
u32 version;
constexpr u64 SINGLE_BYTE_MODULUS = 0x100;
struct {
u8 v_revision;
u8 v_micro;
u8 v_minor;
u8 v_major;
};
};
std::string FormatTitleVersion(u32 version, TitleVersionFormat format) {
std::array<u8, sizeof(u32)> bytes{};
bytes[0] = version % SINGLE_BYTE_MODULUS;
for (size_t i = 1; i < bytes.size(); ++i) {
version /= SINGLE_BYTE_MODULUS;
bytes[i] = version % SINGLE_BYTE_MODULUS;
}
std::string FormatTitleVersion(u32 version_, bool full) {
TitleVersion ver{};
ver.version = version_;
if (full)
return fmt::format("v{}.{}.{}.{}", ver.v_major, ver.v_minor, ver.v_minor, ver.v_revision);
return fmt::format("v{}.{}.{}", ver.v_major, ver.v_minor, ver.v_micro);
if (format == TitleVersionFormat::FourElements)
return fmt::format("v{}.{}.{}.{}", bytes[3], bytes[2], bytes[1], bytes[0]);
return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]);
}
constexpr std::array<const char*, 1> PATCH_TYPE_NAMES{
@ -49,8 +44,9 @@ VirtualDir PatchManager::PatchExeFS(VirtualDir exefs) const {
const auto update = installed->GetEntry(update_tid, ContentRecordType::Program);
if (update != nullptr) {
if (update->GetStatus() == Loader::ResultStatus::ErrorMissingBKTRBaseRomFS &&
update->GetExeFS() != nullptr)
update->GetExeFS() != nullptr) {
exefs = update->GetExeFS();
}
}
return exefs;
@ -81,8 +77,9 @@ std::map<PatchType, u32> PatchManager::GetPatchVersionNames() const {
const auto update_tid = GetUpdateTitleID(title_id);
const auto update_version = installed->GetEntryVersion(update_tid);
if (update_version != boost::none &&
installed->HasEntry(update_tid, ContentRecordType::Program))
installed->HasEntry(update_tid, ContentRecordType::Program)) {
out[PatchType::Update] = update_version.get();
}
return out;
}