Address Todo1 and Todo3

progFunc now prints strings instead of wstrings to avoid an assert being thrown when Command Prompt attempts to print wide characters.

SystemUTF8Conv renamed to SystemShiftJISConv
SystemStringConv renamed to ShiftJISSystemConv

Variable and class member naming has been updated across the codebase.
This commit is contained in:
Minty-Meeo 2021-04-08 14:10:30 -05:00
parent 9329092757
commit ad7754867a
4 changed files with 33 additions and 32 deletions

View File

@ -66,11 +66,12 @@ int main(int argc, char* argv[])
}
auto progFunc = [&](float prog, nod::SystemStringView name, size_t bytes) {
fmt::print(FMT_STRING(_SYS_STR("\r ")));
nod::SystemShiftJISConv shiftjis_name(name);
fmt::print(FMT_STRING("\r "));
if (bytes != SIZE_MAX)
fmt::print(FMT_STRING(_SYS_STR("\r{:g}% {} {} B")), prog * 100.f, name, bytes);
fmt::print(FMT_STRING("\r{:g}% {} {} B"), prog * 100.f, shiftjis_name.shiftjis_str(), bytes);
else
fmt::print(FMT_STRING(_SYS_STR("\r{:g}% {}")), prog * 100.f, name);
fmt::print(FMT_STRING("\r{:g}% {}"), prog * 100.f, shiftjis_name.shiftjis_str());
fflush(stdout);
};

View File

@ -410,9 +410,9 @@ public:
static bool RecursiveCalculateTotalSize(uint64_t& totalSz, const Node* nodeIn, SystemStringView dirIn);
void addBuildName(SystemStringView str) {
SystemUTF8Conv utf8View(str);
m_buildNames.emplace_back(utf8View.utf8_str());
m_buildNameOff += utf8View.utf8_str().size() + 1;
SystemShiftJISConv shiftjisView(str);
m_buildNames.emplace_back(shiftjisView.shiftjis_str());
m_buildNameOff += shiftjisView.shiftjis_str().size() + 1;
}
DiscBuilderBase& m_parent;

View File

@ -93,23 +93,23 @@ 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 SystemUTF8Conv {
std::string m_utf8;
class SystemShiftJISConv {
std::string m_shiftjis;
public:
explicit SystemUTF8Conv(SystemStringView str) {
explicit SystemShiftJISConv(SystemStringView str) {
const size_t len = WideCharToMultiByte(CP_SHIFT_JIS, 0, str.data(), str.size(), nullptr, 0, nullptr, nullptr);
m_utf8.assign(len, '\0');
WideCharToMultiByte(CP_SHIFT_JIS, 0, str.data(), str.size(), &m_utf8[0], len, nullptr, nullptr);
m_shiftjis.assign(len, '\0');
WideCharToMultiByte(CP_SHIFT_JIS, 0, str.data(), str.size(), &m_shiftjis[0], len, nullptr, nullptr);
}
std::string_view utf8_str() const { return m_utf8; }
const char* c_str() const { return m_utf8.c_str(); }
std::string_view shiftjis_str() const { return m_shiftjis; }
const char* c_str() const { return m_shiftjis.c_str(); }
};
class SystemStringConv {
class ShiftJISSystemConv {
std::wstring m_sys;
public:
explicit SystemStringConv(std::string_view str) {
explicit ShiftJISSystemConv(std::string_view str) {
const size_t len = MultiByteToWideChar(CP_SHIFT_JIS, 0, str.data(), str.size(), nullptr, 0);
m_sys.assign(len, L'\0');
MultiByteToWideChar(CP_SHIFT_JIS, 0, str.data(), str.size(), &m_sys[0], len);

View File

@ -127,7 +127,7 @@ std::unique_ptr<uint8_t[]> Node::getBuf() const {
}
bool Node::extractToDirectory(SystemStringView basePath, const ExtractionContext& ctx) const {
SystemStringConv nameView(getName());
ShiftJISSystemConv nameView(getName());
SystemString path = SystemString(basePath) + _SYS_STR('/') + nameView.sys_str().data();
if (m_kind == Kind::Directory) {
@ -406,10 +406,10 @@ void DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodesPre(const Node* n
if (!dirIn.empty()) {
DirectoryEnumerator dEnum(dirIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum) {
SystemUTF8Conv nameView(e.m_name);
SystemShiftJISConv nameView(e.m_name);
if (e.m_isDir) {
auto search = dirNodes.find(nameView.utf8_str().data());
auto search = dirNodes.find(nameView.shiftjis_str().data());
if (search != dirNodes.cend()) {
recursiveMergeNodesPre(search->second, e.m_path.c_str());
dirNodes.erase(search);
@ -417,7 +417,7 @@ void DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodesPre(const Node* n
recursiveMergeNodesPre(nullptr, e.m_path.c_str());
}
} else {
fileNodes.erase(nameView.utf8_str().data());
fileNodes.erase(nameView.shiftjis_str().data());
++m_parent.m_progressTotal;
}
}
@ -452,11 +452,11 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
if (!dirIn.empty()) {
DirectoryEnumerator dEnum(dirIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum) {
SystemUTF8Conv nameView(e.m_name);
SystemShiftJISConv nameView(e.m_name);
SystemString chKeyPath = SystemString(keyPath) + _SYS_STR('/') + e.m_name;
if (e.m_isDir) {
auto search = dirNodes.find(nameView.utf8_str().data());
auto search = dirNodes.find(nameView.shiftjis_str().data());
if (search != dirNodes.cend()) {
if (!recursiveMergeNodes(ws, system, search->second, e.m_path.c_str(), chKeyPath))
return false;
@ -471,7 +471,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
if (system ^ isSys)
continue;
fileNodes.erase(nameView.utf8_str().data());
fileNodes.erase(nameView.shiftjis_str().data());
size_t fileSz = ROUND_UP_32(e.m_fileSz);
uint64_t fileOff = userAllocate(fileSz, ws);
@ -508,7 +508,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
/* Write-through remaining dir nodes */
for (const auto& p : dirNodes) {
SystemStringConv sysName(p.second->getName());
ShiftJISSystemConv sysName(p.second->getName());
SystemString chKeyPath = SystemString(keyPath) + _SYS_STR('/') + sysName.c_str();
if (!recursiveMergeNodes(ws, system, p.second, {}, chKeyPath))
return false;
@ -517,7 +517,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeNodes(IPartWriteStream
/* Write-through remaining file nodes */
for (const auto& p : fileNodes) {
const Node& ch = *p.second;
SystemStringConv sysName(ch.getName());
ShiftJISSystemConv sysName(ch.getName());
SystemString chKeyPath = SystemString(keyPath) + _SYS_STR('/') + sysName.c_str();
bool isDol;
@ -584,7 +584,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Node* nodeIn
if (!dirIn.empty()) {
DirectoryEnumerator dEnum(dirIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum) {
SystemUTF8Conv nameView(e.m_name);
SystemShiftJISConv nameView(e.m_name);
SystemString chKeyPath = SystemString(keyPath) + _SYS_STR('/') + e.m_name;
if (e.m_isDir) {
@ -593,7 +593,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Node* nodeIn
addBuildName(e.m_name);
incParents();
auto search = dirNodes.find(nameView.utf8_str().data());
auto search = dirNodes.find(nameView.shiftjis_str().data());
if (search != dirNodes.cend()) {
if (!recursiveMergeFST(search->second, e.m_path.c_str(),
[&]() {
@ -613,7 +613,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Node* nodeIn
return false;
}
} else {
fileNodes.erase(nameView.utf8_str().data());
fileNodes.erase(nameView.shiftjis_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);
@ -624,7 +624,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Node* nodeIn
/* Write-through remaining dir nodes */
for (const auto& p : dirNodes) {
SystemStringConv sysName(p.second->getName());
ShiftJISSystemConv sysName(p.second->getName());
SystemString chKeyPath = SystemString(keyPath) + _SYS_STR('/') + sysName.sys_str().data();
size_t dirNodeIdx = m_buildNodes.size();
@ -644,7 +644,7 @@ bool DiscBuilderBase::PartitionBuilderBase::recursiveMergeFST(const Node* nodeIn
/* Write-through remaining file nodes */
for (const auto& p : fileNodes) {
const Node& ch = *p.second;
SystemStringConv sysName(ch.getName());
ShiftJISSystemConv sysName(ch.getName());
SystemString chKeyPath = SystemString(keyPath) + _SYS_STR('/') + sysName.sys_str().data();
std::pair<uint64_t, uint64_t> fileOffSz = m_fileOffsetsSizes.at(chKeyPath);
@ -676,10 +676,10 @@ bool DiscBuilderBase::PartitionBuilderBase::RecursiveCalculateTotalSize(uint64_t
if (!dirIn.empty()) {
DirectoryEnumerator dEnum(dirIn, DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
for (const DirectoryEnumerator::Entry& e : dEnum) {
SystemUTF8Conv nameView(e.m_name);
SystemShiftJISConv nameView(e.m_name);
if (e.m_isDir) {
auto search = dirNodes.find(nameView.utf8_str().data());
auto search = dirNodes.find(nameView.shiftjis_str().data());
if (search != dirNodes.cend()) {
if (!RecursiveCalculateTotalSize(totalSz, search->second, e.m_path.c_str()))
return false;
@ -689,7 +689,7 @@ bool DiscBuilderBase::PartitionBuilderBase::RecursiveCalculateTotalSize(uint64_t
return false;
}
} else {
fileNodes.erase(nameView.utf8_str().data());
fileNodes.erase(nameView.shiftjis_str().data());
totalSz += ROUND_UP_32(e.m_fileSz);
}
}