mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-13 17:00:58 +02:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f1950348d4 | |||
| 5603477787 | |||
| 6a9e77cde0 | |||
| 4943d3e5f4 |
+1
-3
@@ -400,9 +400,7 @@ end
|
||||
-- LÖVE process ensures scripts, registries, and assets are all rebuilt from
|
||||
-- the newly selected mod state.
|
||||
function Game:restartWithMods()
|
||||
if love.event and love.event.quit then
|
||||
love.event.quit("restart")
|
||||
end
|
||||
require("src.core.HostShell").restart()
|
||||
end
|
||||
|
||||
function Game:keyreleased(key)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
-- Helpers for calling host tools (curl, zenity/kdialog, ...).
|
||||
|
||||
local HostShell = {}
|
||||
|
||||
-- Our AppRun exports LD_LIBRARY_PATH="$APPDIR/lib:..." so every subprocess we
|
||||
-- spawn tries to link against the libraries we're shipping instead of the
|
||||
-- system ones. We want to unset the var so that any system tools can find
|
||||
-- their proper libraries. Only needed when running in an AppImage.
|
||||
function HostShell.envPrefix()
|
||||
if os.getenv("APPIMAGE") then
|
||||
return "env -u LD_LIBRARY_PATH "
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
-- Wraps io.popen with the AppImage env fix applied and lua errors swallowed
|
||||
function HostShell.popen(command, mode)
|
||||
local ok, pipe = pcall(io.popen, HostShell.envPrefix() .. command, mode or "r")
|
||||
if not ok or not pipe then return nil end
|
||||
return pipe
|
||||
end
|
||||
|
||||
-- Restart the whole app. The obvious love.event.quit("restart") re-runs LÖVE's
|
||||
-- boot in-process, which calls love.filesystem.init a second time -- and inside
|
||||
-- an AppImage physfs is already initialized, so that second init throws
|
||||
-- ("Failed to initialize filesystem: already initialized") and the relaunch
|
||||
-- crashes. So on an AppImage we relaunch the executable; the fresh process's
|
||||
-- Boot step mounts any downloaded update exactly as a manual relaunch would.
|
||||
-- On every other platform the in-process restart works, so keep it.
|
||||
function HostShell.restart()
|
||||
if not (love and love.event and love.event.quit) then return end
|
||||
local appimage = os.getenv("APPIMAGE")
|
||||
if not appimage then
|
||||
love.event.quit("restart")
|
||||
return
|
||||
end
|
||||
|
||||
-- We have to restart the process with this cursed execv call to prevent the
|
||||
-- PID from changing, which might cause SteamOS and other Linux launchers to
|
||||
-- think the app has crashed.
|
||||
local ffi = require("ffi")
|
||||
pcall(ffi.cdef, [[
|
||||
int execv(const char *path, char *const argv[]);
|
||||
int unsetenv(const char *name);
|
||||
]])
|
||||
ffi.C.unsetenv("LD_LIBRARY_PATH")
|
||||
local argv = ffi.new("const char *[2]", appimage, nil)
|
||||
ffi.C.execv(appimage, ffi.cast("char *const *", argv))
|
||||
end
|
||||
|
||||
return HostShell
|
||||
@@ -1,5 +1,6 @@
|
||||
local GameVersion = require("src.core.GameVersion")
|
||||
local Strings = require("src.core.Strings")
|
||||
local HostShell = require("src.core.HostShell")
|
||||
|
||||
local RomImporter = {}
|
||||
RomImporter.__index = RomImporter
|
||||
@@ -285,7 +286,7 @@ end
|
||||
|
||||
local function commandOutput(command)
|
||||
releasePointerGrab()
|
||||
local pipe = io.popen(command, "r")
|
||||
local pipe = HostShell.popen(command)
|
||||
if not pipe then return nil end
|
||||
local result = pipe:read("*a")
|
||||
pipe:close()
|
||||
@@ -1859,7 +1860,7 @@ function RomImporter:mousepressed(x, y, button)
|
||||
if action == "download" and self.Check then
|
||||
pcall(self.Check.download)
|
||||
elseif action == "restart" then
|
||||
love.event.quit("restart")
|
||||
HostShell.restart()
|
||||
elseif action == "openurl" and self.Check then
|
||||
love.system.openURL(self.Check.releaseUrl())
|
||||
end
|
||||
|
||||
@@ -35,6 +35,7 @@ local Json = loadModule("src/link/Json.lua")
|
||||
local Check = loadModule("src/update/Check.lua")
|
||||
local Version = loadModule("src/core/Version.lua")
|
||||
local Semver = loadModule("src/update/Semver.lua")
|
||||
local HostShell = loadModule("src/core/HostShell.lua")
|
||||
-- Boot's top-level require("src.update.Semver") cannot resolve in this thread
|
||||
-- (no src.* searcher), which would leave Boot nil and the minShell gate
|
||||
-- permanently permissive. Seed the loaded table first so it resolves.
|
||||
@@ -76,8 +77,8 @@ local function curlCapture(url)
|
||||
.. "-H " .. shq("User-Agent: gen1recomp-updater") .. " "
|
||||
.. "-H " .. shq("Accept: application/vnd.github+json") .. " "
|
||||
.. shq(url)
|
||||
local ok, pipe = pcall(io.popen, cmd)
|
||||
if not ok or not pipe then return nil end
|
||||
local pipe = HostShell.popen(cmd)
|
||||
if not pipe then return nil end
|
||||
local out = pipe:read("*a")
|
||||
pipe:close()
|
||||
if not out or out == "" then return nil end
|
||||
@@ -85,8 +86,8 @@ local function curlCapture(url)
|
||||
end
|
||||
|
||||
local function haveCurl()
|
||||
local ok, pipe = pcall(io.popen, "curl --version")
|
||||
if not ok or not pipe then return false end
|
||||
local pipe = HostShell.popen("curl --version")
|
||||
if not pipe then return false end
|
||||
local out = pipe:read("*a")
|
||||
pipe:close()
|
||||
return out ~= nil and out:find("curl", 1, true) ~= nil
|
||||
@@ -239,7 +240,7 @@ local function launchDownload(url, partAbs, doneAbs)
|
||||
os.execute('start "" /b ' .. shq(saveDir .. "/" .. batRel))
|
||||
else
|
||||
-- ( ... ) & backgrounds the whole group so os.execute returns at once
|
||||
os.execute("( curl -fsSL --connect-timeout 15 --max-time 900 -o "
|
||||
os.execute("( " .. HostShell.envPrefix() .. "curl -fsSL --connect-timeout 15 --max-time 900 -o "
|
||||
.. shq(partAbs) .. " " .. shq(url)
|
||||
.. " ; touch " .. shq(doneAbs) .. " ) >/dev/null 2>&1 &")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user