使用lua实现npk操作
This commit is contained in:
@@ -8,104 +8,11 @@
|
||||
#include "sgu_mode_make_diff.h"
|
||||
#include "sgu_mode_apply_patch.h"
|
||||
#include "sgu_mode_hash_file.h"
|
||||
#include "sgu_mode_npk_dump_list.h"
|
||||
#include "sgu_mode_npk_extract_files.h"
|
||||
#include "sgu_mode_download.h"
|
||||
#include "sgu_mode_run_lua_file.h"
|
||||
|
||||
#include "libEncrypt_AES.h"
|
||||
|
||||
//int TestFunc(lua_State* L)
|
||||
//{
|
||||
// printf("# TestFunc\n");
|
||||
// return lua_yield(L, 0);
|
||||
//}
|
||||
//
|
||||
//int TestFunc2(lua_State* L, float a)
|
||||
//{
|
||||
// printf("# TestFunc2(L,%f)\n", a);
|
||||
// return lua_yield(L, 0);
|
||||
//}
|
||||
//
|
||||
//class TestClass
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// int TestFunc(lua_State* L, int a)
|
||||
// {
|
||||
// m_data = a;
|
||||
// printf("# TestClass::TestFunc\n");
|
||||
// return lua_yield(L, 0);
|
||||
// }
|
||||
//
|
||||
// int TestFunc2(lua_State* L, float a)
|
||||
// {
|
||||
// printf("# TestClass::TestFunc2(L,%d, %f)\n", m_data, a);
|
||||
// return lua_yield(L, 0);
|
||||
// }
|
||||
//
|
||||
//private:
|
||||
// int m_data;
|
||||
//};
|
||||
//
|
||||
//int foo()
|
||||
//{
|
||||
// lua_State* L = lua_open();
|
||||
// luaopen_base(L);
|
||||
// luaopen_string(L);
|
||||
//
|
||||
// lua_tinker::def(L, "TestFunc", &TestFunc);
|
||||
// lua_tinker::def(L, "TestFunc2", &TestFunc2);
|
||||
//
|
||||
// lua_tinker::class_add<TestClass>(L, "TestClass");
|
||||
// lua_tinker::class_def<TestClass>(L, "TestFunc", &TestClass::TestFunc);
|
||||
// lua_tinker::class_def<TestClass>(L, "TestFunc2", &TestClass::TestFunc2);
|
||||
//
|
||||
// TestClass g_test;
|
||||
// lua_tinker::set(L, "g_test", &g_test);
|
||||
//
|
||||
//
|
||||
//
|
||||
// lua_tinker::dostring(L,
|
||||
// "function ThreadTest()\n"
|
||||
// " print(\"ThreadTest\")\n"
|
||||
//
|
||||
// " print(\"TestFunc Begin\")"
|
||||
// " TestFunc()\n"
|
||||
// " TestFunc2(1.2)\n"
|
||||
// " print(\"TestFunc End\")\n"
|
||||
//
|
||||
// " print(\"g_test::TestFunc()\")\n"
|
||||
// " g_test:TestFunc(123)\n"
|
||||
// " g_test:TestFunc2(2.3)\n"
|
||||
// " print(\"g_test::TestFunc()\")\n"
|
||||
// "end\n"
|
||||
// );
|
||||
//
|
||||
// lua_newthread(L);
|
||||
// lua_pushstring(L, "ThreadTest");
|
||||
// lua_gettable(L, LUA_GLOBALSINDEX);
|
||||
//
|
||||
// printf("* lua_resume() 1\n");
|
||||
// lua_resume(L, 0);
|
||||
//
|
||||
// printf("* lua_resume() 2\n");
|
||||
// lua_resume(L, 0);
|
||||
//
|
||||
// printf("* lua_resume() 3\n");
|
||||
// lua_resume(L, 0);
|
||||
//
|
||||
// printf("* lua_resume() 4\n");
|
||||
// lua_resume(L, 0);
|
||||
//
|
||||
// printf("* lua_resume() 5\n");
|
||||
// lua_resume(L, 0);
|
||||
//
|
||||
// lua_close(L);
|
||||
//
|
||||
// return 0;
|
||||
//}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
enum { OPT_MODE,
|
||||
OPT_INPUT, OPT_INPUT2, OPT_OUTPUT,
|
||||
OPT_MIN_SIZE, OPT_MAX_SIZE,
|
||||
@@ -153,8 +60,6 @@ static void printUsage(const char* moduleName)
|
||||
printf(" MakeDiff\tCreates a binary diff patch file between two input files using BSDIFF43.\n");
|
||||
printf(" ApplyPatch\tApplies a BSDIFF43 binary patch to an input file and writes the patched result to an output file.\n");
|
||||
printf(" HashFile\tCalculates the hash(MD5|SHA256) of the contents of a specified file.\n");
|
||||
printf(" NPKDumpList\tDumps the file list from an NPK archive to a text file.\n");
|
||||
printf(" NPKExtractFiles\tExtracts all files from an NPK archive to a specified output directory.\n");
|
||||
printf(" HttpDownload\tDownloads a file from a specified URL and saves it to a local file.\n");
|
||||
printf(" RunLuaFile\t xxxx \n");
|
||||
printf("\nSample:\n");
|
||||
@@ -166,8 +71,6 @@ static void printUsage(const char* moduleName)
|
||||
printf(" -m ApplyPatch -i ver01.bin -i2 patch_ver01_ver02.diff -o ver02.bin\n");
|
||||
printf(" -m HashFile -t md5 -i ver01.bin\n");
|
||||
printf(" -m HashFile -t sha256 -i ver01.bin\n");
|
||||
printf(" -m NPKDumpList -i abc.npk -o abc_file_list.txt\n");
|
||||
printf(" -m NPKExtractFiles -i abc.npk -o output\n");
|
||||
printf(" -m HttpDownload -i http://download.com/file.txt -o file.txt\n");
|
||||
printf(" -m RunLuaFile -i script.lua\n");
|
||||
}
|
||||
@@ -183,8 +86,6 @@ enum WorkMode {
|
||||
WM_APPLY_PATCH,
|
||||
WM_HASH_FILE,
|
||||
WM_HTTP_DOWNLOAD,
|
||||
WM_NPK_DUMPLIST,
|
||||
WM_NPK_EXTRACT_FILES,
|
||||
WM_RUN_LUA_FILE,
|
||||
};
|
||||
|
||||
@@ -226,12 +127,6 @@ WorkMode parserWorkMode(const char* modeStr)
|
||||
else if (_stricmp(modeStr, "HttpDownload") == 0) {
|
||||
return WM_HTTP_DOWNLOAD;
|
||||
}
|
||||
else if (_stricmp(modeStr, "NPKDumpList") == 0) {
|
||||
return WM_NPK_DUMPLIST;
|
||||
}
|
||||
else if (_stricmp(modeStr, "NPKExtractFiles") == 0) {
|
||||
return WM_NPK_EXTRACT_FILES;
|
||||
}
|
||||
else if (_stricmp(modeStr, "RunLuaFile") == 0) {
|
||||
return WM_RUN_LUA_FILE;
|
||||
}
|
||||
@@ -482,39 +377,6 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_NPK_DUMPLIST:
|
||||
{
|
||||
if (inputFilename == nullptr || outputFilename == nullptr)
|
||||
{
|
||||
printf("Error: For 'NPKDumpList' mode, you must specify input NPK file and output file.\n");
|
||||
printUsage(::PathFindFileNameA(argv[0]));
|
||||
return 1;
|
||||
}
|
||||
printf("Dumping NPK list from %s to %s\n", inputFilename, outputFilename);
|
||||
if (!dumpNPKFileList(inputFilename, outputFilename))
|
||||
{
|
||||
printf("Error: Failed to dump NPK list.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_NPK_EXTRACT_FILES:
|
||||
{
|
||||
if (inputFilename == nullptr || outputFilename == nullptr)
|
||||
{
|
||||
printf("Error: For 'NPKExtractFiles' mode, you must specify input NPK file and output directory.\n");
|
||||
printUsage(::PathFindFileNameA(argv[0]));
|
||||
return 1;
|
||||
}
|
||||
printf("Extracting files from NPK '%s' to directory '%s'\n", inputFilename, outputFilename);
|
||||
if(!extractNPKFiles(inputFilename, outputFilename))
|
||||
{
|
||||
printf("Error: Failed to extract files from NPK.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_RUN_LUA_FILE:
|
||||
{
|
||||
if (inputFilename == nullptr)
|
||||
|
||||
Reference in New Issue
Block a user