Skip to content

Commit

Permalink
Merge c7ede9f into d701d7a
Browse files Browse the repository at this point in the history
  • Loading branch information
timfel authored Jan 15, 2023
2 parents d701d7a + c7ede9f commit 9f5c32e
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 29 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: AppImage Continuous

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
strategy:
matrix:
game: [{id: wargus, name: Wargus}, {id: war1gus, name: War1gus}]
name: Linux x64_64 (Continuous)
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Build game ${{ matrix.game.id }}
run: bash -x ./tools/build_appimage.sh ${{ matrix.game.id }} ${{ matrix.game.name }}
- name: Create continuous release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: "*.AppImage*"
body: |
:heavy_check_mark: AppImage built from latest commit ([${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})).
:scroll: Build log: https://github.com/${{ github.repository }}/commit/${{ github.sha }}/checks?check_suite_id=${{ github.run_id }}
commit: ${{ github.sha }}
draft: false
name: Continuous appimage builds
prerelease: true
removeArtifacts: false
replacesArtifacts: true
skipIfReleaseExists: false
tag: continuous
token: "${{ secrets.GITHUB_TOKEN }}"
58 changes: 45 additions & 13 deletions gameheaders/stratagus-game-launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,34 @@ static void SetUserDataPath(char* data_path) {
}
}
SHGetFolderPathA(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, 0, data_path);
// strcpy(data_path, getenv("APPDATA"));
#else
strcpy(data_path, getenv("HOME"));
#endif
int datalen = strlen(data_path);
#if defined(WIN32)
if (!data_path[0]) {
strcpy(data_path, getenv("APPDATA"));
}
strcat(data_path, "\\Stratagus\\");
#elif defined(USE_MAC)
strcat(data_path, "/Library/Stratagus/");
#else
strcat(data_path, "/.stratagus/");
std::string appimage = std::string(getenv("APPIMAGE"));
if (!appimage.empty() && fs::exists(fs::path(appimage))) {
if (fs::exists(fs::path(appimage + ".data"))) {
strcpy(data_path, (appimage + ".data/stratagus").c_str());
strcat(data_path, "data." GAME_NAME);
return;
}
}
char *dataDir = getenv("XDG_DATA_DIR");
if (dataDir) {
strcpy(data_path, dataDir);
strcat(data_path, "/stratagus/");
} else {
dataDir = getenv("HOME");
if (dataDir) {
strcpy(data_path, dataDir);
#ifdef USE_MAC
strcat(data_path, "/Library/Stratagus/");
#else
strcat(data_path, "/.local/share/stratagus/");
#endif
}
}
#endif
strcat(data_path, "data." GAME_NAME);
}
Expand Down Expand Up @@ -332,7 +349,7 @@ static void ExtractData(char* extractor_tool, const char *const extractor_args[]
std::vector<std::wstring> argv = {L"-i", fs::path(datafile).wstring()};
#else
const char *file = "innoextract";
char *argv[] = {"-i", (char*)datafile.c_str(), NULL};
char *argv[] = {"-i", (char*)datafile.c_str(), NULL, NULL, NULL};
#endif
if (runCommand(file, argv) == 0) {
// innoextract exists and this exe file is an innosetup file
Expand All @@ -354,6 +371,9 @@ static void ExtractData(char* extractor_tool, const char *const extractor_args[]
argv[0] = L"-m";
#else
argv[0] = "-m";
argv[1] = "-d";
argv[2] = tmpp.string().c_str();
argv[3] = (char*)datafile.c_str();
#endif
success = runCommand(file, argv) == 0;
#ifdef WIN32
Expand Down Expand Up @@ -509,9 +529,19 @@ static void ExtractData(char* extractor_tool, const char *const extractor_args[]
strcat(cmdbuf, "osascript -e \"tell application \\\"Terminal\\\"\n"
" set w to do script \\\"");
#else
int hasXterm = 0;
if (!isatty(1)) {
strcat(cmdbuf, "xterm -e bash -c ");
strcat(cmdbuf, " \"");
hasXterm = detectPresence("xterm");
if (hasXterm) {
strcat(cmdbuf, "xterm -e bash -c ");
strcat(cmdbuf, " \"");
} else {
tinyfd_messageBox("", "Extracting data, cannot find xterm to display output.\n"
"Please be patient. If something fails, re-run from terminal.", "ok", "info", 1);
}
}
if (getenv("APPIMAGE") && !detectPresence("ffmpeg")) {
tinyfd_messageBox("", "Could not find ffmpeg on PATH, video\nand/or audio conversion may not work...", "ok", "info", 1);
}
#endif

Expand Down Expand Up @@ -544,7 +574,9 @@ static void ExtractData(char* extractor_tool, const char *const extractor_args[]
"end tell\"");
#else
if (!isatty(1)) {
strcat(cmdbuf, "; echo 'Press RETURN to continue...'; read\"");
if (hasXterm) {
strcat(cmdbuf, "; echo 'Press RETURN to continue...'; read\"");
}
}
#endif

Expand Down
34 changes: 18 additions & 16 deletions src/stratagus/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,26 @@ void Parameters::SetDefaultUserDirectory(bool noPortable)
}
char data_path[4096] = {'\0'};
SHGetFolderPathA(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, 0, data_path);
userDirectory = data_path;
// userDirectory = getenv("APPDATA");
#else
userDirectory = getenv("HOME");
#endif

if (!userDirectory.empty()) {
userDirectory += "/";
if (data_path[0]) {
userDirectory = std::string(data_path) + "/Stratagus";
} else if (getenv("APPDATA")) {
userDirectory = std::string(getenv("APPDATA")) + "/Stratagus";
}

#ifdef USE_GAME_DIR
#elif USE_WIN32
userDirectory += "Stratagus";
#elif defined(USE_MAC)
userDirectory += "Library/Stratagus";
#else // USE_GAME_DIR
char *configDir = getenv("XDG_CONFIG_DIR");
if (configDir) {
userDirectory = std::string(configDir) + "/stratagus";
} else {
configDir = getenv("HOME");
if (configDir) {
#ifdef USE_MAC
userDirectory = std::string(configDir) + "/Library/Stratagus";
#else
userDirectory += ".stratagus";
#endif
userDirectory = std::string(configDir) + "/.config/stratagus";
#endif // USE_MAC
}
}
#endif // USE_GAME_DIR
}

static std::string GetLocalPlayerNameFromEnv()
Expand Down
139 changes: 139 additions & 0 deletions tools/build_appimage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

# Tested with
# appimagecrafters/appimage-builder
# and
# centos:centos-7

# config
if [ -z "$GAME_ID" ]; then
if [ $# -gt 0 ]; then
export GAME_ID="$1"
else
echo "Need GAME_ID set or passed as first argument"
exit 1
fi
fi
if [ -z "$GAME_NAME" ]; then
if [ $# -gt 1 ]; then
export GAME_NAME="$2"
else
echo "Need GAME_NAME set or passed as second argument"
exit 1
fi
fi
if [ -z "$GAME_VERSION" ]; then
if [ $# -gt 2 ]; then
export GAME_VERSION="$3"
else
export GAME_VERSION="$(head -1 debian/changelog | cut -f2 -d' ' | sed 's/(//' | sed 's/)//')"
fi
fi
export GAME_ARCH=$(uname -m)

CENTOS=`which yum || true`
if [ -n "$CENTOS" ]; then
# centos (>= 7) build tools
yum install -yy centos-release-scl && yum install -yy git devtoolset-7-toolchain
yum install -yy zlib-devel file
scl enable devtoolset-7 bash
# centos SDL dependencies
yum install -yy libX11-devel libXext-devel libXrandr-devel libXi-devel libXfixes-devel libXcursor-devel
yum install -yy pulseaudio-libs-devel
yum install -yy mesa-libGL-devel
yum install -yy wayland-devel
else
# ubuntu (>= 18.04) build tools
sudo apt-get update && apt-get install -yy git build-essential
sudo apt-get install -yy zlib1g-dev file
# ubuntu SDL dependencies
sudo apt-get install -yy libx11-dev libxext-dev libxrandr-dev libxi-dev libxfixes-dev libxcursor-dev
sudo apt-get install -yy libpulse-dev
sudo apt-get install -yy libgl1-mesa-dev libgles2-mesa-dev
sudo apt-get install -yy libwayland-dev
fi

if [ -n "$CENTOS" ]; then
# cmake
curl -L -O https://cmake.org/files/v3.20/cmake-3.20.0.tar.gz
tar zxf cmake-3.20.0.tar.gz
pushd cmake-3.20.0
sed -i 's/cmake_options="-DCMAKE_BOOTSTRAP=1"/cmake_options="-DCMAKE_BOOTSTRAP=1 -DCMAKE_USE_OPENSSL=OFF"/' bootstrap
./bootstrap --prefix=/usr/local
make -j$(nproc)
make install
popd
fi

# git clone --depth 1 https://github.com/Wargus/stratagus
git clone --depth 1 https://github.com/Wargus/${GAME_ID}

# pushd stratagus
git submodule update --init --recursive
mkdir build
pushd build
cmake .. \
-DBUILD_VENDORED_LUA=ON \
-DBUILD_VENDORED_SDL=ON \
-DBUILD_VENDORED_MEDIA_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DGAMEDIR=/usr/bin
make -j$(nproc) install DESTDIR=../AppDir
popd
# popd
pushd ${GAME_ID}
git submodule update --init --recursive
mkdir build
pushd build
cmake .. \
-DENABLE_VENDORED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DSTRATAGUS_INCLUDE_DIR=$PWD/../../gameheaders \
-DSTRATAGUS=stratagus \
-DCMAKE_INSTALL_PREFIX=/usr \
-DDATA_PATH=../../share/games/stratagus/${GAME_ID}/ \
-DGAMEDIR=/usr/bin \
-DICONDIR=/usr/share/icons/default/64x64/ \
-DGAMEDIRABS=""
make -j$(nproc) install DESTDIR=../../AppDir
popd
popd

if [ -n "$CENTOS" ]; then
# using linuxdeploy
echo '#!/bin/sh' > AppDir/AppRun
echo -n 'exec $APPDIR/usr/bin/' >> AppDir/AppRun
echo -n "${GAME_ID}" >> AppDir/AppRun
echo -n ' --argv0=$APPDIR/usr/bin/' >> AppDir/AppRun
echo -n "${GAME_ID}" >> AppDir/AppRun
echo ' $@' >> AppDir/AppRun
chmod +x AppDir/AppRun
cat AppDir/AppRun
curl -L -O "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
chmod +x linuxdeploy-x86_64.AppImage
./linuxdeploy-x86_64.AppImage --appimage-extract-and-run --appdir AppDir --output appimage
rm -f ./linuxdeploy-x86_64.AppImage
else
# using appimage-builder
echo "version: 1" > appimagebuilder.yaml
echo "AppDir:" >> appimagebuilder.yaml
echo " path: ./AppDir" >> appimagebuilder.yaml
echo " app_info:" >> appimagebuilder.yaml
echo " id: com.stratagus.${GAME_ID}" >> appimagebuilder.yaml
echo " name: '${GAME_NAME}'" >> appimagebuilder.yaml
echo " icon: '${GAME_ID}'" >> appimagebuilder.yaml
echo " version: '${GAME_VERSION}'" >> appimagebuilder.yaml
echo " exec: usr/bin/${GAME_ID}" >> appimagebuilder.yaml
echo " exec_args: '\"--argv0=\$APPDIR/usr/bin/${GAME_ID}\" \$@'" >> appimagebuilder.yaml
echo "AppImage:" >> appimagebuilder.yaml
echo " arch: '${GAME_ARCH}'" >> appimagebuilder.yaml
APPIMAGEBUILDER=`which appimage-builder || true`
if [ -z "$APPIMAGEBUILDER" ]; then
wget https://github.com/AppImageCrafters/appimage-builder/releases/download/v1.1.0/appimage-builder-1.1.0-x86_64.AppImage
chmod +x appimage-builder-1.1.0-x86_64.AppImage
APPIMAGEBUILDER=$(pwd)/appimage-builder-1.1.0-x86_64.AppImage
fi
$APPIMAGEBUILDER --recipe appimagebuilder.yaml
rm -f ./appimage-builder-1.1.0-x86_64.AppImage
fi

0 comments on commit 9f5c32e

Please sign in to comment.