From 37b73ed223ff323f31afa851541c94437bbff0ea Mon Sep 17 00:00:00 2001 From: xarkes Date: Mon, 23 Oct 2017 11:22:15 +0200 Subject: [PATCH] Fix share path for AppImage --- .travis.yml | 4 ++-- src/main.cpp | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index cd510f26..8c9fd56c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,9 +52,9 @@ after_success: before_script: - git submodule init ; git submodule update - cd radare2 - # Hack to modify r2 prefixes - - sed -i s,__WINDOWS__,1, libr/include/r_userconf.h.acr - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then + # PREFIX modification for AppImage + PREFIX=/tmp/.cutter_usr/ INSTALL_TARGET=install sys/install.sh; else LDFLAGS=-headerpad_max_install_names INSTALL_TARGET=install sys/install.sh; diff --git a/src/main.cpp b/src/main.cpp index d5890aec..4a01f9b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,28 @@ #include "dialogs/NewFileDialog.h" #include "dialogs/OptionsDialog.h" +#ifdef __unix__ +#define SYMLINK "/tmp/.cutter_usr" +#include +#include +#include +#include + +void set_appimage_symlink(char* argv0) +{ + char* path = strdup(argv0); + char* i = strrchr(path, '/'); + *(i+1) = '\0'; + char* dest = strcat(path, "usr/"); + struct stat buf; + if (lstat(SYMLINK, &buf) == 0 && S_ISLNK(buf.st_mode)) { + remove(SYMLINK); + } + symlink(dest, SYMLINK); + free(path); +} +#endif + int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -21,7 +43,6 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); #endif - QCommandLineParser cmd_parser; cmd_parser.setApplicationDescription(QObject::tr("A Qt and C++ GUI for radare2 reverse engineering framework")); cmd_parser.addHelpOption(); @@ -85,5 +106,16 @@ int main(int argc, char *argv[]) main->openNewFile(args[0], anal_level_specified ? anal_level : -1); } - return a.exec(); + // Hack to make it work with AppImage +#ifdef __unix__ + set_appimage_symlink(argv[0]); +#endif + + int ret = a.exec(); + +#ifdef __unix__ + remove(SYMLINK); +#endif + + return ret; }