mirror of https://github.com/AxioDL/nod.git
Use std::optional for CalculateTotalSizeBuild
This commit is contained in:
parent
97cfcea14e
commit
091262ace1
|
@ -96,7 +96,7 @@ int main(int argc, char* argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (nod::DiscBuilderGCN::CalculateTotalSizeRequired(argv[2]) == UINT64_MAX)
|
||||
if (!nod::DiscBuilderGCN::CalculateTotalSizeRequired(argv[2]))
|
||||
return 1;
|
||||
|
||||
nod::EBuildResult ret;
|
||||
|
@ -123,7 +123,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
bool dual = false;
|
||||
if (nod::DiscBuilderWii::CalculateTotalSizeRequired(argv[2], dual) == UINT64_MAX)
|
||||
if (!nod::DiscBuilderWii::CalculateTotalSizeRequired(argv[2], dual))
|
||||
return 1;
|
||||
|
||||
nod::EBuildResult ret;
|
||||
|
@ -164,7 +164,7 @@ int main(int argc, char* argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (nod::DiscMergerGCN::CalculateTotalSizeRequired(static_cast<nod::DiscGCN&>(*disc), argv[2]) == UINT64_MAX)
|
||||
if (!nod::DiscMergerGCN::CalculateTotalSizeRequired(static_cast<nod::DiscGCN&>(*disc), argv[2]))
|
||||
return 1;
|
||||
|
||||
nod::EBuildResult ret;
|
||||
|
@ -206,7 +206,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
bool dual = false;
|
||||
if (nod::DiscMergerWii::CalculateTotalSizeRequired(static_cast<nod::DiscWii&>(*disc), argv[2], dual) == UINT64_MAX)
|
||||
if (!nod::DiscMergerWii::CalculateTotalSizeRequired(static_cast<nod::DiscWii&>(*disc), argv[2], dual))
|
||||
return 1;
|
||||
|
||||
nod::EBuildResult ret;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
@ -425,9 +426,9 @@ public:
|
|||
: m_parent(parent), m_kind(kind), m_isWii(isWii) {}
|
||||
virtual std::unique_ptr<IPartWriteStream> beginWriteStream(uint64_t offset) = 0;
|
||||
bool buildFromDirectory(IPartWriteStream& ws, SystemStringView dirIn);
|
||||
static uint64_t CalculateTotalSizeBuild(SystemStringView dirIn, PartitionKind kind, bool isWii);
|
||||
static std::optional<uint64_t> CalculateTotalSizeBuild(SystemStringView dirIn, PartitionKind kind, bool isWii);
|
||||
bool mergeFromDirectory(IPartWriteStream& ws, const IPartition* partIn, SystemStringView dirIn);
|
||||
static uint64_t CalculateTotalSizeMerge(const IPartition* partIn, SystemStringView dirIn);
|
||||
static std::optional<uint64_t> CalculateTotalSizeMerge(const IPartition* partIn, SystemStringView dirIn);
|
||||
};
|
||||
|
||||
protected:
|
||||
|
|
|
@ -20,7 +20,7 @@ class DiscBuilderGCN : public DiscBuilderBase {
|
|||
public:
|
||||
DiscBuilderGCN(SystemStringView outPath, FProgress progressCB);
|
||||
EBuildResult buildFromDirectory(SystemStringView dirIn);
|
||||
static uint64_t CalculateTotalSizeRequired(SystemStringView dirIn);
|
||||
static std::optional<uint64_t> CalculateTotalSizeRequired(SystemStringView dirIn);
|
||||
};
|
||||
|
||||
class DiscMergerGCN {
|
||||
|
@ -30,7 +30,7 @@ class DiscMergerGCN {
|
|||
public:
|
||||
DiscMergerGCN(SystemStringView outPath, DiscGCN& sourceDisc, FProgress progressCB);
|
||||
EBuildResult mergeFromDirectory(SystemStringView dirIn);
|
||||
static uint64_t CalculateTotalSizeRequired(DiscGCN& sourceDisc, SystemStringView dirIn);
|
||||
static std::optional<uint64_t> CalculateTotalSizeRequired(DiscGCN& sourceDisc, SystemStringView dirIn);
|
||||
};
|
||||
|
||||
} // namespace nod
|
||||
|
|
|
@ -16,7 +16,7 @@ class DiscBuilderWii : public DiscBuilderBase {
|
|||
public:
|
||||
DiscBuilderWii(SystemStringView outPath, bool dualLayer, FProgress progressCB);
|
||||
EBuildResult buildFromDirectory(SystemStringView dirIn);
|
||||
static uint64_t CalculateTotalSizeRequired(SystemStringView dirIn, bool& dualLayer);
|
||||
static std::optional<uint64_t> CalculateTotalSizeRequired(SystemStringView dirIn, bool& dualLayer);
|
||||
};
|
||||
|
||||
class DiscMergerWii {
|
||||
|
@ -26,7 +26,7 @@ class DiscMergerWii {
|
|||
public:
|
||||
DiscMergerWii(SystemStringView outPath, DiscWii& sourceDisc, bool dualLayer, FProgress progressCB);
|
||||
EBuildResult mergeFromDirectory(SystemStringView dirIn);
|
||||
static uint64_t CalculateTotalSizeRequired(DiscWii& sourceDisc, SystemStringView dirIn, bool& dualLayer);
|
||||
static std::optional<uint64_t> CalculateTotalSizeRequired(DiscWii& sourceDisc, SystemStringView dirIn, bool& dualLayer);
|
||||
};
|
||||
|
||||
} // namespace nod
|
||||
|
|
|
@ -769,8 +769,8 @@ bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(IPartWriteStream&
|
|||
return true;
|
||||
}
|
||||
|
||||
uint64_t DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(SystemStringView dirIn, PartitionKind kind,
|
||||
bool isWii) {
|
||||
std::optional<uint64_t> DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(SystemStringView dirIn,
|
||||
PartitionKind kind, bool isWii) {
|
||||
SystemString dirStr(dirIn);
|
||||
SystemString basePath = isWii ? dirStr + _SYS_STR("/") + getKindString(kind) : dirStr;
|
||||
SystemString dolIn = basePath + _SYS_STR("/sys/main.dol");
|
||||
|
@ -779,11 +779,11 @@ uint64_t DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(SystemSt
|
|||
Sstat dolStat;
|
||||
if (Stat(dolIn.c_str(), &dolStat)) {
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to stat {}")), dolIn);
|
||||
return UINT64_MAX;
|
||||
return std::nullopt;
|
||||
}
|
||||
uint64_t totalSz = ROUND_UP_32(dolStat.st_size);
|
||||
if (!RecursiveCalculateTotalSize(totalSz, nullptr, filesIn.c_str()))
|
||||
return UINT64_MAX;
|
||||
return std::nullopt;
|
||||
return totalSz;
|
||||
}
|
||||
|
||||
|
@ -843,15 +843,15 @@ bool DiscBuilderBase::PartitionBuilderBase::mergeFromDirectory(IPartWriteStream&
|
|||
return true;
|
||||
}
|
||||
|
||||
uint64_t DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeMerge(const IPartition* partIn,
|
||||
SystemStringView dirIn) {
|
||||
std::optional<uint64_t> DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeMerge(const IPartition* partIn,
|
||||
SystemStringView dirIn) {
|
||||
SystemString dirStr(dirIn);
|
||||
SystemString basePath = partIn->isWii() ? dirStr + _SYS_STR("/") + getKindString(partIn->getKind()) : dirStr;
|
||||
SystemString filesIn = basePath + _SYS_STR("/files");
|
||||
|
||||
uint64_t totalSz = ROUND_UP_32(partIn->getDOLSize());
|
||||
if (!RecursiveCalculateTotalSize(totalSz, &partIn->getFSTRoot(), filesIn.c_str()))
|
||||
return UINT64_MAX;
|
||||
return std::nullopt;
|
||||
return totalSz;
|
||||
}
|
||||
|
||||
|
|
|
@ -372,14 +372,14 @@ EBuildResult DiscBuilderGCN::buildFromDirectory(SystemStringView dirIn) {
|
|||
return pb.buildFromDirectory(dirIn) ? EBuildResult::Success : EBuildResult::Failed;
|
||||
}
|
||||
|
||||
uint64_t DiscBuilderGCN::CalculateTotalSizeRequired(SystemStringView dirIn) {
|
||||
uint64_t sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(dirIn, PartitionKind::Data, false);
|
||||
if (sz == UINT64_MAX)
|
||||
return UINT64_MAX;
|
||||
sz += 0x30000;
|
||||
std::optional<uint64_t> DiscBuilderGCN::CalculateTotalSizeRequired(SystemStringView dirIn) {
|
||||
std::optional<uint64_t> sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(dirIn, PartitionKind::Data, false);
|
||||
if (!sz)
|
||||
return sz;
|
||||
*sz += 0x30000;
|
||||
if (sz > 0x57058000) {
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), sz, 0x57058000);
|
||||
return UINT64_MAX;
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), *sz, 0x57058000);
|
||||
return std::nullopt;
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
@ -416,14 +416,14 @@ EBuildResult DiscMergerGCN::mergeFromDirectory(SystemStringView dirIn) {
|
|||
: EBuildResult::Failed;
|
||||
}
|
||||
|
||||
uint64_t DiscMergerGCN::CalculateTotalSizeRequired(DiscGCN& sourceDisc, SystemStringView dirIn) {
|
||||
uint64_t sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeMerge(sourceDisc.getDataPartition(), dirIn);
|
||||
if (sz == UINT64_MAX)
|
||||
return UINT64_MAX;
|
||||
sz += 0x30000;
|
||||
std::optional<uint64_t> DiscMergerGCN::CalculateTotalSizeRequired(DiscGCN& sourceDisc, SystemStringView dirIn) {
|
||||
std::optional<uint64_t> sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeMerge(sourceDisc.getDataPartition(), dirIn);
|
||||
if (!sz)
|
||||
return std::nullopt;
|
||||
*sz += 0x30000;
|
||||
if (sz > 0x57058000) {
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), sz, 0x57058000);
|
||||
return -1;
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), *sz, 0x57058000);
|
||||
return std::nullopt;
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
|
|
@ -1229,19 +1229,19 @@ EBuildResult DiscBuilderWii::buildFromDirectory(SystemStringView dirIn) {
|
|||
return EBuildResult::Success;
|
||||
}
|
||||
|
||||
uint64_t DiscBuilderWii::CalculateTotalSizeRequired(SystemStringView dirIn, bool& dualLayer) {
|
||||
uint64_t sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(dirIn, PartitionKind::Data, true);
|
||||
if (sz == UINT64_MAX)
|
||||
return UINT64_MAX;
|
||||
auto szDiv = std::lldiv(sz, 0x1F0000);
|
||||
std::optional<uint64_t> DiscBuilderWii::CalculateTotalSizeRequired(SystemStringView dirIn, bool& dualLayer) {
|
||||
std::optional<uint64_t> sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(dirIn, PartitionKind::Data, true);
|
||||
if (!sz)
|
||||
return sz;
|
||||
auto szDiv = std::lldiv(*sz, 0x1F0000);
|
||||
if (szDiv.rem)
|
||||
++szDiv.quot;
|
||||
sz = szDiv.quot * 0x200000;
|
||||
sz += 0x200000;
|
||||
*sz += 0x200000;
|
||||
dualLayer = (sz > 0x118240000);
|
||||
if (sz > 0x1FB4E0000) {
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), sz, 0x1FB4E0000);
|
||||
return UINT64_MAX;
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), *sz, 0x1FB4E0000);
|
||||
return std::nullopt;
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
@ -1336,19 +1336,19 @@ EBuildResult DiscMergerWii::mergeFromDirectory(SystemStringView dirIn) {
|
|||
return EBuildResult::Success;
|
||||
}
|
||||
|
||||
uint64_t DiscMergerWii::CalculateTotalSizeRequired(DiscWii& sourceDisc, SystemStringView dirIn, bool& dualLayer) {
|
||||
uint64_t sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeMerge(sourceDisc.getDataPartition(), dirIn);
|
||||
if (sz == UINT64_MAX)
|
||||
return UINT64_MAX;
|
||||
auto szDiv = std::lldiv(sz, 0x1F0000);
|
||||
std::optional<uint64_t> DiscMergerWii::CalculateTotalSizeRequired(DiscWii& sourceDisc, SystemStringView dirIn, bool& dualLayer) {
|
||||
std::optional<uint64_t> sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeMerge(sourceDisc.getDataPartition(), dirIn);
|
||||
if (!sz)
|
||||
return std::nullopt;
|
||||
auto szDiv = std::lldiv(*sz, 0x1F0000);
|
||||
if (szDiv.rem)
|
||||
++szDiv.quot;
|
||||
sz = szDiv.quot * 0x200000;
|
||||
sz += 0x200000;
|
||||
*sz += 0x200000;
|
||||
dualLayer = (sz > 0x118240000);
|
||||
if (sz > 0x1FB4E0000) {
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), sz, 0x1FB4E0000);
|
||||
return UINT64_MAX;
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("disc capacity exceeded [{} / {}]")), *sz, 0x1FB4E0000);
|
||||
return std::nullopt;
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue