mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-28 14:51:16 -04:00
+ Make kiwix-launcher able to find xulrunner binary on the system
This commit is contained in:
parent
13d6098820
commit
a789ae8147
@ -33,11 +33,28 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "pathTools.h"
|
#include "pathTools.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/* Split string in a token array */
|
||||||
|
std::vector<std::string> split(const std::string & str,
|
||||||
|
const std::string & delims=" *-")
|
||||||
|
{
|
||||||
|
std::string::size_type lastPos = str.find_first_not_of(delims, 0);
|
||||||
|
std::string::size_type pos = str.find_first_of(delims, lastPos);
|
||||||
|
std::vector<std::string> tokens;
|
||||||
|
|
||||||
|
while (std::string::npos != pos || std::string::npos != lastPos)
|
||||||
|
{
|
||||||
|
tokens.push_back(str.substr(lastPos, pos - lastPos));
|
||||||
|
lastPos = str.find_first_not_of(delims, pos);
|
||||||
|
pos = str.find_first_of(delims, lastPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
/* Quote string on Windows */
|
/* Quote string on Windows */
|
||||||
char *prepareArgument(const char *argument) {
|
char *prepareArgument(const char *argument) {
|
||||||
if (argument != NULL) {
|
if (argument != NULL) {
|
||||||
@ -60,47 +77,82 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
/* Possible xulrunner paths */
|
/* Possible xulrunner paths */
|
||||||
std::vector<std::string> xulrunnerPossibleDirectories;
|
std::vector<std::string> xulrunnerPossibleDirectories;
|
||||||
xulrunnerPossibleDirectories.push_back("xulrunner");
|
std::vector<std::string>::iterator directoriesIt;
|
||||||
xulrunnerPossibleDirectories.push_back("kiwix/xulrunner");
|
|
||||||
xulrunnerPossibleDirectories.push_back("kiwix-linux/xulrunner");
|
|
||||||
xulrunnerPossibleDirectories.push_back("kiwix-win/xulrunner");
|
|
||||||
xulrunnerPossibleDirectories.push_back("kiwix-windows/xulrunner");
|
|
||||||
|
|
||||||
/* Find xulrunner directory */
|
/* Possible xulrunner paths: local directories */
|
||||||
string xulrunnerDirectory;
|
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "xulrunner"));
|
||||||
std::vector<std::string>::iterator directoriesIt = xulrunnerPossibleDirectories.begin();
|
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix/xulrunner"));
|
||||||
while (xulrunnerDirectory.empty() && directoriesIt != xulrunnerPossibleDirectories.end()) {
|
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix-linux/xulrunner"));
|
||||||
xulrunnerDirectory = computeAbsolutePath(executableDirectory, *directoriesIt);
|
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix-win/xulrunner"));
|
||||||
if (!fileExists(xulrunnerDirectory)) {
|
xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix-windows/xulrunner"));
|
||||||
xulrunnerDirectory.clear();
|
|
||||||
directoriesIt++;
|
/* Possible xulrunner paths: system directories */
|
||||||
}
|
string binaryPath = getenv("PATH") == NULL ? "" : string(getenv("PATH"));
|
||||||
|
std::vector<std::string> xulrunnerPossibleSystemDirectories = ::split(binaryPath, ":");
|
||||||
|
for (directoriesIt = xulrunnerPossibleSystemDirectories.begin() ;
|
||||||
|
directoriesIt != xulrunnerPossibleSystemDirectories.end() ;
|
||||||
|
directoriesIt++) {
|
||||||
|
xulrunnerPossibleDirectories.push_back(*directoriesIt);
|
||||||
}
|
}
|
||||||
if (!fileExists(xulrunnerDirectory)) {
|
|
||||||
perror("Unable to find the xulrunner directory");
|
/* Find xulrunner (binary) path */
|
||||||
|
string xulrunnerPath;
|
||||||
|
directoriesIt = xulrunnerPossibleDirectories.begin();
|
||||||
|
while (xulrunnerPath.empty() && directoriesIt != xulrunnerPossibleDirectories.end()) {
|
||||||
|
if (fileExists(*directoriesIt)) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
xulrunnerPath = computeAbsolutePath(*directoriesIt, "xulrunner-bin.exe");
|
||||||
|
#else
|
||||||
|
xulrunnerPath = computeAbsolutePath(*directoriesIt, "xulrunner-bin");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!fileExists(xulrunnerPath)) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
xulrunnerPath = computeAbsolutePath(*directoriesIt, "xulrunner.exe");
|
||||||
|
#else
|
||||||
|
xulrunnerPath = computeAbsolutePath(*directoriesIt, "xulrunner");
|
||||||
|
#endif
|
||||||
|
if (!fileExists(xulrunnerPath)) {
|
||||||
|
xulrunnerPath.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
directoriesIt++;
|
||||||
|
}
|
||||||
|
if (!fileExists(xulrunnerPath)) {
|
||||||
|
perror("Unable to find neither the 'xulrunner-bin' nor the 'xulrunner' binary");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find xulrunner binary path */
|
/* Compute xulrunner directory */
|
||||||
#ifdef _WIN32
|
string xulrunnerDirectory = removeLastPathElement(xulrunnerPath);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Compute application.ini path */
|
/* Compute application.ini path */
|
||||||
string applicationIniPath = computeAbsolutePath(removeLastPathElement(xulrunnerDirectory, false, false), "application.ini");
|
std::vector<std::string> applicationIniPossiblePaths;
|
||||||
|
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
|
||||||
|
"application.ini"));
|
||||||
|
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
|
||||||
|
"kiwix/application.ini"));
|
||||||
|
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
|
||||||
|
"kiwix-linux/application.ini"));
|
||||||
|
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
|
||||||
|
"kiwix-win/application.ini"));
|
||||||
|
applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory,
|
||||||
|
"kiwix-windows/application.ini"));
|
||||||
|
|
||||||
|
string applicationIniPath;
|
||||||
|
std::vector<std::string>::iterator filesIt = applicationIniPossiblePaths.begin();
|
||||||
|
while (applicationIniPath.empty() &&
|
||||||
|
filesIt != applicationIniPossiblePaths.end()) {
|
||||||
|
if (fileExists(*filesIt)) {
|
||||||
|
applicationIniPath = *filesIt;
|
||||||
|
}
|
||||||
|
filesIt++;
|
||||||
|
};
|
||||||
|
if (!fileExists(xulrunnerPath)) {
|
||||||
|
perror("Unable to find the application.ini file");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Debug prints */
|
/* Debug prints */
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user