From d017a95a3a7deb0cf4b6839721813aa5e18478bb Mon Sep 17 00:00:00 2001 From: jakcron Date: Wed, 25 Apr 2018 20:27:18 +0800 Subject: [PATCH] [fnd|nstool] Replaced io::makePath() with io::appendToPath(). Enabled utf-8 support to io::makeDirectory. --- lib/libfnd/include/fnd/io.h | 8 ++++++- lib/libfnd/source/io.cpp | 29 +++++++++++++------------ programs/nstool/source/UserSettings.cpp | 9 +++----- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/libfnd/include/fnd/io.h b/lib/libfnd/include/fnd/io.h index df31808..58aa895 100644 --- a/lib/libfnd/include/fnd/io.h +++ b/lib/libfnd/include/fnd/io.h @@ -6,6 +6,12 @@ namespace fnd { namespace io { +#ifdef _WIN32 + const std::string kPathDivider = "\\"; +#else + const std::string kPathDivider = "/"; +#endif + size_t getFileSize(const std::string& path); void readFile(const std::string& path, MemoryBlob& blob); void readFile(const std::string& path, size_t offset, size_t len, MemoryBlob& blob); @@ -13,6 +19,6 @@ namespace fnd void writeFile(const std::string& path, const byte_t* data, size_t len); void makeDirectory(const std::string& path); void getEnvironVar(std::string& var, const std::string& key); - void makePath(std::string& out, const std::vector& elements); + void appendToPath(std::string& base, const std::string& add); } } diff --git a/lib/libfnd/source/io.cpp b/lib/libfnd/source/io.cpp index 34b9210..82323a3 100644 --- a/lib/libfnd/source/io.cpp +++ b/lib/libfnd/source/io.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #ifdef _WIN32 @@ -133,7 +134,8 @@ void io::writeFile(const std::string & path, const byte_t * data, size_t len) void io::makeDirectory(const std::string& path) { #ifdef _WIN32 - _mkdir(path.c_str()); + std::u16string wpath = fnd::StringConv::ConvertChar8ToChar16(path); + _wmkdir(wpath.c_str()); #else mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); #endif @@ -163,20 +165,19 @@ void fnd::io::getEnvironVar(std::string & var, const std::string & key) #endif } -void fnd::io::makePath(std::string & out, const std::vector& elements) +void fnd::io::appendToPath(std::string& base, const std::string& add) { - out.clear(); - out = ""; - for (size_t i = 0; i < elements.size(); i++) + if (add.empty()) + return; + + if (base.empty()) { - if (i > 0) - { -#ifdef _WIN32 - out += "\\"; -#else - out += "/"; -#endif - } - out += elements[i]; + base = add; + } + else + { + if (base[base.length()-1] != io::kPathDivider[0]) + base += io::kPathDivider; + base += add; } } diff --git a/programs/nstool/source/UserSettings.cpp b/programs/nstool/source/UserSettings.cpp index 2d77146..d95993d 100644 --- a/programs/nstool/source/UserSettings.cpp +++ b/programs/nstool/source/UserSettings.cpp @@ -264,14 +264,11 @@ void UserSettings::populateKeyset(sCmdArgs& args) const std::string kKeysetNameStr[2] = {"prod.keys", "dev.keys"}; const std::string kHomeSwitchDirStr = ".switch"; - - std::vector path_list; - path_list.push_back(home); - path_list.push_back(kHomeSwitchDirStr); - path_list.push_back(kKeysetNameStr[args.devkit_keys.isSet ? *args.devkit_keys : 0]); std::string keyset_path; - fnd::io::makePath(keyset_path, path_list); + fnd::io::appendToPath(keyset_path, home); + fnd::io::appendToPath(keyset_path, kHomeSwitchDirStr); + fnd::io::appendToPath(keyset_path, kKeysetNameStr[args.devkit_keys.isSet ? *args.devkit_keys : 0]); try {