增加Lua函数
This commit is contained in:
@@ -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