mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 01:27:03 +08:00
Added windows function to find relative dir of exe for conf and runtime
data
This commit is contained in:
@@ -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;
|
||||
|
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "simpleini/simpleini.h"
|
||||
#include "support/filesystem.h"
|
||||
#include "support/platform.h"
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
|
@@ -21,6 +21,7 @@
|
||||
|
||||
|
||||
|
||||
#define RUNTIME_DIR "/runtime_data"
|
||||
#define CONFIG_FILE "/openalpr.conf"
|
||||
#define KEYPOINTS_DIR "/keypoints"
|
||||
#define CASCADE_DIR "/region/"
|
||||
|
@@ -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
|
||||
}
|
@@ -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
|
||||
|
Reference in New Issue
Block a user