finish migration from py to c++
This commit is contained in:
parent
6fc223b208
commit
2a6cd48ac9
|
@ -1,7 +1,7 @@
|
||||||
import VTReader, VTStruct, VTConstants
|
import VTReader, VTStruct, VTConstants
|
||||||
|
|
||||||
ckFile = VTStruct.CKFile()
|
ckFile = VTStruct.CKFile()
|
||||||
VTReader.CKFileReader.Load(ckFile, "D:\\libcmo21\\PyCmo\\Language.nmo", VTConstants.CK_LOAD_FLAGS(VTConstants.CK_LOAD_FLAGS.CK_LOAD_DEFAULT))
|
VTReader.CKFileReader.Load(ckFile, "D:\\libcmo21\\PyCmo\\Language.old.nmo", VTConstants.CK_LOAD_FLAGS(VTConstants.CK_LOAD_FLAGS.CK_LOAD_DEFAULT))
|
||||||
print(ckFile)
|
print(ckFile)
|
||||||
print(str(ckFile.m_FileObjects))
|
print(str(ckFile.m_FileObjects))
|
||||||
|
|
||||||
|
|
|
@ -231,30 +231,31 @@ namespace Unvirt {
|
||||||
|
|
||||||
void GetAccessibleFileSize(std::string& strl, uint64_t size) {
|
void GetAccessibleFileSize(std::string& strl, uint64_t size) {
|
||||||
static double denominator = (double)0b1111111111;
|
static double denominator = (double)0b1111111111;
|
||||||
|
uint64_t probe = size;
|
||||||
|
|
||||||
// check bytes
|
// check bytes
|
||||||
if ((size >> 10) == UINT64_C(0)) {
|
if ((probe >> 10) == UINT64_C(0)) {
|
||||||
StringHelper::StdstringPrintf(strl, "%" PRIu64 "Bytes", size);
|
StringHelper::StdstringPrintf(strl, "%" PRIu64 "Bytes", probe);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size >>= 10;
|
probe >>= 10;
|
||||||
|
|
||||||
// check kb
|
// check kb
|
||||||
if ((size >> 10) == UINT64_C(0)) {
|
if ((probe >> 10) == UINT64_C(0)) {
|
||||||
StringHelper::StdstringPrintf(strl, "%.2lfKiB", size / denominator);
|
StringHelper::StdstringPrintf(strl, "%.2lfKiB", size / static_cast<double>(UINT64_C(1) << 10));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size >>= 10;
|
probe >>= 10;
|
||||||
|
|
||||||
// check mb
|
// check mb
|
||||||
if ((size >> 10) == UINT64_C(0)) {
|
if ((probe >> 10) == UINT64_C(0)) {
|
||||||
StringHelper::StdstringPrintf(strl, "%.2lfMiB", size / denominator);
|
StringHelper::StdstringPrintf(strl, "%.2lfMiB", size / static_cast<double>(UINT64_C(1) << 20));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size >>= 10;
|
probe >>= 10;
|
||||||
|
|
||||||
// otherwise gb
|
// otherwise gb
|
||||||
StringHelper::StdstringPrintf(strl, "%.2lfGiB", size / denominator);
|
StringHelper::StdstringPrintf(strl, "%.2lfGiB", size / static_cast<double>(UINT64_C(1) << 30));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
#include "CmdHelper.hpp"
|
#include "CmdHelper.hpp"
|
||||||
#include "TerminalHelper.hpp"
|
#include "TerminalHelper.hpp"
|
||||||
|
#include "VTUtils.hpp"
|
||||||
|
#include "VTEncoding.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
namespace Unvirt {
|
namespace Unvirt {
|
||||||
namespace CmdHelper {
|
namespace CmdHelper {
|
||||||
|
@ -15,7 +20,7 @@ namespace Unvirt {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> CmdSplitter::Convert(const std::string& u8cmd) {
|
const std::vector<std::string> CmdSplitter::Convert(const std::string& u8cmd) {
|
||||||
// set up variables
|
// set up variables
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
|
@ -129,7 +134,7 @@ namespace Unvirt {
|
||||||
if (search == mShortNameMapping.end()) return nullptr;
|
if (search == mShortNameMapping.end()) return nullptr;
|
||||||
return GetDescByLongName((*search).second);
|
return GetDescByLongName((*search).second);
|
||||||
}
|
}
|
||||||
OptionDescription* OptionsDescription::GetDescByPosition(int pos) {
|
OptionDescription* OptionsDescription::GetDescByPosition(size_t pos) {
|
||||||
if (pos >= mPositionalArgMapping.size()) return nullptr;
|
if (pos >= mPositionalArgMapping.size()) return nullptr;
|
||||||
return GetDescByLongName(mPositionalArgMapping[pos]);
|
return GetDescByLongName(mPositionalArgMapping[pos]);
|
||||||
}
|
}
|
||||||
|
@ -167,7 +172,7 @@ namespace Unvirt {
|
||||||
mDataPair.clear();
|
mDataPair.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VariablesMap::AddPair(std::string& name, CmdArgType t, std::string& val) {
|
bool VariablesMap::AddPair(const std::string& name, CmdArgType t, const std::string& val) {
|
||||||
if (mDataPair.contains(name)) return false;
|
if (mDataPair.contains(name)) return false;
|
||||||
|
|
||||||
AnyVariable var;
|
AnyVariable var;
|
||||||
|
@ -206,41 +211,75 @@ namespace Unvirt {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDataPair.emplace(name, std::move(var));
|
mDataPair.emplace(name, std::move(var));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region ExecEnvironment
|
#pragma region ExecEnvironment
|
||||||
|
|
||||||
ExecEnvironment::ExecEnvironment() {
|
ExecEnvironment::ExecEnvironment() :
|
||||||
|
mVtFile(nullptr), mVtFileEnv(nullptr) {
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecEnvironment::~ExecEnvironment() {
|
ExecEnvironment::~ExecEnvironment() {
|
||||||
|
if (mVtFile != nullptr) delete mVtFile;
|
||||||
|
if (mVtFileEnv != nullptr) delete mVtFileEnv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecEnvironment::ProcLoad(OptionsDescription& od, VariablesMap& vm) {
|
void ExecEnvironment::ProcLoad(OptionsDescription& od, VariablesMap& vm) {
|
||||||
|
if (mVtFile != nullptr || mVtFileEnv != nullptr) {
|
||||||
|
printf(UNVIRT_TERMCOL_LIGHT_RED(("Please close current opened Vrtools file first.\n")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* filename = vm.GetData<char>("file");
|
||||||
|
if (filename == nullptr) {
|
||||||
|
printf(UNVIRT_TERMCOL_LIGHT_RED(("You should specify a file first.\n")));
|
||||||
|
od.PrintHelp(stdout);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mVtFileEnv = new LibCmo::Utils::VirtoolsContext();
|
||||||
|
const char* enc = vm.GetData<char>("encoding");
|
||||||
|
mVtFileEnv->NameEncoding = enc == nullptr ? "" : enc;
|
||||||
|
|
||||||
|
mVtFile = new LibCmo::CKFile(*mVtFileEnv);
|
||||||
|
mVtFile->Load(filename, LibCmo::CK_LOAD_FLAGS::CK_LOAD_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecEnvironment::ProcInfo(OptionsDescription& od, VariablesMap& vm) {
|
void ExecEnvironment::ProcInfo(OptionsDescription& od, VariablesMap& vm) {
|
||||||
|
printf(UNVIRT_TERMCOL_LIGHT_RED(("Sorry. This feature is not supported now.\n")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecEnvironment::ProcClear(OptionsDescription& od, VariablesMap& vm) {
|
void ExecEnvironment::ProcClear(OptionsDescription& od, VariablesMap& vm) {
|
||||||
|
if (mVtFile == nullptr && mVtFileEnv == nullptr) {
|
||||||
|
printf(UNVIRT_TERMCOL_LIGHT_RED(("Virtools file already is empty.\n")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mVtFile != nullptr) delete mVtFile;
|
||||||
|
if (mVtFileEnv != nullptr) delete mVtFileEnv;
|
||||||
|
|
||||||
|
mVtFile = nullptr;
|
||||||
|
mVtFileEnv = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecEnvironment::ProcExportSql(OptionsDescription& od, VariablesMap& vm) {
|
void ExecEnvironment::ProcExportSql(OptionsDescription& od, VariablesMap& vm) {
|
||||||
|
printf(UNVIRT_TERMCOL_LIGHT_RED(("Sorry. This feature is not supported now.\n")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
#pragma region InteractiveCmd
|
#pragma region InteractiveCmd
|
||||||
|
|
||||||
InteractiveCmd::InteractiveCmd() :
|
InteractiveCmd::InteractiveCmd() :
|
||||||
mCmdDispatcher(), mExecEnv(), mVm(), mBlank()
|
mCmdDispatcher(), mExecEnv(), mVm(), mBlank(), mExitRunFlag(false), mCmdSplitter() {
|
||||||
{
|
|
||||||
// add load subcommand
|
// add load subcommand
|
||||||
CmdRegisteryEntry entryLoad;
|
CmdRegisteryEntry entryLoad;
|
||||||
|
const std::string entryLoadName = "load";
|
||||||
entryLoad.mSubCmdDesc = "Load Virtools file.";
|
entryLoad.mSubCmdDesc = "Load Virtools file.";
|
||||||
entryLoad.mOptDesc.AddOption("file", 'f', CmdArgType::STRING, "The loaded Virtools file.");
|
entryLoad.mOptDesc.AddOption("file", 'f', CmdArgType::STRING, "The loaded Virtools file.");
|
||||||
entryLoad.mOptDesc.AddPositionalOption("file");
|
entryLoad.mOptDesc.AddPositionalOption("file");
|
||||||
|
@ -249,33 +288,57 @@ namespace Unvirt {
|
||||||
entryLoad.mOptDesc.AddOption("temp", 't', CmdArgType::STRING, "The temp folder used by engine.");
|
entryLoad.mOptDesc.AddOption("temp", 't', CmdArgType::STRING, "The temp folder used by engine.");
|
||||||
entryLoad.mOptDesc.AddPositionalOption("temp");
|
entryLoad.mOptDesc.AddPositionalOption("temp");
|
||||||
entryLoad.mBindProc = std::bind(&ExecEnvironment::ProcLoad, &this->mExecEnv, std::placeholders::_1, std::placeholders::_2);
|
entryLoad.mBindProc = std::bind(&ExecEnvironment::ProcLoad, &this->mExecEnv, std::placeholders::_1, std::placeholders::_2);
|
||||||
mCmdDispatcher.emplace("load", std::move(entryLoad));
|
//mCmdDispatcher.emplace("load", std::move(entryLoad));
|
||||||
|
|
||||||
CmdRegisteryEntry entryInfo;
|
CmdRegisteryEntry entryInfo;
|
||||||
entryInfo.mSubCmdDesc = "Show loaded Virtools file header info.";
|
entryInfo.mSubCmdDesc = "Show loaded Virtools file header info.";
|
||||||
entryInfo.mBindProc = std::bind(&ExecEnvironment::ProcInfo, &this->mExecEnv, std::placeholders::_1, std::placeholders::_2);
|
entryInfo.mBindProc = std::bind(&ExecEnvironment::ProcInfo, &this->mExecEnv, std::placeholders::_1, std::placeholders::_2);
|
||||||
mCmdDispatcher.emplace("info", std::move(entryInfo));
|
//mCmdDispatcher.emplace("info", std::move(entryInfo));
|
||||||
|
|
||||||
CmdRegisteryEntry entryClear;
|
CmdRegisteryEntry entryClear;
|
||||||
entryClear.mSubCmdDesc = "Clear current loaded Virtools file.";
|
entryClear.mSubCmdDesc = "Clear current loaded Virtools file.";
|
||||||
entryClear.mBindProc = std::bind(&ExecEnvironment::ProcClear, &this->mExecEnv, std::placeholders::_1, std::placeholders::_2);
|
entryClear.mBindProc = std::bind(&ExecEnvironment::ProcClear, &this->mExecEnv, std::placeholders::_1, std::placeholders::_2);
|
||||||
mCmdDispatcher.emplace("clear", std::move(entryClear));
|
//mCmdDispatcher.emplace("clear", std::move(entryClear));
|
||||||
|
|
||||||
CmdRegisteryEntry entryExportSql;
|
CmdRegisteryEntry entryExportSql;
|
||||||
entryExportSql.mSubCmdDesc = "Export loaded Virtools file as a SQList database file.";
|
entryExportSql.mSubCmdDesc = "Export loaded Virtools file as a SQList database file.";
|
||||||
entryExportSql.mOptDesc.AddOption("file", 'f', CmdArgType::STRING, "The exported SQL file.");
|
entryExportSql.mOptDesc.AddOption("file", 'f', CmdArgType::STRING, "The exported SQL file.");
|
||||||
entryExportSql.mOptDesc.AddPositionalOption("file");
|
entryExportSql.mOptDesc.AddPositionalOption("file");
|
||||||
entryExportSql.mBindProc = std::bind(&ExecEnvironment::ProcExportSql, &this->mExecEnv, std::placeholders::_1, std::placeholders::_2);
|
entryExportSql.mBindProc = std::bind(&ExecEnvironment::ProcExportSql, &this->mExecEnv, std::placeholders::_1, std::placeholders::_2);
|
||||||
mCmdDispatcher.emplace("sql", std::move(entryExportSql));
|
//mCmdDispatcher.emplace("sql", std::move(entryExportSql));
|
||||||
|
|
||||||
|
CmdRegisteryEntry entryExit;
|
||||||
|
entryExit.mSubCmdDesc = "Exit this interactive commander.";
|
||||||
|
entryExit.mBindProc = std::bind(&InteractiveCmd::ProcExit, this, std::placeholders::_1, std::placeholders::_2);
|
||||||
|
//mCmdDispatcher.emplace("exit", std::move(entryExit));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InteractiveCmd::~InteractiveCmd() {
|
InteractiveCmd::~InteractiveCmd() {
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractiveCmd::Run(void) {
|
void InteractiveCmd::Run(void) {
|
||||||
|
std::string u8cmd;
|
||||||
|
|
||||||
|
mExitRunFlag = false;
|
||||||
|
while (!mExitRunFlag) {
|
||||||
|
// get command
|
||||||
|
GetCmdLine(u8cmd);
|
||||||
|
|
||||||
|
// split cmd and parse it
|
||||||
|
CmdParser(mCmdSplitter.Convert(u8cmd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InteractiveCmd::GetCmdLine(std::string& u8cmd) {
|
||||||
|
#if defined(LIBCMO_OS_WIN32)
|
||||||
|
std::wstring wcmd;
|
||||||
|
std::getline(std::wcin, wcmd);
|
||||||
|
LibCmo::Encoding::WcharToChar(wcmd, u8cmd, CP_UTF8);
|
||||||
|
#else
|
||||||
|
std::getline(std::cin, u8cmd);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractiveCmd::CmdParser(const std::vector<std::string>& args) {
|
void InteractiveCmd::CmdParser(const std::vector<std::string>& args) {
|
||||||
|
@ -316,7 +379,7 @@ namespace Unvirt {
|
||||||
optsDesc.PrintHelp(f);
|
optsDesc.PrintHelp(f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
optsDesc.GetDescByShortName(opt[1]);
|
optDesc = optsDesc.GetDescByShortName(opt[1]);
|
||||||
} else {
|
} else {
|
||||||
// position
|
// position
|
||||||
optDesc = optsDesc.GetDescByPosition(position_counter++);
|
optDesc = optsDesc.GetDescByPosition(position_counter++);
|
||||||
|
@ -330,11 +393,17 @@ namespace Unvirt {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get value
|
// get value
|
||||||
|
bool add_success = true;
|
||||||
switch (optDesc->mType) {
|
switch (optDesc->mType) {
|
||||||
case CmdArgType::NONE:
|
case CmdArgType::NONE:
|
||||||
// just a switch
|
// just a switch
|
||||||
mVm.AddPair(optDesc->mLongName, optDesc->mType, this->mBlank);
|
add_success = mVm.AddPair(optDesc->mLongName, optDesc->mType, this->mBlank);
|
||||||
++arg;
|
++arg;
|
||||||
|
if (!add_success) {
|
||||||
|
fprintf(f, UNVIRT_TERMCOL_LIGHT_RED(("Error! Duplicated option \"%s\"! \n")), opt.c_str());
|
||||||
|
optsDesc.PrintHelp(f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CmdArgType::INT:
|
case CmdArgType::INT:
|
||||||
case CmdArgType::STRING:
|
case CmdArgType::STRING:
|
||||||
|
@ -345,8 +414,13 @@ namespace Unvirt {
|
||||||
optsDesc.PrintHelp(f);
|
optsDesc.PrintHelp(f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mVm.AddPair(optDesc->mLongName, optDesc->mType, *arg);
|
add_success = mVm.AddPair(optDesc->mLongName, optDesc->mType, *arg);
|
||||||
++arg;
|
++arg;
|
||||||
|
if (!add_success) {
|
||||||
|
fprintf(f, UNVIRT_TERMCOL_LIGHT_RED(("Error! Duplicated option \"%s\"! \n")), opt.c_str());
|
||||||
|
optsDesc.PrintHelp(f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw std::invalid_argument("Invalid Option Type.");
|
throw std::invalid_argument("Invalid Option Type.");
|
||||||
|
@ -364,8 +438,13 @@ namespace Unvirt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InteractiveCmd::ProcExit(OptionsDescription&, VariablesMap&) {
|
||||||
|
mExitRunFlag = true;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
*/
|
|
@ -6,6 +6,10 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "VTUtils.hpp"
|
||||||
|
#include "VTStruct.hpp"
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
namespace Unvirt {
|
namespace Unvirt {
|
||||||
namespace CmdHelper {
|
namespace CmdHelper {
|
||||||
|
@ -17,7 +21,7 @@ namespace Unvirt {
|
||||||
CmdSplitter& operator=(const CmdSplitter&) = delete;
|
CmdSplitter& operator=(const CmdSplitter&) = delete;
|
||||||
~CmdSplitter();
|
~CmdSplitter();
|
||||||
|
|
||||||
std::vector<std::string> Convert(const std::string& u8cmd);
|
const std::vector<std::string> Convert(const std::string& u8cmd);
|
||||||
private:
|
private:
|
||||||
char mCmdChar;
|
char mCmdChar;
|
||||||
std::string* mBuffer;
|
std::string* mBuffer;
|
||||||
|
@ -154,7 +158,7 @@ namespace Unvirt {
|
||||||
|
|
||||||
OptionDescription* GetDescByLongName(const std::string& longname);
|
OptionDescription* GetDescByLongName(const std::string& longname);
|
||||||
OptionDescription* GetDescByShortName(char shortname);
|
OptionDescription* GetDescByShortName(char shortname);
|
||||||
OptionDescription* GetDescByPosition(int pos);
|
OptionDescription* GetDescByPosition(size_t pos);
|
||||||
|
|
||||||
void PrintHelp(FILE* f);
|
void PrintHelp(FILE* f);
|
||||||
private:
|
private:
|
||||||
|
@ -186,7 +190,7 @@ namespace Unvirt {
|
||||||
/// <param name="t"></param>
|
/// <param name="t"></param>
|
||||||
/// <param name="val"></param>
|
/// <param name="val"></param>
|
||||||
/// <returns>return false when this opt is existed.</returns>
|
/// <returns>return false when this opt is existed.</returns>
|
||||||
bool AddPair(std::string& name, CmdArgType t, std::string& val);
|
bool AddPair(const std::string& name, CmdArgType t, const std::string& val);
|
||||||
bool Contain(const char* opt) {
|
bool Contain(const char* opt) {
|
||||||
if (opt == nullptr) throw std::invalid_argument("Invalid Option Name.");
|
if (opt == nullptr) throw std::invalid_argument("Invalid Option Name.");
|
||||||
return mDataPair.contains(opt);
|
return mDataPair.contains(opt);
|
||||||
|
@ -220,7 +224,8 @@ namespace Unvirt {
|
||||||
void ProcClear(OptionsDescription&, VariablesMap&);
|
void ProcClear(OptionsDescription&, VariablesMap&);
|
||||||
void ProcExportSql(OptionsDescription&, VariablesMap&);
|
void ProcExportSql(OptionsDescription&, VariablesMap&);
|
||||||
private:
|
private:
|
||||||
|
LibCmo::CKFile* mVtFile;
|
||||||
|
LibCmo::Utils::VirtoolsContext* mVtFileEnv;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InteractiveCmd {
|
class InteractiveCmd {
|
||||||
|
@ -233,14 +238,20 @@ namespace Unvirt {
|
||||||
void Run(void);
|
void Run(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void GetCmdLine(std::string& u8cmd);
|
||||||
void CmdParser(const std::vector<std::string>& args);
|
void CmdParser(const std::vector<std::string>& args);
|
||||||
void PrintHelp(FILE* f);
|
void PrintHelp(FILE* f);
|
||||||
|
|
||||||
|
void ProcExit(OptionsDescription&, VariablesMap&);
|
||||||
|
|
||||||
std::unordered_map<std::string, CmdRegisteryEntry> mCmdDispatcher;
|
std::unordered_map<std::string, CmdRegisteryEntry> mCmdDispatcher;
|
||||||
|
CmdSplitter mCmdSplitter;
|
||||||
ExecEnvironment mExecEnv;
|
ExecEnvironment mExecEnv;
|
||||||
VariablesMap mVm;
|
VariablesMap mVm;
|
||||||
std::string mBlank;
|
std::string mBlank;
|
||||||
|
bool mExitRunFlag;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -17,7 +17,7 @@ namespace Unvirt {
|
||||||
strl.resize(count);
|
strl.resize(count);
|
||||||
int write_result = _vsnprintf(strl.data(), count, format, argptr);
|
int write_result = _vsnprintf(strl.data(), count, format, argptr);
|
||||||
|
|
||||||
if (write_result < 0 || write_result >= count) throw new std::length_error("Invalid write_result in _vsnprintf.");
|
if (write_result < 0 || write_result > count) throw new std::length_error("Invalid write_result in _vsnprintf.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
61
Unvirt/StructFormatter.cpp
Normal file
61
Unvirt/StructFormatter.cpp
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#include "StructFormatter.hpp"
|
||||||
|
#include "AccessibleValue.hpp"
|
||||||
|
#include "TerminalHelper.hpp"
|
||||||
|
|
||||||
|
namespace Unvirt {
|
||||||
|
namespace StructFormatter {
|
||||||
|
|
||||||
|
static FILE* fout = stdout;
|
||||||
|
|
||||||
|
void PrintCKFileInfo(const LibCmo::CKFileInfo& fileinfo) {
|
||||||
|
std::string container;
|
||||||
|
|
||||||
|
fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKFileInfo\n")), fout);
|
||||||
|
fprintf(fout, "Version (File / CK): %" PRIu32 " / 0x%08" PRIX32 "\n",
|
||||||
|
fileinfo.FileVersion, fileinfo.CKVersion
|
||||||
|
);
|
||||||
|
|
||||||
|
LibCmo::CKDWORD product_series[4]{
|
||||||
|
(fileinfo.ProductBuild >> 24) & 0xFF,
|
||||||
|
(fileinfo.ProductBuild >> 16) & 0xFF,
|
||||||
|
(fileinfo.ProductBuild >> 8) & 0xFF,
|
||||||
|
(fileinfo.ProductBuild >> 0) & 0xFF,
|
||||||
|
};
|
||||||
|
fprintf(fout, "Product (Version / Build): %" PRIu32 " / %" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32 "\n",
|
||||||
|
fileinfo.ProductVersion, product_series[0], product_series[1], product_series[2], product_series[3]
|
||||||
|
);
|
||||||
|
|
||||||
|
Unvirt::AccessibleValue::GetFlagEnumName<LibCmo::CK_FILE_WRITEMODE>(
|
||||||
|
Unvirt::AccessibleValue::EnumDesc::CK_FILE_WRITEMODE, container, fileinfo.FileWriteMode
|
||||||
|
);
|
||||||
|
fprintf(fout, "Save Flags: %s\n", container.c_str());
|
||||||
|
|
||||||
|
Unvirt::AccessibleValue::GetAccessibleFileSize(container, fileinfo.FileSize);
|
||||||
|
fprintf(fout, "File Size: %s\n", container.c_str());
|
||||||
|
|
||||||
|
fprintf(fout, "Crc: 0x%" PRIX32 "\n", fileinfo.Crc);
|
||||||
|
fputc('\n', fout);
|
||||||
|
|
||||||
|
|
||||||
|
fputs("Hdr1 (Pack / UnPack): ", fout);
|
||||||
|
Unvirt::AccessibleValue::GetAccessibleFileSize(container, fileinfo.Hdr1PackSize);
|
||||||
|
fprintf(fout, "%s / ", container.c_str());
|
||||||
|
Unvirt::AccessibleValue::GetAccessibleFileSize(container, fileinfo.Hdr1UnPackSize);
|
||||||
|
fprintf(fout, "%s\n", container.c_str());
|
||||||
|
|
||||||
|
fputs("Data (Pack / UnPack): ", fout);
|
||||||
|
Unvirt::AccessibleValue::GetAccessibleFileSize(container, fileinfo.DataPackSize);
|
||||||
|
fprintf(fout, "%s / ", container.c_str());
|
||||||
|
Unvirt::AccessibleValue::GetAccessibleFileSize(container, fileinfo.DataUnPackSize);
|
||||||
|
fprintf(fout, "%s\n", container.c_str());
|
||||||
|
fputc('\n', fout);
|
||||||
|
|
||||||
|
|
||||||
|
fprintf(fout, "Manager Count: %" PRIu32 "\nObject Count: %" PRIu32 "\nMax ID Saved: %" PRIu32 "\n",
|
||||||
|
fileinfo.ManagerCount, fileinfo.ObjectCount, fileinfo.MaxIDSaved
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
Unvirt/StructFormatter.hpp
Normal file
11
Unvirt/StructFormatter.hpp
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "VTStruct.hpp"
|
||||||
|
|
||||||
|
namespace Unvirt {
|
||||||
|
namespace StructFormatter {
|
||||||
|
|
||||||
|
void PrintCKFileInfo(const LibCmo::CKFileInfo& fileinfo);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
#include "AccessibleValue.hpp"
|
#include "AccessibleValue.hpp"
|
||||||
#include "TerminalHelper.hpp"
|
#include "TerminalHelper.hpp"
|
||||||
#include "CmdHelper.hpp"
|
#include "StructFormatter.hpp"
|
||||||
#include "VTStruct.hpp"
|
#include "VTStruct.hpp"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -13,12 +13,7 @@ int main(int argc, char* argv[]) {
|
||||||
LibCmo::CKFile vtfile(vtctx);
|
LibCmo::CKFile vtfile(vtctx);
|
||||||
vtfile.Load("Language.old.nmo", LibCmo::CK_LOAD_FLAGS::CK_LOAD_DEFAULT);
|
vtfile.Load("Language.old.nmo", LibCmo::CK_LOAD_FLAGS::CK_LOAD_DEFAULT);
|
||||||
|
|
||||||
//printf(UNVIRT_TERMCOL_LIGHT_YELLOW(("Hello, %s\n")), u8"㴮!");
|
Unvirt::StructFormatter::PrintCKFileInfo(vtfile.m_FileInfo);
|
||||||
|
|
||||||
//std::string bbb("load \"Language. 㴮!old.nmo\" utf8 ");
|
|
||||||
//Unvirt::CmdHelper::CmdSplitter sp;
|
|
||||||
//auto a = sp.Convert(bbb);
|
|
||||||
//printf(UNVIRT_TERMCOL_LIGHT_YELLOW(("%s\n")), a[1].c_str());
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,6 +173,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="AccessibleValue.cpp" />
|
<ClCompile Include="AccessibleValue.cpp" />
|
||||||
<ClCompile Include="CmdHelper.cpp" />
|
<ClCompile Include="CmdHelper.cpp" />
|
||||||
|
<ClCompile Include="StructFormatter.cpp" />
|
||||||
<ClCompile Include="TerminalHelper.cpp" />
|
<ClCompile Include="TerminalHelper.cpp" />
|
||||||
<ClCompile Include="StringHelper.cpp" />
|
<ClCompile Include="StringHelper.cpp" />
|
||||||
<ClCompile Include="Unvirt.cpp" />
|
<ClCompile Include="Unvirt.cpp" />
|
||||||
|
@ -180,6 +181,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="AccessibleValue.hpp" />
|
<ClInclude Include="AccessibleValue.hpp" />
|
||||||
<ClInclude Include="CmdHelper.hpp" />
|
<ClInclude Include="CmdHelper.hpp" />
|
||||||
|
<ClInclude Include="StructFormatter.hpp" />
|
||||||
<ClInclude Include="TerminalHelper.hpp" />
|
<ClInclude Include="TerminalHelper.hpp" />
|
||||||
<ClInclude Include="StringHelper.hpp" />
|
<ClInclude Include="StringHelper.hpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
<ClCompile Include="CmdHelper.cpp">
|
<ClCompile Include="CmdHelper.cpp">
|
||||||
<Filter>Sources</Filter>
|
<Filter>Sources</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="StructFormatter.cpp">
|
||||||
|
<Filter>Sources</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="AccessibleValue.hpp">
|
<ClInclude Include="AccessibleValue.hpp">
|
||||||
|
@ -44,5 +47,8 @@
|
||||||
<ClInclude Include="CmdHelper.hpp">
|
<ClInclude Include="CmdHelper.hpp">
|
||||||
<Filter>Headers</Filter>
|
<Filter>Headers</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="StructFormatter.hpp">
|
||||||
|
<Filter>Headers</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue
Block a user