Files
dnf-utils/sgutil/lua/extrace_npk_file.lua
T
2025-09-04 14:30:09 +08:00

63 lines
1.6 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 = 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();
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;