Added windows function to find relative dir of exe for conf and runtime

data
This commit is contained in:
Matt Hill
2014-08-19 22:14:32 -04:00
parent c6cc360d5a
commit 1390eaeecd
5 changed files with 42 additions and 0 deletions

View File

@@ -46,6 +46,11 @@ Config::Config(const std::string country, const std::string config_file, const s
configFile = envConfigFile;
debug_message = "Config file location provided via environment variable: " + string(ENV_VARIABLE_CONFIG_FILE);
}
else if (DirectoryExists(getExeDir().c_str()) && fileExists((getExeDir() + CONFIG_FILE).c_str()))
{
configFile = getExeDir() + CONFIG_FILE;
debug_message = "Config file location provided via exe location";
}
else
{
// Use the default
@@ -83,6 +88,14 @@ Config::Config(const std::string country, const std::string config_file, const s
this->runtimeBaseDir = runtime_dir;
}
if ((DirectoryExists(this->runtimeBaseDir.c_str()) == false) &&
(DirectoryExists((getExeDir() + RUNTIME_DIR).c_str())))
{
// Runtime dir in the config is invalid and there is a runtime dir in the same dir as the exe.
this->runtimeBaseDir = getExeDir() + RUNTIME_DIR;
}
if (DirectoryExists(this->runtimeBaseDir.c_str()) == false)
{
std::cerr << "--(!) Runtime directory '" << this->runtimeBaseDir << "' does not exist!" << endl;

View File

@@ -24,6 +24,7 @@
#include "simpleini/simpleini.h"
#include "support/filesystem.h"
#include "support/platform.h"
#include "constants.h"

View File

@@ -21,6 +21,7 @@
#define RUNTIME_DIR "/runtime_data"
#define CONFIG_FILE "/openalpr.conf"
#define KEYPOINTS_DIR "/keypoints"
#define CASCADE_DIR "/region/"

View File

@@ -8,3 +8,24 @@ void sleep_ms(int sleepMs)
usleep(sleepMs * 1000); // usleep takes sleep time in us (1 millionth of a second)
#endif
}
std::string getExeDir()
{
#ifdef WINDOWS
TCHAR szEXEPath[2048];
std::stringstream ss;
GetModuleFileName(NULL, szEXEPath, 2048);
ss << szEXEPath;
std::string exeFile = ss.str();
std::string directory;
const size_t last_slash_idx = exeFile.rfind('\\');
if (std::string::npos != last_slash_idx)
{
directory = exeFile.substr(0, last_slash_idx);
}
return directory;
#else
return "";
#endif
}

View File

@@ -1,6 +1,9 @@
#ifndef OPENALPR_PLATFORM_H
#define OPENALPR_PLATFORM_H
#include <string>
#include <sstream>
#ifdef WINDOWS
#include <windows.h>
#else
@@ -8,7 +11,10 @@
#endif
void sleep_ms(int sleepMs);
std::string getExeDir();
#endif //OPENALPR_PLATFORM_H