From c8f18bce0c01173bb78f4b24e8bb388b8180b58c Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sun, 27 Aug 2023 16:45:07 +0800 Subject: [PATCH] can compile now --- Unvirt/.editorconfig | 69 ++++++++++ Unvirt/CmdHelper.hpp | 8 +- Unvirt/StructFormatter.cpp | 12 +- Unvirt/StructFormatter.hpp | 3 + Unvirt/Unvirt.cpp | 2 +- Unvirt/UnvirtContext.cpp | 258 +++++++++++++++++++++++++------------ 6 files changed, 262 insertions(+), 90 deletions(-) create mode 100644 Unvirt/.editorconfig diff --git a/Unvirt/.editorconfig b/Unvirt/.editorconfig new file mode 100644 index 0000000..2d0456f --- /dev/null +++ b/Unvirt/.editorconfig @@ -0,0 +1,69 @@ +# Visual Studio 生成了具有 C++ 设置的 .editorconfig 文件。 +root = true + +[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}] + +# Visual C++ 代码样式设置 + +cpp_generate_documentation_comments = doxygen_slash_star + +# Visual C++ 格式设置 + +cpp_indent_braces = false +cpp_indent_multi_line_relative_to = statement_begin +cpp_indent_within_parentheses = indent +cpp_indent_preserve_within_parentheses = true +cpp_indent_case_contents = true +cpp_indent_case_labels = true +cpp_indent_case_contents_when_block = false +cpp_indent_lambda_braces_when_parameter = true +cpp_indent_goto_labels = one_left +cpp_indent_preprocessor = leftmost_column +cpp_indent_access_specifiers = false +cpp_indent_namespace_contents = true +cpp_indent_preserve_comments = false +cpp_new_line_before_open_brace_namespace = same_line +cpp_new_line_before_open_brace_type = same_line +cpp_new_line_before_open_brace_function = same_line +cpp_new_line_before_open_brace_block = same_line +cpp_new_line_before_open_brace_lambda = same_line +cpp_new_line_scope_braces_on_separate_lines = true +cpp_new_line_close_brace_same_line_empty_type = true +cpp_new_line_close_brace_same_line_empty_function = true +cpp_new_line_before_catch = false +cpp_new_line_before_else = false +cpp_new_line_before_while_in_do_while = false +cpp_space_before_function_open_parenthesis = remove +cpp_space_within_parameter_list_parentheses = false +cpp_space_between_empty_parameter_list_parentheses = false +cpp_space_after_keywords_in_control_flow_statements = true +cpp_space_within_control_flow_statement_parentheses = false +cpp_space_before_lambda_open_parenthesis = false +cpp_space_within_cast_parentheses = false +cpp_space_after_cast_close_parenthesis = false +cpp_space_within_expression_parentheses = false +cpp_space_before_block_open_brace = true +cpp_space_between_empty_braces = false +cpp_space_before_initializer_list_open_brace = true +cpp_space_within_initializer_list_braces = true +cpp_space_preserve_in_initializer_list = true +cpp_space_before_open_square_bracket = false +cpp_space_within_square_brackets = false +cpp_space_before_empty_square_brackets = false +cpp_space_between_empty_square_brackets = false +cpp_space_group_square_brackets = true +cpp_space_within_lambda_brackets = false +cpp_space_between_empty_lambda_brackets = false +cpp_space_before_comma = false +cpp_space_after_comma = true +cpp_space_remove_around_member_operators = true +cpp_space_before_inheritance_colon = true +cpp_space_before_constructor_colon = true +cpp_space_remove_before_semicolon = true +cpp_space_after_semicolon = true +cpp_space_remove_around_unary_operator = true +cpp_space_around_binary_operator = insert +cpp_space_around_assignment_operator = insert +cpp_space_pointer_reference_alignment = left +cpp_space_around_ternary_operator = insert +cpp_wrap_preserve_blocks = one_liners diff --git a/Unvirt/CmdHelper.hpp b/Unvirt/CmdHelper.hpp index a7a0709..a45be12 100644 --- a/Unvirt/CmdHelper.hpp +++ b/Unvirt/CmdHelper.hpp @@ -148,12 +148,12 @@ namespace Unvirt::CmdHelper { friend class Literal; friend class AbstractArgument; public: - using vType = int32_t; + using vType = size_t; Choice(const char* argname, const std::initializer_list& vocabulary); virtual ~Choice(); LIBCMO_DISABLE_COPY_MOVE(Choice); - size_t* GetIndex(); + vType* GetIndex(); public: virtual NodeType GetNodeType() override; @@ -260,9 +260,9 @@ namespace Unvirt::CmdHelper { AbstractNode* node = finder->second; switch (node->GetNodeType()) { case NodeType::Argument: - return dynamic_cast(node)->GetData<_Ty*>(); + return reinterpret_cast<_Ty*>(dynamic_cast(node)->GetData<_Ty*>()); case NodeType::Choice: - return dynamic_cast(node)->GetIndex(); + return reinterpret_cast<_Ty*>(dynamic_cast(node)->GetIndex()); case NodeType::Literal: default: throw std::runtime_error("No such argument type."); diff --git a/Unvirt/StructFormatter.cpp b/Unvirt/StructFormatter.cpp index a8cfb70..8684b14 100644 --- a/Unvirt/StructFormatter.cpp +++ b/Unvirt/StructFormatter.cpp @@ -17,7 +17,7 @@ namespace Unvirt::StructFormatter { (fileinfo.CKVersion >> 0) & 0xFFFF ); - LibCmo::CK2::CKDWORD product_series[4]{ + LibCmo::CK2::CKDWORD product_series[4] { (fileinfo.ProductBuild >> 24) & 0xFF, (fileinfo.ProductBuild >> 16) & 0xFF, (fileinfo.ProductBuild >> 8) & 0xFF, @@ -127,4 +127,14 @@ namespace Unvirt::StructFormatter { fprintf(fout, "Page %zu of %zu\n", page + 1, fullpage + 1); } + void PrintCKObject(const LibCmo::CK2::ObjImpls::CKObject*) { + fputs(UNVIRT_TERMCOL_MAGENTA(("NO IMPLEMENTS\n")), fout); + } + void PrintCKBaseManager(const LibCmo::CK2::MgrImpls::CKBaseManager*) { + fputs(UNVIRT_TERMCOL_MAGENTA(("NO IMPLEMENTS\n")), fout); + } + void PrintCKStateChunk(const LibCmo::CK2::CKStateChunk*) { + fputs(UNVIRT_TERMCOL_MAGENTA(("NO IMPLEMENTS\n")), fout); + } + } diff --git a/Unvirt/StructFormatter.hpp b/Unvirt/StructFormatter.hpp index f1fd4a2..d225016 100644 --- a/Unvirt/StructFormatter.hpp +++ b/Unvirt/StructFormatter.hpp @@ -8,5 +8,8 @@ namespace Unvirt::StructFormatter { void PrintCKFileInfo(const LibCmo::CK2::CKFileInfo& fileinfo); void PrintObjectList(const LibCmo::XContainer::XArray& ls, size_t page, size_t pageitems); void PrintManagerList(const LibCmo::XContainer::XArray& ls, size_t page, size_t pageitems); + void PrintCKObject(const LibCmo::CK2::ObjImpls::CKObject*); + void PrintCKBaseManager(const LibCmo::CK2::MgrImpls::CKBaseManager*); + void PrintCKStateChunk(const LibCmo::CK2::CKStateChunk*); } diff --git a/Unvirt/Unvirt.cpp b/Unvirt/Unvirt.cpp index d24f15b..398d08a 100644 --- a/Unvirt/Unvirt.cpp +++ b/Unvirt/Unvirt.cpp @@ -12,7 +12,7 @@ int main(int argc, char* argv[]) { //if (doc) // Unvirt::StructFormatter::PrintCKFileInfo(doc->m_FileInfo); - Unvirt::UnvirtContext ctx; + Unvirt::Context::UnvirtContext ctx; ctx.Run(); return 0; diff --git a/Unvirt/UnvirtContext.cpp b/Unvirt/UnvirtContext.cpp index 0ba2c91..ce7112a 100644 --- a/Unvirt/UnvirtContext.cpp +++ b/Unvirt/UnvirtContext.cpp @@ -18,61 +18,107 @@ namespace Unvirt::Context { // create command root CmdHelper::CommandRoot* root = &m_Root; - root->Then( - (new CmdHelper::Literal("deepload")) - ->Then((new CmdHelper::StringArgument("filepath")) - ->Comment("The path to loading file.") - ->Executes( - std::bind(&UnvirtContext::ProcLoad, this, true, std::placeholders::_1), - "Load a Virtools composition deeply. Load file to CKObject stage." - ) - ) - ); - root->Then( - (new CmdHelper::Literal("shallowload"))->Then( - (new CmdHelper::StringArgument("filepath", "The path to loading file."))->Executes( - std::bind(&UnvirtContext::ProcLoad, this, false, std::placeholders::_1), - "Load a Virtools composition shallowly. Load file to CKStateChunk stage." - ) - ) - ); - root->Then( - (new CmdHelper::Literal("unload"))->Executes( - std::bind(&UnvirtContext::ProcUnLoad, this, std::placeholders::_1), - "Release loaded Virtools composition." - ) - ); - root->Then( - (new CmdHelper::Literal("info"))->Executes( - std::bind(&UnvirtContext::ProcInfo, this, std::placeholders::_1), - "Show the header info of loaded Virtools composition." - ) - ); - - - root->Then( - (new CmdHelper::Literal("foo"))->Then( - (new CmdHelper::Literal("bar"))->Executes([](const CmdHelper::ArgumentsMap& amap) -> void { - fprintf(stdout, "foobar!\n"); - }, "simple foobar") - )->Then( - (new CmdHelper::IntArgument("bar", "the calling target 1"))->Executes([](const CmdHelper::ArgumentsMap& amap) -> void { - fprintf(stdout, "foo%" PRIi32 "!\n", *(amap.Get("bar")->GetData())); - }, "specialized foo bar") - ) - )->Then( - (new CmdHelper::Literal("call"))->Then( - (new CmdHelper::IntArgument("bar", "the calling taget 2"))->Executes([](const CmdHelper::ArgumentsMap& amap) -> void { - fprintf(stdout, "call%" PRIi32 "!\n", *(amap.Get("bar")->GetData())); - }, "calling someone") + root + ->Then((new CmdHelper::Literal("load")) + ->Then((new CmdHelper::Choice("stage", { "deep", "shallow"})) + ->Comment("The stage of loading. 'deep' will load to CKObject stage. 'shallow' will load to CKStateChunk stage.") + ->Then((new CmdHelper::StringArgument("filepath")) + ->Comment("The path to loading file.") + ->Executes( + std::bind(&UnvirtContext::ProcLoad, this, std::placeholders::_1), + "Load a Virtools composition deeply." + ) ) - ); - // create help - m_Help = root->RootHelp(); + ) + ) + ->Then((new CmdHelper::Literal("unload")) + ->Executes( + std::bind(&UnvirtContext::ProcUnLoad, this, std::placeholders::_1), + "Release loaded Virtools composition." + ) + ) + ->Then((new CmdHelper::Literal("info")) + ->Executes( + std::bind(&UnvirtContext::ProcInfo, this, std::placeholders::_1), + "Show the header info of loaded Virtools composition." + ) + ) + ->Then((new CmdHelper::Literal("ls")) + ->Then((new CmdHelper::Choice("part", { "obj", "mgr"})) + ->Comment("Which list you want to list.") + ->Then((new CmdHelper::IntArgument("page", [](int32_t v) -> bool { return v > 0; })) + ->Comment("The page index. Start with 1.") + ->Executes( + std::bind(&UnvirtContext::ProcLs, this, std::placeholders::_1), + "List something about loaded Virtools composition." + ) + ) + ) + ) + ->Then((new CmdHelper::Literal("data")) + ->Then((new CmdHelper::Choice("part", { "obj", "mgr"})) + ->Comment("Which list you want to show data.") + ->Then((new CmdHelper::IntArgument("index", [](int32_t v) -> bool { return v >= 0; })) + ->Comment("The index. Start with 0.") + ->Executes( + std::bind(&UnvirtContext::ProcData, this, std::placeholders::_1), + "Show the specific CKObject / CKBaseManager data." + ) + ) + ) + ) + ->Then((new CmdHelper::Literal("chunk")) + ->Then((new CmdHelper::Choice("part", { "obj", "mgr"})) + ->Comment("Which list you want to show chunk.") + ->Then((new CmdHelper::IntArgument("index", [](int32_t v) -> bool { return v >= 0; })) + ->Comment("The index. Start with 0.") + ->Executes( + std::bind(&UnvirtContext::ProcChunk, this, std::placeholders::_1), + "Show the specific CKStateChunk data." + ) + ) + ) + ) + ->Then((new CmdHelper::Literal("items")) + ->Then((new CmdHelper::IntArgument("count", [](int32_t v) -> bool { return v > 0; })) + ->Comment("The count of items you want to show in one page.") + ->Executes( + std::bind(&UnvirtContext::ProcItems, this, std::placeholders::_1), + "Set up how many items should be listed in one page when using 'ls' command." + ) + ) + ) + ->Then((new CmdHelper::Literal("encoding")) + ->Then((new CmdHelper::EncodingArgument("enc")) + ->Comment("CKContext used encoding splitted by ','. Support mutiple encoding.") + ->Executes( + std::bind(&UnvirtContext::ProcEncoding, this, std::placeholders::_1), + "Set the encoding series for CKContext." + ) + ) + ) + ->Then((new CmdHelper::Literal("temp")) + ->Then((new CmdHelper::StringArgument("temppath")) + ->Comment("The path to Temp folder.") + ->Executes( + std::bind(&UnvirtContext::ProcTemp, this, std::placeholders::_1), + "Set the Temp path for CKContext." + ) + ) + ) + ->Then((new CmdHelper::Literal("temp")) + ->Executes( + std::bind(&UnvirtContext::ProcExit, this, std::placeholders::_1), + "Exit program." + ) + ); - // create context - m_Ctx = new LibCmo::CK2::CKContext(); - m_Ctx->SetOutputCallback(std::bind(&UnvirtContext::PrintContextMsg, this, std::placeholders::_1)); + // create help + m_Help = root->RootHelp(); + + // create context + m_Ctx = new LibCmo::CK2::CKContext(); + m_Ctx->SetOutputCallback(std::bind(&UnvirtContext::PrintContextMsg, this, std::placeholders::_1)); } UnvirtContext::~UnvirtContext() { @@ -167,7 +213,7 @@ namespace Unvirt::Context { } } - void UnvirtContext::ProcUnLoad(const CmdHelper::ArgumentsMap* amap) { + void UnvirtContext::ProcUnLoad(const CmdHelper::ArgumentsMap*) { // check pre-requirement if (!HasOpenedFile()) { this->PrintCommonError("No loaded file."); @@ -178,7 +224,7 @@ namespace Unvirt::Context { ClearDocument(); } - void UnvirtContext::ProcInfo(const CmdHelper::ArgumentsMap* amap) { + void UnvirtContext::ProcInfo(const CmdHelper::ArgumentsMap*) { // check pre-requirement if (!HasOpenedFile()) { PrintCommonError("No loaded file."); @@ -196,17 +242,12 @@ namespace Unvirt::Context { return; } - // check requirement - int32_t gotten_page = *amap.Get("page")->GetData(); - if (gotten_page <= 0) { - PrintCommonError("Page out of range."); - return; - } - size_t page = static_cast(gotten_page) - 1; + // get page + size_t page = *amap->Get("page") - 1; // show list - switch (parts) { - case ViewPart::Objects: + switch (*amap->Get("part")) { + case 0: { // obj list if (page * m_PageLen >= m_FileReader->GetFileObjects().size()) { @@ -217,7 +258,7 @@ namespace Unvirt::Context { Unvirt::StructFormatter::PrintObjectList(m_FileReader->GetFileObjects(), page, this->m_PageLen); break; } - case ViewPart::Managers: + case 1: { // mgr list if (page * m_PageLen >= m_FileReader->GetManagersData().size()) { @@ -232,38 +273,87 @@ namespace Unvirt::Context { } void UnvirtContext::ProcData( const CmdHelper::ArgumentsMap* amap) { - - } - - void UnvirtContext::ProcChunk(const CmdHelper::ArgumentsMap* amap) { - - } - - void UnvirtContext::ProcItems(const CmdHelper::ArgumentsMap* amap) { - // check requirement - int32_t count = *amap.Get("count")->GetData(); - if (count <= 0) { - PrintCommonError("Value out of range."); + // check pre-requirement + if (!HasOpenedFile()) { + this->PrintCommonError("No loaded file."); return; } + // get index + size_t index = *amap->Get("index"); + + // show data + switch (*amap->Get("part")) { + case 0: + { + if (index >= m_FileReader->GetFileObjects().size()) { + PrintCommonError("Index out of range."); + return; + } + Unvirt::StructFormatter::PrintCKObject(m_FileReader->GetFileObjects()[index].ObjPtr); + break; + } + case 1: + { + if (index >= m_FileReader->GetManagersData().size()) { + PrintCommonError("Index out of range."); + return; + } + //Unvirt::StructFormatter::PrintCKBaseManager(m_FileReader->GetManagersData()[index].Data); + break; + } + } + } + + void UnvirtContext::ProcChunk(const CmdHelper::ArgumentsMap* amap) { + // check pre-requirement + if (!HasOpenedFile()) { + this->PrintCommonError("No loaded file."); + return; + } + + // get index + size_t index = *amap->Get("index"); + + // show data + switch (*amap->Get("part")) { + case 0: + { + if (index >= m_FileReader->GetFileObjects().size()) { + PrintCommonError("Index out of range."); + return; + } + Unvirt::StructFormatter::PrintCKStateChunk(m_FileReader->GetFileObjects()[index].Data); + break; + } + case 1: + { + if (index >= m_FileReader->GetManagersData().size()) { + PrintCommonError("Index out of range."); + return; + } + Unvirt::StructFormatter::PrintCKStateChunk(m_FileReader->GetManagersData()[index].Data); + break; + } + } + } + + void UnvirtContext::ProcItems(const CmdHelper::ArgumentsMap* amap) { // assign - m_PageLen = static_cast(count); + m_PageLen = *amap->Get("count"); } void UnvirtContext::ProcEncoding(const CmdHelper::ArgumentsMap* amap) { - + const auto& encodings = *amap->Get("enc"); + m_Ctx->SetEncoding(encodings); } void UnvirtContext::ProcTemp(const CmdHelper::ArgumentsMap* amap) { - // check requirement - std::string temppath = *amap.Get("temppath")->GetData(); - // assign - m_Ctx->SetTempPath(temppath.c_str()); + m_Ctx->SetTempPath(amap->Get("temppath")->c_str()); } - void UnvirtContext::ProcExit(const CmdHelper::ArgumentsMap* amap) { + void UnvirtContext::ProcExit(const CmdHelper::ArgumentsMap*) { m_OrderExit = true; }