Skip to content

Commit

Permalink
Merge pull request #53 from MoetaYuko/v2
Browse files Browse the repository at this point in the history
Windows fixes
  • Loading branch information
JuanZoran authored Feb 13, 2024
2 parents 50c2f00 + a13c09e commit 98507fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lua/Trans/backend/offline.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local Trans = require 'Trans'

local db = require 'sqlite.db'
local path = Trans.conf.dir .. Trans.separator .. 'ultimate.db'
local path = Trans.conf.dir .. '/ultimate.db'
local dict = db:open(path)
local db_name = 'stardict'
vim.api.nvim_create_autocmd('VimLeavePre', {
Expand Down
15 changes: 7 additions & 8 deletions lua/Trans/core/install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ return function()
local fn = vim.fn
-- INFO :Check ultimate.db exists
local dir = Trans.conf.dir
local path = dir .. 'ultimate.db'
local path = dir .. '/ultimate.db'

if fn.isdirectory(dir) == 0 then
fn.mkdir(dir, 'p')
Expand All @@ -18,16 +18,15 @@ return function()

-- INFO :Download ultimate.db
local uri = 'https://github.com/skywind3000/ECDICT-ultimate/releases/download/1.0.0/ecdict-ultimate-sqlite.zip'
local zip = dir .. 'ultimate.zip'
local zip = dir .. '/ultimate.zip'
local continue = fn.filereadable(zip) == 1
local handle = function(output)
if output.exit == 0 and fn.filereadable(zip) then
if fn.executable 'unzip' == 0 then
vim.notify('unzip not found, Please unzip ' .. zip .. 'manually', vim.log.ERROR)
return
end

local cmd = string.format('unzip %s -d %s', zip, dir)
local cmd =
Trans.system == 'win' and
string.format('powershell.exe -Command "Expand-Archive -Force %s %s"', zip, dir) or
fn.executable('unzip') == 1 and string.format('unzip %s -d %s', zip, dir) or
error('unzip not found, Please unzip ' .. zip .. ' manually')
local status = os.execute(cmd)
os.remove(zip)
if status == 0 then
Expand Down
4 changes: 2 additions & 2 deletions lua/Trans/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ local function check_binary_dependencies()
end

local function check_database()
local db_path = Trans.conf.dir .. Trans.separator .. 'ultimate.db'
local db_path = Trans.conf.dir .. '/ultimate.db'
if fn.filereadable(db_path) == 1 then
ok [[ultimate database found ]]
else
Expand All @@ -69,7 +69,7 @@ local function check_database()
end

local function check_configure_file()
local path = fn.expand(Trans.conf.dir .. Trans.separator .. 'Trans.json')
local path = fn.expand(Trans.conf.dir .. '/Trans.json')
if not fn.filereadable(path) then
warn 'Backend configuration file[%s] not found'
end
Expand Down
15 changes: 2 additions & 13 deletions lua/Trans/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,18 @@ local system =
uname == 'Linux' and (vim.fn.executable 'termux-api-start' == 1 and 'termux' or 'linux') or
error 'Unknown System, Please Report Issue'

local sep = system == 'win' and '\\\\' or '/'
---@class Trans
---@field style table @Style module
---@field cache table<string, TransData> @Cache for translated data object
---@field plugin_dir string @Plugin directory
---@field separator string @Path separator
---@field system 'mac'|'win'|'termux'|'linux' @Path separator
---@field system 'mac'|'win'|'termux'|'linux' @Operating system
local M = metatable('core', {
cache = {},
style = metatable 'style',
separator = sep,
system = system,
plugin_dir = debug.getinfo(1, 'S').source:sub(2):match('(.-)lua' .. sep .. 'Trans'),
plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, 'S').source:sub(2), ':p:h:h:h'),
})

M.metatable = metatable

---Get abs_path of file
---@param path string[]
---@param is_dir boolean?
---@return string
function M.relative_path(path, is_dir)
return M.plugin_dir .. table.concat(path, sep) .. (is_dir and sep or '')
end

return M

0 comments on commit 98507fa

Please sign in to comment.