Added AmiUpdate support. Made a lot of changes in paths manipulation

This commit is contained in:
George Sokianos 2024-02-17 17:47:15 +00:00
parent df8eaa64d1
commit 9c2eec9066
11 changed files with 75 additions and 49 deletions

View File

@ -89,6 +89,7 @@ release: clean LiteXL
@mkdir -p release/LiteXL2
@cp -r resources/amiga/* release/LiteXL2/
@mv release/LiteXL2/LiteXL2.info release/
@mv release/LiteXL2/AutoInstall release/
@cp -r data release/LiteXL2/
@cp changelog.md release/LiteXL2/
@cp $(outfile) release/LiteXL2/

View File

@ -223,10 +223,13 @@ https://git.walkero.gr/walkero/lite-xl/issues
# Changelog
## [2.1.2r1] - future
## [2.1.3r1] - future
### Added
- Added AmiUpdate support
### Updated
- Updated the code to the upstream 2.1.3 release
- Compiled with SDL 2.30.x that supports writing in ISO encodings, other
- Compiled with SDL 2.30.0 that supports editing with ISO encodings, other
than English. Now the editor should be able to support any language
and in conjuction with the codesets plugin be able to make text
encodings conversions (AmigsOS 4 version only)
@ -238,7 +241,10 @@ https://git.walkero.gr/walkero/lite-xl/issues
were left over
### Fixed
- Fixed opening partition and assign paths
- I did a lot of changes on path manipulation and usage, fixing opening
the root of a partition or an assign path
- Fixed an error with the codesets plugin, where an empty file could
not be opened
## [2.1.2r1] - 2023-12-19
### Added

View File

@ -465,6 +465,20 @@ function common.basename(path)
end
---Returns the base path with the pathsep, if needed.
---@param path string
---@return string
function common.basepath(path)
-- Check for AmigaOS 4 and MorphOS if the last character is semicolon
-- In these systems the volume name doesn't have a / or \ after the name
-- but it is like VOLUME:
if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") and (string.sub(path, -1) == ":") then
return path
end
return path .. PATHSEP
end
---Returns the directory name of a path.
---If the path doesn't have a directory, this function may return nil.
---@param path string
@ -657,7 +671,7 @@ function common.mkdirp(path)
path = updir
end
for _, dirname in ipairs(subdirs) do
path = path and path .. PATHSEP .. dirname or dirname
path = path and common.basepath(path) .. dirname or dirname
if not system.mkdir(path) then
return false, "cannot create directory", path
end
@ -721,4 +735,3 @@ end
return common

View File

@ -97,7 +97,7 @@ function dirwatch:check(change_callback, scan_time, wait_time)
if self.monitor:mode() == "single" then
local path = common.dirname(id)
if not string.match(id, "^/") and not string.match(id, "^%a:[/\\]") then
path = common.dirname(self.single_watch_top .. PATHSEP .. id)
path = common.dirname(common.basepath(self.single_watch_top) .. id)
end
change_callback(path)
elseif self.reverse_watched[id] then
@ -177,12 +177,7 @@ end
-- compute a file's info entry completed with "filename" to be used
-- in project scan or falsy if it shouldn't appear in the list.
local function get_project_file_info(root, file, ignore_compiled)
local info
if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") and (string.sub(root, -1) == ":") then
info = system.get_file_info(root .. file)
else
info = system.get_file_info(root .. PATHSEP .. file)
end
local info = system.get_file_info(common.basepath(root) .. file)
-- info can be not nil but info.type may be nil if is neither a file neither
-- a directory, for example for /dev/* entries on linux.
@ -206,12 +201,7 @@ function dirwatch.get_directory_files(dir, root, path, entries_count, recurse_pr
local t0 = system.get_time()
local ignore_compiled = compile_ignore_files()
local all
if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") and (string.sub(root, -1) == ":") then
all = system.list_dir(root .. path)
else
all = system.list_dir(root .. PATHSEP .. path)
end
local all = system.list_dir(common.basepath(root) .. path)
if not all then return nil end
local entries = { }

View File

@ -46,7 +46,7 @@ function Doc:reset_syntax()
local header = self:get_text(1, 1, self:position_offset(1, 1, 128))
local path = self.abs_filename
if not path and self.filename then
path = core.project_dir .. PATHSEP .. self.filename
path = common.basepath(core.project_dir) .. self.filename
end
if path then path = common.normalize_path(path) end
local syn = syntax.get(path, header)

View File

@ -18,13 +18,13 @@ local Doc
local core = {}
local function load_session()
local ok, t = pcall(dofile, USERDIR .. PATHSEP .. "session.lua")
local ok, t = pcall(dofile, common.basepath(USERDIR) .. "session.lua")
return ok and t or {}
end
local function save_session()
local fp = io.open(USERDIR .. PATHSEP .. "session.lua", "w")
local fp = io.open(common.basepath(USERDIR) .. "session.lua", "w")
if fp then
fp:write("return {recents=", common.serialize(core.recent_projects),
", window=", common.serialize(table.pack(system.get_window_size())),
@ -188,7 +188,7 @@ local function refresh_directory(topdir, target)
-- If this file doesn't exist, we should be calling this on our parent directory, assume we'll do that.
-- Unwatch just in case.
if files == nil then
topdir.watch:unwatch(topdir.name .. PATHSEP .. (target or ""))
topdir.watch:unwatch(common.basepath(topdir.name) .. (target or ""))
return true
end
@ -212,7 +212,7 @@ local function refresh_directory(topdir, target)
-- If it's not there, remove the entry from the list as being out of order.
table.remove(topdir.files, old_idx)
if old_info.type == "dir" then
topdir.watch:unwatch(topdir.name .. PATHSEP .. old_info.filename)
topdir.watch:unwatch(common.basepath(topdir.name) .. old_info.filename)
end
directory_end_idx = directory_end_idx - 1
end
@ -223,7 +223,7 @@ local function refresh_directory(topdir, target)
end
end
for i, v in ipairs(new_directories) do
topdir.watch:watch(topdir.name .. PATHSEP .. v.filename)
topdir.watch:watch(common.basepath(topdir.name) .. v.filename)
if not topdir.files_limit or core.project_subdir_is_shown(topdir, v.filename) then
refresh_directory(topdir, v.filename)
end
@ -273,7 +273,7 @@ function core.add_project_directory(path)
refresh_directory(topdir)
else
for i,v in ipairs(t) do
if v.type == "dir" then topdir.watch:watch(path .. PATHSEP .. v.filename) end
if v.type == "dir" then topdir.watch:watch(common.basepath(path) .. v.filename) end
end
end
topdir.watch:watch(topdir.name)
@ -287,7 +287,7 @@ function core.add_project_directory(path)
local changed = topdir.watch:check(function(target)
if target == topdir.name then return refresh_directory(topdir) end
local dirpath = target:sub(#topdir.name + 2)
local abs_dirpath = topdir.name .. PATHSEP .. dirpath
local abs_dirpath = common.basepath(topdir.name) .. dirpath
if dirpath then
-- check if the directory is in the project files list, if not exit.
local dir_index, dir_match = file_search(topdir.files, {filename = dirpath, type = "dir"})
@ -374,9 +374,9 @@ function core.update_project_subdir(dir, filename, expanded)
assert(dir.files_limit, "function should be called only when directory is in files limit mode")
dir.shown_subdir[filename] = expanded
if expanded then
dir.watch:watch(dir.name .. PATHSEP .. filename)
dir.watch:watch(common.basepath(dir.name) .. filename)
else
dir.watch:unwatch(dir.name .. PATHSEP .. filename)
dir.watch:unwatch(common.basepath(dir.name) .. filename)
end
return refresh_directory(dir, filename)
end
@ -388,7 +388,7 @@ end
local function find_files_rec(root, path)
local all = system.list_dir(root .. path) or {}
for _, file in ipairs(all) do
local file = path .. PATHSEP .. file
local file = common.basepath(path) .. file
local info = system.get_file_info(root .. file)
if info then
info.filename = strip_leading_path(file)
@ -463,7 +463,7 @@ local function create_user_directory()
error("cannot create directory \"" .. USERDIR .. "\": " .. err)
end
for _, modname in ipairs {'plugins', 'colors', 'fonts'} do
local subdirname = USERDIR .. PATHSEP .. modname
local subdirname = common.basepath(USERDIR) .. modname
if not system.mkdir(subdirname) then
error("cannot create directory: \"" .. subdirname .. "\"")
end
@ -603,7 +603,7 @@ function core.load_user_directory()
if not stat_dir then
create_user_directory()
end
local init_filename = USERDIR .. PATHSEP .. "init.lua"
local init_filename = common.basepath(USERDIR) .. "init.lua"
local stat_file = system.get_file_info(init_filename)
if not stat_file then
write_user_init_file(init_filename)
@ -636,7 +636,7 @@ end
local function add_config_files_hooks()
-- auto-realod style when user's module is saved by overriding Doc:Save()
local doc_save = Doc.save
local user_filename = system.absolute_path(USERDIR .. PATHSEP .. "init.lua")
local user_filename = system.absolute_path(common.basepath(USERDIR) .. "init.lua")
function Doc:save(filename, abs_filename)
local module_filename = system.absolute_path(".lite_project.lua")
doc_save(self, filename, abs_filename)
@ -661,9 +661,9 @@ function core.project_absolute_path(filename)
return common.normalize_path(filename)
elseif not core.project_dir then
local cwd = system.absolute_path(".")
return cwd .. PATHSEP .. common.normalize_path(filename)
return common.basepath(cwd) .. common.normalize_path(filename)
else
return core.project_dir .. PATHSEP .. filename
return common.basepath(core.project_dir) .. filename
end
end
@ -879,7 +879,7 @@ function core.delete_temp_files(dir)
dir = type(dir) == "string" and common.normalize_path(dir) or USERDIR
for _, filename in ipairs(system.list_dir(dir) or {}) do
if filename:find(temp_file_prefix, 1, true) == 1 then
os.remove(dir .. PATHSEP .. filename)
os.remove(common.basepath(dir) .. filename)
end
end
end
@ -887,7 +887,7 @@ end
function core.temp_filename(ext, dir)
dir = type(dir) == "string" and common.normalize_path(dir) or USERDIR
temp_file_counter = temp_file_counter + 1
return dir .. PATHSEP .. temp_file_prefix
return common.basepath(dir) .. temp_file_prefix
.. string.format("%06x", temp_file_counter) .. (ext or "")
end
@ -963,7 +963,7 @@ function core.load_plugins()
}
local files, ordered = {}, {}
for _, root_dir in ipairs {DATADIR, USERDIR} do
local plugin_dir = root_dir .. PATHSEP .. "plugins"
local plugin_dir = common.basepath(root_dir) .. "plugins"
for _, filename in ipairs(system.list_dir(plugin_dir) or {}) do
if not files[filename] then
table.insert(
@ -978,7 +978,7 @@ function core.load_plugins()
for _, plugin in ipairs(ordered) do
local dir = files[plugin.file]
local name = plugin.file:match("(.-)%.lua$") or plugin.file
local is_lua_file, details = get_plugin_details(dir .. PATHSEP .. plugin.file)
local is_lua_file, details = get_plugin_details(common.basepath(dir) .. plugin.file)
plugin.valid = is_lua_file
plugin.name = name
@ -1452,7 +1452,7 @@ end
function core.on_error(err)
-- write error to file
local fp = io.open(USERDIR .. PATHSEP .. "error.txt", "wb")
local fp = io.open(common.basepath(USERDIR) .. "error.txt", "wb")
fp:write("Error: " .. tostring(err) .. "\n")
fp:write(debug.traceback("", 4) .. "\n")
fp:close()

View File

@ -83,7 +83,7 @@ function TreeView:get_cached(dir, item, dirname)
else
t.filename = item.filename
t.depth = get_depth(item.filename)
t.abs_filename = dirname .. PATHSEP .. item.filename
t.abs_filename = common.basepath(dirname) .. item.filename
end
t.name = basename
t.type = item.type
@ -679,7 +679,7 @@ command.add(
local relfilename = item.filename
if item.dir_name ~= core.project_dir then
-- add secondary project dirs names to the file path to show
relfilename = common.basename(item.dir_name) .. PATHSEP .. relfilename
relfilename = common.basepath(common.basename(item.dir_name)) .. PATHSEP .. relfilename
end
local file_info = system.get_file_info(filename)
local file_type = file_info.type == "dir" and "Directory" or "File"
@ -724,7 +724,7 @@ command.add(
submit = function(filename)
local abs_filename = filename
if not common.is_absolute_path(filename) then
abs_filename = item.dir_name .. PATHSEP .. filename
abs_filename = common.basepath(item.dir_name) .. filename
end
local res, err = os.rename(old_abs_filename, abs_filename)
if res then -- successfully renamed
@ -754,7 +754,7 @@ command.add(
core.command_view:enter("Filename", {
text = text,
submit = function(filename)
local doc_filename = item.dir_name .. PATHSEP .. filename
local doc_filename = common.basepath(item.dir_name) .. filename
core.log(doc_filename)
local file = io.open(doc_filename, "a+")
file:write("")
@ -776,7 +776,7 @@ command.add(
core.command_view:enter("Folder Name", {
text = text,
submit = function(filename)
local dir_path = item.dir_name .. PATHSEP .. filename
local dir_path = common.basepath(item.dir_name) .. filename
common.mkdirp(dir_path)
core.log("Created %s", dir_path)
end,

View File

@ -7,7 +7,7 @@ local LogView = require "core.logview"
local function workspace_files_for(project_dir)
local basename = common.basename(project_dir)
local workspace_dir = USERDIR .. PATHSEP .. "ws"
local workspace_dir = common.basepath(USERDIR) .. "ws"
local info_wsdir = system.get_file_info(workspace_dir)
if not info_wsdir then
local ok, err = system.mkdir(workspace_dir)
@ -22,7 +22,7 @@ local function workspace_files_for(project_dir)
if file:sub(1, n) == basename then
local id = tonumber(file:sub(n + 1):match("^-(%d+)$"))
if id then
coroutine.yield(workspace_dir .. PATHSEP .. file, id)
coroutine.yield(common.basepath(workspace_dir) .. file, id)
end
end
end
@ -52,7 +52,7 @@ local function get_workspace_filename(project_dir)
id = id + 1
end
local basename = common.basename(project_dir)
return USERDIR .. PATHSEP .. "ws" .. PATHSEP .. basename .. "-" .. tostring(id)
return common.basepath(USERDIR) .. "ws" .. PATHSEP .. basename .. "-" .. tostring(id)
end
@ -166,7 +166,7 @@ local function load_node(node, t)
active_view = view
end
if not view:is(DocView) then
view.scroll = v.scroll
view.scroll = v.scroll
end
end
end

View File

@ -0,0 +1,10 @@
; Lite-XL AutoInstall
; $VER: Lite-XL AutoInstall 1.0 (15.02.2024)
; Get the path to the executable from the ENV variable
Set litexlPath `GetEnv AppDir/lite-xl`
copy LiteXL2/#? "$litexlPath" CLONE ALL
; Free the variable
UnSet litexlPath

View File

@ -8,7 +8,7 @@
#include <signal.h>
#if defined(__amigaos4__) || defined(__morphos__)
#define VSTRING "Lite XL 2.1.2r1 (28.12.2023)"
#define VSTRING "Lite XL 2.1.3r1 (17.02.2024)"
#define VERSTAG "\0$VER: " VSTRING
#endif

View File

@ -156,6 +156,12 @@ int Lcodesets_convert(lua_State *L) {
const unsigned char* bom;
size_t bom_len = 0;
if (text_len == 0)
{
lua_pushlstring(L, text, text_len);
return 1;
}
if (lua_gettop(L) > 3 && lua_istable(L, 4)) {
lua_getfield(L, 4, "handle_to_bom");
if (lua_isboolean(L, -1)) {