fix: fix plugin_dir and use left slash as path separator for windows

Fixes #46
This commit is contained in:
Moeta Yuko 2024-02-13 13:37:19 +08:00
parent 4b9e8a7ab9
commit 863213bbc8
4 changed files with 7 additions and 10 deletions

View File

@ -1,7 +1,7 @@
local Trans = require 'Trans' local Trans = require 'Trans'
local db = require 'sqlite.db' 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 dict = db:open(path)
local db_name = 'stardict' local db_name = 'stardict'
vim.api.nvim_create_autocmd('VimLeavePre', { vim.api.nvim_create_autocmd('VimLeavePre', {

View File

@ -5,7 +5,7 @@ return function()
local fn = vim.fn local fn = vim.fn
-- INFO :Check ultimate.db exists -- INFO :Check ultimate.db exists
local dir = Trans.conf.dir local dir = Trans.conf.dir
local path = dir .. 'ultimate.db' local path = dir .. '/ultimate.db'
if fn.isdirectory(dir) == 0 then if fn.isdirectory(dir) == 0 then
fn.mkdir(dir, 'p') fn.mkdir(dir, 'p')
@ -18,7 +18,7 @@ return function()
-- INFO :Download ultimate.db -- INFO :Download ultimate.db
local uri = 'https://github.com/skywind3000/ECDICT-ultimate/releases/download/1.0.0/ecdict-ultimate-sqlite.zip' 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 continue = fn.filereadable(zip) == 1
local handle = function(output) local handle = function(output)
if output.exit == 0 and fn.filereadable(zip) then if output.exit == 0 and fn.filereadable(zip) then

View File

@ -57,7 +57,7 @@ local function check_binary_dependencies()
end end
local function check_database() 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 if fn.filereadable(db_path) == 1 then
ok [[ultimate database found ]] ok [[ultimate database found ]]
else else
@ -69,7 +69,7 @@ local function check_database()
end end
local function check_configure_file() 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 if not fn.filereadable(path) then
warn 'Backend configuration file[%s] not found' warn 'Backend configuration file[%s] not found'
end end

View File

@ -25,19 +25,16 @@ local system =
uname == 'Linux' and (vim.fn.executable 'termux-api-start' == 1 and 'termux' or 'linux') or uname == 'Linux' and (vim.fn.executable 'termux-api-start' == 1 and 'termux' or 'linux') or
error 'Unknown System, Please Report Issue' error 'Unknown System, Please Report Issue'
local sep = system == 'win' and '\\\\' or '/'
---@class Trans ---@class Trans
---@field style table @Style module ---@field style table @Style module
---@field cache table<string, TransData> @Cache for translated data object ---@field cache table<string, TransData> @Cache for translated data object
---@field plugin_dir string @Plugin directory ---@field plugin_dir string @Plugin directory
---@field separator string @Path separator ---@field system 'mac'|'win'|'termux'|'linux' @Operating system
---@field system 'mac'|'win'|'termux'|'linux' @Path separator
local M = metatable('core', { local M = metatable('core', {
cache = {}, cache = {},
style = metatable 'style', style = metatable 'style',
separator = sep,
system = system, 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 M.metatable = metatable