From f2ea7ba114e45f3bf90d630a965c96870c564c0d Mon Sep 17 00:00:00 2001 From: ishmal Date: Thu, 29 May 2008 19:15:08 +0000 Subject: [PATCH] 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. --- src/bind/javabind.cpp | 6 ++- src/extension/init.cpp | 20 -------- src/main.cpp | 113 ++++++++++++++++++++++++----------------- src/path-prefix.h | 38 +++++++------- src/prefix.cpp | 75 +++++++++++++++++++++++++++ src/prefix.h | 11 ++++ 6 files changed, 177 insertions(+), 86 deletions(-) diff --git a/src/bind/javabind.cpp b/src/bind/javabind.cpp index af287dc7e..7185330e8 100644 --- a/src/bind/javabind.cpp +++ b/src/bind/javabind.cpp @@ -479,10 +479,14 @@ static CreateVMFunc getCreateVMFunc() */ static void getJavaRoot(String &javaroot) { - javaroot = getExePath(); + /* + javaroot = getExePath(); javaroot.append("\\"); javaroot.append(INKSCAPE_BINDDIR); javaroot.append("\\java"); + */ + javaroot = INKSCAPE_BINDDIR; + javaroot.append("\\java"); } diff --git a/src/extension/init.cpp b/src/extension/init.cpp index 649a65471..458f15e78 100644 --- a/src/extension/init.cpp +++ b/src/extension/init.cpp @@ -239,27 +239,7 @@ init() { Inkscape::Extension::Extension::search_path.push_back(profile_path("extensions")); -#ifdef WIN32 -/* - * The native Windows Save dialogs change the current directory of Inkscape to the path selected in the dialog - * Putting relative paths in the search_path breaks things after the Save dialog ha been shown - * Especially the XAML-save: https://bugs.launchpad.net/inkscape/+bug/168896 - * This code inserts an absolute path based on the current working dir when Inkscape starts. - * Only included in WIN32 to avoid messing around with other platforms for the moment - * After testing on other platforms this code can be enabled on other platforms (it "should" not break anything). - */ - gchar * cwd = g_get_current_dir(); - gchar * fname = g_build_filename( - cwd, - g_strdup(INKSCAPE_EXTENSIONDIR), - NULL); - Glib::ustring filename = fname; - Inkscape::Extension::Extension::search_path.push_back(g_strdup(filename.c_str())); - g_free(cwd); - g_free(fname); -#else Inkscape::Extension::Extension::search_path.push_back(g_strdup(INKSCAPE_EXTENSIONDIR)); -#endif } diff --git a/src/main.cpp b/src/main.cpp index 463428e0c..83170931f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -413,36 +413,41 @@ struct poptOption options[] = { static bool needToRecodeParams = true; gchar * blankParam = g_strdup(""); -#ifdef WIN32 -static int _win32_set_inkscape_env(char *argv0) -{ - CHAR szFullPath[_MAX_PATH]; - CHAR szDrive[_MAX_DRIVE]; - CHAR szDir[_MAX_DIR]; - CHAR szFile[_MAX_FNAME]; - CHAR szExt[_MAX_EXT]; - std::string tmp; +#ifdef WIN32 - if (GetModuleFileName(NULL, szFullPath, sizeof(szFullPath)) == 0) { - strcpy(szFullPath, argv0); - } +/** + * 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; +} - _splitpath(szFullPath, szDrive, szDir, szFile, szExt); - strcpy(szFullPath, szDrive); - strcat(szFullPath, szDir); +/** + * Set up the PATH and PYTHONPATH environment variables on + * win32 + */ +static int _win32_set_inkscape_env(const Glib::ustring &exePath) +{ char *oldenv = getenv("PATH"); - tmp = "PATH="; - tmp += szFullPath; + Glib::ustring tmp = "PATH="; + tmp += exePath; tmp += ";"; - tmp += szFullPath; - tmp += "python;"; - tmp += szFullPath; - tmp += "python\\Scripts;"; // for uniconv.cmd - tmp += szFullPath; - tmp += "perl"; + tmp += exePath; + tmp += "\\python;"; + tmp += exePath; + tmp += "\\python\\Scripts;"; // for uniconv.cmd + tmp += exePath; + tmp += "\\perl"; if(oldenv != NULL) { tmp += ";"; tmp += oldenv; @@ -451,12 +456,12 @@ static int _win32_set_inkscape_env(char *argv0) oldenv = getenv("PYTHONPATH"); tmp = "PYTHONPATH="; - tmp += szFullPath; - tmp += "python;"; - tmp += szFullPath; - tmp += "python\\Lib;"; - tmp += szFullPath; - tmp += "python\\DLLs"; + tmp += exePath; + tmp += "\\python;"; + tmp += exePath; + tmp += "\\python\\Lib;"; + tmp += exePath; + tmp += "\\python\\DLLs"; if(oldenv != NULL) { tmp += ";"; tmp += oldenv; @@ -467,6 +472,12 @@ static int _win32_set_inkscape_env(char *argv0) } #endif + + +/** + * This is the classic main() entry point of the program, though on some + * architectures it might be called by something else. + */ int main(int argc, char **argv) { @@ -477,14 +488,30 @@ main(int argc, char **argv) fpsetmask(fpgetmask() & ~(FP_X_DZ | FP_X_INV)); #endif -#ifdef ENABLE_NLS #ifdef WIN32 - _win32_set_inkscape_env(argv[0]); + /* + Set the current directory to the directory of the + executable. This seems redundant, but is needed for + when inkscape.exe is executed from another directory. + We use relative paths on win32. + HKCR\svgfile\shell\open\command is a good example + */ + Glib::ustring homedir = _win32_getExePath(); + SetCurrentDirectory(homedir.c_str()); + _win32_set_inkscape_env(homedir); RegistryTool rt; rt.setPathInfo(); - gchar *pathBuf = g_strconcat(g_path_get_dirname(argv[0]), "\\", PACKAGE_LOCALE_DIR, NULL); - bindtextdomain(GETTEXT_PACKAGE, pathBuf); - g_free(pathBuf); +#endif + + /** + * Call bindtextdomain() for various machines's paths + */ +#ifdef ENABLE_NLS +#ifdef WIN32 + Glib::ustring localePath = homedir; + localePath += "\\"; + localePath += PACKAGE_LOCALE_DIR; + bindtextdomain(GETTEXT_PACKAGE, localePath.c_str()); #else #ifdef ENABLE_BINRELOC bindtextdomain(GETTEXT_PACKAGE, BR_LOCALEDIR("")); @@ -513,21 +540,10 @@ main(int argc, char **argv) Inkscape::Debug::Logger::init(); gboolean use_gui; + #ifndef WIN32 use_gui = (getenv("DISPLAY") != NULL); #else - /* - Set the current directory to the directory of the - executable. This seems redundant, but is needed for - when inkscape.exe is executed from another directory. - We use relative paths on win32. - HKCR\svgfile\shell\open\command is a good example - */ - /// \todo FIXME BROKEN - non-UTF-8 sneaks in here. - char *homedir = g_path_get_dirname(argv[0]); - SetCurrentDirectory(homedir); - g_free(homedir); - use_gui = TRUE; #endif /* Test whether with/without GUI is forced */ @@ -594,6 +610,9 @@ main(int argc, char **argv) return app.run(); } + + + void fixupSingleFilename( gchar **orig, gchar **spare ) { if ( orig && *orig && **orig ) { @@ -610,6 +629,8 @@ void fixupSingleFilename( gchar **orig, gchar **spare ) } } + + GSList *fixupFilenameEncoding( GSList* fl ) { GSList *newFl = NULL; diff --git a/src/path-prefix.h b/src/path-prefix.h index 72c21ca55..447ddcf85 100644 --- a/src/path-prefix.h +++ b/src/path-prefix.h @@ -43,26 +43,26 @@ extern "C" { # define CREATE_PATTERNSDIR BR_DATADIR( "/create/patterns/vector" ) #else # ifdef WIN32 -# define INKSCAPE_APPICONDIR "pixmaps" -# define INKSCAPE_BINDDIR "share\\bind" -# define INKSCAPE_EXAMPLESDIR "share\\examples" -# define INKSCAPE_EXTENSIONDIR "share\\extensions" -# define INKSCAPE_FILTERDIR "share\\filters" -# define INKSCAPE_GRADIENTSDIR "share\\gradients" -# define INKSCAPE_KEYSDIR "share\\keys" -# define INKSCAPE_PIXMAPDIR "share\\icons" -# define INKSCAPE_MARKERSDIR "share\\markers" -# define INKSCAPE_PALETTESDIR "share\\palettes" -# define INKSCAPE_PATTERNSDIR "share\\patterns" -# define INKSCAPE_SCREENSDIR "share\\screens" -# define INKSCAPE_TUTORIALSDIR "share\\tutorials" -# define INKSCAPE_PLUGINDIR "plugins" -# define INKSCAPE_TEMPLATESDIR "share\\templates" -# define INKSCAPE_UIDIR INKSCAPE_DATADIR "\\share\\ui" +# define INKSCAPE_APPICONDIR WIN32_DATADIR("pixmaps") +# define INKSCAPE_BINDDIR WIN32_DATADIR("share\\bind") +# define INKSCAPE_EXAMPLESDIR WIN32_DATADIR("share\\examples") +# define INKSCAPE_EXTENSIONDIR WIN32_DATADIR("share\\extensions") +# define INKSCAPE_FILTERDIR WIN32_DATADIR("share\\filters") +# define INKSCAPE_GRADIENTSDIR WIN32_DATADIR("share\\gradients") +# define INKSCAPE_KEYSDIR WIN32_DATADIR("share\\keys") +# define INKSCAPE_PIXMAPDIR WIN32_DATADIR("share\\icons") +# define INKSCAPE_MARKERSDIR WIN32_DATADIR("share\\markers") +# define INKSCAPE_PALETTESDIR WIN32_DATADIR("share\\palettes") +# define INKSCAPE_PATTERNSDIR WIN32_DATADIR("share\\patterns") +# define INKSCAPE_SCREENSDIR WIN32_DATADIR("share\\screens") +# define INKSCAPE_TUTORIALSDIR WIN32_DATADIR("share\\tutorials") +# define INKSCAPE_PLUGINDIR WIN32_DATADIR("plugins") +# define INKSCAPE_TEMPLATESDIR WIN32_DATADIR("share\\templates") +# define INKSCAPE_UIDIR WIN32_DATADIR("share\\ui") //CREATE V0.1 WIN32 support -# define CREATE_GRADIENTSDIR INKSCAPE_DATADIR "create\\gradients\\gimp" -# define CREATE_PALETTESDIR INKSCAPE_DATADIR "create\\swatches" -# define CREATE_PATTERNSDIR INKSCAPE_DATADIR "create\\patterns\\vector" +# define CREATE_GRADIENTSDIR WIN32_DATADIR("create\\gradients\\gimp") +# define CREATE_PALETTESDIR WIN32_DATADIR("create\\swatches") +# define CREATE_PATTERNSDIR WIN32_DATADIR("create\\patterns\\vector") # elif defined ENABLE_OSX_APP_LOCATIONS # define INKSCAPE_APPICONDIR "Contents/Resources/pixmaps" # define INKSCAPE_BINDDIR "Contents/Resources/bind" 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 #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 +#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 */ diff --git a/src/prefix.h b/src/prefix.h index 0406f29f8..0c2db5b58 100644 --- a/src/prefix.h +++ b/src/prefix.h @@ -114,6 +114,17 @@ char *br_strcat (const char *str1, const char *str2); char *br_extract_dir (const char *path); char *br_extract_prefix(const char *path); +#ifdef __WIN32__ + +/** + * Win32 version of a relocatable function + */ +char *win32_relative_path(const char *childPath); + +#define WIN32_DATADIR(suffix) (win32_relative_path(suffix)) + +#endif + #ifdef __cplusplus } -- 2.30.2