56 lines
1.4 KiB
Lua
56 lines
1.4 KiB
Lua
--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
|
|
print("Can't open npk file:" .. npkFileName)
|
|
return false
|
|
end
|
|
|
|
ret = createEmptyPath(outputPath)
|
|
if(not ret) then
|
|
print("Can't create ouput path: " .. outputPath)
|
|
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())
|
|
|
|
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;
|