summaryrefslogtreecommitdiffstats
path: root/src/prefix.cpp
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-06-24 17:50:36 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-06-24 17:50:36 +0000
commitd71265c629a103d8c821fe85ccf71bd9c93baf47 (patch)
treec01fe4543cd48f64a8ca4b60e01e1bb5040922d9 /src/prefix.cpp
parentWorking with powerclip and powermask (diff)
parentMerge branch 'ui-files-for-ui-xml' (diff)
downloadinkscape-d71265c629a103d8c821fe85ccf71bd9c93baf47.tar.gz
inkscape-d71265c629a103d8c821fe85ccf71bd9c93baf47.zip
Updating to master
Diffstat (limited to 'src/prefix.cpp')
-rw-r--r--src/prefix.cpp75
1 files changed, 20 insertions, 55 deletions
diff --git a/src/prefix.cpp b/src/prefix.cpp
index 4e2204cff..c8bf7abec 100644
--- a/src/prefix.cpp
+++ b/src/prefix.cpp
@@ -419,72 +419,37 @@ br_extract_prefix (const char *path)
#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
*/
-Glib::ustring win32_getExePath()
-{
- gunichar2 path[2048];
- GetModuleFileNameW(0, (WCHAR*) path, 2048);
- gchar *exe = g_utf16_to_utf8(path, -1, 0,0,0);
- gchar *dir = g_path_get_dirname(exe);
- Glib::ustring ret = dir;
- g_free(dir);
- g_free(exe);
- return ret;
-}
-
/**
- * Return the relocatable version of the datadir,
- * probably c:\inkscape
+ * Get the Windows-equivalent of INKSCAPE_DATADIR and append a relative path
+ *
+ * - by default INKSCAPE_DATADIR will be relative to the called executable
+ * (typically inkscape/share but also handles the case where the executable is in a /bin subfolder)
+ * - to override set the INKSCAPE_DATADIR environment variable
*/
-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)
+char *win32_append_datadir(const char *relative_path)
{
- Glib::ustring dir = win32_getDataDir();
- if (childPath.size() > 0)
- {
- dir += "\\";
- dir += childPath;
+ static gchar *datadir;
+ if (!datadir) {
+ gchar const *inkscape_datadir = g_getenv("INKSCAPE_DATADIR");
+ if (inkscape_datadir) {
+ datadir = g_strdup(inkscape_datadir);
+ } else {
+ gchar *module_path = g_win32_get_package_installation_directory_of_module(NULL);
+ datadir = g_build_filename(module_path, "share", NULL);
+ g_free(module_path);
}
- return dir;
-}
+ }
+ if (!relative_path) {
+ relative_path = "";
+ }
-/**
- * This is the visible utility function
- */
-char *win32_relative_path(const char *childPath)
-{
- static char *returnPath = 0;
- if (!childPath)
- childPath = "";
- Glib::ustring resourcePath = win32_getResourcePath(childPath);
- if (returnPath)
- free(returnPath);
- returnPath = strdup(resourcePath.c_str());
- return returnPath;
+ return g_build_filename(datadir, relative_path, NULL);
}
#endif /* __WIN32__ */