fix: try to fix install.lua mistakes

This commit is contained in:
JuanZoran
2023-03-16 19:25:08 +08:00
parent 0d4eec6f2e
commit 4a0f9b5c85
3 changed files with 20 additions and 15 deletions

View File

@@ -5,29 +5,34 @@ return function()
-- INFO :Check ultimate.db exists
local dir = Trans.conf.dir
local path = dir .. '/ultimate.db'
local fn = vim.fn
if fn.isdirectory(dir) == 0 then
fn.mkdir(dir, 'p')
end
if fn.filereadable(path) == 1 then
vim.notify('Database already exists', vim.log.WARN)
return
else
vim.notify('Trying to download database', vim.log.INFO)
end
vim.notify('Trying to download database', vim.log.INFO)
-- INFO :Download ultimate.db
local uri = 'https://github.com/skywind3000/ECDICT-ultimate/releases/download/1.0.0/ecdict-ultimate-sqlite.zip'
local loc = dir .. '/ultimate.zip'
local zip = dir .. '/ultimate.zip'
if fn.filereadable(zip) then os.remove(zip) end
local handle = function(output)
if output.exit == 0 and fn.filereadable(loc) then
if output.exit == 0 and fn.filereadable(zip) then
if fn.executable('unzip') == 0 then
vim.notify('unzip not found, Please unzip ' .. loc .. 'manually', vim.log.ERROR)
vim.notify('unzip not found, Please unzip ' .. zip .. 'manually', vim.log.ERROR)
return
end
local cmd = string.format('unzip %s -d %s', path, dir)
local cmd = string.format('unzip %s -d %s', zip, dir)
local status = os.execute(cmd)
os.remove(path)
os.remove(zip)
if status == 0 then
vim.notify('Download database successfully', vim.log.INFO)
return
@@ -40,7 +45,7 @@ return function()
Trans.curl.get(uri, {
output = loc,
output = zip,
callback = handle,
})