string_view refactor

This commit is contained in:
Jack Andersen 2017-11-12 20:18:53 -10:00
parent c374038103
commit 27a2cb5998
18 changed files with 209 additions and 222 deletions

View File

@ -1,7 +1,7 @@
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) # because of CMAKE_CXX_STANDARD
project(nod)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

View File

@ -41,9 +41,9 @@ int main(int argc, char* argv[])
bool verbose = false;
nod::ExtractionContext ctx = {true,
[&](const std::string& str, float c) {
[&](std::string_view str, float c) {
if (verbose)
fprintf(stderr, "Current node: %s, Extraction %g%% Complete\n", str.c_str(), c * 100.f);
fprintf(stderr, "Current node: %s, Extraction %g%% Complete\n", str.data(), c * 100.f);
}};
const nod::SystemChar* inDir = nullptr;
const nod::SystemChar* outDir = _S(".");

View File

@ -8,21 +8,21 @@ namespace nod
struct CaseInsensitiveCompare
{
bool operator()(const std::string& lhs, const std::string& rhs) const
bool operator()(std::string_view lhs, std::string_view rhs) const
{
#if _WIN32
if (_stricmp(lhs.c_str(), rhs.c_str()) < 0)
if (_stricmp(lhs.data(), rhs.data()) < 0)
#else
if (strcasecmp(lhs.c_str(), rhs.c_str()) < 0)
if (strcasecmp(lhs.data(), rhs.data()) < 0)
#endif
return true;
return false;
}
#if _WIN32
bool operator()(const std::wstring& lhs, const std::wstring& rhs) const
bool operator()(std::wstring_view lhs, std::wstring_view rhs) const
{
if (_wcsicmp(lhs.c_str(), rhs.c_str()) < 0)
if (_wcsicmp(lhs.data(), rhs.data()) < 0)
return true;
return false;
}
@ -56,10 +56,7 @@ private:
std::vector<Entry> m_entries;
public:
DirectoryEnumerator(const SystemString& path, Mode mode=Mode::DirsThenFilesSorted,
bool sizeSort=false, bool reverse=false, bool noHidden=false)
: DirectoryEnumerator(path.c_str(), mode, sizeSort, reverse, noHidden) {}
DirectoryEnumerator(const SystemChar* path, Mode mode=Mode::DirsThenFilesSorted,
DirectoryEnumerator(SystemStringView path, Mode mode=Mode::DirsThenFilesSorted,
bool sizeSort=false, bool reverse=false, bool noHidden=false);
operator bool() const {return m_entries.size() != 0;}

View File

@ -15,7 +15,7 @@
namespace nod
{
using FProgress = std::function<void(float totalProg, const SystemString& fileName, size_t fileBytesXfered)>;
using FProgress = std::function<void(float totalProg, SystemStringView fileName, size_t fileBytesXfered)>;
enum class EBuildResult
{
@ -229,14 +229,14 @@ public:
std::vector<Node>::iterator m_childrenEnd;
public:
Node(const IPartition& parent, const FSTNode& node, const char* name)
Node(const IPartition& parent, const FSTNode& node, std::string_view name)
: m_parent(parent),
m_kind(node.isDir() ? Kind::Directory : Kind::File),
m_discOffset(parent.normalizeOffset(node.getOffset())),
m_discLength(node.getLength()),
m_name(name) {}
inline Kind getKind() const {return m_kind;}
inline const std::string& getName() const {return m_name;}
inline std::string_view getName() const {return m_name;}
inline uint64_t size() const {return m_discLength;}
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset=0) const
{
@ -283,7 +283,7 @@ public:
};
inline DirectoryIterator begin() const {return DirectoryIterator(m_childrenBegin);}
inline DirectoryIterator end() const {return DirectoryIterator(m_childrenEnd);}
inline DirectoryIterator find(const std::string& name) const
inline DirectoryIterator find(std::string_view name) const
{
if (m_kind == Kind::Directory)
{
@ -298,7 +298,7 @@ public:
return end();
}
bool extractToDirectory(const SystemString& basePath, const ExtractionContext& ctx) const;
bool extractToDirectory(SystemStringView basePath, const ExtractionContext& ctx) const;
};
protected:
Header m_header;
@ -313,7 +313,6 @@ public:
std::vector<FSTNode> m_buildNodes;
std::vector<std::string> m_buildNames;
size_t m_buildNameOff = 0;
void recursiveBuildNodes(const SystemChar* dirIn, std::function<void(void)> incParents);
uint64_t m_dolSz;
void parseDOL(IPartReadStream& s);
@ -351,7 +350,7 @@ public:
{return beginReadStream(0x2440 + offset);}
inline const Node& getFSTRoot() const {return m_nodes[0];}
inline Node& getFSTRoot() {return m_nodes[0];}
bool extractToDirectory(const SystemString& path, const ExtractionContext& ctx);
bool extractToDirectory(SystemStringView path, const ExtractionContext& ctx);
inline uint64_t getDOLSize() const {return m_dolSz;}
inline std::unique_ptr<uint8_t[]> getDOLBuf() const
@ -380,8 +379,8 @@ public:
inline size_t getNodeCount() const { return m_nodes.size(); }
inline const Header& getHeader() const { return m_header; }
inline const BI2Header& getBI2() const { return m_bi2Header; }
virtual bool extractCryptoFiles(const SystemString& path, const ExtractionContext& ctx) const { return true; }
bool extractSysFiles(const SystemString& path, const ExtractionContext& ctx) const;
virtual bool extractCryptoFiles(SystemStringView path, const ExtractionContext& ctx) const { return true; }
bool extractSysFiles(SystemStringView path, const ExtractionContext& ctx) const;
};
protected:
@ -417,13 +416,13 @@ public:
return nullptr;
}
inline void extractToDirectory(const SystemString& path, const ExtractionContext& ctx)
inline void extractToDirectory(SystemStringView path, const ExtractionContext& ctx)
{
for (std::unique_ptr<IPartition>& part : m_partitions)
part->extractToDirectory(path, ctx);
}
virtual bool extractDiscHeaderFiles(const SystemString& path, const ExtractionContext& ctx) const=0;
virtual bool extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const=0;
};
class DiscBuilderBase
@ -442,29 +441,29 @@ public:
virtual uint64_t userAllocate(uint64_t reqSz, IPartWriteStream& ws)=0;
virtual uint32_t packOffset(uint64_t offset) const=0;
void recursiveBuildNodesPre(const SystemChar* dirIn);
bool recursiveBuildNodes(IPartWriteStream& ws, bool system, const SystemChar* dirIn);
void recursiveBuildNodesPre(SystemStringView dirIn);
bool recursiveBuildNodes(IPartWriteStream& ws, bool system, SystemStringView dirIn);
bool recursiveBuildFST(const SystemChar* dirIn,
bool recursiveBuildFST(SystemStringView dirIn,
std::function<void(void)> incParents,
size_t parentDirIdx);
void recursiveMergeNodesPre(const DiscBase::IPartition::Node* nodeIn, const SystemChar* dirIn);
void recursiveMergeNodesPre(const DiscBase::IPartition::Node* nodeIn, SystemStringView dirIn);
bool recursiveMergeNodes(IPartWriteStream& ws, bool system,
const DiscBase::IPartition::Node* nodeIn, const SystemChar* dirIn,
const SystemString& keyPath);
const DiscBase::IPartition::Node* nodeIn, SystemStringView dirIn,
SystemStringView keyPath);
bool recursiveMergeFST(const DiscBase::IPartition::Node* nodeIn,
const SystemChar* dirIn, std::function<void(void)> incParents,
const SystemString& keyPath);
SystemStringView dirIn, std::function<void(void)> incParents,
SystemStringView keyPath);
static bool RecursiveCalculateTotalSize(uint64_t& totalSz,
const DiscBase::IPartition::Node* nodeIn,
const SystemChar* dirIn);
SystemStringView dirIn);
void addBuildName(const SystemString& str)
void addBuildName(SystemStringView str)
{
SystemUTF8View utf8View(str);
m_buildNames.push_back(utf8View.utf8_str());
SystemUTF8Conv utf8View(str);
m_buildNames.emplace_back(utf8View.utf8_str());
m_buildNameOff += str.size() + 1;
}
@ -478,15 +477,10 @@ public:
: m_parent(parent), m_kind(kind), m_isWii(isWii)
{}
virtual std::unique_ptr<IPartWriteStream> beginWriteStream(uint64_t offset)=0;
bool buildFromDirectory(IPartWriteStream& ws,
const SystemChar* dirIn);
static uint64_t CalculateTotalSizeBuild(const SystemChar* dirIn,
PartitionKind kind, bool isWii);
bool mergeFromDirectory(IPartWriteStream& ws,
const DiscBase::IPartition* partIn,
const SystemChar* dirIn);
static uint64_t CalculateTotalSizeMerge(const DiscBase::IPartition* partIn,
const SystemChar* dirIn);
bool buildFromDirectory(IPartWriteStream& ws, SystemStringView dirIn);
static uint64_t CalculateTotalSizeBuild(SystemStringView dirIn, PartitionKind kind, bool isWii);
bool mergeFromDirectory(IPartWriteStream& ws, const DiscBase::IPartition* partIn, SystemStringView dirIn);
static uint64_t CalculateTotalSizeMerge(const DiscBase::IPartition* partIn, SystemStringView dirIn);
};
protected:
SystemString m_outPath;
@ -513,7 +507,7 @@ public:
}
virtual ~DiscBuilderBase() = default;
DiscBuilderBase(const SystemChar* outPath,
DiscBuilderBase(SystemStringView outPath,
int64_t discCapacity, FProgress progressCB)
: m_outPath(outPath), m_fileIO(NewFileIO(outPath, discCapacity)),
m_discCapacity(discCapacity), m_progressCB(progressCB) {}

View File

@ -10,19 +10,19 @@ class DiscBuilderGCN;
class DiscGCN : public DiscBase
{
friend class DiscMergerGCN;
DiscBuilderGCN makeMergeBuilder(const SystemChar* outPath, FProgress progressCB);
DiscBuilderGCN makeMergeBuilder(SystemStringView outPath, FProgress progressCB);
public:
DiscGCN(std::unique_ptr<IDiscIO>&& dio, bool& err);
bool extractDiscHeaderFiles(const SystemString& path, const ExtractionContext& ctx) const;
bool extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const;
};
class DiscBuilderGCN : public DiscBuilderBase
{
friend class DiscMergerGCN;
public:
DiscBuilderGCN(const SystemChar* outPath, FProgress progressCB);
EBuildResult buildFromDirectory(const SystemChar* dirIn);
static uint64_t CalculateTotalSizeRequired(const SystemChar* dirIn);
DiscBuilderGCN(SystemStringView outPath, FProgress progressCB);
EBuildResult buildFromDirectory(SystemStringView dirIn);
static uint64_t CalculateTotalSizeRequired(SystemStringView dirIn);
};
class DiscMergerGCN
@ -30,9 +30,9 @@ class DiscMergerGCN
DiscGCN& m_sourceDisc;
DiscBuilderGCN m_builder;
public:
DiscMergerGCN(const SystemChar* outPath, DiscGCN& sourceDisc, FProgress progressCB);
EBuildResult mergeFromDirectory(const SystemChar* dirIn);
static uint64_t CalculateTotalSizeRequired(DiscGCN& sourceDisc, const SystemChar* dirIn);
DiscMergerGCN(SystemStringView outPath, DiscGCN& sourceDisc, FProgress progressCB);
EBuildResult mergeFromDirectory(SystemStringView dirIn);
static uint64_t CalculateTotalSizeRequired(DiscGCN& sourceDisc, SystemStringView dirIn);
};
}

View File

@ -11,17 +11,17 @@ class DiscWii : public DiscBase
{
public:
DiscWii(std::unique_ptr<IDiscIO>&& dio, bool& err);
DiscBuilderWii makeMergeBuilder(const SystemChar* outPath, bool dualLayer, FProgress progressCB);
bool extractDiscHeaderFiles(const SystemString& path, const ExtractionContext& ctx) const;
DiscBuilderWii makeMergeBuilder(SystemStringView outPath, bool dualLayer, FProgress progressCB);
bool extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const;
};
class DiscBuilderWii : public DiscBuilderBase
{
bool m_dualLayer;
public:
DiscBuilderWii(const SystemChar* outPath, bool dualLayer, FProgress progressCB);
EBuildResult buildFromDirectory(const SystemChar* dirIn);
static uint64_t CalculateTotalSizeRequired(const SystemChar* dirIn, bool& dualLayer);
DiscBuilderWii(SystemStringView outPath, bool dualLayer, FProgress progressCB);
EBuildResult buildFromDirectory(SystemStringView dirIn);
static uint64_t CalculateTotalSizeRequired(SystemStringView dirIn, bool& dualLayer);
};
class DiscMergerWii
@ -29,10 +29,10 @@ class DiscMergerWii
DiscWii& m_sourceDisc;
DiscBuilderWii m_builder;
public:
DiscMergerWii(const SystemChar* outPath, DiscWii& sourceDisc,
DiscMergerWii(SystemStringView outPath, DiscWii& sourceDisc,
bool dualLayer, FProgress progressCB);
EBuildResult mergeFromDirectory(const SystemChar* dirIn);
static uint64_t CalculateTotalSizeRequired(DiscWii& sourceDisc, const SystemChar* dirIn,
EBuildResult mergeFromDirectory(SystemStringView dirIn);
static uint64_t CalculateTotalSizeRequired(DiscWii& sourceDisc, SystemStringView dirIn,
bool& dualLayer);
};

View File

@ -79,8 +79,7 @@ public:
virtual std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const=0;
};
std::unique_ptr<IFileIO> NewFileIO(const SystemString& path, int64_t maxWriteSize=-1);
std::unique_ptr<IFileIO> NewFileIO(const SystemChar* path, int64_t maxWriteSize=-1);
std::unique_ptr<IFileIO> NewFileIO(SystemStringView path, int64_t maxWriteSize=-1);
}

View File

@ -23,6 +23,7 @@
#include <sys/stat.h>
#include <string>
#include <string_view>
#include <cstring>
#include <algorithm>
#include "logvisor/logvisor.hpp"
@ -74,34 +75,37 @@ static inline int Stat(const char* path, Sstat* statout) {return stat(path, stat
#if NOD_UCS2
typedef wchar_t SystemChar;
typedef std::wstring SystemString;
typedef std::wstring_view SystemStringView;
static inline void ToLower(SystemString& str)
{std::transform(str.begin(), str.end(), str.begin(), towlower);}
static inline void ToUpper(SystemString& str)
{std::transform(str.begin(), str.end(), str.begin(), towupper);}
static inline size_t StrLen(const SystemChar* str) {return wcslen(str);}
class SystemUTF8View
class SystemUTF8Conv
{
std::string m_utf8;
public:
explicit SystemUTF8View(const SystemString& str)
explicit SystemUTF8Conv(SystemStringView str)
{
int len = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.size(), nullptr, 0, nullptr, nullptr);
int len = WideCharToMultiByte(CP_UTF8, 0, str.data(), str.size(), nullptr, 0, nullptr, nullptr);
m_utf8.assign(len, '\0');
WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.size(), &m_utf8[0], len, nullptr, nullptr);
WideCharToMultiByte(CP_UTF8, 0, str.data(), str.size(), &m_utf8[0], len, nullptr, nullptr);
}
inline const std::string& utf8_str() {return m_utf8;}
inline std::string_view utf8_str() const {return m_utf8;}
inline const char* c_str() const {return m_utf8.c_str();}
};
class SystemStringView
class SystemStringConv
{
std::wstring m_sys;
public:
explicit SystemStringView(const std::string& str)
explicit SystemStringConv(std::string_view str)
{
int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), nullptr, 0);
int len = MultiByteToWideChar(CP_UTF8, 0, str.data(), str.size(), nullptr, 0);
m_sys.assign(len, L'\0');
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), &m_sys[0], len);
MultiByteToWideChar(CP_UTF8, 0, str.data(), str.size(), &m_sys[0], len);
}
inline const std::wstring& sys_str() {return m_sys;}
inline SystemStringView sys_str() const {return m_sys;}
inline const SystemChar* c_str() const {return m_sys.c_str();}
};
#ifndef _S
#define _S(val) L ## val
@ -109,26 +113,29 @@ public:
#else
typedef char SystemChar;
typedef std::string SystemString;
typedef std::string_view SystemStringView;
static inline void ToLower(SystemString& str)
{std::transform(str.begin(), str.end(), str.begin(), tolower);}
static inline void ToUpper(SystemString& str)
{std::transform(str.begin(), str.end(), str.begin(), toupper);}
static inline size_t StrLen(const SystemChar* str) {return strlen(str);}
class SystemUTF8View
class SystemUTF8Conv
{
const std::string& m_utf8;
std::string_view m_utf8;
public:
explicit SystemUTF8View(const SystemString& str)
explicit SystemUTF8Conv(SystemStringView str)
: m_utf8(str) {}
inline const std::string& utf8_str() {return m_utf8;}
inline std::string_view utf8_str() const {return m_utf8;}
inline const char* c_str() const {return m_utf8.data();}
};
class SystemStringView
class SystemStringConv
{
const std::string& m_sys;
SystemStringView m_sys;
public:
explicit SystemStringView(const std::string& str)
explicit SystemStringConv(std::string_view str)
: m_sys(str) {}
inline const std::string& sys_str() {return m_sys;}
inline SystemStringView sys_str() const {return m_sys;}
inline const SystemChar* c_str() const {return m_sys.data();}
};
#ifndef _S
#define _S(val) val

View File

@ -14,11 +14,11 @@ class DiscBase;
struct ExtractionContext final
{
bool force : 1;
std::function<void(const std::string&, float)> progressCB;
std::function<void(std::string_view, float)> progressCB;
};
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path);
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii);
std::unique_ptr<DiscBase> OpenDiscFromImage(SystemStringView path);
std::unique_ptr<DiscBase> OpenDiscFromImage(SystemStringView path, bool& isWii);
}

View File

@ -12,11 +12,11 @@
namespace nod
{
DirectoryEnumerator::DirectoryEnumerator(const SystemChar* path, Mode mode,
DirectoryEnumerator::DirectoryEnumerator(SystemStringView path, Mode mode,
bool sizeSort, bool reverse, bool noHidden)
{
Sstat theStat;
if (Stat(path, &theStat) || !S_ISDIR(theStat.st_mode))
if (Stat(path.data(), &theStat) || !S_ISDIR(theStat.st_mode))
return;
#if _WIN32
@ -151,7 +151,7 @@ DirectoryEnumerator::DirectoryEnumerator(const SystemChar* path, Mode mode,
#else
DIR* dir = opendir(path);
DIR* dir = opendir(path.data());
if (!dir)
return;
const dirent* d;

View File

@ -104,11 +104,11 @@ void DiscBase::IPartition::parseDOL(IPartReadStream& s)
m_dolSz = dolSize;
}
bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath,
bool DiscBase::IPartition::Node::extractToDirectory(SystemStringView basePath,
const ExtractionContext& ctx) const
{
SystemStringView nameView(getName());
SystemString path = basePath + _S("/") + nameView.sys_str();
SystemStringConv nameView(getName());
SystemString path = SystemString(basePath) + _S('/') + nameView.sys_str().data();
if (m_kind == Kind::Directory)
{
@ -148,17 +148,17 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
return true;
}
bool DiscBase::IPartition::extractToDirectory(const SystemString& path,
bool DiscBase::IPartition::extractToDirectory(SystemStringView path,
const ExtractionContext& ctx)
{
m_curNodeIdx = 0;
if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
if (Mkdir(path.data(), 0755) && errno != EEXIST)
{
LogModule.report(logvisor::Error, _S("unable to mkdir '%s'"), path.c_str());
LogModule.report(logvisor::Error, _S("unable to mkdir '%s'"), path.data());
return false;
}
SystemString basePath = m_isWii ? path + _S("/") + getKindString(m_kind) : path;
SystemString basePath = m_isWii ? SystemString(path) + _S("/") + getKindString(m_kind) : SystemString(path);
if (m_isWii)
{
if (Mkdir(basePath.c_str(), 0755) && errno != EEXIST)
@ -190,17 +190,18 @@ bool DiscBase::IPartition::extractToDirectory(const SystemString& path,
return m_nodes[0].extractToDirectory(fsPath, ctx);
}
bool DiscBase::IPartition::extractSysFiles(const SystemString& basePath, const ExtractionContext& ctx) const
bool DiscBase::IPartition::extractSysFiles(SystemStringView basePath, const ExtractionContext& ctx) const
{
if (Mkdir((basePath + _S("/sys")).c_str(), 0755) && errno != EEXIST)
SystemString basePathStr(basePath);
if (Mkdir((basePathStr + _S("/sys")).c_str(), 0755) && errno != EEXIST)
{
LogModule.report(logvisor::Error, _S("unable to mkdir '%s/sys'"), basePath.c_str());
LogModule.report(logvisor::Error, _S("unable to mkdir '%s/sys'"), basePath.data());
return false;
}
Sstat theStat;
/* Extract Apploader */
SystemString apploaderPath = basePath + _S("/sys/apploader.img");
SystemString apploaderPath = basePathStr + _S("/sys/apploader.img");
if (ctx.force || Stat(apploaderPath.c_str(), &theStat))
{
if (ctx.progressCB)
@ -213,7 +214,7 @@ bool DiscBase::IPartition::extractSysFiles(const SystemString& basePath, const E
}
/* Extract Dol */
SystemString dolPath = basePath + _S("/sys/main.dol");
SystemString dolPath = basePathStr + _S("/sys/main.dol");
if (ctx.force || Stat(dolPath.c_str(), &theStat))
{
if (ctx.progressCB)
@ -226,7 +227,7 @@ bool DiscBase::IPartition::extractSysFiles(const SystemString& basePath, const E
}
/* Extract Boot info */
SystemString bootPath = basePath + _S("/sys/boot.bin");
SystemString bootPath = basePathStr + _S("/sys/boot.bin");
if (ctx.force || Stat(bootPath.c_str(), &theStat))
{
if (ctx.progressCB)
@ -238,7 +239,7 @@ bool DiscBase::IPartition::extractSysFiles(const SystemString& basePath, const E
}
/* Extract BI2 info */
SystemString bi2Path = basePath + _S("/sys/bi2.bin");
SystemString bi2Path = basePathStr + _S("/sys/bi2.bin");
if (ctx.force || Stat(bi2Path.c_str(), &theStat))
{
if (ctx.progressCB)
@ -290,7 +291,7 @@ static uint64_t GetInode(const SystemChar* path)
return inode;
}
static bool IsSystemFile(const SystemString& name, bool& isDol)
static bool IsSystemFile(SystemStringView name, bool& isDol)
{
isDol = false;
if (name.size() < 4)
@ -340,7 +341,7 @@ static size_t PatchDOL(IFileIO::IReadStream& in, IPartWriteStream& out, size_t s
return out.write(buf.get(), sz);
}
void DiscBuilderBase::PartitionBuilderBase::recursiveBuildNodesPre(const SystemChar* filesIn)
void DiscBuilderBase::PartitionBuilderBase::recursiveBuildNodesPre(SystemStringView filesIn)
{
DirectoryEnumerator dEnum(filesIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum)
@ -354,7 +355,7 @@ void DiscBuilderBase::PartitionBuilderBase::recursiveBuildNodesPre(const SystemC
bool DiscBuilderBase::PartitionBuilderBase::recursiveBuildNodes(IPartWriteStream& ws,
bool system,
const SystemChar* filesIn)
SystemStringView filesIn)
{
DirectoryEnumerator dEnum(filesIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum)
@ -409,7 +410,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveBuildNodes(IPartWriteStream
return true;
}
bool DiscBuilderBase::PartitionBuilderBase::recursiveBuildFST(const SystemChar* filesIn,
bool DiscBuilderBase::PartitionBuilderBase::recursiveBuildFST(SystemStringView filesIn,
std::function<void(void)> incParents,
size_t parentDirIdx)
{
@ -440,7 +441,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveBuildFST(const SystemChar*
}
void DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodesPre(const DiscBase::IPartition::Node* nodeIn,
const SystemChar* dirIn)
SystemStringView dirIn)
{
/* Build map of existing nodes to write-through later */
std::unordered_map<std::string, const Partition::Node*> fileNodes;
@ -459,16 +460,16 @@ void DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodesPre(const DiscBas
}
/* Merge this directory's files */
if (dirIn)
if (!dirIn.empty())
{
DirectoryEnumerator dEnum(dirIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum)
{
SystemUTF8View nameView(e.m_name);
SystemUTF8Conv nameView(e.m_name);
if (e.m_isDir)
{
auto search = dirNodes.find(nameView.utf8_str());
auto search = dirNodes.find(nameView.utf8_str().data());
if (search != dirNodes.cend())
{
recursiveMergeNodesPre(search->second, e.m_path.c_str());
@ -481,7 +482,7 @@ void DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodesPre(const DiscBas
}
else
{
fileNodes.erase(nameView.utf8_str());
fileNodes.erase(nameView.utf8_str().data());
++m_parent.m_progressTotal;
}
}
@ -500,8 +501,8 @@ void DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodesPre(const DiscBas
bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream& ws,
bool system,
const DiscBase::IPartition::Node* nodeIn,
const SystemChar* dirIn,
const SystemString& keyPath)
SystemStringView dirIn,
SystemStringView keyPath)
{
/* Build map of existing nodes to write-through later */
std::unordered_map<std::string, const Partition::Node*> fileNodes;
@ -520,17 +521,17 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
}
/* Merge this directory's files */
if (dirIn)
if (!dirIn.empty())
{
DirectoryEnumerator dEnum(dirIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum)
{
SystemUTF8View nameView(e.m_name);
SystemString chKeyPath = keyPath + _S('/') + e.m_name;
SystemUTF8Conv nameView(e.m_name);
SystemString chKeyPath = SystemString(keyPath) + _S('/') + e.m_name;
if (e.m_isDir)
{
auto search = dirNodes.find(nameView.utf8_str());
auto search = dirNodes.find(nameView.utf8_str().data());
if (search != dirNodes.cend())
{
if (!recursiveMergeNodes(ws, system, search->second, e.m_path.c_str(), chKeyPath))
@ -550,7 +551,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
if (system ^ isSys)
continue;
fileNodes.erase(nameView.utf8_str());
fileNodes.erase(nameView.utf8_str().data());
size_t fileSz = ROUND_UP_32(e.m_fileSz);
uint64_t fileOff = userAllocate(fileSz, ws);
@ -592,8 +593,8 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
/* Write-through remaining dir nodes */
for (const auto& p : dirNodes)
{
SystemStringView sysName(p.second->getName());
SystemString chKeyPath = keyPath + _S('/') + sysName.sys_str();
SystemStringConv sysName(p.second->getName());
SystemString chKeyPath = SystemString(keyPath) + _S('/') + sysName.c_str();
if (!recursiveMergeNodes(ws, system, p.second, nullptr, chKeyPath))
return false;
}
@ -602,8 +603,8 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
for (const auto& p : fileNodes)
{
const Partition::Node& ch = *p.second;
SystemStringView sysName(ch.getName());
SystemString chKeyPath = keyPath + _S('/') + sysName.sys_str();
SystemStringConv sysName(ch.getName());
SystemString chKeyPath = SystemString(keyPath) + _S('/') + sysName.c_str();
bool isDol;
bool isSys = IsSystemFile(sysName.sys_str(), isDol);
@ -626,7 +627,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
bool patched;
PatchDOL(dolBuf, xferSz, patched);
ws.write(dolBuf.get(), xferSz);
m_parent.m_progressCB(m_parent.getProgressFactor(), sysName.sys_str() +
m_parent.m_progressCB(m_parent.getProgressFactor(), SystemString(sysName.sys_str()) +
(patched ? _S(" [PATCHED]") : _S("")), xferSz);
++m_parent.m_progressIdx;
}
@ -652,9 +653,9 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
}
bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Partition::Node* nodeIn,
const SystemChar* dirIn,
SystemStringView dirIn,
std::function<void(void)> incParents,
const SystemString& keyPath)
SystemStringView keyPath)
{
/* Build map of existing nodes to write-through later */
std::unordered_map<std::string, const Partition::Node*> fileNodes;
@ -673,13 +674,13 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Partition::N
}
/* Merge this directory's files */
if (dirIn)
if (!dirIn.empty())
{
DirectoryEnumerator dEnum(dirIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum)
{
SystemUTF8View nameView(e.m_name);
SystemString chKeyPath = keyPath + _S('/') + e.m_name;
SystemUTF8Conv nameView(e.m_name);
SystemString chKeyPath = SystemString(keyPath) + _S('/') + e.m_name;
if (e.m_isDir)
{
@ -688,7 +689,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Partition::N
addBuildName(e.m_name);
incParents();
auto search = dirNodes.find(nameView.utf8_str());
auto search = dirNodes.find(nameView.utf8_str().data());
if (search != dirNodes.cend())
{
if (!recursiveMergeFST(search->second, e.m_path.c_str(),
@ -707,7 +708,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Partition::N
}
else
{
fileNodes.erase(nameView.utf8_str());
fileNodes.erase(nameView.utf8_str().data());
std::pair<uint64_t,uint64_t> fileOffSz = m_fileOffsetsSizes.at(chKeyPath);
m_buildNodes.emplace_back(false, m_buildNameOff, packOffset(fileOffSz.first), fileOffSz.second);
addBuildName(e.m_name);
@ -720,8 +721,8 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Partition::N
/* Write-through remaining dir nodes */
for (const auto& p : dirNodes)
{
SystemStringView sysName(p.second->getName());
SystemString chKeyPath = keyPath + _S('/') + sysName.sys_str();
SystemStringConv sysName(p.second->getName());
SystemString chKeyPath = SystemString(keyPath) + _S('/') + sysName.sys_str().data();
size_t dirNodeIdx = m_buildNodes.size();
m_buildNodes.emplace_back(true, m_buildNameOff, 0, dirNodeIdx+1);
@ -738,8 +739,8 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Partition::N
for (const auto& p : fileNodes)
{
const Partition::Node& ch = *p.second;
SystemStringView sysName(ch.getName());
SystemString chKeyPath = keyPath + _S('/') + sysName.sys_str();
SystemStringConv sysName(ch.getName());
SystemString chKeyPath = SystemString(keyPath) + _S('/') + sysName.sys_str().data();
std::pair<uint64_t,uint64_t> fileOffSz = m_fileOffsetsSizes.at(chKeyPath);
m_buildNodes.emplace_back(false, m_buildNameOff, packOffset(fileOffSz.first), fileOffSz.second);
@ -753,7 +754,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Partition::N
bool DiscBuilderBase::PartitionBuilderBase::RecursiveCalculateTotalSize(
uint64_t& totalSz,
const DiscBase::IPartition::Node* nodeIn,
const SystemChar* dirIn)
SystemStringView dirIn)
{
/* Build map of existing nodes to write-through later */
std::unordered_map<std::string, const Partition::Node*> fileNodes;
@ -772,16 +773,16 @@ bool DiscBuilderBase::PartitionBuilderBase::RecursiveCalculateTotalSize(
}
/* Merge this directory's files */
if (dirIn)
if (!dirIn.empty())
{
DirectoryEnumerator dEnum(dirIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum)
{
SystemUTF8View nameView(e.m_name);
SystemUTF8Conv nameView(e.m_name);
if (e.m_isDir)
{
auto search = dirNodes.find(nameView.utf8_str());
auto search = dirNodes.find(nameView.utf8_str().data());
if (search != dirNodes.cend())
{
if (!RecursiveCalculateTotalSize(totalSz, search->second, e.m_path.c_str()))
@ -796,7 +797,7 @@ bool DiscBuilderBase::PartitionBuilderBase::RecursiveCalculateTotalSize(
}
else
{
fileNodes.erase(nameView.utf8_str());
fileNodes.erase(nameView.utf8_str().data());
totalSz += ROUND_UP_32(e.m_fileSz);
}
}
@ -820,9 +821,9 @@ bool DiscBuilderBase::PartitionBuilderBase::RecursiveCalculateTotalSize(
}
bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(IPartWriteStream& ws,
const SystemChar* dirIn)
SystemStringView dirIn)
{
if (!dirIn)
if (dirIn.empty())
{
LogModule.report(logvisor::Error, _S("all arguments must be supplied to buildFromDirectory()"));
return false;
@ -882,7 +883,7 @@ bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(IPartWriteStream&
return true;
}
uint64_t DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(const SystemChar* dirIn,
uint64_t DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(SystemStringView dirIn,
PartitionKind kind, bool isWii)
{
SystemString dirStr(dirIn);
@ -904,9 +905,9 @@ uint64_t DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(const Sy
bool DiscBuilderBase::PartitionBuilderBase::mergeFromDirectory(IPartWriteStream& ws,
const nod::Partition* partIn,
const SystemChar* dirIn)
SystemStringView dirIn)
{
if (!dirIn)
if (dirIn.empty())
{
LogModule.report(logvisor::Error, _S("all arguments must be supplied to mergeFromDirectory()"));
return false;
@ -961,7 +962,7 @@ bool DiscBuilderBase::PartitionBuilderBase::mergeFromDirectory(IPartWriteStream&
}
uint64_t DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeMerge(const DiscBase::IPartition* partIn,
const SystemChar* dirIn)
SystemStringView dirIn)
{
SystemString dirStr(dirIn);
SystemString basePath = partIn->isWii() ? dirStr + _S("/") + getKindString(partIn->getKind()) : dirStr;

View File

@ -129,12 +129,12 @@ DiscGCN::DiscGCN(std::unique_ptr<IDiscIO>&& dio, bool& err)
m_partitions.emplace_back(new PartitionGCN(*this, 0, err));
}
DiscBuilderGCN DiscGCN::makeMergeBuilder(const SystemChar* outPath, FProgress progressCB)
DiscBuilderGCN DiscGCN::makeMergeBuilder(SystemStringView outPath, FProgress progressCB)
{
return DiscBuilderGCN(outPath, progressCB);
}
bool DiscGCN::extractDiscHeaderFiles(const SystemString& path, const ExtractionContext& ctx) const
bool DiscGCN::extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const
{
return true;
}
@ -244,7 +244,7 @@ public:
return true;
}
bool buildFromDirectory(const SystemChar* dirIn)
bool buildFromDirectory(SystemStringView dirIn)
{
std::unique_ptr<IPartWriteStream> ws = beginWriteStream(0);
if (!ws)
@ -336,7 +336,7 @@ public:
});
}
bool mergeFromDirectory(const PartitionGCN* partIn, const SystemChar* dirIn)
bool mergeFromDirectory(const PartitionGCN* partIn, SystemStringView dirIn)
{
std::unique_ptr<IPartWriteStream> ws = beginWriteStream(0);
if (!ws)
@ -384,7 +384,7 @@ public:
}
};
EBuildResult DiscBuilderGCN::buildFromDirectory(const SystemChar* dirIn)
EBuildResult DiscBuilderGCN::buildFromDirectory(SystemStringView dirIn)
{
if (!m_fileIO->beginWriteStream())
return EBuildResult::Failed;
@ -408,7 +408,7 @@ EBuildResult DiscBuilderGCN::buildFromDirectory(const SystemChar* dirIn)
return pb.buildFromDirectory(dirIn) ? EBuildResult::Success : EBuildResult::Failed;
}
uint64_t DiscBuilderGCN::CalculateTotalSizeRequired(const SystemChar* dirIn)
uint64_t DiscBuilderGCN::CalculateTotalSizeRequired(SystemStringView dirIn)
{
uint64_t sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(dirIn, PartitionKind::Data, false);
if (sz == -1)
@ -422,18 +422,18 @@ uint64_t DiscBuilderGCN::CalculateTotalSizeRequired(const SystemChar* dirIn)
return sz;
}
DiscBuilderGCN::DiscBuilderGCN(const SystemChar* outPath, FProgress progressCB)
DiscBuilderGCN::DiscBuilderGCN(SystemStringView outPath, FProgress progressCB)
: DiscBuilderBase(outPath, 0x57058000, progressCB)
{
PartitionBuilderGCN* partBuilder = new PartitionBuilderGCN(*this);
m_partitions.emplace_back(partBuilder);
}
DiscMergerGCN::DiscMergerGCN(const SystemChar* outPath, DiscGCN& sourceDisc, FProgress progressCB)
DiscMergerGCN::DiscMergerGCN(SystemStringView outPath, DiscGCN& sourceDisc, FProgress progressCB)
: m_sourceDisc(sourceDisc), m_builder(sourceDisc.makeMergeBuilder(outPath, progressCB))
{}
EBuildResult DiscMergerGCN::mergeFromDirectory(const SystemChar* dirIn)
EBuildResult DiscMergerGCN::mergeFromDirectory(SystemStringView dirIn)
{
if (!m_builder.getFileIO().beginWriteStream())
return EBuildResult::Failed;
@ -458,7 +458,7 @@ EBuildResult DiscMergerGCN::mergeFromDirectory(const SystemChar* dirIn)
EBuildResult::Success : EBuildResult::Failed;
}
uint64_t DiscMergerGCN::CalculateTotalSizeRequired(DiscGCN& sourceDisc, const SystemChar* dirIn)
uint64_t DiscMergerGCN::CalculateTotalSizeRequired(DiscGCN& sourceDisc, SystemStringView dirIn)
{
uint64_t sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeMerge(
sourceDisc.getDataPartition(), dirIn);

View File

@ -10,7 +10,7 @@ class DiscIOISO : public IDiscIO
{
std::unique_ptr<IFileIO> m_fio;
public:
DiscIOISO(const SystemString& fpin)
DiscIOISO(SystemStringView fpin)
: m_fio(NewFileIO(fpin)) {}
class ReadStream : public IReadStream
@ -60,7 +60,7 @@ public:
}
};
std::unique_ptr<IDiscIO> NewDiscIOISO(const SystemChar* path)
std::unique_ptr<IDiscIO> NewDiscIOISO(SystemStringView path)
{
return std::unique_ptr<IDiscIO>(new DiscIOISO(path));
}

View File

@ -87,7 +87,7 @@ class DiscIOWBFS : public IDiscIO
}
public:
DiscIOWBFS(const SystemString& fpin)
DiscIOWBFS(SystemStringView fpin)
: filepath(fpin)
{
/* Temporary file handle to read LBA table */
@ -296,7 +296,7 @@ public:
}
};
std::unique_ptr<IDiscIO> NewDiscIOWBFS(const SystemChar* path)
std::unique_ptr<IDiscIO> NewDiscIOWBFS(SystemStringView path)
{
return std::unique_ptr<IDiscIO>(new DiscIOWBFS(path));
}

View File

@ -473,12 +473,13 @@ public:
return buf;
}
bool extractCryptoFiles(const SystemString& basePath, const ExtractionContext& ctx) const
bool extractCryptoFiles(SystemStringView basePath, const ExtractionContext& ctx) const
{
Sstat theStat;
SystemString basePathStr(basePath);
/* Extract Ticket */
SystemString ticketPath = basePath + _S("/ticket.bin");
SystemString ticketPath = basePathStr + _S("/ticket.bin");
if (ctx.force || Stat(ticketPath.c_str(), &theStat))
{
if (ctx.progressCB)
@ -490,7 +491,7 @@ public:
}
/* Extract TMD */
SystemString tmdPath = basePath + _S("/tmd.bin");
SystemString tmdPath = basePathStr + _S("/tmd.bin");
if (ctx.force || Stat(tmdPath.c_str(), &theStat))
{
if (ctx.progressCB)
@ -502,7 +503,7 @@ public:
}
/* Extract Certs */
SystemString certPath = basePath + _S("/cert.bin");
SystemString certPath = basePathStr + _S("/cert.bin");
if (ctx.force || Stat(certPath.c_str(), &theStat))
{
if (ctx.progressCB)
@ -516,7 +517,7 @@ public:
}
/* Extract H3 */
SystemString h3Path = basePath + _S("/h3.bin");
SystemString h3Path = basePathStr + _S("/h3.bin");
if (ctx.force || Stat(h3Path.c_str(), &theStat))
{
if (ctx.progressCB)
@ -596,23 +597,25 @@ DiscWii::DiscWii(std::unique_ptr<IDiscIO>&& dio, bool& err)
}
}
DiscBuilderWii DiscWii::makeMergeBuilder(const SystemChar* outPath, bool dualLayer, FProgress progressCB)
DiscBuilderWii DiscWii::makeMergeBuilder(SystemStringView outPath, bool dualLayer, FProgress progressCB)
{
return DiscBuilderWii(outPath, dualLayer, progressCB);
}
bool DiscWii::extractDiscHeaderFiles(const SystemString& basePath, const ExtractionContext& ctx) const
bool DiscWii::extractDiscHeaderFiles(SystemStringView basePath, const ExtractionContext& ctx) const
{
if (Mkdir((basePath + _S("/disc")).c_str(), 0755) && errno != EEXIST)
SystemString basePathStr(basePath);
if (Mkdir((basePathStr + _S("/disc")).c_str(), 0755) && errno != EEXIST)
{
LogModule.report(logvisor::Error, _S("unable to mkdir '%s/disc'"), basePath.c_str());
LogModule.report(logvisor::Error, _S("unable to mkdir '%s/disc'"), basePathStr.c_str());
return false;
}
Sstat theStat;
/* Extract Header */
SystemString headerPath = basePath + _S("/disc/header.bin");
SystemString headerPath = basePathStr + _S("/disc/header.bin");
if (ctx.force || Stat(headerPath.c_str(), &theStat))
{
if (ctx.progressCB)
@ -629,7 +632,7 @@ bool DiscWii::extractDiscHeaderFiles(const SystemString& basePath, const Extract
}
/* Extract Region info */
SystemString regionPath = basePath + _S("/disc/region.bin");
SystemString regionPath = basePathStr + _S("/disc/region.bin");
if (ctx.force || Stat(regionPath.c_str(), &theStat))
{
if (ctx.progressCB)
@ -1016,7 +1019,7 @@ public:
return m_baseOffset + dataOff + groupCount * 0x200000;
}
uint64_t buildFromDirectory(const SystemChar* dirIn)
uint64_t buildFromDirectory(SystemStringView dirIn)
{
SystemString dirStr(dirIn);
SystemString basePath = dirStr + _S("/") + getKindString(m_kind);
@ -1186,7 +1189,7 @@ public:
}, apploaderStat.st_size);
}
uint64_t mergeFromDirectory(const PartitionWii* partIn, const SystemChar* dirIn)
uint64_t mergeFromDirectory(const PartitionWii* partIn, SystemStringView dirIn)
{
size_t phSz;
std::unique_ptr<uint8_t[]> phBuf = partIn->readPartitionHeaderBuf(phSz);
@ -1252,10 +1255,10 @@ public:
}
};
EBuildResult DiscBuilderWii::buildFromDirectory(const SystemChar* dirIn)
EBuildResult DiscBuilderWii::buildFromDirectory(SystemStringView dirIn)
{
SystemString dirStr(dirIn);
SystemString basePath = dirStr + _S("/") + getKindString(PartitionKind::Data);
SystemString basePath = SystemString(dirStr) + _S("/") + getKindString(PartitionKind::Data);
PartitionBuilderWii& pb = static_cast<PartitionBuilderWii&>(*m_partitions[0]);
uint64_t filledSz = pb.m_baseOffset;
@ -1349,7 +1352,7 @@ EBuildResult DiscBuilderWii::buildFromDirectory(const SystemChar* dirIn)
return EBuildResult::Success;
}
uint64_t DiscBuilderWii::CalculateTotalSizeRequired(const SystemChar* dirIn, bool& dualLayer)
uint64_t DiscBuilderWii::CalculateTotalSizeRequired(SystemStringView dirIn, bool& dualLayer)
{
uint64_t sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeBuild(dirIn, PartitionKind::Data, true);
if (sz == -1)
@ -1367,19 +1370,19 @@ uint64_t DiscBuilderWii::CalculateTotalSizeRequired(const SystemChar* dirIn, boo
return sz;
}
DiscBuilderWii::DiscBuilderWii(const SystemChar* outPath, bool dualLayer, FProgress progressCB)
DiscBuilderWii::DiscBuilderWii(SystemStringView outPath, bool dualLayer, FProgress progressCB)
: DiscBuilderBase(outPath, dualLayer ? 0x1FB4E0000 : 0x118240000, progressCB), m_dualLayer(dualLayer)
{
PartitionBuilderWii* partBuilder = new PartitionBuilderWii(*this, PartitionKind::Data, 0x200000);
m_partitions.emplace_back(partBuilder);
}
DiscMergerWii::DiscMergerWii(const SystemChar* outPath, DiscWii& sourceDisc,
DiscMergerWii::DiscMergerWii(SystemStringView outPath, DiscWii& sourceDisc,
bool dualLayer, FProgress progressCB)
: m_sourceDisc(sourceDisc), m_builder(sourceDisc.makeMergeBuilder(outPath, dualLayer, progressCB))
{}
EBuildResult DiscMergerWii::mergeFromDirectory(const SystemChar* dirIn)
EBuildResult DiscMergerWii::mergeFromDirectory(SystemStringView dirIn)
{
PartitionBuilderWii& pb = static_cast<PartitionBuilderWii&>(*m_builder.m_partitions[0]);
uint64_t filledSz = pb.m_baseOffset;
@ -1467,7 +1470,7 @@ EBuildResult DiscMergerWii::mergeFromDirectory(const SystemChar* dirIn)
}
uint64_t DiscMergerWii::CalculateTotalSizeRequired(DiscWii& sourceDisc,
const SystemChar* dirIn, bool& dualLayer)
SystemStringView dirIn, bool& dualLayer)
{
uint64_t sz = DiscBuilderBase::PartitionBuilderBase::CalculateTotalSizeMerge(
sourceDisc.getDataPartition(), dirIn);

View File

@ -12,9 +12,7 @@ class FileIOFILE : public IFileIO
SystemString m_path;
int64_t m_maxWriteSize;
public:
FileIOFILE(const SystemString& path, int64_t maxWriteSize)
: m_path(path), m_maxWriteSize(maxWriteSize) {}
FileIOFILE(const SystemChar* path, int64_t maxWriteSize)
FileIOFILE(SystemStringView path, int64_t maxWriteSize)
: m_path(path), m_maxWriteSize(maxWriteSize) {}
bool exists()
@ -41,30 +39,30 @@ public:
{
FILE* fp;
int64_t m_maxWriteSize;
WriteStream(const SystemString& path, int64_t maxWriteSize, bool& err)
WriteStream(SystemStringView path, int64_t maxWriteSize, bool& err)
: m_maxWriteSize(maxWriteSize)
{
fp = fopen(path.c_str(), "wb");
fp = fopen(path.data(), "wb");
if (!fp)
{
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.c_str());
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.data());
err = true;
}
}
WriteStream(const SystemString& path, uint64_t offset, int64_t maxWriteSize, bool& err)
WriteStream(SystemStringView path, uint64_t offset, int64_t maxWriteSize, bool& err)
: m_maxWriteSize(maxWriteSize)
{
fp = fopen(path.c_str(), "ab");
fp = fopen(path.data(), "ab");
if (!fp)
goto FailLoc;
fclose(fp);
fp = fopen(path.c_str(), "r+b");
fp = fopen(path.data(), "r+b");
if (!fp)
goto FailLoc;
FSeek(fp, offset, SEEK_SET);
return;
FailLoc:
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.c_str());
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.data());
err = true;
}
~WriteStream()
@ -104,16 +102,16 @@ public:
struct ReadStream : public IFileIO::IReadStream
{
FILE* fp;
ReadStream(const SystemString& path, bool& err)
ReadStream(SystemStringView path, bool& err)
{
fp = fopen(path.c_str(), "rb");
fp = fopen(path.data(), "rb");
if (!fp)
{
err = true;
LogModule.report(logvisor::Error, _S("unable to open '%s' for reading"), path.c_str());
LogModule.report(logvisor::Error, _S("unable to open '%s' for reading"), path.data());
}
}
ReadStream(const SystemString& path, uint64_t offset, bool& err)
ReadStream(SystemStringView path, uint64_t offset, bool& err)
: ReadStream(path, err)
{
if (err)
@ -177,12 +175,7 @@ public:
}
};
std::unique_ptr<IFileIO> NewFileIO(const SystemString& path, int64_t maxWriteSize)
{
return std::unique_ptr<IFileIO>(new FileIOFILE(path, maxWriteSize));
}
std::unique_ptr<IFileIO> NewFileIO(const SystemChar* path, int64_t maxWriteSize)
std::unique_ptr<IFileIO> NewFileIO(SystemStringView path, int64_t maxWriteSize)
{
return std::unique_ptr<IFileIO>(new FileIOFILE(path, maxWriteSize));
}

View File

@ -12,9 +12,7 @@ class FileIOWin32 : public IFileIO
SystemString m_path;
int64_t m_maxWriteSize;
public:
FileIOWin32(const SystemString& path, int64_t maxWriteSize)
: m_path(path), m_maxWriteSize(maxWriteSize) {}
FileIOWin32(const SystemChar* path, int64_t maxWriteSize)
FileIOWin32(SystemStringView path, int64_t maxWriteSize)
: m_path(path), m_maxWriteSize(maxWriteSize) {}
bool exists()
@ -47,25 +45,25 @@ public:
{
HANDLE fp;
int64_t m_maxWriteSize;
WriteStream(const SystemString& path, int64_t maxWriteSize, bool& err)
WriteStream(SystemStringView path, int64_t maxWriteSize, bool& err)
: m_maxWriteSize(maxWriteSize)
{
fp = CreateFileW(path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE,
fp = CreateFileW(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (fp == INVALID_HANDLE_VALUE)
{
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.c_str());
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.data());
err = true;
}
}
WriteStream(const SystemString& path, uint64_t offset, int64_t maxWriteSize, bool& err)
WriteStream(SystemStringView path, uint64_t offset, int64_t maxWriteSize, bool& err)
: m_maxWriteSize(maxWriteSize)
{
fp = CreateFileW(path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE,
fp = CreateFileW(path.data(), GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (fp == INVALID_HANDLE_VALUE)
{
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.c_str());
LogModule.report(logvisor::Error, _S("unable to open '%s' for writing"), path.data());
err = true;
return;
}
@ -116,7 +114,7 @@ public:
struct ReadStream : public IFileIO::IReadStream
{
HANDLE fp;
ReadStream(const SystemString& path, bool& err)
ReadStream(SystemStringView path, bool& err)
{
fp = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
@ -126,7 +124,7 @@ public:
LogModule.report(logvisor::Error, _S("unable to open '%s' for reading"), path.c_str());
}
}
ReadStream(const SystemString& path, uint64_t offset, bool& err)
ReadStream(SystemStringView path, uint64_t offset, bool& err)
: ReadStream(path, err)
{
if (err)
@ -199,12 +197,7 @@ public:
}
};
std::unique_ptr<IFileIO> NewFileIO(const SystemString& path, int64_t maxWriteSize)
{
return std::unique_ptr<IFileIO>(new FileIOWin32(path, maxWriteSize));
}
std::unique_ptr<IFileIO> NewFileIO(const SystemChar* path, int64_t maxWriteSize)
std::unique_ptr<IFileIO> NewFileIO(SystemStringView path, int64_t maxWriteSize)
{
return std::unique_ptr<IFileIO>(new FileIOWin32(path, maxWriteSize));
}

View File

@ -7,16 +7,16 @@ namespace nod
logvisor::Module LogModule("nod");
std::unique_ptr<IDiscIO> NewDiscIOISO(const SystemChar* path);
std::unique_ptr<IDiscIO> NewDiscIOWBFS(const SystemChar* path);
std::unique_ptr<IDiscIO> NewDiscIOISO(SystemStringView path);
std::unique_ptr<IDiscIO> NewDiscIOWBFS(SystemStringView path);
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
std::unique_ptr<DiscBase> OpenDiscFromImage(SystemStringView path, bool& isWii)
{
/* Temporary file handle to determine image type */
std::unique_ptr<IFileIO> fio = NewFileIO(path);
if (!fio->exists())
{
LogModule.report(logvisor::Error, _S("Unable to open '%s'"), path);
LogModule.report(logvisor::Error, _S("Unable to open '%s'"), path.data());
return {};
}
std::unique_ptr<IFileIO::IReadStream> rs = fio->beginReadStream();
@ -28,7 +28,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
uint32_t magic = 0;
if (rs->read(&magic, 4) != 4)
{
LogModule.report(logvisor::Error, _S("Unable to read magic from '%s'"), path);
LogModule.report(logvisor::Error, _S("Unable to read magic from '%s'"), path.data());
return {};
}
@ -58,7 +58,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
if (!discIO)
{
LogModule.report(logvisor::Error, _S("'%s' is not a valid image"), path);
LogModule.report(logvisor::Error, _S("'%s' is not a valid image"), path.data());
return {};
}
@ -78,7 +78,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
return ret;
}
std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path)
std::unique_ptr<DiscBase> OpenDiscFromImage(SystemStringView path)
{
bool isWii;
return OpenDiscFromImage(path, isWii);