我正在开发一个lightroom插件,并且需要用插件管理器更新插件。我正在将服务器上的所有插件版本存储在一个zip文件中。现在我想下载该文件并将其解压缩到插件目录中。我可以在插件目录上下载这个zip文件,但是我不知道如何提取这个zip文件。插件与windows和mac兼容,所以我需要一些解决方案,可以将插件文件解压缩到插件目录中。下面是下载zip文件的代码。
local downloadButton = f:push_button { -- create button
enabled = bind 'downloadButton',
visible = false,
title = "Download",
bind_to_object = prefs,
action = function( button )
local headers = {
{ field = 'Content-Type', value = "application/json" }
}
LrTasks.startAsyncTask(
function()
local url = "https://WEBSITEPATH/assets/plugins/staging/1.3.5/BatchAI.lrdevplugin.zip"
local response, hdrs = LrHttp.get(url,headers)
local saveFile = assert(io.open(downloadPath .. "BatchAI.lrdevplugin", 'wb'))
saveFile:write(response)
saveFile:close()
LrDialogs.message('Plugin updated')
end
)
end
}如果有人有一个解决方案如何提取zip文件或任何其他解决方案更新插件与插件管理器,请分享您的想法在这里。谢谢。
发布于 2022-09-14 16:55:11
您考虑过使用LrTasks.execute(cmd)通过shell命令执行此操作吗?然后,您可以使用Lightroom的LrPathUtils和LrFileUtils名称空间根据需要复制/移动/删除文件。
MacOS有本机解压缩支持:
unzip plugin.zip - d ~/another/foo在Windows10中,PowerShell可以使用PowerShell version V5+中提供的“”cmdlet来完成这一任务,默认情况下,该版本在Windows 10中安装。
使用PowerShell v5+的Windows 10:
Expand-Archive C:\foo\plugin.zip C:\somefolder或者如果你想更精确:
Expand-Archive -Path "C:\my foo\plugin.zip" -DestinationPath "C:\My Docs"或者通过LrTasks.execute(Cmd)调用:
local cmd = 'powershell -Command "Expand-Archive C:\foo\plugin.zip C:\somewhere"'
local status = LrTasks.execute(cmd)但是,自2018年4月以来,Windows 10在命令提示符和PowerShell中都提供了PowerShell,使Windows 10与MacOS和Linux保持一致,使一切变得更加方便:
tar -xf foo.zip -C c:\somefolder或(更清楚)的长形式:
tar --extract --file foo.zip --directory c:\somefolder尽管如此,一个好的做法是检查Windows中是否存在一个命令,并相应地采取进一步的步骤。
在命令提示符中,可以使用WHERE检查是否存在命令:
WHERE tar如果命令存在,它将返回可执行文件的路径,如果不存在,它将返回一条相应的消息。
WHERE tar
C:\Windows\System32\tar.exe
WHERE foo
INFO: Could not find files for the given pattern(s).在PowerShell中,可以使用Get- command检查命令是否存在:
Get-Command Expand-Archive
Get-Command Extract-Archive如果存在命令,PowerShell将显示该命令的版本,否则将显示错误:
Get-Command Expand-Archive
Function Expand-Archive 1.0.1.0 Microsoft.PowerShell.Archive
Get-Command Extract-Archive
Get-Command : The term 'Extract-Archive' is not recognized as the name of a cmdlet...在任何情况下,Lightroom的LrTasks.execute(cmd)将返回OS shell命令的退出状态,如果出现错误或未找到,则返回0表示成功或返回1(或其他数字):
local status = LrTasks.execute('cmd /c "WHERE tar"')下面是我为此创建的一个示例要点,用于使用Lua和Lightroom:https://gist.github.com/27shutterclicks/6fb07c58d3bc5477612c6e0257d20e6f检查命令支持
我自己倾向于坚持使用tar,因为它允许跨操作系统执行相同的命令,另外还有一个特殊特性,它允许删除存档的根文件夹:
tar --strip-components=1 -xf foo.zip -C c:\somefolder这在从GitHub下载发布包时非常有用,因为它创建了包含回购名称和版本作为根文件夹的归档文件。
https://stackoverflow.com/questions/71676896
复制相似问题