diff options
| author | Bob Jamison <ishmalius@gmail.com> | 2008-05-29 19:15:08 +0000 |
|---|---|---|
| committer | ishmal <ishmal@users.sourceforge.net> | 2008-05-29 19:15:08 +0000 |
| commit | 22e5131176ae8ca14aebb445203144fba3d1dfc9 (patch) | |
| tree | 038f531ff71e2e0a1805c3d27cfb053d54a3bbff /src/prefix.cpp | |
| parent | fix some crashes. Now I check for the existence of the d atrtibute (diff) | |
| download | inkscape-22e5131176ae8ca14aebb445203144fba3d1dfc9.tar.gz inkscape-22e5131176ae8ca14aebb445203144fba3d1dfc9.zip | |
Create a new macro in path-prefix.h, WIN32_DATADIR, that works similarly to BR_DATADIR. This should solve the "current directory" problems. This is a temporary fix.
(bzr r5762)
Diffstat (limited to 'src/prefix.cpp')
| -rw-r--r-- | src/prefix.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/prefix.cpp b/src/prefix.cpp index 0814bd53f..3af45269c 100644 --- a/src/prefix.cpp +++ b/src/prefix.cpp @@ -45,6 +45,7 @@ #include <limits.h> #include "prefix.h" + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -424,4 +425,78 @@ br_extract_prefix (const char *path) } #endif /* __cplusplus */ + + +#ifdef __WIN32__ + +/** + * Provide a similar mechanism for Win32. Enable a macro, + * WIN32_DATADIR, that can look up subpaths for inkscape resources + */ + +#include <windows.h> +#include <glibmm/ustring.h> + +/** + * Return the directory of the .exe that is currently running + */ +static Glib::ustring win32_getExePath() +{ + char exeName[MAX_PATH+1]; + GetModuleFileName(NULL, exeName, MAX_PATH); + char *slashPos = strrchr(exeName, '\\'); + if (slashPos) + *slashPos = '\0'; + Glib::ustring s = exeName; + return s; +} + + +/** + * Return the relocatable version of the datadir, + * probably c:\inkscape + */ +static Glib::ustring win32_getDataDir() +{ + Glib::ustring dir = win32_getExePath(); + if (INKSCAPE_DATADIR && *INKSCAPE_DATADIR && + strcmp(INKSCAPE_DATADIR, ".") != 0) + { + dir += "\\"; + dir += INKSCAPE_DATADIR; + } + return dir; +} + +static Glib::ustring win32_getResourcePath(const Glib::ustring &childPath) +{ + Glib::ustring dir = win32_getDataDir(); + if (childPath.size() > 0) + { + dir += "\\"; + dir += childPath; + } + return dir; +} + + +/** + * This is the visible utility function + */ +char *win32_relative_path(const char *childPath) +{ + static char *returnPath = NULL; + if (!childPath) + childPath = ""; + Glib::ustring resourcePath = win32_getResourcePath(childPath); + if (returnPath) + free(returnPath); + returnPath = strdup(resourcePath.c_str()); + return returnPath; +} +#endif /* __WIN32__ */ + + + + #endif /* _PREFIX_C */ |
