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