diff --git a/src/launcher/kiwix-launcher.c b/src/launcher/kiwix-launcher.c deleted file mode 100644 index c737dcc..0000000 --- a/src/launcher/kiwix-launcher.c +++ /dev/null @@ -1,56 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -const char * sep = "\\"; -#else -const char * sep = "/"; -#endif - -int main() { - - char cwd[1024]; - - char * previous_env = getenv("LD_LIBRARY_PATH"); - if (getcwd(cwd, sizeof(cwd)) != NULL) { - char env[1024] = "LD_LIBRARY_PATH="; - strcat(env, cwd); - strcat(env, ":"); - strcat(env, previous_env); - putenv(env); - // fprintf(stdout, "LD_LIBRARY_PATH: %s\n", env); - // fprintf(stdout, "Current working dir: %s\n", cwd); - } else - perror("Unable to find current directory"); - - char *path = (char *)malloc(2048); - strcpy(path, cwd); - strcat(path, sep); - strcat(path, "xulrunner"); - strcat(path, sep); - strcat(path, "xulrunner"); - // fprintf(stdout, "path: %s\n", path); - - char *inifile = (char *)malloc(2048); - strcpy(inifile, cwd); - strcat(inifile, sep); - strcat(inifile, "application.ini"); - // fprintf(stdout, "ini: %s\n", inifile); - - - if (file_exist(path) == 0) { - perror("Unable to find xulrunner binary"); - } - - return execl(path, "xulrunner", inifile, NULL); -} - -int file_exist (char *filename) { - struct stat buffer; - return (stat (filename, &buffer) == 0); -} diff --git a/src/launcher/kiwix-launcher.cpp b/src/launcher/kiwix-launcher.cpp new file mode 100644 index 0000000..8f754e5 --- /dev/null +++ b/src/launcher/kiwix-launcher.cpp @@ -0,0 +1,52 @@ + +#include +#include +#include +#include +#include +#include + +#include +#include "pathTools.h" + +using namespace std; + +int main(int argc, char *argv[]) +{ + + // find current binary path + string progpath = getExecutablePath(); + string cwd = removeLastPathElement(progpath); + string ld_path = computeAbsolutePath(cwd, "xulrunner"); + + // retrieve existing env if exist. + string previous_env; + char *previous_env_buf = getenv("LD_LIBRARY_PATH"); + if (previous_env_buf == NULL) + previous_env = ""; + else + previous_env = string(previous_env_buf); + + // generate putenv string + string env_str = "LD_LIBRARY_PATH=" + ld_path + ":" + previous_env; + putenv((char *)env_str.c_str()); + + string xulrunner_path = computeAbsolutePath(cwd, "xulrunner/xulrunner"); + string application_ini = computeAbsolutePath(cwd, "application.ini"); + + // debug prints + // cout << "CurProg: " << progpath << endl; + // cout << "cwd: " << cwd << endl; + // cout << "LD path: " << ld_path << endl; + // cout << "xulrunner_path: " << xulrunner_path << endl; + // cout << "application_ini: " << application_ini << endl; + + // exist if xulrunner can't be found + if (!fileExists(xulrunner_path)) { + perror("Unable to find xulrunner binary"); + return EXIT_FAILURE; + } + + // execute xulrunner + return execl(xulrunner_path.c_str(), "xulrunner", application_ini.c_str(), "-jsconsole", NULL); +} \ No newline at end of file