增加Lua函数
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
--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={}
|
||||
function M.dump_npk_file_list(npkFileName, listFileName, npkBase, npkName, keyName, fileOffset, fileSize, fileCRC)
|
||||
local npk = createNPKFile();
|
||||
|
||||
local ret = npk:openPakFile(npkFileName)
|
||||
if(not ret) then
|
||||
return false
|
||||
end
|
||||
|
||||
listOutputFile = io.open(listFileName, "w")
|
||||
fileList = npk:generateFullInfoList();
|
||||
|
||||
counts = fileList:getFileCounts()
|
||||
|
||||
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)
|
||||
return true
|
||||
end
|
||||
|
||||
return M;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
--Extracts all files from an NPK archive to a specified output directory.
|
||||
--[[
|
||||
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={}
|
||||
function M.extract_npk_files(npkFileName, outputPath)
|
||||
local npk = createNPKFile();
|
||||
|
||||
local ret = npk:openPakFile(npkFileName)
|
||||
if(not ret) then
|
||||
return false
|
||||
end
|
||||
|
||||
local counts = npk:getFileCounts()
|
||||
for i=0, counts-1, 1 do
|
||||
local baseInfo = npk:getFileNode(i)
|
||||
|
||||
local fileStream = npk:openFileStream(baseInfo:keyName())
|
||||
|
||||
print("keyName=" .. fileStream:name() .. "\n")
|
||||
|
||||
local diskFileName = outputPath .. "/" .. baseInfo:keyName()
|
||||
ret = forceCreatePathForFile(diskFileName);
|
||||
if(not ret) then
|
||||
print("CreatePathForFile failed: " .. diskFileName)
|
||||
npk:closeFileStream(fileStream)
|
||||
break
|
||||
end
|
||||
|
||||
ret = fileStream:writeToDiskFile(diskFileName)
|
||||
if(not ret) then
|
||||
print("dump file failed: " .. baseInfo:keyName())
|
||||
print("LastErrorMsg=" .. getLastErrorMessage())
|
||||
npk:closeFileStream(fileStream)
|
||||
break
|
||||
end
|
||||
npk:closeFileStream(fileStream)
|
||||
end
|
||||
|
||||
npk:closePakFile()
|
||||
destroyNPKFile(npk)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
return M;
|
||||
Reference in New Issue
Block a user