X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fprefix.cpp;h=f1fa3c2cdfae7e9eaff1da5c14b134de645d1103;hb=905fbb5efba993402ccbb533733255e6466fa86d;hp=3c9ec6caea49e4d88d656065d53988dcfa71e759;hpb=6b15695578f07a3f72c4c9475c1a261a3021472a;p=inkscape.git diff --git a/src/prefix.cpp b/src/prefix.cpp index 3c9ec6cae..f1fa3c2cd 100644 --- a/src/prefix.cpp +++ b/src/prefix.cpp @@ -3,7 +3,7 @@ * Written by: Mike Hearn * Hongli Lai * http://autopackage.org/ - * + * * This source code is public domain. You can relicense this code * under whatever license you want. * @@ -39,12 +39,13 @@ #include //for GThreads #endif /* BR_THREADS */ -#include -#include -#include -#include +#include +#include +#include +#include #include "prefix.h" + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -355,7 +356,8 @@ br_strndup (char *str, size_t size) char * br_extract_dir (const char *path) { - char *end, *result; + const char *end; + char *result; br_return_val_if_fail (path != (char*)NULL, (char*)NULL); @@ -390,7 +392,8 @@ br_extract_dir (const char *path) char * br_extract_prefix (const char *path) { - char *end, *tmp, *result; + const char *end; + char *tmp, *result; br_return_val_if_fail (path != (char*)NULL, (char*)NULL); @@ -424,4 +427,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 +#include + +/** + * 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 */