Libgourou

Libgourou Git Source Tree

Root/utils/launcher.cpp

1#include <iostream>
2#include <unistd.h>
3#include <libgen.h>
4#include <string.h>
5
6#include "utils_common.h"
7
8#ifndef DEFAULT_UTIL
9#define DEFAULT_UTIL "acsmdownloader"
10#endif
11
12/* Inspired from https://discourse.appimage.org/t/call-alternative-binary-from-appimage/93/10*/
13
14int main(int argc, char** argv)
15{
16 char* util, *argv0;
17 char* mountPoint = getenv("APPDIR");
18 std::string fullPath;
19
20 /* Original command is in ARGV0 env variable*/
21 argv0 = strdup(getenv("ARGV0"));
22 util = basename(argv0);
23
24 fullPath = std::string(mountPoint) + util;
25
26 if (std::string(util) == "launcher" || !fileExists(fullPath.c_str()))
27fullPath = std::string(mountPoint) + DEFAULT_UTIL;
28
29 free(argv0);
30
31 argv[0] = strdup(fullPath.c_str());
32
33 if (execvp(argv[0], argv))
34std::cout << "Unable to launch '" << argv[0] << "'" << std::endl;
35
36 /* Should not happens */
37 free(argv[0]);
38
39 return 0;
40}

Archive Download this file