summaryrefslogtreecommitdiffstats
path: root/src/prefix.cpp
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2017-06-23 15:38:19 +0000
committerMartin Owens <doctormo@gmail.com>2017-06-23 15:38:19 +0000
commit131b4d74439118c7533b0adb7353aa7e29ba93ae (patch)
treed502c01751d683ffa73aaec48f6d5e7ea48ca75d /src/prefix.cpp
parentAttempt to make paintbucket build option not cause errors for toolbar loading (diff)
parentAttempt to make paintbucket build option not cause errors for toolbar loading (diff)
downloadinkscape-131b4d74439118c7533b0adb7353aa7e29ba93ae.tar.gz
inkscape-131b4d74439118c7533b0adb7353aa7e29ba93ae.zip
Merge branch 'ui-files-for-ui-xml' of gitlab.com:inkscape/inkscape into ui-files-for-ui-xml
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__ */