Skip to content

Commit

Permalink
Improved tessdata dir detection for windows
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@236 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith committed Jun 2, 2009
1 parent e4b9281 commit 7443d2f
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions ccutil/basedir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
#endif
#include <stdlib.h>
#include "basedir.h"
#include "varable.h"
#include "notdll.h" //must be last include

#ifdef __MSW32__
STRING_VAR(tessedit_module_name, "tessdll.dll",
"Module colocated with tessdata dir");
#endif

/**********************************************************************
* getpath
*
Expand Down Expand Up @@ -88,17 +94,25 @@ DLLSYM inT8 getpath( //get dir name of code
#ifdef __MSW32__
char *path_end; //end of dir

if (GetModuleFileName (NULL, directory, MAX_PATH - 1) == 0) {
return -1;
if (code == NULL) {
// Attempt to get the path of the most relevant module. If the dll
// is being used, this will be the dll. Otherwise GetModuleHandle will
// return NULL and default to the path of the executable.
if (GetModuleFileName(GetModuleHandle(tessedit_module_name.string()),
directory, MAX_PATH - 1) == 0) {
return -1;
}
while ((path_end = strchr (directory, '\\')) != NULL)
*path_end = '/';
path_end = strrchr (directory, '/');
if (path_end != NULL)
path_end[1] = '\0';
else
strcpy (directory, "./");
path = directory;
} else {
path = code;
}
while ((path_end = strchr (directory, '\\')) != NULL)
*path_end = '/';
path_end = strrchr (directory, '/');
if (path_end != NULL)
path_end[1] = '\0';
else
strcpy (directory, "./");
path = directory;
return 0;
#endif
}

0 comments on commit 7443d2f

Please sign in to comment.