Fixed changing of cwd and loading of commandline files

the current-working-directory is now set at the start of `core.init` after the
absolute path for all filename arguments have been resolved
This commit is contained in:
rxi 2020-05-26 10:17:36 +01:00
parent 257b9ab753
commit 064b6d0b95

View file

@ -82,6 +82,19 @@ function core.init()
CommandView = require "core.commandview" CommandView = require "core.commandview"
Doc = require "core.doc" Doc = require "core.doc"
local project_dir = "."
local files = {}
for i = 2, #ARGS do
local info = system.get_file_info(ARGS[i]) or {}
if info.type == "file" then
table.insert(files, system.absolute_path(ARGS[i]))
elseif info.type == "dir" then
project_dir = ARGS[i]
end
end
system.chdir(project_dir)
core.frame_start = 0 core.frame_start = 0
core.clip_rect_stack = {{ 0,0,0,0 }} core.clip_rect_stack = {{ 0,0,0,0 }}
core.log_items = {} core.log_items = {}
@ -103,20 +116,13 @@ function core.init()
local got_user_error = not core.try(require, "user") local got_user_error = not core.try(require, "user")
local got_project_error = not core.load_project_module() local got_project_error = not core.load_project_module()
for i = 2, #ARGS do for _, filename in ipairs(files) do
local filename = ARGS[i]
local info = system.get_file_info(filename)
if info and info.type == "file" then
core.root_view:open_doc(core.open_doc(filename)) core.root_view:open_doc(core.open_doc(filename))
end end
end
if got_plugin_error or got_user_error or got_project_error then if got_plugin_error or got_user_error or got_project_error then
command.perform("core:open-log") command.perform("core:open-log")
end end
local info = ARGS[2] and system.get_file_info(ARGS[2])
system.chdir(info and info.type == "dir" and ARGS[2] or ".")
end end