From a5174e935a0b1a417fc28d2c0c3a2cc9fd0ea708 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Sat, 25 Apr 2020 12:28:57 +0800 Subject: [PATCH] add full env export and add icon for viewer --- SuperScriptMaterializer/database.cpp | 73 ++++++++++++++++++++- SuperScriptMaterializer/database.h | 45 ++++++++++++- SuperScriptMaterializer/env_export.cpp | 61 ++++++++++++++++- SuperScriptMaterializer/env_export.h | 3 + SuperScriptMaterializer/vt_menu.cpp | 3 + SuperScriptViewer/CustomConfig.py | 7 ++ SuperScriptViewer/DecoratorCore.py | 13 ++-- SuperScriptViewer/ServerCore.py | 6 +- SuperScriptViewer/SuperScriptViewer.py | 35 ++++++++-- SuperScriptViewer/SuperScriptViewer.pyproj | 3 + SuperScriptViewer/static/icon.png | Bin 0 -> 1785 bytes SuperScriptViewer/templates/about.html | 4 +- 12 files changed, 233 insertions(+), 20 deletions(-) create mode 100644 SuperScriptViewer/CustomConfig.py create mode 100644 SuperScriptViewer/static/icon.png diff --git a/SuperScriptMaterializer/database.cpp b/SuperScriptMaterializer/database.cpp index 0bcd7a0..b715c73 100644 --- a/SuperScriptMaterializer/database.cpp +++ b/SuperScriptMaterializer/database.cpp @@ -39,11 +39,17 @@ void dbScriptDataStructHelper::dispose() { 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; } void dbEnvDataStructHelper::dispose() { delete _db_envOp; delete _db_envParam; + delete _db_envMsg; + delete _db_envAttr; + delete _db_envPlugin; } #pragma endregion @@ -181,7 +187,19 @@ BOOL envDatabase::init() { NULL, NULL, &errmsg); 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_plugin_id] INTEGER, [dw_param] INTEGER, [dw_flags] INTEGER, [cid] INTEGER, [saver_manager] TEXT);", + "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, &errmsg); + if (result != SQLITE_OK) return FALSE; + result = sqlite3_exec(db, + "CREATE TABLE msg([index] INTEGER, [name] TEXT);", + NULL, NULL, &errmsg); + 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, &errmsg); + 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, &errmsg); if (result != SQLITE_OK) return FALSE; @@ -419,7 +437,7 @@ void envDatabase::write_envOp(db_envOp* data) { void envDatabase::write_envParam(db_envParam* data) { if (db == NULL) return; - sprintf(commandStr, "INSERT INTO param VALUES (%d, '%d,%d', '%d,%d', '%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, '%d,%d');", + sprintf(commandStr, "INSERT INTO param VALUES (%d, '%d,%d', '%d,%d', '%s', %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, '%d,%d');", data->index, data->guid[0], data->guid[1], @@ -434,7 +452,8 @@ void envDatabase::write_envParam(db_envParam* data) { data->func_Copy, data->func_String, data->func_UICreator, - data->creator_plugin_id, + data->creator_dll_index, + data->creator_plugin_index, data->dw_param, data->dw_flags, data->cid, @@ -444,5 +463,53 @@ void envDatabase::write_envParam(db_envParam* data) { sqlite3_exec(db, commandStr, NULL, NULL, &errmsg); } +void envDatabase::write_envMsg(db_envMsg* data) { + if (db == NULL) return; + + sprintf(commandStr, "INSERT INTO msg VALUES (%d, '%s');", + data->index, + data->name); + + sqlite3_exec(db, commandStr, NULL, NULL, &errmsg); +} + +void envDatabase::write_envAttr(db_envAttr* data) { + if (db == NULL) return; + + sprintf(commandStr, "INSERT INTO attr VALUES (%d, '%s', %d, '%s', %d, %d, %d, '%s');", + data->index, + data->name, + data->category_index, + data->category_name, + data->flags, + data->param_index, + data->compatible_classid, + data->default_value); + + sqlite3_exec(db, commandStr, NULL, NULL, &errmsg); +} + +void envDatabase::write_envPlugin(db_envPlugin* data) { + if (db == NULL) return; + + sprintf(commandStr, "INSERT INTO plugin VALUES (%d, '%s', %d, '%s', %d, %d, '%d,%d', '%s', '%s', '%s', %d, %d, %d);", + data->dll_index, + data->dll_name, + data->plugin_index, + data->category, + data->active, + data->needed_by_file, + data->guid[0], + data->guid[1], + data->desc, + data->author, + data->summary, + data->version, + data->func_init, + data->func_exit); + + sqlite3_exec(db, commandStr, NULL, NULL, &errmsg); +} + #pragma endregion diff --git a/SuperScriptMaterializer/database.h b/SuperScriptMaterializer/database.h index caa0d08..250235b 100644 --- a/SuperScriptMaterializer/database.h +++ b/SuperScriptMaterializer/database.h @@ -4,8 +4,6 @@ #include #include "stdafx.h" -#pragma region data struct define - typedef long EXPAND_CK_ID; enum bLinkInputOutputType { bLinkInputOutputType_INPUT, @@ -18,6 +16,8 @@ enum pLinkInputOutputType { pLinkInputOutputType_PTARGET //when using pTarget, omit [index] and [input_is_bb] }; +#pragma region data struct define + typedef struct { EXPAND_CK_ID thisobj; char name[1024]; @@ -164,13 +164,46 @@ typedef struct { CK_PARAMETERCOPYFUNCTION func_Copy; CK_PARAMETERSTRINGFUNCTION func_String; CK_PARAMETERUICREATORFUNCTION func_UICreator; - int creator_plugin_id; + int creator_dll_index; + int creator_plugin_index; CKDWORD dw_param; CKDWORD dw_flags; CKDWORD cid; CKDWORD saver_manager[2]; }db_envParam; +typedef struct { + CKMessageType index; + char name[1024]; +}db_envMsg; + +typedef struct { + CKAttributeType index; + char name[1024]; + CKAttributeCategory category_index; + char category_name[1024]; + CK_ATTRIBUT_FLAGS flags; + CKParameterType param_index; + CK_CLASSID compatible_classid; + char default_value[1024]; +}db_envAttr; + +typedef struct { + int dll_index; + char dll_name[1024]; + int plugin_index; + char category[1024]; + CKBOOL active; + CKBOOL needed_by_file; + CKDWORD guid[2]; + char desc[1024]; + char author[1024]; + char summary[1024]; + DWORD version; + CK_INITINSTANCEFCT func_init; + CK_EXITINSTANCEFCT func_exit; +}db_envPlugin; + #pragma endregion class dbScriptDataStructHelper { @@ -201,6 +234,9 @@ class dbEnvDataStructHelper { db_envOp* _db_envOp; db_envParam* _db_envParam; + db_envMsg* _db_envMsg; + db_envAttr* _db_envAttr; + db_envPlugin* _db_envPlugin; }; @@ -243,6 +279,9 @@ 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); protected: BOOL init(); diff --git a/SuperScriptMaterializer/env_export.cpp b/SuperScriptMaterializer/env_export.cpp index 44b9776..e7cc30f 100644 --- a/SuperScriptMaterializer/env_export.cpp +++ b/SuperScriptMaterializer/env_export.cpp @@ -54,7 +54,14 @@ void IterateParameter(CKParameterManager* parameterManager, envDatabase* db, dbE helper->_db_envParam->func_Copy = desc->CopyFunction; helper->_db_envParam->func_String = desc->StringFunction; helper->_db_envParam->func_UICreator = desc->UICreatorFunction; - helper->_db_envParam->creator_plugin_id = desc->CreatorDll != NULL ? desc->CreatorDll->m_PluginDllIndex : -1; + 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; + } else { + helper->_db_envParam->creator_dll_index =-1; + helper->_db_envParam->creator_plugin_index =-1; + } helper->_db_envParam->dw_param = desc->dwParam; helper->_db_envParam->dw_flags = desc->dwFlags; helper->_db_envParam->cid = desc->Cid; @@ -62,4 +69,56 @@ void IterateParameter(CKParameterManager* parameterManager, envDatabase* db, dbE db->write_envParam(helper->_db_envParam); } +} + +void IterateMessage(CKMessageManager* msgManager, envDatabase* db, dbEnvDataStructHelper* helper) { + int count = msgManager->GetMessageTypeCount(); + for (int i = 0; i < count; i++) { + helper->_db_envMsg->index = i; + strcpy(helper->_db_envMsg->name, msgManager->GetMessageTypeName(i)); + + db->write_envMsg(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; + strcpy(helper->_db_envAttr->name, attrManager->GetAttributeNameByType(i)); + helper->_db_envAttr->category_index = attrManager->GetAttributeCategoryIndex(i); + strcpy(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); + strcpy(helper->_db_envAttr->default_value, attrManager->GetAttributeDefaultValue(i) != NULL ? attrManager->GetAttributeDefaultValue(i) : ""); + + db->write_envAttr(helper->_db_envAttr); + } +} + +void IteratePlugin(CKPluginManager* plgManager, envDatabase* db, dbEnvDataStructHelper* helper) { + for (int i = 0; i <= 7; i++) { + int catCount = plgManager->GetPluginCount(i); + strcpy(helper->_db_envPlugin->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; + strcpy(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; + CKPluginInfo* plgInfo = &(plgEntry->m_PluginInfo); + cp_guid(helper->_db_envPlugin->guid, plgInfo->m_GUID); + strcpy(helper->_db_envPlugin->desc, plgInfo->m_Description.CStr()); + strcpy(helper->_db_envPlugin->author, plgInfo->m_Author.CStr()); + strcpy(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; + + db->write_envPlugin(helper->_db_envPlugin); + } + } } \ No newline at end of file diff --git a/SuperScriptMaterializer/env_export.h b/SuperScriptMaterializer/env_export.h index bb30a87..d39ce31 100644 --- a/SuperScriptMaterializer/env_export.h +++ b/SuperScriptMaterializer/env_export.h @@ -8,5 +8,8 @@ void IterateParameterOperation(CKParameterManager* parameterManager, envDatabase* db, dbEnvDataStructHelper* helper); void IterateParameter(CKParameterManager* parameterManager, envDatabase* db, dbEnvDataStructHelper* helper); +void IterateMessage(CKMessageManager* msgManager, envDatabase* db, dbEnvDataStructHelper* helper); +void IterateAttribute(CKAttributeManager* attrManager, envDatabase* db, dbEnvDataStructHelper* helper); +void IteratePlugin(CKPluginManager* plgManager, envDatabase* db, dbEnvDataStructHelper* helper); #endif \ No newline at end of file diff --git a/SuperScriptMaterializer/vt_menu.cpp b/SuperScriptMaterializer/vt_menu.cpp index ec8b4ec..ef35063 100644 --- a/SuperScriptMaterializer/vt_menu.cpp +++ b/SuperScriptMaterializer/vt_menu.cpp @@ -115,6 +115,9 @@ void PluginMenuCallback(int commandID) { //iterate parameter operation/param IterateParameterOperation(ctx->GetParameterManager(), _db, _helper); IterateParameter(ctx->GetParameterManager(), _db, _helper); + IterateMessage(ctx->GetMessageManager(), _db, _helper); + IterateAttribute(ctx->GetAttributeManager(), _db, _helper); + IteratePlugin(CKGetPluginManager(), _db, _helper); //release all _helper->dispose(); diff --git a/SuperScriptViewer/CustomConfig.py b/SuperScriptViewer/CustomConfig.py new file mode 100644 index 0000000..1bde382 --- /dev/null +++ b/SuperScriptViewer/CustomConfig.py @@ -0,0 +1,7 @@ +import locale + +database_encoding = locale.getpreferredencoding() +export_db = "export.db" +decorated_db = "decorate.db" +env_db = "env.db" +force_regenerate = False \ No newline at end of file diff --git a/SuperScriptViewer/DecoratorCore.py b/SuperScriptViewer/DecoratorCore.py index b0f3ef4..3159f9c 100644 --- a/SuperScriptViewer/DecoratorCore.py +++ b/SuperScriptViewer/DecoratorCore.py @@ -1,23 +1,25 @@ import sqlite3 import DecoratorConstValue as dcv import json -import locale +import CustomConfig def run(): - exportDb = sqlite3.connect('export.db') - exportDb.text_factory = lambda x: x.decode(locale.getpreferredencoding()) - decorateDb = sqlite3.connect('decorate.db') + exportDb = sqlite3.connect(CustomConfig.export_db) + exportDb.text_factory = lambda x: x.decode(CustomConfig.database_encoding) + decorateDb = sqlite3.connect(CustomConfig.decorated_db) # init table - print('Init decorate.dll') + print('Init decorate database...') initDecorateDb(decorateDb) decorateDb.commit() # decorate graph + print('Generating gragh list...') graphList = [] decorateGraph(exportDb, decorateDb, graphList) # decorate each graph + print('Generating graph...') currentGraphBlockCell = {} for i in graphList: currentGraphBlockCell.clear() @@ -26,6 +28,7 @@ def run(): buildLink(exportDb, decorateDb, i, currentGraphBlockCell, graphPIO) # export information + print('Generating info...') buildInfo(exportDb, decorateDb) # give up all change of eexport.db (because no change) diff --git a/SuperScriptViewer/ServerCore.py b/SuperScriptViewer/ServerCore.py index 37953af..47d6f60 100644 --- a/SuperScriptViewer/ServerCore.py +++ b/SuperScriptViewer/ServerCore.py @@ -1,3 +1,5 @@ +import CustomConfig + from flask import Flask from flask import g from flask import render_template @@ -17,7 +19,7 @@ app = Flask(__name__) def get_db(): db = getattr(g, '_database', None) if db is None: - db = g._database = sqlite3.connect('decorate.db') + db = g._database = sqlite3.connect(CustomConfig.decorated_db) return db @app.teardown_appcontext @@ -47,7 +49,7 @@ def helpHandle(): @app.route('/about', methods=['GET']) def aboutHandle(): - return render_template("about.html") + return render_template("about.html", static_icon = url_for('static', filename='icon.png')) @app.route('/index', methods=['GET']) def indexHandle(): diff --git a/SuperScriptViewer/SuperScriptViewer.py b/SuperScriptViewer/SuperScriptViewer.py index bd898c7..7cdbeec 100644 --- a/SuperScriptViewer/SuperScriptViewer.py +++ b/SuperScriptViewer/SuperScriptViewer.py @@ -1,15 +1,42 @@ +import CustomConfig import DecoratorCore import ServerCore import os import sys +import getopt -# debug use -# os.remove('decorate.db') +try: + opts, args = getopt.getopt(sys.argv, "hi:o:e:f") +except getopt.GetoptError: + print('Wrong arguments!') + print('test.py -i -o -e -f') + sys.exit(1) +for opt, arg in opts: + if opt == '-h': + print('test.py -i -o -e -f') + sys.exit(0) + elif opt == '-i': + CustomConfig.export_db = arg + elif opt == '-o': + CustomConfig.decorated_db = arg + elif opt == '-e': + CustomConfig.env_db = arg + elif opt == '-f': + CustomConfig.force_regenerate = True + +# process -f +if (CustomConfig.force_regenerate): + if os.path.isfile(CustomConfig.decorated_db): + os.remove(CustomConfig.decorated_db) print('Super Script View') -if not os.path.isfile("decorate.db"): +if not os.path.isfile(CustomConfig.env_db): + print('No environment database. Fail to generate. Exit app.') + sys.exit(1) + +if not os.path.isfile(CustomConfig.decorated_db): print('No decorated database, generating it.') - if not os.path.isfile('export.db'): + if not os.path.isfile(CustomConfig.export_db): print('No export.db. Fail to generate. Exit app.') sys.exit(1) diff --git a/SuperScriptViewer/SuperScriptViewer.pyproj b/SuperScriptViewer/SuperScriptViewer.pyproj index 871403e..f3dde01 100644 --- a/SuperScriptViewer/SuperScriptViewer.pyproj +++ b/SuperScriptViewer/SuperScriptViewer.pyproj @@ -21,6 +21,9 @@ false + + Code + Code diff --git a/SuperScriptViewer/static/icon.png b/SuperScriptViewer/static/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..284b163caf89b7c3ee9829416e316036961ca485 GIT binary patch literal 1785 zcmVC00001b5ch_0Itp) z=>Px#eo#zQMeQ6U`_t9@`TX~rpZATCpQGhQP|yGW{{R30K1j{|=;-evD)U}s@A3Tk zs;qB!+VDF<@=sN_yY1uU_*7ie$ja~i+uhRC^xWR`_JM_~uj%=;w(l%7m7C=M@$p}0 z*89iFy}|DLzrlTl-uIQ6kdTl*NXtY-MDH9Vv$M0W1hnq}00t>ZL_t(|+U=WLd#XAR zhEWo;iim<|t%}yNp8fy-;4WgwX$FRavM!n{Yaw~b%zQJG7Vpo%!}|sJ1&|-ayT`W) z@ZZ}3cHbI+7-TdCSZ=pN0?g)Fmd%&X{oC$d27o7#Ig%$pmWb{1(-rpaB-ynGkk7dqLmu!LCvkXw0x+M~(aZw@Bx)Hm09NuB*+K9O z!<0KnGY4BZ2lwX|p!2 zwnaeCM3a$i1$TWRuDV;yR?d|+QX>E(>@rxIbjXYOtdo5GRqZ2GrsLUxpC;A#wyTtW z%9p~79LqDw^}x(Ru%)F8#SeY?osm+Cbx)kHO3!RkkQ4|Xn6?1~iJ1`!(=CfFJHRQ8RfSWE!=VY{{`hc$0dcC&d4I7iDy%wm|9ID8OjS1!hNfWJJgXJQzF+p~C z)&u}4?AILtPR+6vTr=|y0KDM^>q)1+pgRE6+%)V9Is)XCIRA1x*7pGv=K}{WN2|U- z1ys_Su%i+_0}748mje{eG`WgF05)lgv~_O*2tv>E;!VvguLB4cUOpD%fdJ02SBz*N z0J*-mZv`+)N8JEYxxVLD&oYMq&LsD#1n}kh)1dlqUtp$-N$yh#z=#`gfX*-E_8ofw zsM!FxeV5zEdH~oHW#9ze+yUSz0=09%LC^z0=nV@nq6Q(HuH()C)F6b@b%`If1}KB@ zSSx2hx-RiIodNa)MR(J+ygO{AgrkTtMl>Qah&~7coJ;pFo`F3^GSp(;iIfZwqe1age5X!aP>VSnAT$9| zG%B^NQE@R2$%zaBux+S`(=;^FR1C#MRV}rNjLd=n*fwM;H3f!!QYbP5+)GBGwOph5@ST&mBhd^{in7;=@?Dxq7`Yjdg% zIBMN1M92hGW`-L<24GN=qD4rkd=(;O0w^;hN-l5#?sEH7zcLNfUTpMRfGAW#8i{rQ zKsMZ~l|thdAPOtmOd`P8EfamU(gpo(|RX>C*xL3@Gr%%>X`&N-$5H zj_Th97J4BLKsCV~D1R5Oj=}&?Jz7q<*pL96-Y61w=06Gy07^wSM1?Q_r#H&29PG8{ zk1SWwBq;<^kv?He5F(LIZI6FsL0|R=8{1XN1yqS(c>E3RsE~>%0um>FlB=U4#lQmV zs1N|t2uKHXch^_>$$~aq=t$@bv<7vGHMlpZS;I6(cOgbOB|BRNhmHpqK(yco6Srw2 z0LrlY_^A41c$c9DsxZVZ%`qH=UOrZ)vU48BAeoD`oziImq3@;u-1FSWG@7>#%pZzu7IsJY+z~A5Zj(-9E b6@dQ%&;D90nf+_100000NkvXXu0mjfA7DN? literal 0 HcmV?d00001 diff --git a/SuperScriptViewer/templates/about.html b/SuperScriptViewer/templates/about.html index c73a03d..a09c6ff 100644 --- a/SuperScriptViewer/templates/about.html +++ b/SuperScriptViewer/templates/about.html @@ -7,10 +7,10 @@ -

Super Script Materializer

+

Super Script Materializer

There are no secret script behind Virtools. Super Script Materializer will destroy all locks and show you the real code.
But Super Script Materializer only show you code. It couldn't analyse the result and touch author's heart and intention. This is your work.
-This also is the meaning of this app's icon.

+So, let we crack all scripts and destroy close-source illusion.


SuperScriptMaterializer. All codes are under GPLv3.
Web interface is powered by Flask.