From 73a2c9f14a0bb4cdb9eb312572f76296f14288e9 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sun, 26 Sep 2021 15:10:49 +0800 Subject: [PATCH] Do some refactor works * Move CKParameter digger into shared_export * Update database for new database file * Rename some name for more readable experience --- .../SuperScriptMaterializer.vcxproj | 53 +-- .../SuperScriptMaterializer.vcxproj.filters | 390 +----------------- SuperScriptMaterializer/data_export.cpp | 2 + SuperScriptMaterializer/data_export.h | 9 + SuperScriptMaterializer/database.cpp | 390 ++++++++++-------- SuperScriptMaterializer/database.h | 196 ++++++--- SuperScriptMaterializer/env_export.cpp | 120 +++--- SuperScriptMaterializer/env_export.h | 4 +- SuperScriptMaterializer/script_export.cpp | 32 +- SuperScriptMaterializer/shared_export.cpp | 42 ++ SuperScriptMaterializer/shared_export.h | 31 ++ 11 files changed, 554 insertions(+), 715 deletions(-) create mode 100644 SuperScriptMaterializer/data_export.cpp create mode 100644 SuperScriptMaterializer/data_export.h create mode 100644 SuperScriptMaterializer/shared_export.cpp create mode 100644 SuperScriptMaterializer/shared_export.h diff --git a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj index 0755ec8..23634ee 100644 --- a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj +++ b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj @@ -1,4 +1,5 @@ - + + Debug @@ -15,12 +16,12 @@ SuperScriptMaterializer 10.0 - + v100 Dynamic MultiByte - Application + DynamicLibrary false @@ -28,20 +29,20 @@ true MultiByte Dynamic - Application + DynamicLibrary - + - + - + - + $(VIRTOOLS_OUTPUT_PATH) true @@ -107,27 +108,31 @@ - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + + + - + - + \ No newline at end of file diff --git a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.filters b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.filters index b8a05d0..672533e 100644 --- a/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.filters +++ b/SuperScriptMaterializer/SuperScriptMaterializer.vcxproj.filters @@ -33,240 +33,15 @@ 头文件 - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - 头文件 + + 头文件 + + + 头文件 + @@ -287,156 +62,15 @@ 源文件 - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - 源文件 + + 源文件 + + + 源文件 + diff --git a/SuperScriptMaterializer/data_export.cpp b/SuperScriptMaterializer/data_export.cpp new file mode 100644 index 0000000..e6f9e9f --- /dev/null +++ b/SuperScriptMaterializer/data_export.cpp @@ -0,0 +1,2 @@ +#include "data_export.h" + diff --git a/SuperScriptMaterializer/data_export.h b/SuperScriptMaterializer/data_export.h new file mode 100644 index 0000000..d1bbbb2 --- /dev/null +++ b/SuperScriptMaterializer/data_export.h @@ -0,0 +1,9 @@ +#if !defined(_YYCDLL_DATA_EXPORT_H__IMPORTED_) +#define _YYCDLL_DATA_EXPORT_H__IMPORTED_ + +#include "stdafx.h" +#include "database.h" + +void DigCKObjectData(CKObject* cko, scriptDatabase* db, db_shared_dictData* helper, EXPAND_CK_ID parents); + +#endif \ No newline at end of file diff --git a/SuperScriptMaterializer/database.cpp b/SuperScriptMaterializer/database.cpp index 46a5761..3397fa9 100644 --- a/SuperScriptMaterializer/database.cpp +++ b/SuperScriptMaterializer/database.cpp @@ -3,20 +3,20 @@ #pragma region helper void dbScriptDataStructHelper::init(CKParameterManager* paramManager) { - _dbCKBehavior = new dbCKBehavior(); - _dbCKScript = new dbCKScript(); - _db_pTarget = new db_pTarget(); - _db_pIn = new db_pIn(); - _db_pOut = new db_pOut(); - _db_bIn = new db_bIn(); - _db_bOut = new db_bOut(); - _db_bLink = new db_bLink(); - _db_pLocal = new db_pLocal(); - _db_pAttr = new db_pAttr(); - _db_pLink = new db_pLink(); - _db_pData = new db_pData(); - _db_pOper = new db_pOper(); - _db_eLink = new db_eLink(); + _db_behavior = new db_script_behavior(); + _db_script = new db_script_script(); + _db_pTarget = new db_script_pTarget(); + _db_pIn = new db_script_pIn(); + _db_pOut = new db_script_pOut(); + _db_bIn = new db_script_bIn(); + _db_bOut = new db_script_bOut(); + _db_bLink = new db_script_bLink(); + _db_pLocal = new db_script_pLocal(); + _db_pAttr = new db_script_pAttr(); + _db_pLink = new db_script_pLink(); + _db_pData = new db_script_pData(); + _db_pOper = new db_script_pOper(); + _db_eLink = new db_script_eLink(); _parameterManager = paramManager; _stringCache = (char*)malloc(STRINGCACHE_SIZE * sizeof(char)); @@ -25,8 +25,8 @@ void dbScriptDataStructHelper::init(CKParameterManager* paramManager) { } void dbScriptDataStructHelper::dispose() { - delete _dbCKBehavior; - delete _dbCKScript; + delete _db_behavior; + delete _db_script; delete _db_pTarget; delete _db_pIn; delete _db_pOut; @@ -44,13 +44,36 @@ void dbScriptDataStructHelper::dispose() { free(_stringCache); } +void dbDataDataStructHelper::init(CKParameterManager* paramManager) { + _db_obj = new db_data_obj(); + _db_objHeader = new db_data_objHeader(); + _db_objBody = new db_data_objBody(); + _db_objParam = new db_data_objParam(); + _db_msg = new db_data_msg(); + + _parameterManager = paramManager; + _stringCache = (char*)malloc(STRINGCACHE_SIZE * sizeof(char)); + if (_stringCache == NULL) + throw new std::bad_alloc(); +} + +void dbDataDataStructHelper::dispose() { + delete _db_obj; + delete _db_objHeader; + delete _db_objBody; + delete _db_objParam; + delete _db_msg; + + _parameterManager = NULL; + free(_stringCache); +} + void dbEnvDataStructHelper::init() { - _db_envOp = new db_envOp; - _db_envParam = new db_envParam; - _db_envMsg = new db_envMsg; - _db_envAttr = new db_envAttr; - _db_envPlugin = new db_envPlugin; - _db_envVariable = new db_envVariable; + _db_op = new db_env_op(); + _db_param = new db_env_param(); + _db_attr = new db_env_attr(); + _db_plugin = new db_env_plugin(); + _db_variable = new db_env_variable(); _stringCache = (char*)malloc(STRINGCACHE_SIZE * sizeof(char)); if (_stringCache == NULL) @@ -58,12 +81,11 @@ void dbEnvDataStructHelper::init() { } void dbEnvDataStructHelper::dispose() { - delete _db_envOp; - delete _db_envParam; - delete _db_envMsg; - delete _db_envAttr; - delete _db_envPlugin; - delete _db_envVariable; + delete _db_op; + delete _db_param; + delete _db_attr; + delete _db_plugin; + delete _db_variable; free(_stringCache); } @@ -75,15 +97,23 @@ void dbEnvDataStructHelper::dispose() { void database::open(const char* file) { db = NULL; - stmtCache = new std::vector(14, NULL); // TODO: sync with tryGetStmt's count + stmtCache = new std::vector(); //open db int result; result = sqlite3_open(file, &db); if (result != SQLITE_OK) goto fail; + // disable synchronous + result = sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); + if (result != SQLITE_OK) goto fail; + + // do some custom init if (!init()) goto fail; + //start job + sqlite3_exec(db, "begin;", NULL, NULL, NULL); + return; fail: db = NULL; @@ -92,6 +122,14 @@ fail: void database::close() { if (db == NULL) return; + //stop job + for (auto it = stmtCache->begin(); it != stmtCache->end(); it++) { + if (*it != NULL) + sqlite3_finalize(*it); + } + sqlite3_exec(db, "commit;", NULL, NULL, NULL); + + // do some custom job finalJob(); //release res @@ -100,91 +138,46 @@ void database::close() { delete stmtCache; } +sqlite3_stmt* database::safeStmt(size_t index) { + if (index >= stmtCache->size()) { + // need resize + stmtCache->resize(index + 1, NULL); + } +} + +#define createTable(sql) result=sqlite3_exec(db,sql,NULL,NULL,NULL);if(result!=SQLITE_OK)return FALSE; + BOOL scriptDatabase::init() { pAttrUniqueEnsurance = new std::set(); int result; - result = sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; //init table result = sqlite3_exec(db, "begin;", NULL, NULL, NULL); if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE script([thisobj] INTEGER, [name] TEXT, [index] INTEGER, [behavior] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE behavior([thisobj] INTEGER, [name] TEXT, [type] INTEGER, [proto_name] TEXT, [proto_guid] TEXT, [flags] INTEGER, [priority] INTEGER, [version] INTEGER, [pin_count] TEXT, [parent] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE pTarget([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE pIn([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE pOut([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE bIn([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [belong_to] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE bOut([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [belong_to] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE bLink([input] INTEGER, [output] INTEGER, [delay] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_index] INETEGR, [belong_to] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE pLocal([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [is_setting] INTEGER, [belong_to] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE pData([field] TEXT, [data] TEXT, [belong_to] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE pLink([input] INTEGER, [output] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_is_bb] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_is_bb] INTEGER, [output_index] INETEGR, [belong_to] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE pOper([thisobj] INTEGER, [op] TEXT, [op_guid] TEXT, [belong_to] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE eLink([export_obj] INTEGER, [internal_obj] INTEGER, [is_in] INTEGER, [index] INTEGER, [belong_to] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE pAttr([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; + createTable("CREATE TABLE script([thisobj] INTEGER, [name] TEXT, [index] INTEGER, [behavior] INTEGER);"); + createTable("CREATE TABLE behavior([thisobj] INTEGER, [name] TEXT, [type] INTEGER, [proto_name] TEXT, [proto_guid] TEXT, [flags] INTEGER, [priority] INTEGER, [version] INTEGER, [pin_count] TEXT, [parent] INTEGER);"); + createTable("CREATE TABLE pTarget([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);"); + createTable("CREATE TABLE pIn([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER, [direct_source] INTEGER, [shard_source] INTEGER);"); + createTable("CREATE TABLE pOut([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [belong_to] INTEGER);"); + createTable("CREATE TABLE bIn([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [belong_to] INTEGER);"); + createTable("CREATE TABLE bOut([thisobj] INTEGER, [index] INTEGER, [name] TEXT, [belong_to] INTEGER);"); + createTable("CREATE TABLE bLink([input] INTEGER, [output] INTEGER, [delay] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_index] INETEGR, [belong_to] INTEGER);"); + createTable("CREATE TABLE pLocal([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT, [is_setting] INTEGER, [belong_to] INTEGER);"); + createTable("CREATE TABLE pData([field] TEXT, [data] TEXT, [belong_to] INTEGER);"); + createTable("CREATE TABLE pLink([input] INTEGER, [output] INTEGER, [input_obj] INTEGER, [input_type] INTEGER, [input_is_bb] INTEGER, [input_index] INETEGR, [output_obj] INTEGER, [output_type] INTEGER, [output_is_bb] INTEGER, [output_index] INETEGR, [belong_to] INTEGER);"); + createTable("CREATE TABLE pOper([thisobj] INTEGER, [op] TEXT, [op_guid] TEXT, [belong_to] INTEGER);"); + createTable("CREATE TABLE eLink([export_obj] INTEGER, [internal_obj] INTEGER, [is_in] INTEGER, [index] INTEGER, [belong_to] INTEGER);"); + createTable("CREATE TABLE pAttr([thisobj] INTEGER, [name] TEXT, [type] TEXT, [type_guid] TEXT);"); result = sqlite3_exec(db, "commit;", NULL, NULL, NULL); if (result != SQLITE_OK) return FALSE; - //start job - sqlite3_exec(db, "begin;", NULL, NULL, NULL); - return TRUE; } BOOL scriptDatabase::finalJob() { - //stop job - for (auto it = stmtCache->begin(); it != stmtCache->end(); it++) { - if (*it != NULL) - sqlite3_finalize(*it); - } - sqlite3_exec(db, "commit;", NULL, NULL, NULL); - //create index for quick select in following app sqlite3_exec(db, "begin;", NULL, NULL, NULL); sqlite3_exec(db, "CREATE INDEX [quick_where1] ON behavior ([parent])", NULL, NULL, NULL); @@ -205,70 +198,63 @@ BOOL scriptDatabase::finalJob() { return TRUE; } -BOOL envDatabase::init() { - stmtCache = new std::vector(6, NULL); // TODO: sync with tryGetStmt's count - +BOOL dataDatabase::init() { int result; - result = sqlite3_exec(db, "PRAGMA synchronous = OFF;", NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; //init table result = sqlite3_exec(db, "begin;", NULL, NULL, NULL); if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE op([funcptr] INTEGER, [in1_guid] TEXT, [in2_guid] TEXT, [out_guid] TEXT, [op_guid] TEXT, [op_name] TEXT, [op_code] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE param([index] INTEGER, [guid] TEXT, [derived_from] TEXT, [type_name] TEXT, [default_size] INTEGER, [func_CreateDefault] INTEGER, [func_Delete] INTEGER, [func_SaveLoad] INTEGER, [func_Check] INTEGER, [func_Copy] INTEGER, [func_String] INTEGER, [func_UICreator] INTEGER, [creator_dll_index] INTEGER, [creator_plugin_index] INTEGER, [dw_param] INTEGER, [dw_flags] INTEGER, [cid] INTEGER, [saver_manager] TEXT);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE msg([index] INTEGER, [name] TEXT);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE attr([index] INTEGER, [name] TEXT, [category_index] INTEGER, [category_name] TEXT, [flags] INTEGER, [param_index] INTEGER, [compatible_classid] INTEGER, [default_value] TEXT);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE plugin([dll_index] INTEGER, [dll_name] TEXT, [plugin_index] INTEGER, [category] TEXT, [active] INTEGER, [needed_by_file] INTEGER, [guid] TEXT, [desc] TEXT, [author] TEXT, [summary] TEXT, [version] INTEGER, [func_init] INTEGER, [func_exit] INTEGER);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; - result = sqlite3_exec(db, - "CREATE TABLE [variable] ([name] TEXT, [description] TEXT, [flags] INTEGER, [type] INTEGER, [representation] TEXT, [data] TEXT);", - NULL, NULL, NULL); - if (result != SQLITE_OK) return FALSE; + createTable("CREATE TABLE obj([thisObj] INTEGER, [name] TEXT, [type_classid] INTEGER, [type_guid] TEXT, [type_name] TEXT, [rows] INTEGER, [columns] INTEGER);"); + createTable("CREATE TABLE objHeader([index] INTEGER, [name] TEXT, [type] INTEGER, [param_type] TEXT, [param_type_guid] TEXT, [belong_to] INTEGER);"); + createTable("CREATE TABLE objBody([row] INTEGER, [column] INTEGER, [showcase] TEXT, [inner_object] INTEGER, [inner_param] INTEGER, [belong_to] INTEGER);"); + createTable("CREATE TABLE objParam([field] TEXT, [data] TEXT, [belong_to] INTEGER);"); + createTable("CREATE TABLE msg([index] INTEGER, [name] TEXT);"); result = sqlite3_exec(db, "commit;", NULL, NULL, NULL); if (result != SQLITE_OK) return FALSE; - //start job - sqlite3_exec(db, "begin;", NULL, NULL, NULL); + return TRUE; +} + +BOOL dataDatabase::finalJob() { + return TRUE; +} + +BOOL envDatabase::init() { + + int result; + + //init table + result = sqlite3_exec(db, "begin;", NULL, NULL, NULL); + if (result != SQLITE_OK) return FALSE; + + createTable("CREATE TABLE op([funcptr] INTEGER, [in1_guid] TEXT, [in2_guid] TEXT, [out_guid] TEXT, [op_guid] TEXT, [op_name] TEXT, [op_code] INTEGER);"); + createTable("CREATE TABLE param([index] INTEGER, [guid] TEXT, [derived_from] TEXT, [type_name] TEXT, [default_size] INTEGER, [func_CreateDefault] INTEGER, [func_Delete] INTEGER, [func_SaveLoad] INTEGER, [func_Check] INTEGER, [func_Copy] INTEGER, [func_String] INTEGER, [func_UICreator] INTEGER, [creator_dll_index] INTEGER, [creator_plugin_index] INTEGER, [dw_param] INTEGER, [dw_flags] INTEGER, [cid] INTEGER, [saver_manager] TEXT);"); + createTable("CREATE TABLE attr([index] INTEGER, [name] TEXT, [category_index] INTEGER, [category_name] TEXT, [flags] INTEGER, [param_index] INTEGER, [compatible_classid] INTEGER, [default_value] TEXT);"); + createTable("CREATE TABLE plugin([dll_index] INTEGER, [dll_name] TEXT, [plugin_index] INTEGER, [category] TEXT, [active] INTEGER, [needed_by_file] INTEGER, [guid] TEXT, [desc] TEXT, [author] TEXT, [summary] TEXT, [version] INTEGER, [func_init] INTEGER, [func_exit] INTEGER);"); + createTable("CREATE TABLE [variable] ([name] TEXT, [description] TEXT, [flags] INTEGER, [type] INTEGER, [representation] TEXT, [data] TEXT);"); + + result = sqlite3_exec(db, "commit;", NULL, NULL, NULL); + if (result != SQLITE_OK) return FALSE; return TRUE; } BOOL envDatabase::finalJob() { - //stop job - for (auto it = stmtCache->begin(); it != stmtCache->end(); it++) { - if (*it != NULL) - sqlite3_finalize(*it); - } - sqlite3_exec(db, "commit;", NULL, NULL, NULL); - return TRUE; } +#undef createTable + #pragma endregion #pragma region write func -#define tryGetStmt(index,defaultStr) stmt=(*stmtCache)[index];if(stmt==NULL){sqlite3_prepare_v2(db,defaultStr,-1,&stmt,NULL);(*stmtCache)[index]=stmt;} +#define tryGetStmt(index,defaultStr) safeStmt(index);stmt=(*stmtCache)[index];if(stmt==NULL){sqlite3_prepare_v2(db,defaultStr,-1,&stmt,NULL);(*stmtCache)[index]=stmt;} -void scriptDatabase::write_CKBehavior(dbCKBehavior* data) { +void scriptDatabase::write_behavior(db_script_behavior* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -288,7 +274,7 @@ void scriptDatabase::write_CKBehavior(dbCKBehavior* data) { sqlite3_step(stmt); } -void scriptDatabase::write_CKScript(dbCKScript* data) { +void scriptDatabase::write_script(db_script_script* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -302,7 +288,7 @@ void scriptDatabase::write_CKScript(dbCKScript* data) { sqlite3_step(stmt); } -void scriptDatabase::write_pTarget(db_pTarget* data) { +void scriptDatabase::write_pTarget(db_script_pTarget* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -319,7 +305,7 @@ void scriptDatabase::write_pTarget(db_pTarget* data) { sqlite3_step(stmt); } -void scriptDatabase::write_pIn(db_pIn* data) { +void scriptDatabase::write_pIn(db_script_pIn* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -337,7 +323,7 @@ void scriptDatabase::write_pIn(db_pIn* data) { sqlite3_step(stmt); } -void scriptDatabase::write_pOut(db_pOut* data) { +void scriptDatabase::write_pOut(db_script_pOut* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -353,7 +339,7 @@ void scriptDatabase::write_pOut(db_pOut* data) { sqlite3_step(stmt); } -void scriptDatabase::write_bIn(db_bIn* data) { +void scriptDatabase::write_bIn(db_script_bIn* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -367,7 +353,7 @@ void scriptDatabase::write_bIn(db_bIn* data) { sqlite3_step(stmt); } -void scriptDatabase::write_bOut(db_bOut* data) { +void scriptDatabase::write_bOut(db_script_bOut* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -381,7 +367,7 @@ void scriptDatabase::write_bOut(db_bOut* data) { sqlite3_step(stmt); } -void scriptDatabase::write_bLink(db_bLink* data) { +void scriptDatabase::write_bLink(db_script_bLink* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -401,7 +387,7 @@ void scriptDatabase::write_bLink(db_bLink* data) { sqlite3_step(stmt); } -void scriptDatabase::write_pLocal(db_pLocal* data) { +void scriptDatabase::write_pLocal(db_script_pLocal* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -417,7 +403,7 @@ void scriptDatabase::write_pLocal(db_pLocal* data) { sqlite3_step(stmt); } -void scriptDatabase::write_pLink(db_pLink* data) { +void scriptDatabase::write_pLink(db_script_pLink* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -438,7 +424,7 @@ void scriptDatabase::write_pLink(db_pLink* data) { sqlite3_step(stmt); } -void scriptDatabase::write_pData(db_pData* data) { +void scriptDatabase::write_pData(db_script_pData* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -451,7 +437,7 @@ void scriptDatabase::write_pData(db_pData* data) { sqlite3_step(stmt); } -void scriptDatabase::write_pOper(db_pOper* data) { +void scriptDatabase::write_pOper(db_script_pOper* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -465,7 +451,7 @@ void scriptDatabase::write_pOper(db_pOper* data) { sqlite3_step(stmt); } -void scriptDatabase::write_eLink(db_eLink* data) { +void scriptDatabase::write_eLink(db_script_eLink* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -480,7 +466,7 @@ void scriptDatabase::write_eLink(db_eLink* data) { sqlite3_step(stmt); } -BOOL scriptDatabase::write_pAttr(db_pAttr* data) { +BOOL scriptDatabase::write_pAttr(db_script_pAttr* data) { if (db == NULL) return TRUE; if (pAttrUniqueEnsurance->find(data->thisobj) != pAttrUniqueEnsurance->end()) @@ -500,7 +486,83 @@ BOOL scriptDatabase::write_pAttr(db_pAttr* data) { return TRUE; } -void envDatabase::write_envOp(db_envOp* data) { + +void dataDatabase::write_obj(db_data_obj* data) { + if (db == NULL) return; + + sqlite3_stmt* stmt = NULL; + tryGetStmt(0, "INSERT INTO objParam VALUES (?, ?, ?)"); + sqlite3_reset(stmt); + + sqlite3_bind_int(stmt, 1, data->thisobj); + sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 3, data->type_classid); + sqlite3_bind_text(stmt, 4, data->type_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 5, data->type_name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 6, data->rows); + sqlite3_bind_int(stmt, 7, data->columns); + sqlite3_step(stmt); +} + +void dataDatabase::write_objHeader(db_data_objHeader* data) { + if (db == NULL) return; + + sqlite3_stmt* stmt = NULL; + tryGetStmt(1, "INSERT INTO objParam VALUES (?, ?, ?)"); + sqlite3_reset(stmt); + + sqlite3_bind_int(stmt, 1, data->index); + sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 3, data->type); + sqlite3_bind_text(stmt, 4, data->param_type.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 5, data->param_type_guid.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 6, data->belong_to); + sqlite3_step(stmt); +} + +void dataDatabase::write_objBody(db_data_objBody* data) { + if (db == NULL) return; + + sqlite3_stmt* stmt = NULL; + tryGetStmt(2, "INSERT INTO objParam VALUES (?, ?, ?)"); + sqlite3_reset(stmt); + + sqlite3_bind_int(stmt, 1, data->row); + sqlite3_bind_int(stmt, 2, data->column); + sqlite3_bind_text(stmt, 3, data->showcase.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 4, data->inner_object); + sqlite3_bind_int(stmt, 5, data->inner_param); + sqlite3_bind_int(stmt, 6, data->belong_to); + sqlite3_step(stmt); +} + +void dataDatabase::write_objParam(db_data_objParam* data) { + if (db == NULL) return; + + sqlite3_stmt* stmt = NULL; + tryGetStmt(3, "INSERT INTO objParam VALUES (?, ?, ?)"); + sqlite3_reset(stmt); + + sqlite3_bind_text(stmt, 1, data->field.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 2, data->data.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 3, data->belong_to); + sqlite3_step(stmt); +} + +void dataDatabase::write_msg(db_data_msg* data) { + if (db == NULL) return; + + sqlite3_stmt* stmt = NULL; + tryGetStmt(4, "INSERT INTO msg VALUES (?, ?)"); + sqlite3_reset(stmt); + + sqlite3_bind_int(stmt, 1, data->index); + sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_step(stmt); +} + + +void envDatabase::write_op(db_env_op* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -517,7 +579,7 @@ void envDatabase::write_envOp(db_envOp* data) { sqlite3_step(stmt); } -void envDatabase::write_envParam(db_envParam* data) { +void envDatabase::write_param(db_env_param* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; @@ -545,23 +607,11 @@ void envDatabase::write_envParam(db_envParam* data) { sqlite3_step(stmt); } -void envDatabase::write_envMsg(db_envMsg* data) { +void envDatabase::write_attr(db_env_attr* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(2, "INSERT INTO msg VALUES (?, ?)"); - sqlite3_reset(stmt); - - sqlite3_bind_int(stmt, 1, data->index); - sqlite3_bind_text(stmt, 2, data->name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_step(stmt); -} - -void envDatabase::write_envAttr(db_envAttr* data) { - if (db == NULL) return; - - sqlite3_stmt* stmt = NULL; - tryGetStmt(3, "INSERT INTO attr VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + tryGetStmt(2, "INSERT INTO attr VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); sqlite3_bind_int(stmt, 1, data->index); @@ -575,11 +625,11 @@ void envDatabase::write_envAttr(db_envAttr* data) { sqlite3_step(stmt); } -void envDatabase::write_envPlugin(db_envPlugin* data) { +void envDatabase::write_plugin(db_env_plugin* data) { if (db == NULL) return; sqlite3_stmt* stmt = NULL; - tryGetStmt(4, "INSERT INTO plugin VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + tryGetStmt(3, "INSERT INTO plugin VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); sqlite3_bind_int(stmt, 1, data->dll_index); @@ -598,12 +648,12 @@ void envDatabase::write_envPlugin(db_envPlugin* data) { sqlite3_step(stmt); } -void envDatabase::write_envVariable(db_envVariable* data) { +void envDatabase::write_variable(db_env_variable* data) { if (db == NULL) return; #if !defined(VIRTOOLS_21) sqlite3_stmt* stmt = NULL; - tryGetStmt(5, "INSERT INTO [variable] VALUES (?, ?, ?, ?, ?, ?)"); + tryGetStmt(4, "INSERT INTO [variable] VALUES (?, ?, ?, ?, ?, ?)"); sqlite3_reset(stmt); sqlite3_bind_text(stmt, 1, data->name.c_str(), -1, SQLITE_TRANSIENT); diff --git a/SuperScriptMaterializer/database.h b/SuperScriptMaterializer/database.h index b33a934..bd27a98 100644 --- a/SuperScriptMaterializer/database.h +++ b/SuperScriptMaterializer/database.h @@ -25,6 +25,8 @@ enum pLinkInputOutputType { #pragma region data struct define +// =================== script db + typedef struct { EXPAND_CK_ID thisobj; std::string name; @@ -37,14 +39,14 @@ typedef struct { //pTarget, pIn, pOut, bIn, bOut std::string pin_count; EXPAND_CK_ID parent; -}dbCKBehavior; +}db_script_behavior; typedef struct { EXPAND_CK_ID thisobj; std::string host_name; int index; EXPAND_CK_ID behavior; -}dbCKScript; +}db_script_script; typedef struct { EXPAND_CK_ID thisobj; @@ -54,7 +56,7 @@ typedef struct { EXPAND_CK_ID belong_to; EXPAND_CK_ID direct_source; EXPAND_CK_ID shared_source; -}db_pTarget; +}db_script_pTarget; typedef struct { EXPAND_CK_ID thisobj; @@ -65,7 +67,7 @@ typedef struct { EXPAND_CK_ID belong_to; EXPAND_CK_ID direct_source; EXPAND_CK_ID shared_source; -}db_pIn; +}db_script_pIn; typedef struct { EXPAND_CK_ID thisobj; @@ -74,16 +76,16 @@ typedef struct { std::string type; std::string type_guid; EXPAND_CK_ID belong_to; -}db_pOut; +}db_script_pOut; typedef struct { EXPAND_CK_ID thisobj; int index; std::string name; EXPAND_CK_ID belong_to; -}db_bIO; -typedef db_bIO db_bIn; -typedef db_bIO db_bOut; +}db_shared_bIO; +typedef db_shared_bIO db_script_bIn; +typedef db_shared_bIO db_script_bOut; typedef struct { EXPAND_CK_ID input; @@ -98,7 +100,7 @@ typedef struct { EXPAND_CK_ID output_obj; bLinkInputOutputType output_type; int output_index; -}db_bLink; +}db_script_bLink; typedef struct { EXPAND_CK_ID thisobj; @@ -107,20 +109,21 @@ typedef struct { std::string type_guid; BOOL is_setting; EXPAND_CK_ID belong_to; -}db_pLocal; +}db_script_pLocal; typedef struct { EXPAND_CK_ID thisobj; std::string name; std::string type; std::string type_guid; -}db_pAttr; +}db_script_pAttr; typedef struct { std::string field; std::string data; EXPAND_CK_ID belong_to; -}db_pData; +}db_shared_dictData; +typedef db_shared_dictData db_script_pData; typedef struct { EXPAND_CK_ID input; @@ -136,14 +139,14 @@ typedef struct { pLinkInputOutputType output_type; BOOL output_is_bb; int output_index; -}db_pLink; +}db_script_pLink; typedef struct { EXPAND_CK_ID thisobj; std::string op; std::string op_guid; EXPAND_CK_ID belong_to; -}db_pOper; +}db_script_pOper; typedef struct { EXPAND_CK_ID export_obj; @@ -151,9 +154,47 @@ typedef struct { BOOL is_in; int index; EXPAND_CK_ID belong_to; -}db_eLink; +}db_script_eLink; +// =================== data db + +typedef struct { + EXPAND_CK_ID thisobj; + std::string name; + CK_CLASSID type_classid; + std::string type_guid; + std::string type_name; + int rows; + int columns; +}db_data_obj; + +typedef struct { + int index; + std::string name; + CK_ARRAYTYPE type; + std::string param_type; + std::string param_type_guid; + EXPAND_CK_ID belong_to; +}db_data_objHeader; + +typedef struct { + int row; + int column; + std::string showcase; + EXPAND_CK_ID inner_object; + EXPAND_CK_ID inner_param; + EXPAND_CK_ID belong_to; +}db_data_objBody; + +typedef db_shared_dictData db_data_objParam; + +typedef struct { + CKMessageType index; + std::string name; +}db_data_msg; + +// =================== env db typedef struct { CK_PARAMETEROPERATION funcPtr; @@ -163,7 +204,7 @@ typedef struct { std::string op_guid; std::string op_name; CKOperationType op_code; -}db_envOp; +}db_env_op; typedef struct { CKParameterType index; @@ -184,12 +225,7 @@ typedef struct { CKDWORD dw_flags; CKDWORD cid; std::string saver_manager; -}db_envParam; - -typedef struct { - CKMessageType index; - std::string name; -}db_envMsg; +}db_env_param; typedef struct { CKAttributeType index; @@ -200,7 +236,7 @@ typedef struct { CKParameterType param_index; CK_CLASSID compatible_classid; std::string default_value; -}db_envAttr; +}db_env_attr; typedef struct { int dll_index; @@ -216,7 +252,7 @@ typedef struct { DWORD version; CK_INITINSTANCEFCT func_init; CK_EXITINSTANCEFCT func_exit; -}db_envPlugin; +}db_env_plugin; typedef struct { std::string name; @@ -225,7 +261,7 @@ typedef struct { UNIVERSAL_VAR_TYPE type; std::string representation; std::string data; -}db_envVariable; +}db_env_variable; #pragma endregion @@ -236,20 +272,35 @@ class dbScriptDataStructHelper { char* _stringCache; CKParameterManager* _parameterManager; - dbCKBehavior* _dbCKBehavior; - dbCKScript* _dbCKScript; - db_pTarget* _db_pTarget; - db_pIn* _db_pIn; - db_pOut* _db_pOut; - db_bIn* _db_bIn; - db_bOut* _db_bOut; - db_bLink* _db_bLink; - db_pLocal* _db_pLocal; - db_pAttr* _db_pAttr; - db_pLink* _db_pLink; - db_pData* _db_pData; - db_pOper* _db_pOper; - db_eLink* _db_eLink; + db_script_behavior* _db_behavior; + db_script_script* _db_script; + db_script_pTarget* _db_pTarget; + db_script_pIn* _db_pIn; + db_script_pOut* _db_pOut; + db_script_bIn* _db_bIn; + db_script_bOut* _db_bOut; + db_script_bLink* _db_bLink; + db_script_pLocal* _db_pLocal; + db_script_pAttr* _db_pAttr; + db_script_pLink* _db_pLink; + db_script_pData* _db_pData; + db_script_pOper* _db_pOper; + db_script_eLink* _db_eLink; +}; + +class dbDataDataStructHelper { +public: + void init(CKParameterManager* paramManager); + void dispose(); + + char* _stringCache; + CKParameterManager* _parameterManager; + db_data_obj* _db_obj; + db_data_objHeader* _db_objHeader; + db_data_objBody* _db_objBody; + db_data_objParam* _db_objParam; + db_data_msg* _db_msg; + }; class dbEnvDataStructHelper { @@ -258,12 +309,12 @@ class dbEnvDataStructHelper { void dispose(); char* _stringCache; - db_envOp* _db_envOp; - db_envParam* _db_envParam; - db_envMsg* _db_envMsg; - db_envAttr* _db_envAttr; - db_envPlugin* _db_envPlugin; - db_envVariable* _db_envVariable; + db_env_op* _db_op; + db_env_param* _db_param; + //db_data_msg* _db_envMsg; + db_env_attr* _db_attr; + db_env_plugin* _db_plugin; + db_env_variable* _db_variable; }; @@ -273,6 +324,7 @@ class database { void close(); protected: + sqlite3_stmt* safeStmt(size_t index); virtual BOOL init() { return TRUE; } virtual BOOL finalJob() { return TRUE; } @@ -282,20 +334,20 @@ class database { class scriptDatabase : public database { public: - void write_CKBehavior(dbCKBehavior* data); - void write_CKScript(dbCKScript* data); - void write_pTarget(db_pTarget* data); - void write_pIn(db_pIn* data); - void write_pOut(db_pOut* data); - void write_bIn(db_bIn* data); - void write_bOut(db_bOut* data); - void write_bLink(db_bLink* data); - void write_pLocal(db_pLocal* data); - void write_pLink(db_pLink* data); - void write_pData(db_pData* data); - void write_pOper(db_pOper* data); - void write_eLink(db_eLink* data); - BOOL write_pAttr(db_pAttr* data); + void write_behavior(db_script_behavior* data); + void write_script(db_script_script* data); + void write_pTarget(db_script_pTarget* data); + void write_pIn(db_script_pIn* data); + void write_pOut(db_script_pOut* data); + void write_bIn(db_script_bIn* data); + void write_bOut(db_script_bOut* data); + void write_bLink(db_script_bLink* data); + void write_pLocal(db_script_pLocal* data); + void write_pLink(db_script_pLink* data); + void write_pData(db_script_pData* data); + void write_pOper(db_script_pOper* data); + void write_eLink(db_script_eLink* data); + BOOL write_pAttr(db_script_pAttr* data); protected: BOOL init(); @@ -304,14 +356,28 @@ class scriptDatabase : public database { std::set* pAttrUniqueEnsurance; }; +class dataDatabase : public database { +public: + void write_obj(db_data_obj* data); + void write_objHeader(db_data_objHeader* data); + void write_objBody(db_data_objBody* data); + void write_objParam(db_data_objParam* data); + void write_msg(db_data_msg* data); + +protected: + BOOL init(); + BOOL finalJob(); + +}; + class envDatabase : public database { public: - void write_envOp(db_envOp* data); - void write_envParam(db_envParam* data); - void write_envMsg(db_envMsg* data); - void write_envAttr(db_envAttr* data); - void write_envPlugin(db_envPlugin* data); - void write_envVariable(db_envVariable* data); + void write_op(db_env_op* data); + void write_param(db_env_param* data); + //void write_msg(db_data_msg* data); + void write_attr(db_env_attr* data); + void write_plugin(db_env_plugin* data); + void write_variable(db_env_variable* data); protected: BOOL init(); diff --git a/SuperScriptMaterializer/env_export.cpp b/SuperScriptMaterializer/env_export.cpp index fa88529..687ecc1 100644 --- a/SuperScriptMaterializer/env_export.cpp +++ b/SuperScriptMaterializer/env_export.cpp @@ -12,10 +12,10 @@ void IterateParameterOperation(CKParameterManager* parameterManager, envDatabase CKGUID _guid; for (int i = 0; i < count; i++) { //fill basic data - helper->_db_envOp->op_code = i; + helper->_db_op->op_code = i; _guid = parameterManager->OperationCodeToGuid(i); - copyGuid(_guid,helper->_db_envOp->op_guid); - helper->_db_envOp->op_name = parameterManager->OperationCodeToName(i); + copyGuid(_guid,helper->_db_op->op_guid); + helper->_db_op->op_name = parameterManager->OperationCodeToName(i); //allocate mem cacheListCount = parameterManager->GetAvailableOperationsDesc(_guid, NULL, NULL, NULL, NULL); @@ -27,12 +27,12 @@ void IterateParameterOperation(CKParameterManager* parameterManager, envDatabase parameterManager->GetAvailableOperationsDesc(_guid, NULL, NULL, NULL, opList); for (int j = 0; j < cacheListCount; j++) { - copyGuid(opList[j].P1Guid, helper->_db_envOp->in1_guid); - copyGuid(opList[j].P2Guid, helper->_db_envOp->in2_guid); - copyGuid(opList[j].ResGuid, helper->_db_envOp->out_guid); - helper->_db_envOp->funcPtr = opList[j].Fct; + copyGuid(opList[j].P1Guid, helper->_db_op->in1_guid); + copyGuid(opList[j].P2Guid, helper->_db_op->in2_guid); + copyGuid(opList[j].ResGuid, helper->_db_op->out_guid); + helper->_db_op->funcPtr = opList[j].Fct; - db->write_envOp(helper->_db_envOp); + db->write_op(helper->_db_op); } } if (opList != NULL) free(opList); @@ -45,32 +45,32 @@ void IterateParameter(CKParameterManager* parameterManager, envDatabase* db, dbE for (int i = 0; i < count; i++) { desc = parameterManager->GetParameterTypeDescription(i); - helper->_db_envParam->index = desc->Index; - copyGuid(desc->Guid, helper->_db_envParam->guid); - copyGuid(desc->DerivedFrom, helper->_db_envParam->derived_from); - helper->_db_envParam->type_name = desc->TypeName.CStr(); - helper->_db_envParam->default_size = desc->DefaultSize; - helper->_db_envParam->func_CreateDefault = desc->CreateDefaultFunction; - helper->_db_envParam->func_Delete = desc->DeleteFunction; - helper->_db_envParam->func_SaveLoad = desc->SaveLoadFunction; - helper->_db_envParam->func_Check = desc->CheckFunction; - helper->_db_envParam->func_Copy = desc->CopyFunction; - helper->_db_envParam->func_String = desc->StringFunction; - helper->_db_envParam->func_UICreator = desc->UICreatorFunction; + helper->_db_param->index = desc->Index; + copyGuid(desc->Guid, helper->_db_param->guid); + copyGuid(desc->DerivedFrom, helper->_db_param->derived_from); + helper->_db_param->type_name = desc->TypeName.CStr(); + helper->_db_param->default_size = desc->DefaultSize; + helper->_db_param->func_CreateDefault = desc->CreateDefaultFunction; + helper->_db_param->func_Delete = desc->DeleteFunction; + helper->_db_param->func_SaveLoad = desc->SaveLoadFunction; + helper->_db_param->func_Check = desc->CheckFunction; + helper->_db_param->func_Copy = desc->CopyFunction; + helper->_db_param->func_String = desc->StringFunction; + helper->_db_param->func_UICreator = desc->UICreatorFunction; CKPluginEntry* plgEntry = desc->CreatorDll; if (plgEntry != NULL) { - helper->_db_envParam->creator_dll_index = plgEntry->m_PluginDllIndex; - helper->_db_envParam->creator_plugin_index = plgEntry->m_PositionInDll; + helper->_db_param->creator_dll_index = plgEntry->m_PluginDllIndex; + helper->_db_param->creator_plugin_index = plgEntry->m_PositionInDll; } else { - helper->_db_envParam->creator_dll_index =-1; - helper->_db_envParam->creator_plugin_index =-1; + helper->_db_param->creator_dll_index =-1; + helper->_db_param->creator_plugin_index =-1; } - helper->_db_envParam->dw_param = desc->dwParam; - helper->_db_envParam->dw_flags = desc->dwFlags; - helper->_db_envParam->cid = desc->Cid; - copyGuid(desc->Saver_Manager, helper->_db_envParam->saver_manager); + helper->_db_param->dw_param = desc->dwParam; + helper->_db_param->dw_flags = desc->dwFlags; + helper->_db_param->cid = desc->Cid; + copyGuid(desc->Saver_Manager, helper->_db_param->saver_manager); - db->write_envParam(helper->_db_envParam); + db->write_param(helper->_db_param); } } @@ -80,48 +80,48 @@ void IterateMessage(CKMessageManager* msgManager, envDatabase* db, dbEnvDataStru helper->_db_envMsg->index = i; helper->_db_envMsg->name = msgManager->GetMessageTypeName(i); - db->write_envMsg(helper->_db_envMsg); + db->write_msg(helper->_db_envMsg); } } void IterateAttribute(CKAttributeManager* attrManager, envDatabase* db, dbEnvDataStructHelper* helper) { int count = attrManager->GetAttributeCount(); for (int i = 0; i < count; i++) { - helper->_db_envAttr->index = i; - helper->_db_envAttr->name = attrManager->GetAttributeNameByType(i); - helper->_db_envAttr->category_index = attrManager->GetAttributeCategoryIndex(i); - helper->_db_envAttr->category_name = attrManager->GetAttributeCategory(i) != NULL ? attrManager->GetAttributeCategory(i) : ""; - helper->_db_envAttr->flags = attrManager->GetAttributeFlags(i); - helper->_db_envAttr->param_index = attrManager->GetAttributeParameterType(i); - helper->_db_envAttr->compatible_classid = attrManager->GetAttributeCompatibleClassId(i); - helper->_db_envAttr->default_value = attrManager->GetAttributeDefaultValue(i) != NULL ? attrManager->GetAttributeDefaultValue(i) : ""; + helper->_db_attr->index = i; + helper->_db_attr->name = attrManager->GetAttributeNameByType(i); + helper->_db_attr->category_index = attrManager->GetAttributeCategoryIndex(i); + helper->_db_attr->category_name = attrManager->GetAttributeCategory(i) != NULL ? attrManager->GetAttributeCategory(i) : ""; + helper->_db_attr->flags = attrManager->GetAttributeFlags(i); + helper->_db_attr->param_index = attrManager->GetAttributeParameterType(i); + helper->_db_attr->compatible_classid = attrManager->GetAttributeCompatibleClassId(i); + helper->_db_attr->default_value = attrManager->GetAttributeDefaultValue(i) != NULL ? attrManager->GetAttributeDefaultValue(i) : ""; - db->write_envAttr(helper->_db_envAttr); + db->write_attr(helper->_db_attr); } } void IteratePlugin(CKPluginManager* plgManager, envDatabase* db, dbEnvDataStructHelper* helper) { for (int i = 0; i <= 7; i++) { int catCount = plgManager->GetPluginCount(i); - helper->_db_envPlugin->category = plgManager->GetCategoryName(i); + helper->_db_plugin->category = plgManager->GetCategoryName(i); for (int j = 0; j < catCount; j++) { CKPluginEntry* plgEntry = plgManager->GetPluginInfo(i, j); - helper->_db_envPlugin->dll_index = plgEntry->m_PluginDllIndex; - helper->_db_envPlugin->dll_name = plgManager->GetPluginDllInfo(plgEntry->m_PluginDllIndex)->m_DllFileName.CStr(); - helper->_db_envPlugin->plugin_index = plgEntry->m_PositionInDll; - helper->_db_envPlugin->active = plgEntry->m_Active; - helper->_db_envPlugin->needed_by_file = plgEntry->m_NeededByFile; + helper->_db_plugin->dll_index = plgEntry->m_PluginDllIndex; + helper->_db_plugin->dll_name = plgManager->GetPluginDllInfo(plgEntry->m_PluginDllIndex)->m_DllFileName.CStr(); + helper->_db_plugin->plugin_index = plgEntry->m_PositionInDll; + helper->_db_plugin->active = plgEntry->m_Active; + helper->_db_plugin->needed_by_file = plgEntry->m_NeededByFile; CKPluginInfo* plgInfo = &(plgEntry->m_PluginInfo); - copyGuid(plgInfo->m_GUID, helper->_db_envPlugin->guid); - helper->_db_envPlugin->desc = plgInfo->m_Description.CStr(); - helper->_db_envPlugin->author = plgInfo->m_Author.CStr(); - helper->_db_envPlugin->summary = plgInfo->m_Summary.CStr(); - helper->_db_envPlugin->version = plgInfo->m_Version; - helper->_db_envPlugin->func_init = plgInfo->m_InitInstanceFct; - helper->_db_envPlugin->func_exit = plgInfo->m_ExitInstanceFct; + copyGuid(plgInfo->m_GUID, helper->_db_plugin->guid); + helper->_db_plugin->desc = plgInfo->m_Description.CStr(); + helper->_db_plugin->author = plgInfo->m_Author.CStr(); + helper->_db_plugin->summary = plgInfo->m_Summary.CStr(); + helper->_db_plugin->version = plgInfo->m_Version; + helper->_db_plugin->func_init = plgInfo->m_InitInstanceFct; + helper->_db_plugin->func_exit = plgInfo->m_ExitInstanceFct; - db->write_envPlugin(helper->_db_envPlugin); + db->write_plugin(helper->_db_plugin); } } } @@ -133,15 +133,15 @@ void IterateVariable(CKVariableManager* varManager, envDatabase* db, dbEnvDataSt XString dataCopyCache; for (; !it.End(); it++) { varobj = it.GetVariable(); - helper->_db_envVariable->name = it.GetName(); - safeStringCopy(helper->_db_envVariable->desciption, varobj->GetDescription()); - helper->_db_envVariable->flags = varobj->GetFlags(); - helper->_db_envVariable->type = varobj->GetType(); - safeStringCopy(helper->_db_envVariable->representation, varobj->GetRepresentation()); + helper->_db_variable->name = it.GetName(); + safeStringCopy(helper->_db_variable->desciption, varobj->GetDescription()); + helper->_db_variable->flags = varobj->GetFlags(); + helper->_db_variable->type = varobj->GetType(); + safeStringCopy(helper->_db_variable->representation, varobj->GetRepresentation()); varobj->GetStringValue(dataCopyCache); - helper->_db_envVariable->data = dataCopyCache.CStr(); + helper->_db_variable->data = dataCopyCache.CStr(); - db->write_envVariable(helper->_db_envVariable); + db->write_variable(helper->_db_variable); } } #endif \ No newline at end of file diff --git a/SuperScriptMaterializer/env_export.h b/SuperScriptMaterializer/env_export.h index c43ecb6..9d31b0c 100644 --- a/SuperScriptMaterializer/env_export.h +++ b/SuperScriptMaterializer/env_export.h @@ -1,5 +1,5 @@ -#if !defined(_YYCDLL_HELP_EXPORT_H__IMPORTED_) -#define _YYCDLL_HELP_EXPORT_H__IMPORTED_ +#if !defined(_YYCDLL_ENV_EXPORT_H__IMPORTED_) +#define _YYCDLL_ENV_EXPORT_H__IMPORTED_ #include "stdafx.h" #include "database.h" diff --git a/SuperScriptMaterializer/script_export.cpp b/SuperScriptMaterializer/script_export.cpp index 0c8fc78..8123595 100644 --- a/SuperScriptMaterializer/script_export.cpp +++ b/SuperScriptMaterializer/script_export.cpp @@ -338,11 +338,11 @@ void IterateScript(CKContext* ctx, scriptDatabase* db, dbScriptDataStructHelper* //write script table beh = beobj->GetScript(j); - helper->_dbCKScript->thisobj = beobj->GetID(); - helper->_dbCKScript->host_name = beobj->GetName(); - helper->_dbCKScript->index = j; - helper->_dbCKScript->behavior = beh->GetID(); - db->write_CKScript(helper->_dbCKScript); + helper->_db_script->thisobj = beobj->GetID(); + helper->_db_script->host_name = beobj->GetName(); + helper->_db_script->index = j; + helper->_db_script->behavior = beh->GetID(); + db->write_script(helper->_db_script); //iterate script IterateBehavior(ctx, beh, db, helper, -1); @@ -352,23 +352,23 @@ void IterateScript(CKContext* ctx, scriptDatabase* db, dbScriptDataStructHelper* void IterateBehavior(CKContext* ctx, CKBehavior* bhv, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { //write self data - helper->_dbCKBehavior->thisobj = bhv->GetID(); - helper->_dbCKBehavior->name = bhv->GetName(); - helper->_dbCKBehavior->type = bhv->GetType(); - helper->_dbCKBehavior->proto_name = bhv->GetPrototypeName() ? bhv->GetPrototypeName() : ""; - copyGuid(bhv->GetPrototypeGuid(), helper->_dbCKBehavior->proto_guid); - helper->_dbCKBehavior->flags = bhv->GetFlags(); - helper->_dbCKBehavior->priority = bhv->GetPriority(); - helper->_dbCKBehavior->version = bhv->GetVersion(); - helper->_dbCKBehavior->parent = parents; + helper->_db_behavior->thisobj = bhv->GetID(); + helper->_db_behavior->name = bhv->GetName(); + helper->_db_behavior->type = bhv->GetType(); + helper->_db_behavior->proto_name = bhv->GetPrototypeName() ? bhv->GetPrototypeName() : ""; + copyGuid(bhv->GetPrototypeGuid(), helper->_db_behavior->proto_guid); + helper->_db_behavior->flags = bhv->GetFlags(); + helper->_db_behavior->priority = bhv->GetPriority(); + helper->_db_behavior->version = bhv->GetVersion(); + helper->_db_behavior->parent = parents; sprintf(helper->_stringCache, "%d,%d,%d,%d,%d", (bhv->IsUsingTarget() ? 1 : 0), bhv->GetInputParameterCount(), bhv->GetOutputParameterCount(), bhv->GetInputCount(), bhv->GetOutputCount()); - helper->_dbCKBehavior->pin_count = helper->_stringCache; - db->write_CKBehavior(helper->_dbCKBehavior); + helper->_db_behavior->pin_count = helper->_stringCache; + db->write_behavior(helper->_db_behavior); //write target if (bhv->IsUsingTarget()) diff --git a/SuperScriptMaterializer/shared_export.cpp b/SuperScriptMaterializer/shared_export.cpp new file mode 100644 index 0000000..cb4267d --- /dev/null +++ b/SuperScriptMaterializer/shared_export.cpp @@ -0,0 +1,42 @@ +#include "shared_export.h" + +combined_database::combined_database() : + db_script(NULL), + helper_script(NULL), + db_data(NULL), + helper_data(NULL) { + ; +} + +db_shared_dictData* combined_database::get_struct() { + if (helper_script != NULL) return helper_script->_db_pData; + if (helper_data != NULL) return helper_data->_db_objParam; + return NULL; +} + +char* combined_database::get_string_cache() { + if (helper_script != NULL) return helper_script->_stringCache; + if (helper_data != NULL) return helper_data->_stringCache; + return NULL; +} + +void combined_database::write_dict(db_shared_dictData* data) { + if (db_script != NULL) db_script->write_pData(data); + if (db_data != NULL) db_data->write_objParam(data); +} + +void DigParameterData(CKParameter* p, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents) { + combined_database cdb; + cdb.db_script = db; + cdb.helper_script = helper; + + DigParameterData(p, &cdb, parents); +} + +void DigParameterData(CKParameter* p, dataDatabase* db, dbDataDataStructHelper* helper, EXPAND_CK_ID parents) { + combined_database cdb; + cdb.db_data = db; + cdb.helper_data = helper; + + DigParameterData(p, &cdb, parents); +} diff --git a/SuperScriptMaterializer/shared_export.h b/SuperScriptMaterializer/shared_export.h new file mode 100644 index 0000000..d8272d3 --- /dev/null +++ b/SuperScriptMaterializer/shared_export.h @@ -0,0 +1,31 @@ +#if !defined(_YYCDLL_SHARED_EXPORT_H__IMPORTED_) +#define _YYCDLL_SHARED_EXPORT_H__IMPORTED_ + +#include "stdafx.h" +#include "database.h" + +class combined_database { +public: + combined_database(); + db_shared_dictData* get_struct(); + char* get_string_cache(); + void write_dict(db_shared_dictData* data); + + scriptDatabase* db_script; + dbScriptDataStructHelper* helper_script; + dataDatabase* db_data; + dbDataDataStructHelper* helper_data; +}; + +#define copyGuid(guid,str) sprintf(helper->_stringCache,"%d,%d",guid.d1,guid.d2);str=helper->_stringCache; +#define safeStringCopy(storage,str) storage=(str)?(str):""; + +void DigParameterData(CKParameter* p, combined_database* helper, EXPAND_CK_ID parents); +void DigParameterData(CKParameter* p, scriptDatabase* db, dbScriptDataStructHelper* helper, EXPAND_CK_ID parents); +void DigParameterData(CKParameter* p, dataDatabase* db, dbDataDataStructHelper* helper, EXPAND_CK_ID parents); + +void helper_FillStruct(const char* field, long data, db_shared_dictData* helper); +void helper_FillStruct(const char* field, float data, db_shared_dictData* helper); +void helper_FillStruct(const char* field, const char* data, db_shared_dictData* helper); + +#endif \ No newline at end of file