Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AppImage environment overrides before switching mods #17167

Merged
merged 3 commits into from
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion OpenRA.Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static class Game
public static ICursor Cursor;
public static bool HideCursor;
static WorldRenderer worldRenderer;
static string modLaunchWrapper;

internal static OrderManager OrderManager;
static Server.Server server;
Expand Down Expand Up @@ -351,6 +352,8 @@ static void Initialize(Arguments args)
foreach (var mod in Mods)
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Metadata.Title, mod.Value.Metadata.Version);

modLaunchWrapper = args.GetValue("Engine.LaunchWrapper", null);

ExternalMods = new ExternalMods();

Manifest currentMod;
Expand Down Expand Up @@ -509,8 +512,15 @@ public static void SwitchToExternalMod(ExternalMod mod, string[] launchArguments
{
try
{
var path = mod.LaunchPath;
var args = launchArguments != null ? mod.LaunchArgs.Append(launchArguments) : mod.LaunchArgs;
var p = Process.Start(mod.LaunchPath, args.Select(a => "\"" + a + "\"").JoinWith(" "));
if (modLaunchWrapper != null)
{
path = modLaunchWrapper;
args = new[] { mod.LaunchPath }.Concat(args);
}

var p = Process.Start(path, args.Select(a => "\"" + a + "\"").JoinWith(" "));
if (p == null || p.HasExited)
onFailed();
else
Expand Down
16 changes: 13 additions & 3 deletions packaging/linux/AppRun.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

HERE="$(dirname "$(readlink -f "${0}")")"

# Override runtime paths
# Stash original environment values so they can be restored
# when switching to other mods using restore-environment
export OPENRA_ORIG_PATH="${PATH}"
export OPENRA_ORIG_XDG_DATA_DIRS="${XDG_DATA_DIRS}"
export OPENRA_ORIG_DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}"
export OPENRA_ORIG_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
export OPENRA_ORIG_MONO_PATH="${MONO_PATH}"
export OPENRA_ORIG_MONO_CFG_DIR="${MONO_CFG_DIR}"
export OPENRA_ORIG_MONO_CONFIG="${MONO_CONFIG}"

# Override runtime paths to use bundled mono and shared libraries
export PATH="${HERE}/usr/bin:${PATH}"
export XDG_DATA_DIRS="${HERE}/usr/share:${XDG_DATA_DIRS}"
export DYLD_LIBRARY_PATH="${HERE}/usr/lib:$DYLD_LIBRARY_PATH"
export LD_LIBRARY_PATH="${HERE}/usr/lib:$LD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="${HERE}/usr/lib:${DYLD_LIBRARY_PATH}"
export LD_LIBRARY_PATH="${HERE}/usr/lib:${LD_LIBRARY_PATH}"
export MONO_PATH="${HERE}/usr/lib/mono/4.5"
export MONO_CFG_DIR="${HERE}/etc"
export MONO_CONFIG="${HERE}/etc/mono/config"
Expand Down
2 changes: 2 additions & 0 deletions packaging/linux/buildpackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ build_appimage() {

install -m 0755 gtk-dialog.py "${APPDIR}/usr/bin/gtk-dialog.py"

install -m 0755 restore-environment.sh "${APPDIR}/usr/bin/restore-environment.sh"

# travis-ci doesn't support mounting FUSE filesystems so extract and run the contents manually
./appimagetool-x86_64.AppImage --appimage-extract

Expand Down
4 changes: 2 additions & 2 deletions packaging/linux/openra.appimage.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cd "${HERE}/../lib/openra" || exit 1

# APPIMAGE is an environment variable set by the runtime
# defining the absolute path to the .AppImage file
if [ ! -z "${APPIMAGE}" ]; then
if [ -n "${APPIMAGE}" ]; then
LAUNCHER=${APPIMAGE}

# appimaged doesn't update the mime or icon caches when registering AppImages.
Expand Down Expand Up @@ -35,7 +35,7 @@ fi

# Run the game
export SDL_VIDEO_X11_WMCLASS="openra-{MODID}-{TAG}"
mono --debug OpenRA.Game.exe Game.Mod={MODID} Engine.LaunchPath="${LAUNCHER}" "${JOIN_SERVER}" "$@"
mono --debug OpenRA.Game.exe Game.Mod={MODID} Engine.LaunchPath="${LAUNCHER}" Engine.LaunchWrapper="${HERE}/restore-environment.sh" "${JOIN_SERVER}" "$@"

# Show a crash dialog if something went wrong
if [ $? != 0 ] && [ $? != 1 ]; then
Expand Down
26 changes: 26 additions & 0 deletions packaging/linux/restore-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

# Restore the environment variables that were set by AppRun
export PATH="${OPENRA_ORIG_PATH}"
export XDG_DATA_DIRS="${OPENRA_ORIG_XDG_DATA_DIRS}"
export DYLD_LIBRARY_PATH="${OPENRA_ORIG_DYLD_LIBRARY_PATH}"
export LD_LIBRARY_PATH="${OPENRA_ORIG_LD_LIBRARY_PATH}"
unset OPENRA_ORIG_PATH OPENRA_ORIG_XDG_DATA_DIRS OPENRA_ORIG_DYLD_LIBRARY_PATH OPENRA_ORIG_LD_LIBRARY_PATH

unset MONO_PATH MONO_CFG_DIR MONO_CONFIG
if [ -n "${OPENRA_ORIG_MONO_PATH}" ]; then
export MONO_PATH="${OPENRA_ORIG_MONO_PATH}"
fi

if [ -n "${OPENRA_ORIG_MONO_CFG_DIR}" ]; then
export MONO_CFG_DIR="${OPENRA_ORIG_MONO_CFG_DIR}"
fi

if [ -n "${OPENRA_ORIG_MONO_CONFIG}" ]; then
export MONO_CONFIG="${OPENRA_ORIG_MONO_CONFIG}"
fi

unset SDL_VIDEO_X11_WMCLASS OPENRA_ORIG_MONO_PATH OPENRA_ORIG_MONO_CFG_DIR OPENRA_ORIG_MONO_CONFIG

# Run the given command
exec "$@"