Skip to content
Snippets Groups Projects
boot.lua 3.4 KiB
Newer Older
dg's avatar
dg committed
-- This file is the very first lua file loaded
-- It will be called before anything else is setup, including paths
-- Usualy it will be put inside a zip that is concatenated to the executable itself

DarkGod's avatar
DarkGod committed
--[[ Example to move the saves somewhere else
local old = fs.getHomePath()
function fs.getHomePath() return old:gsub("T%-Engine", "BoneToBeWild"):gsub("t%-engine", "bone-to-be-wild") end
]]

dg's avatar
dg committed
print("Booting T-Engine from: "..tostring(__SELFEXE))

-- Mount the engine, either from a path guessed from SELFEXE, or directly from current dir
if __SELFEXE then
	local dir = __SELFEXE

	-- Remove bin/Debug from the path, to make dev easier
	dir = dir:gsub("bin"..fs.getPathSeparator().."Debug"..fs.getPathSeparator(), "")

	if not __APPLE__ then
		-- Now remove executable name
		dir = dir:gsub("(.*"..fs.getPathSeparator()..").+", "%1")
dg's avatar
dg committed
	else
TomeDev's avatar
TomeDev committed
		-- This is a little un-OSX like: we grab our data from the folder containing T-Engine.app
		-- It is a bit strange but way way better for people to install addons and such
		dir = dir:gsub("(.*"..fs.getPathSeparator()..").+", "%1"):gsub("(.*"..fs.getPathSeparator()..").+", "%1"):gsub("(.*"..fs.getPathSeparator()..").+", "%1")
--		dir = dir:gsub("(.*"..fs.getPathSeparator()..").+", "%1")..fs.getPathSeparator().."Resources"..fs.getPathSeparator()
dg's avatar
dg committed

	print("SelfExe gave us app directory of:", dir)
	fs.mount(dir..fs.getPathSeparator().."game"..fs.getPathSeparator().."thirdparty", "/", true)
	fs.mount(dir..fs.getPathSeparator().."game", "/", true)
DarkGod's avatar
DarkGod committed
	fs.setPathAllowed(dir..fs.getPathSeparator().."game", false)
dg's avatar
dg committed
else
	print("No SelfExe, using basic path")
dg's avatar
dg committed
	fs.mount("game"..fs.getPathSeparator().."thirdparty", "/", true)
	fs.mount("game", "/", true)
dg's avatar
dg committed
end

DarkGod's avatar
DarkGod committed
fs.setPathAllowed(fs.getRealPath("/engines/"), false)
fs.setPathAllowed(fs.getRealPath("/thirdparty/"), false)
fs.setPathAllowed(fs.getRealPath("/addons/"), true)
if fs.getRealPath("/dlcs/") then fs.setPathAllowed(fs.getRealPath("/dlcs/"), true) end
fs.setPathAllowed(fs.getRealPath("/modules/"), true)

dg's avatar
dg committed
-- Look for a core
dg's avatar
dg committed
function get_core(coretype, id)
	coretype = coretype or "te4core"

dg's avatar
dg committed
	local homepath = fs.getUserPath()..fs.getPathSeparator()..fs.getHomePath()..fs.getPathSeparator().."4.0"
	fs.mount(homepath, "/", 1)

	-- Look for possible cores - if id is -1 then check all the ones matching the given type and use the newest one
	local usable = {}
dg's avatar
dg committed
	for i, file in ipairs(fs.list("/engines/cores/")) do
		if file:find("%.tec$") then
dg's avatar
dg committed
			print("Looking for cores", coretype, id, " <=> ", file)
			if id > 0 and file == coretype.."-"..id..".tec" then
				usable[#usable+1] = {file=file, id=id}
				print("Possible engine core", file)
			elseif id == -1 and file:find(coretype) then
dg's avatar
dg committed
				local _, _, cid = file:find("%-([0-9]+)%.tec$")
				cid = tonumber(cid)
				if cid then
					usable[#usable+1] = {file=file, id=cid}
dg's avatar
dg committed
					print("Possible engine core", file)
dg's avatar
dg committed
				end
			end
dg's avatar
dg committed
		end
	end
dg's avatar
dg committed
	-- Order the cores to find the newest
	table.sort(usable, function(a, b) return b.id < a.id end)
dg's avatar
dg committed
	for i, file in ipairs(usable) do print("Selected cores:", file.id, file.file) end
dg's avatar
dg committed

	-- Check for sanity and tell the runner to use it
	local core = "/engines/cores/"..usable[1].file
dg's avatar
dg committed
	if fs.exists(core) then
		local rcore = fs.getRealPath(core)
		print("Using TE4CORE: ", core, rcore)
dg's avatar
dg committed
		fs.umount(homepath)
dg's avatar
dg committed
		return rcore
dg's avatar
dg committed
	fs.umount(homepath)
dg's avatar
dg committed
	return "NO CORE"
dg's avatar
dg committed
end

-- We need it no more, lets forget about it just it case some malovelant script tried something silly
__SELFEXE = nil