packMod
Definition
-- @/lua/ge/extensions/core/modmanager.lua:1084
local function packMod(dirPath)
log('D', 'packMod', 'Packing : ' .. tostring(dirPath))
if not FS:directoryExists(dirPath) then
log('E', 'packMod', 'path is not a folder path='..dumps(dirPath))
return false
end
local modpath, modname, modext = path.splitWithoutExt( dirPath:gsub('/$', '')..'.zip' )
if not mods[modname] then
guihooks.trigger('modmanagerError', 'Unable to pack mod: not existing: ' .. tostring(dirPath))
return false
end
if not mods[modname].unpackedPath then
guihooks.trigger('modmanagerError', 'Unable to pack mod: not unpacked: ' .. tostring(filename))
log('E', 'packMod', 'unable to pack mod: not unpacked: ' .. tostring(filename))
return false
end
if FS:isMounted(mods[modname].unpackedPath) then
FS:unmount(mods[modname].unpackedPath)
end
local zipFilename = mods[modname].orgZipFilename
if not zipFilename then
log('E', 'packMod', 'unable to pack mod: no zip filename')
guihooks.trigger('modmanagerError', 'Unable to pack mod: no zip existing')
return false
end
safeDelete(zipFilename)
local zip = ZipArchive()
zip:openArchiveName(zipFilename, 'w')
if not string.find(zip:getModeString(), "write") then
log('E', 'packMod', 'unable to pack mod: Zip is in read only')
guihooks.trigger('modmanagerError', 'Unable to pack mod: Zip is in read only, close other software')
return false
end
Engine.Platform.taskbarSetProgressState(1)
local fileList = FS:findFiles( mods[modname].unpackedPath, "*", -1, false, false )
Engine.Platform.taskbarSetProgress(0.0)
Engine.Platform.taskbarSetProgressState(2)
for k,v in pairs(fileList) do
local zipPath = v
-- copy only files
if zipPath:startswith(mods[modname].unpackedPath) then
zipPath = string.sub(zipPath, string.len(mods[modname].unpackedPath) + 1)
if string.startswith(zipPath, '/') then
zipPath = string.sub(zipPath, 2)
end
end
log('D', 'packMod', 'zip-addfile: ' .. tostring(v) .. ' > ' .. tostring(zipPath))
zip:addFile(v, zipPath)
Engine.Platform.taskbarSetProgress(k/#fileList)
end
zip:close()
Engine.Platform.taskbarSetProgressState(0)
-- debug output the files in there
--zip = ZipArchive()
--zip:openArchiveName(zipFilename, 'r')
--local files = zip:getFileList()
--dump(files)
safeDeleteFolder(mods[modname].unpackedPath)
mods[modname].unpackedPath = nil
mods[modname].orgZipFilename = nil
mods[modname].fullpath = zipFilename
mods[modname].dirname, mods[modname].filename = path.split(zipFilename)
mods[modname].stat = FS:stat(zipFilename)
stateChanged()
end
Callers
@/ui/modules/modmanager/modmanager.js
} else {
bngApi.engineLua('core_modmanager.packMod("' + $scope.mod.fullpath + '")')
}
@/ui/modules/repository/repository.js
} else {
bngApi.engineLua('core_modmanager.packMod("' + vm.localData.fullpath + '")')
}
@/ui/modules/automation/automation.js
} else {
bngApi.engineLua('core_modmanager.packMod("' + vm.localData.fullpath + '")')
}