mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-24 04:20:56 -04:00
This commit is contained in:
parent
257ab58299
commit
afb0ac6947
@ -17,7 +17,6 @@
|
|||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <libgen.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -40,6 +39,7 @@
|
|||||||
#include <kiwix/reader.h>
|
#include <kiwix/reader.h>
|
||||||
#include <kiwix/xapianSearcher.h>
|
#include <kiwix/xapianSearcher.h>
|
||||||
#include <kiwix/cluceneSearcher.h>
|
#include <kiwix/cluceneSearcher.h>
|
||||||
|
#include <pathTools.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -345,9 +345,9 @@ static int accessHandlerCallback(void *cls,
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct MHD_Daemon *daemon;
|
struct MHD_Daemon *daemon;
|
||||||
string zimPath = "";
|
string zimPath;
|
||||||
string indexPath = "";
|
string indexPath;
|
||||||
char rootPath[PATH_MAX];
|
string rootPath;
|
||||||
int serverPort = 80;
|
int serverPort = 80;
|
||||||
int daemonFlag = false;
|
int daemonFlag = false;
|
||||||
|
|
||||||
@ -436,27 +436,32 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
/* Change the current dir to binary dir */
|
/* Change the current dir to binary dir */
|
||||||
/* Non portable linux solution */
|
/* Non portable linux solution */
|
||||||
readlink("/proc/self/exe", rootPath, PATH_MAX);
|
rootPath = getExecutablePath();
|
||||||
chdir(dirname(rootPath));
|
chdir(removeLastPathElement(rootPath).c_str());
|
||||||
|
|
||||||
/* Try to load the result template */
|
/* Try to load the result template */
|
||||||
try {
|
try {
|
||||||
fstream templateStream;
|
|
||||||
templateStream.open("../share/kiwix/static/results.tmpl", ifstream::in);
|
#ifdef _WIN32
|
||||||
|
const char* pathArray[] = {"chrome\\static\\results.tmpl"};
|
||||||
if (templateStream.fail()) {
|
std::vector<std::string> templatePaths(pathArray, pathArray+1);
|
||||||
templateStream.open("../../static/results.tmpl", ifstream::in);
|
#elif APPLE
|
||||||
|
#else
|
||||||
if (templateStream.fail()) {
|
const char* pathArray[] = {"../share/kiwix/static/results.tmpl", "../../static/results.tmpl"};
|
||||||
throw "Unable to find a result template file.";
|
std::vector<std::string> templatePaths(pathArray, pathArray+2);
|
||||||
} else {
|
#endif
|
||||||
realpath("../../static/results.tmpl", rootPath);
|
vector<string>::const_iterator templatePathsIt;
|
||||||
searcher->setResultTemplatePath(rootPath);
|
bool templateFound = false;
|
||||||
|
for(templatePathsIt=templatePaths.begin(); !templateFound && templatePathsIt != templatePaths.end(); templatePathsIt++) {
|
||||||
|
string templatePath = computeAbsolutePath(removeLastPathElement(rootPath), *templatePathsIt);
|
||||||
|
if (fileExists(templatePath)) {
|
||||||
|
searcher->setResultTemplatePath(templatePath);
|
||||||
|
templateFound = true;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
realpath("../share/kiwix/static/results.tmpl", rootPath);
|
if (!templateFound) {
|
||||||
searcher->setResultTemplatePath(rootPath);
|
throw("Unable to find a valid template file.");
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
cerr << "Unable to open the result template file." << endl;
|
cerr << "Unable to open the result template file." << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user