mirror of https://github.com/AxioDL/nod.git
General: Use std::make_unique where applicable
Makes for a little less reading in certain cases.
This commit is contained in:
parent
df1e450728
commit
a8753e273f
|
@ -110,11 +110,12 @@ std::unique_ptr<IPartReadStream> Node::beginReadStream(uint64_t offset) const {
|
|||
std::unique_ptr<uint8_t[]> Node::getBuf() const {
|
||||
if (m_kind != Kind::File) {
|
||||
LogModule.report(logvisor::Error, fmt("unable to buffer a non-file {}"), m_name);
|
||||
return std::unique_ptr<uint8_t[]>();
|
||||
return nullptr;
|
||||
}
|
||||
uint8_t* buf = new uint8_t[m_discLength];
|
||||
beginReadStream()->read(buf, m_discLength);
|
||||
return std::unique_ptr<uint8_t[]>(buf);
|
||||
|
||||
auto buf = std::unique_ptr<uint8_t[]>(new uint8_t[m_discLength]);
|
||||
beginReadStream()->read(buf.get(), m_discLength);
|
||||
return buf;
|
||||
}
|
||||
|
||||
bool Node::extractToDirectory(SystemStringView basePath, const ExtractionContext& ctx) const {
|
||||
|
|
|
@ -97,10 +97,13 @@ public:
|
|||
};
|
||||
|
||||
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset) const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IPartReadStream>(new PartReadStream(*this, offset, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::make_unique<PartReadStream>(*this, offset, err);
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
@ -110,7 +113,7 @@ DiscGCN::DiscGCN(std::unique_ptr<IDiscIO>&& dio, bool& err) : DiscBase(std::move
|
|||
return;
|
||||
|
||||
/* One lone partition for GCN */
|
||||
m_partitions.emplace_back(new PartitionGCN(*this, 0, err));
|
||||
m_partitions.emplace_back(std::make_unique<PartitionGCN>(*this, 0, err));
|
||||
}
|
||||
|
||||
DiscBuilderGCN DiscGCN::makeMergeBuilder(SystemStringView outPath, FProgress progressCB) {
|
||||
|
@ -165,10 +168,13 @@ public:
|
|||
uint32_t packOffset(uint64_t offset) const override { return offset; }
|
||||
|
||||
std::unique_ptr<IPartWriteStream> beginWriteStream(uint64_t offset) override {
|
||||
bool Err = false;
|
||||
std::unique_ptr<IPartWriteStream> ret = std::make_unique<PartWriteStream>(*this, offset, Err);
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::make_unique<PartWriteStream>(*this, offset, err);
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -370,8 +376,7 @@ uint64_t DiscBuilderGCN::CalculateTotalSizeRequired(SystemStringView dirIn) {
|
|||
|
||||
DiscBuilderGCN::DiscBuilderGCN(SystemStringView outPath, FProgress progressCB)
|
||||
: DiscBuilderBase(outPath, 0x57058000, progressCB) {
|
||||
PartitionBuilderGCN* partBuilder = new PartitionBuilderGCN(*this);
|
||||
m_partitions.emplace_back(partBuilder);
|
||||
m_partitions.emplace_back(std::make_unique<PartitionBuilderGCN>(*this));
|
||||
}
|
||||
|
||||
DiscMergerGCN::DiscMergerGCN(SystemStringView outPath, DiscGCN& sourceDisc, FProgress progressCB)
|
||||
|
|
|
@ -26,10 +26,13 @@ public:
|
|||
};
|
||||
|
||||
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_fio->beginReadStream(offset), Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_fio->beginReadStream(offset), err));
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -46,14 +49,17 @@ public:
|
|||
};
|
||||
|
||||
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_fio->beginWriteStream(offset), Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_fio->beginWriteStream(offset), err));
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<IDiscIO> NewDiscIOISO(SystemStringView path) { return std::unique_ptr<IDiscIO>(new DiscIOISO(path)); }
|
||||
std::unique_ptr<IDiscIO> NewDiscIOISO(SystemStringView path) { return std::make_unique<DiscIOISO>(path); }
|
||||
|
||||
} // namespace nod
|
||||
|
|
|
@ -259,18 +259,19 @@ public:
|
|||
};
|
||||
|
||||
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(*this, NewFileIO(filepath)->beginReadStream(), offset, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(*this, NewFileIO(filepath)->beginReadStream(), offset, err));
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override {
|
||||
return std::unique_ptr<IWriteStream>();
|
||||
}
|
||||
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override { return nullptr; }
|
||||
};
|
||||
|
||||
std::unique_ptr<IDiscIO> NewDiscIOWBFS(SystemStringView path) { return std::unique_ptr<IDiscIO>(new DiscIOWBFS(path)); }
|
||||
std::unique_ptr<IDiscIO> NewDiscIOWBFS(SystemStringView path) { return std::make_unique<DiscIOWBFS>(path); }
|
||||
|
||||
} // namespace nod
|
||||
|
|
|
@ -390,10 +390,13 @@ public:
|
|||
};
|
||||
|
||||
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset) const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IPartReadStream>(new PartReadStream(*this, m_dataOff, offset, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::make_unique<PartReadStream>(*this, m_dataOff, offset, err);
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -402,21 +405,23 @@ public:
|
|||
std::unique_ptr<uint8_t[]> readPartitionHeaderBuf(size_t& szOut) const {
|
||||
{
|
||||
std::unique_ptr<IReadStream> rs = m_parent.getDiscIO().beginReadStream(m_offset + 0x2B4);
|
||||
if (!rs)
|
||||
return {};
|
||||
if (!rs) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t h3;
|
||||
if (rs->read(&h3, 4) != 4) {
|
||||
LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to read H3 offset apploader")));
|
||||
return {};
|
||||
return nullptr;
|
||||
}
|
||||
h3 = SBig(h3);
|
||||
szOut = uint64_t(h3) << 2;
|
||||
}
|
||||
|
||||
std::unique_ptr<IReadStream> rs = m_parent.getDiscIO().beginReadStream(m_offset);
|
||||
if (!rs)
|
||||
return {};
|
||||
if (!rs) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[szOut]);
|
||||
rs->read(buf.get(), szOut);
|
||||
|
@ -528,7 +533,7 @@ DiscWii::DiscWii(std::unique_ptr<IDiscIO>&& dio, bool& err) : DiscBase(std::move
|
|||
err = true;
|
||||
return;
|
||||
}
|
||||
m_partitions.emplace_back(new PartitionWii(*this, kind, part.partDataOff << 2, err));
|
||||
m_partitions.emplace_back(std::make_unique<PartitionWii>(*this, kind, part.partDataOff << 2, err));
|
||||
if (err)
|
||||
return;
|
||||
}
|
||||
|
@ -757,11 +762,13 @@ public:
|
|||
uint32_t packOffset(uint64_t offset) const override { return uint32_t(offset >> uint64_t(2)); }
|
||||
|
||||
std::unique_ptr<IPartWriteStream> beginWriteStream(uint64_t offset) override {
|
||||
bool Err = false;
|
||||
std::unique_ptr<IPartWriteStream> ret =
|
||||
std::make_unique<PartWriteStream>(*this, m_baseOffset + m_userOffset, offset, Err);
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::make_unique<PartWriteStream>(*this, m_baseOffset + m_userOffset, offset, err);
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1237,8 +1244,7 @@ uint64_t DiscBuilderWii::CalculateTotalSizeRequired(SystemStringView dirIn, bool
|
|||
|
||||
DiscBuilderWii::DiscBuilderWii(SystemStringView outPath, bool dualLayer, FProgress progressCB)
|
||||
: DiscBuilderBase(outPath, dualLayer ? 0x1FB4E0000 : 0x118240000, progressCB) {
|
||||
PartitionBuilderWii* partBuilder = new PartitionBuilderWii(*this, PartitionKind::Data, 0x200000);
|
||||
m_partitions.emplace_back(partBuilder);
|
||||
m_partitions.emplace_back(std::make_unique<PartitionBuilderWii>(*this, PartitionKind::Data, 0x200000));
|
||||
}
|
||||
|
||||
DiscMergerWii::DiscMergerWii(SystemStringView outPath, DiscWii& sourceDisc, bool dualLayer, FProgress progressCB)
|
||||
|
|
|
@ -68,18 +68,26 @@ public:
|
|||
return fwrite(buf, 1, length, fp);
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<IWriteStream> beginWriteStream() const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, m_maxWriteSize, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, m_maxWriteSize, err));
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, offset, m_maxWriteSize, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, offset, m_maxWriteSize, err));
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -120,24 +128,32 @@ public:
|
|||
return written;
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<IReadStream> beginReadStream() const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, err));
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, offset, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, offset, err));
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<IFileIO> NewFileIO(SystemStringView path, int64_t maxWriteSize) {
|
||||
return std::unique_ptr<IFileIO>(new FileIOFILE(path, maxWriteSize));
|
||||
return std::make_unique<FileIOFILE>(path, maxWriteSize);
|
||||
}
|
||||
|
||||
} // namespace nod
|
||||
|
|
|
@ -95,17 +95,23 @@ public:
|
|||
}
|
||||
};
|
||||
std::unique_ptr<IWriteStream> beginWriteStream() const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, m_maxWriteSize, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::make_unique<WriteStream>(m_path, m_maxWriteSize, err);
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, offset, m_maxWriteSize, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::make_unique<WriteStream>(m_path, offset, m_maxWriteSize, err);
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -166,24 +172,32 @@ public:
|
|||
return written;
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<IReadStream> beginReadStream() const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::make_unique<ReadStream>(m_path, err);
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const override {
|
||||
bool Err = false;
|
||||
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, offset, Err));
|
||||
if (Err)
|
||||
return {};
|
||||
bool err = false;
|
||||
auto ret = std::make_unique<ReadStream>(m_path, offset, err);
|
||||
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<IFileIO> NewFileIO(SystemStringView path, int64_t maxWriteSize) {
|
||||
return std::unique_ptr<IFileIO>(new FileIOWin32(path, maxWriteSize));
|
||||
return std::make_unique<FileIOWin32>(path, maxWriteSize);
|
||||
}
|
||||
|
||||
} // namespace nod
|
||||
|
|
|
@ -563,11 +563,11 @@ std::unique_ptr<IAES> NewAES() {
|
|||
#endif
|
||||
}
|
||||
if (HAS_AES_NI)
|
||||
return std::unique_ptr<IAES>(new NiAES);
|
||||
return std::make_unique<NiAES>();
|
||||
else
|
||||
return std::unique_ptr<IAES>(new SoftwareAES);
|
||||
return std::make_unique<SoftwareAES>();
|
||||
#else
|
||||
return std::unique_ptr<IAES>(new SoftwareAES);
|
||||
return std::make_unique<SoftwareAES>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
16
lib/nod.cpp
16
lib/nod.cpp
|
@ -51,18 +51,20 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(SystemStringView path, bool& isWii)
|
|||
return {};
|
||||
}
|
||||
|
||||
bool Err = false;
|
||||
bool err = false;
|
||||
std::unique_ptr<DiscBase> ret;
|
||||
if (isWii) {
|
||||
ret = std::unique_ptr<DiscBase>(new DiscWii(std::move(discIO), Err));
|
||||
if (Err)
|
||||
return {};
|
||||
ret = std::make_unique<DiscWii>(std::move(discIO), err);
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = std::unique_ptr<DiscBase>(new DiscGCN(std::move(discIO), Err));
|
||||
if (Err)
|
||||
return {};
|
||||
ret = std::make_unique<DiscGCN>(std::move(discIO), err);
|
||||
if (err) {
|
||||
return nullptr;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue