增加List处理功能

This commit is contained in:
2025-09-04 14:30:09 +08:00
parent 80390e48a7
commit 4235742d87
13 changed files with 615 additions and 82 deletions
+40 -64
View File
@@ -1,76 +1,52 @@
--print npk file list to file
--[[
npkFileName(string): npk file path name(utf8)
listFileName(string): list output path name(utf8)
keyName(boolean): print key name
npkName(boolean): print npk file name
npkBase(boolean): print npk base dir name
fileSize(boolean): print file size
fileCRC(boolean): print file crc
fileOffset(boolean): print file offset
return(boolean): is success
local M = require("dump_npk_list")
local ret = M.dump_npk_file_list(
{
"D:\\WeGameApps\\地下城与勇士:创新世纪\\ImagePacks2\\sprite_character_archer_effect_air.NPK",
"D:\\WeGameApps\\地下城与勇士:创新世纪\\ImagePacks2\\sprite_interface2_event_20160927_national_day_firework.NPK"
},
"d:\\output.txt",
false, false, false, false, false
)
--]]
local M={}
function M.dump_npk_file_list(npkFileName, listFileName, npkBase, npkName, keyName, fileOffset, fileSize, fileCRC)
local npk = createNPKFile();
function M.dump_npk_file_list(npkFileNames, listFileName, npkBase, npkName, fileOffset, fileSize, fileCRC)
local finalList = createEmptyFileList()
local ret = npk:openPakFile(npkFileName)
if(not ret) then
return false
for i,npkFileName in pairs(npkFileNames) do
local npk = createNPKFile();
local ret = npk:openPakFile(npkFileName)
if(not ret) then
return false
end
local fileList = npk:generateFullInfoList()
if(not fileList)then
return false
end
ret = finalList:mergeOtherListInto(fileList, true)
if(not ret) then
return false
end
destroyFileList(fileList)
npk:closePakFile()
destroyNPKFile(npk)
end
listOutputFile = io.open(listFileName, "w")
fileList = npk:generateFullInfoList();
counts = fileList:getFileCounts()
local flags = 0
if fileCRC then flags = 1 end
if fileSize then flags = flags + bit.lshift(1, 1) end
if fileOffset then flags = flags + bit.lshift(1, 2) end
if npkName then flags = flags + bit.lshift(1, 3) end
if npkBase then flags = flags + bit.lshift(1, 4) end
for i=0, counts-1, 1 do
local fileInfo = fileList:getFileItem(i)
outputLine=""
if(npkBase) then
if(#outputLine>0) then outputLine = outputLine .. "|" end
outputLine = outputLine .. fileInfo:npkBase();
end
if(npkName) then
if(#outputLine>0) then outputLine = outputLine .. "|" end
outputLine = outputLine .. fileInfo:npkName();
end
if(keyName) then
if(#outputLine>0) then outputLine = outputLine .. "|" end
outputLine = outputLine .. fileInfo:keyName();
end
if(fileOffset) then
if(#outputLine>0) then outputLine = outputLine .. "|" end
outputLine = outputLine .. tostring(fileInfo.fileOffset);
end
if(fileSize) then
if(#outputLine>0) then outputLine = outputLine .. "|" end
outputLine = outputLine .. tostring(fileInfo.fileSize);
end
if(fileCRC) then
if(#outputLine>0) then outputLine = outputLine .. "|" end
outputLine = outputLine .. tostring(fileInfo.fileCRC);
end
if(#outputLine>0) then
listOutputFile:write(outputLine .. "\n")
end
end
listOutputFile:close()
destroyFileList(fileList)
npk:closePakFile()
destroyNPKFile(npk)
finalList:dumpToLocalFile(listFileName, flags)
destroyFileList(finalList)
return true
end
+7
View File
@@ -4,6 +4,13 @@ npkFileName The path to the NPK archive file to be extracted.
outputPath The path to the output directory where files will be extracted.
return true if extraction succeeds; false otherwise.
--]]
--[[
local M = require("extrace_npk_file")
local ret = M.extract_npk_files("D:\\WeGameApps\\地下城与勇士:创新世纪\\ImagePacks2\\sprite_character_archer_effect_air.NPK",
"D:\\_temp\\output"
)
--]]
local M={}
function M.extract_npk_files(npkFileName, outputPath)
local npk = createNPKFile();
+78 -3
View File
@@ -13,11 +13,15 @@ extern "C"
////////////////////////////////////////////////////////////////////////////////////
void registerNPKLuaLibs(lua_State* L)
{
//register global functions
lua_tinker::def(L, "getLastErrorCode", &NPK::getLastErrorCode);
lua_tinker::def(L, "getLastErrorMessage", &NPK::getLastErrorMessage);
lua_tinker::def(L, "createNPKFile", &LuaNPKFile::create);
lua_tinker::def(L, "destroyNPKFile", &LuaNPKFile::destroy);
lua_tinker::def(L, "createEmptyFileList", &LuaNPKFileList::createEmpty);
lua_tinker::def(L, "destroyFileList", &LuaNPKFileList::destroy);
lua_tinker::def(L, "getLastErrorMessage", &NPK::getLastErrorMessage);
lua_tinker::class_add<LuaNPKFile>(L, "NPKFile");
lua_tinker::class_def<LuaNPKFile>(L, "openPakFile", &LuaNPKFile::openPakFile);
@@ -42,8 +46,13 @@ void registerNPKLuaLibs(lua_State* L)
lua_tinker::class_mem<LuaNPKFileItemFullInfo>(L, "fileCRC", &LuaNPKFileItemFullInfo::fileCRC);
lua_tinker::class_add<LuaNPKFileList>(L, "LuaNPKFileList");
lua_tinker::class_def<LuaNPKFileList>(L, "loadListFromFile", &LuaNPKFileList::loadListFromFile);
lua_tinker::class_def<LuaNPKFileList>(L, "dumpToLocalFile", &LuaNPKFileList::dumpToLocalFile);
lua_tinker::class_def<LuaNPKFileList>(L, "mergeOtherListInto", &LuaNPKFileList::mergeOtherListInto);
lua_tinker::class_def<LuaNPKFileList>(L, "applyToLocalNPKFiles", &LuaNPKFileList::applyToLocalNPKFiles);
lua_tinker::class_def<LuaNPKFileList>(L, "getFileCounts", &LuaNPKFileList::getFileCounts);
lua_tinker::class_def<LuaNPKFileList>(L, "getFileItem", &LuaNPKFileList::getFileItem);
lua_tinker::class_def<LuaNPKFileList>(L, "getFileItemFromIndex", &LuaNPKFileList::getFileItemFromIndex);
lua_tinker::class_def<LuaNPKFileList>(L, "getFileItemFromName", &LuaNPKFileList::getFileItemFromName);
lua_tinker::class_add<LuaNPKFileStream>(L, "NPKFileStream");
lua_tinker::class_def<LuaNPKFileStream>(L, "name", &LuaNPKFileStream::name);
@@ -189,12 +198,67 @@ void LuaNPKFileList::destroy(LuaNPKFileList* instance)
delete instance;
}
bool LuaNPKFileList::loadListFromFile(const char* wszListFile/*utf8*/, const char* prefix, uint32_t flags, bool bEnableDuplicate)
{
bool bNpkBase = (flags >> 4) & 1;
bool bNpkName = (flags >> 3) & 1;
bool bFileOffset = (flags >> 2) & 1;
bool bFileSize = (flags >> 1) & 1;
bool bFileCRC = flags & 1;
if (m_pFileList)
{
std::wstring wstrListFile = convertUtf8StringToWide(wszListFile);
return m_pFileList->loadListFromFile(wstrListFile.c_str(), prefix,
bNpkBase, bNpkName, bFileOffset, bFileSize, bFileCRC,
bEnableDuplicate);
}
return false;
}
bool LuaNPKFileList::dumpToLocalFile(const char* wszListFile/*utf8*/, uint32_t flags)
{
bool bNpkBase = (flags >> 4) & 1;
bool bNpkName = (flags >> 3) & 1;
bool bFileOffset = (flags >> 2) & 1;
bool bFileSize = (flags >> 1) & 1;
bool bFileCRC = flags & 1;
if (m_pFileList)
{
std::wstring wstrListFile = convertUtf8StringToWide(wszListFile);
return m_pFileList->dumpToLocalFile(wstrListFile.c_str(),
bNpkBase, bNpkName, bFileOffset, bFileSize, bFileCRC
);
}
return false;
}
bool LuaNPKFileList::mergeOtherListInto(const LuaNPKFileList* sourceFileList, bool bEnableDuplicate)
{
if (m_pFileList)
{
return m_pFileList->mergeOtherListInto(sourceFileList->m_pFileList, bEnableDuplicate);
}
return false;
}
bool LuaNPKFileList::applyToLocalNPKFiles(const char* wszNPKBase/*utf8*/)
{
if (m_pFileList)
{
std::wstring strNPKBase = convertUtf8StringToWide(wszNPKBase);
return m_pFileList->applyToLocalNPKFiles(strNPKBase.c_str());
}
return false;
}
int32_t LuaNPKFileList::getFileCounts(void) const
{
return m_pFileList ? m_pFileList->getFileCounts() : 0;
}
LuaNPKFileItemFullInfo LuaNPKFileList::getFileItem(int32_t index) const
LuaNPKFileItemFullInfo LuaNPKFileList::getFileItemFromIndex(int32_t index) const
{
LuaNPKFileItemFullInfo fullInfo;
if (m_pFileList)
@@ -203,3 +267,14 @@ LuaNPKFileItemFullInfo LuaNPKFileList::getFileItem(int32_t index) const
}
return fullInfo;
}
LuaNPKFileItemFullInfo LuaNPKFileList::getFileItemFromName(const char* szKeyName) const
{
LuaNPKFileItemFullInfo fullInfo;
if (m_pFileList)
{
m_pFileList->getFileItem(szKeyName, &fullInfo);
}
return fullInfo;
}
+7 -1
View File
@@ -39,8 +39,14 @@ public:
static LuaNPKFileList* createEmpty();
static void destroy(LuaNPKFileList* instance);
public:
bool loadListFromFile(const char* wszListFile/*utf8*/, const char* prefix, uint32_t flags, bool bEnableDuplicate);
bool dumpToLocalFile(const char* wszListFile/*utf8*/, uint32_t flags);
bool mergeOtherListInto(const LuaNPKFileList* sourceFileList, bool bEnableDuplicate);
bool applyToLocalNPKFiles(const char* wszNPKBase/*utf8*/);
int32_t getFileCounts(void) const;
LuaNPKFileItemFullInfo getFileItem(int32_t index) const;
LuaNPKFileItemFullInfo getFileItemFromIndex(int32_t index) const;
LuaNPKFileItemFullInfo getFileItemFromName(const char* szKeyName) const;
public:
NPK::IFileList* m_pFileList = nullptr;
+9 -4
View File
@@ -15,13 +15,18 @@ extern "C"
bool run_lua_file(const char* szLuaFilename)
{
//NPK::IFileList* pNpkList = NPK::createEmptyFileList();
//pNpkList->loadListFromFile(L"d:\\output.txt", "sprite/",
// true, true, true, true, true,
// false);
//pNpkList->applyToLocalNPKFiles(L"D:\\WeGameApps\\地下城与勇士:创新世纪\\ImagePacks2");
//NPK::destoryFileList(pNpkList);
//return true;
lua_State* L = lua_open();
luaL_openlibs(L);
//register global functions
lua_tinker::def(L, "getLastErrorCode", &NPK::getLastErrorCode);
lua_tinker::def(L, "getLastErrorMessage", &NPK::getLastErrorMessage);
//register classes
registerNPKLuaLibs(L);
registerUtilsLuaLibs(L);