diff --git a/src/prefix.cpp b/src/prefix.cpp
index 3c9ec6caea49e4d88d656065d53988dcfa71e759..f1fa3c2cdfae7e9eaff1da5c14b134de645d1103 100644 (file)
--- a/src/prefix.cpp
+++ b/src/prefix.cpp
* Written by: Mike Hearn <mike@theoretic.com>
* Hongli Lai <h.lai@chello.nl>
* http://autopackage.org/
- *
+ *
* This source code is public domain. You can relicense this code
* under whatever license you want.
*
#include <glib.h> //for GThreads
#endif /* BR_THREADS */
-#include <stdlib.h>
-#include <stdio.h>
-#include <limits.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstdio>
+#include <cstring>
+#include <limits.h>
#include "prefix.h"
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
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);
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);
}
#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 */