cnut_converter.zip/cnut_converter/main.cpp
#include "stdafx.h"
bool proc(const boost::filesystem::path &path) {
if (!boost::filesystem::is_regular_file(path)) {
return false;
}
const unsigned long long int fileSize = boost::filesystem::file_size(path);
if (fileSize == 0) {
return false;
}
boost::filesystem::ifstream ifs(path, std::ios::binary);
if (!ifs.good()) {
return false;
}
const boost::optional<TouhouSE::Squirrel3::CNut> cnut = TouhouSE::Squirrel3::CNut::read(ifs, fileSize);
if (!cnut) {
return false;
}
ifs.close();
const boost::filesystem::path outPath = boost::filesystem::path(path).replace_extension(".nut");
boost::filesystem::ofstream ofs(outPath);
ofs << cnut->toString();
ofs.close();
return true;
}
int main(const unsigned int argc, const char * const * const argv) {
std::locale loc = std::locale("japanese").combine<std::numpunct<char> >(std::locale::classic()).combine<std::numpunct<wchar_t> >(std::locale::classic());
std::locale::global(loc);
std::wcout.imbue(loc);
std::cout.imbue(loc);
if (argc < 2) {
std::wcout << boost::wformat(L"usage: %s filename.cnut\n") % boost::filesystem::path(argv[0]).filename().wstring();
return 1;
}
for (unsigned int i = 1; i < argc; i++) {
if (!proc(argv[i])) {
return 1;
}
}
return 0;
}