Skip to content

Commit

Permalink
linux: use relative path to data in AppImage #74
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed May 18, 2020
1 parent e23d30b commit fc54f5a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .travis/linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cd /home/build
export OS=linux64
export DATE=`date +%Y%m%d`
export COMMIT=`git rev-parse --short=7 HEAD`
export VERSION=$COMMIT
export ARTIFACT=avocado-$OS-$DATE-$COMMIT
export CC="ccache cc -fcolor-diagnostics"
export CXX="ccache c++ -fcolor-diagnostics"
Expand All @@ -28,7 +29,8 @@ wget -nv https://gist.github.com/JaCzekanski/d7a6e06295729a3f81bd9bd488e9d37d/ra

# Package
mkdir -p $ARTIFACT
cp -r data $ARTIFACT/
mkdir -p $ARTIFACT/usr/share/avocado
cp -r data $ARTIFACT/usr/share/avocado/
cp android/app/src/main/ic_launcher-web.png $ARTIFACT/avocado.png

# Remove .gitignore
Expand Down
20 changes: 13 additions & 7 deletions src/platform/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <imgui.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include "config.h"
#include "config_parser.h"
#include "gui/filesystem.h"
#include "gui/gui.h"
#include "input/sdl_input_manager.h"
#include "renderer/opengl/opengl.h"
Expand Down Expand Up @@ -88,22 +90,26 @@ void limitFramerate(std::unique_ptr<System>& sys, SDL_Window* window, bool frame
}

void fatalError(const std::string& error) {
fmt::print(stderr, "[FATAL] %s", error);
fmt::print(stderr, "[FATAL] {}", error);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Avocado", error.c_str(), nullptr);
SDL_Quit();
}

void changeWorkingDirectory() {
std::string workingDirectory = ".";
#if defined(__linux__)
return; // AppImage, no change
#elif defined(ANDROID)
workingDirectory = "/sdcard/avocado";
fs::path workingDirectory;

#if defined(ANDROID)
workingDirectory = fs::path("/sdcard/avocado");
#else
char* basePath = SDL_GetBasePath();
workingDirectory = basePath;
workingDirectory = fs::path(basePath);
SDL_free(basePath);
#endif

if (getenv("APPIMAGE") != nullptr) {
workingDirectory = workingDirectory / ".." / "share" / "avocado";
}

chdir(workingDirectory.c_str());
}

Expand Down

0 comments on commit fc54f5a

Please sign in to comment.