From 48f7c791bbb2716d4df61abc5e753d84ed3d4dfc Mon Sep 17 00:00:00 2001 From: Kelson42 Date: Mon, 19 May 2014 23:54:46 +0200 Subject: [PATCH] + port kiwix-launcher to Windows --- src/launcher/kiwix-launcher.cpp | 50 ++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/launcher/kiwix-launcher.cpp b/src/launcher/kiwix-launcher.cpp index 6d8957f..a4ff35b 100644 --- a/src/launcher/kiwix-launcher.cpp +++ b/src/launcher/kiwix-launcher.cpp @@ -20,7 +20,19 @@ */ #include + + +#ifdef _WIN32 +#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) +#include +#include +#define EXECL _execl +#define PUTENV _putenv +#else #include +#define EXECL execl +#define PUTENV putenv +#endif #include @@ -51,16 +63,24 @@ int main(int argc, char *argv[]) { xulrunnerDirectory.clear(); directoriesIt++; } - } + } if (!fileExists(xulrunnerDirectory)) { perror("Unable to find the xulrunner directory"); - return EXIT_FAILURE; + return EXIT_FAILURE; } /* Find xulrunner binary path */ +#ifdef _WIN32 + string xulrunnerPath = computeAbsolutePath(xulrunnerDirectory, "xulrunner-bin.exe"); +#else string xulrunnerPath = computeAbsolutePath(xulrunnerDirectory, "xulrunner-bin"); +#endif if (!fileExists(xulrunnerPath)) { +#ifdef _WIN32 + xulrunnerPath = computeAbsolutePath(xulrunnerDirectory, "xulrunner.exe"); +#else xulrunnerPath = computeAbsolutePath(xulrunnerDirectory, "xulrunner"); +#endif if (!fileExists(xulrunnerPath)) { perror("Unable to find neither the 'xulrunner-bin' nor the 'xulrunner' binary"); return EXIT_FAILURE; @@ -68,16 +88,14 @@ int main(int argc, char *argv[]) { } /* Compute application.ini path */ - string applicationIniPath = computeAbsolutePath(removeLastPathElement(xulrunnerDirectory, false, false), "application.ini"); + string applicationIniPath = "\"" + computeAbsolutePath(removeLastPathElement(xulrunnerDirectory, false, false), "application.ini") + "\""; /* Debug prints */ - /* cout << "Executable directory (executableDirectory): " << executableDirectory << endl; cout << "Executable path (executablePath): " << executablePath << endl; cout << "Xulrunner directory (xulrunnerDirectory): " << xulrunnerDirectory << endl; cout << "Xulrunner path (xulrunnerPath): " << xulrunnerPath << endl; cout << "Application.ini path (applicationIniPath): " << applicationIniPath << endl; - */ /* Modify environnement variables */ #ifdef _WIN32 @@ -87,41 +105,41 @@ int main(int argc, char *argv[]) { #endif string ldLibraryPath = getenv("LD_LIBRARY_PATH") == NULL ? "" : string(getenv("LD_LIBRARY_PATH")); string putenvStr = "LD_LIBRARY_PATH=" + xulrunnerDirectory + sep + ldLibraryPath; - putenv((char *)putenvStr.c_str()); + PUTENV((char *)putenvStr.c_str()); /* Launch xulrunner */ if (argc == 0) { - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), "", NULL); } else if (argc == 1) { - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), argv[1], NULL); } else if (argc == 2) { - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), argv[1], argv[2], NULL); } else if (argc == 3) { - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), argv[1], argv[2], argv[3], NULL); } else if (argc == 4) { - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), argv[1], argv[2], argv[3], argv[4], NULL); } else if (argc == 5) { - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), argv[1], argv[2], argv[3], argv[4], argv[5], NULL); } else if (argc == 6) { - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], NULL); } else if (argc == 7) { - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], NULL); } else if (argc == 8) { - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], NULL); } else if (argc >= 9) { if (argc > 9) { fprintf(stderr, "Kiwix was not able to forward all your arguments to the xulrunner binary."); } - return execl(xulrunnerPath.c_str(), xulrunnerPath.c_str(), applicationIniPath.c_str(), + return EXECL(xulrunnerPath.c_str(), "kiwix-launcher", applicationIniPath.c_str(), argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], NULL); } }