32 #define _SCL_SECURE_NO_DEPRECATE
60 return LoadLibraryA( dll_file_name );
62 return LoadLibraryA( dll_file_name );
72 return (
void *) GetProcAddress( handle, function_name );
81 return FreeLibrary( handle );
91 long error = GetLastError();
95 szBuf =
new char[1024];
96 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
97 NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &szBuf, 0, NULL );
107 char initial_path[FILENAME_MAX];
109 int bytes = GetModuleFileName( NULL, initial_path, FILENAME_MAX );
117 string initial_path_str( initial_path );
121 last_sep = initial_path_str.find_last_of(
"/\\");
128 string path = initial_path_str.substr( 0, last_sep+1 );
131 string alg_path = path;
132 alg_path.append(
"algs" );
136 string data_path = path;
137 data_path.append(
"data" );
141 string gdal_data_path = path;
142 gdal_data_path.append(
"gdal" );
143 CPLSetConfigOption(
"GDAL_DATA", gdal_data_path.c_str() );
146 string proj_data_path = path;
147 proj_data_path.append(
"nad" );
148 const char * char_path = proj_data_path.c_str();
151 pj_set_searchpath( 1, paths );
158 static string data_path;
161 if ( ! dir.empty() ) {
175 char *env = getenv(
"OM_DATA_DIR" );
179 string om_data_path = (
char const *)env;
181 if ( ! om_data_path.empty() ) {
198 vector<string> entries;
203 if ( ! default_dir.empty() ) {
207 entries.push_back( default_dir );
220 char *env = getenv(
"OM_ALGS_DIR" );
224 string envpath( (
char const *)env );
227 if ( ! envpath.empty() ) {
236 for ( string::size_type start = 0; start < envpath.length() ; ) {
239 string::size_type it = envpath.find(
';', start );
242 if ( it == string::npos ) {
245 entries.push_back( envpath.substr( start ) );
249 else if ( it > start ) {
251 string::size_type len = it - start;
252 entries.push_back( envpath.substr( start, len ) );
267 entries.push_back( OM_ALGS_DIR );
285 string filepattern(dir);
287 struct _finddata_t fileinfo;
289 vector<string> entries;
298 if ( (filepattern.find_last_of(
"/") != filepattern.length() - 1) &&
299 (filepattern.find_last_of(
"\\") != filepattern.length() - 1) )
300 filepattern.append(
"\\");
303 filepattern.append(
"*.dll");
304 dirhandle = _findfirst(filepattern.c_str(), &fileinfo);
306 if (dirhandle == -1L)
310 while (!_findnext(dirhandle, &fileinfo))
317 dirhandle = _findfirst(filepattern.c_str(), &fileinfo);
319 if (dirhandle == -1L)
323 for (
int i = 0; i < nent; i++ )
325 char *found = fileinfo.name;
331 entries.push_back(name);
333 _findnext(dirhandle, &fileinfo);
336 _findclose(dirhandle);
355 seed = (
unsigned int) time( NULL );
365 static unsigned int seed = 0;
367 if ( seed && !new_seed ) {
379 seed = (
unsigned int) time( NULL );
394 * seed = (* seed) * 1103515245 + 12345;
395 return ((
unsigned)(*seed / 65536) % 32768);
404 return ( _getcwd(temp, MAX_PATH) ? std::string( temp ) : std::string(
"") );
412 DWORD ftyp = GetFileAttributesA( path.c_str() );
414 if ( ftyp == INVALID_FILE_ATTRIBUTES ) {
419 if ( ftyp & FILE_ATTRIBUTE_DIRECTORY ) {
432 static const std::string separators(
"\\/");
434 DWORD file_attr = ::GetFileAttributes( (LPCSTR) path.c_str() );
437 if ( file_attr == INVALID_FILE_ATTRIBUTES ) {
440 std::size_t slash_idx = path.find_last_of( separators.c_str() );
442 if ( slash_idx != std::string::npos ) {
449 ::CreateDirectory( (LPCSTR) path.c_str(), NULL );
static std::string getDefaultAlgDir()
dllexp int rand_r(unsigned *seed)
static Log * instance()
Returns the instance pointer, creating the object on the first call.
void setupExternalResources()
DLLHandle dllOpen(char const *dll_file_name)
static std::string get(const std::string &key)
const char * dllError(DLLHandle)
static void setDefaultAlgDir(std::string const dir)
bool createPath(const std::string path)
static int count(const std::string &key)
vector< string > scanDirectory(string dir)
void * dllFunction(DLLHandle handle, char const *function_name)
std::string omDataPath(std::string dir)
vector< string > initialPluginPath()
std::string getWorkingPath()
int dllClose(DLLHandle handle)
bool pathExists(const std::string path)
void debug(const char *format,...)
'Debug' level.