mirror of
https://github.com/jakcron/nstool
synced 2024-11-22 21:49:30 +00:00
[fnd|nstool] Replaced io::makePath() with io::appendToPath(). Enabled utf-8 support to io::makeDirectory.
This commit is contained in:
parent
2bfe11bf16
commit
d017a95a3a
3 changed files with 25 additions and 21 deletions
|
@ -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<std::string>& elements);
|
||||
void appendToPath(std::string& base, const std::string& add);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <fnd/io.h>
|
||||
#include <fnd/StringConv.h>
|
||||
#include <fnd/SimpleFile.h>
|
||||
#include <fstream>
|
||||
#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<std::string>& 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<std::string> 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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue