From 5912342e3f530ce8663a85b75a905beda5914a76 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 19 Oct 2014 17:27:02 +0200 Subject: [PATCH] + support of home path with non-ASCII chars --- src/App/Application.cpp | 37 ++++++++++++++++++++++--------------- src/App/ApplicationPy.cpp | 4 ++-- src/App/FreeCADInit.py | 5 ++--- src/Gui/FreeCADGuiInit.py | 4 ++-- src/Main/MainGui.cpp | 2 -- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 1af228e57..0cdeba513 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -2000,31 +2000,38 @@ std::string Application::FindHomePath(const char* sCall) // We have three ways to start this application either use one of the both executables or // import the FreeCAD.pyd module from a running Python session. In the latter case the // Python interpreter is already initialized. - char szFileName [MAX_PATH] ; + wchar_t szFileName [MAX_PATH]; if (Py_IsInitialized()) { - GetModuleFileName(GetModuleHandle(sCall),szFileName, MAX_PATH-1); + GetModuleFileNameW(GetModuleHandle(sCall),szFileName, MAX_PATH-1); } else { - GetModuleFileName(0, szFileName, MAX_PATH-1); + GetModuleFileNameW(0, szFileName, MAX_PATH-1); } - std::string Call(szFileName), TempHomePath; - std::string::size_type pos = Call.find_last_of(PATHSEP); - TempHomePath.assign(Call,0,pos); - pos = TempHomePath.find_last_of(PATHSEP); - TempHomePath.assign(TempHomePath,0,pos+1); + std::wstring Call(szFileName), homePath; + std::wstring::size_type pos = Call.find_last_of(PATHSEP); + homePath.assign(Call,0,pos); + pos = homePath.find_last_of(PATHSEP); + homePath.assign(homePath,0,pos+1); // switch to posix style - for (std::string::iterator i=TempHomePath.begin();i!=TempHomePath.end();++i) { - if (*i == '\\') - *i = '/'; + for (std::wstring::iterator it = homePath.begin(); it != homePath.end(); ++it) { + if (*it == '\\') + *it = '/'; } // fixes #0001638 to avoid to load DLLs from Windows' system directories before FreeCAD's bin folder - std::string binPath = TempHomePath; - binPath += "bin"; - SetDllDirectory(binPath.c_str()); - return TempHomePath; + std::wstring binPath = homePath; + binPath += L"bin"; + SetDllDirectoryW(binPath.c_str()); + + // http://stackoverflow.com/questions/5625884/conversion-of-stdwstring-to-qstring-throws-linker-error +#ifdef _MSC_VER + QString str = QString::fromUtf16(reinterpret_cast(homePath.c_str())); +#else + QString str = QString::fromStdWString(homePath); +#endif + return str.toStdString(); } #else diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index d874fef66..000a3c440 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -522,7 +522,7 @@ PyObject* Application::sGetResourceDir(PyObject * /*self*/, PyObject *args,PyObj if (!PyArg_ParseTuple(args, "")) // convert args: Python->C return NULL; // NULL triggers exception - Py::String datadir(Application::getResourceDir()); + Py::String datadir(Application::getResourceDir(),"utf-8"); return Py::new_reference_to(datadir); } @@ -531,7 +531,7 @@ PyObject* Application::sGetHomePath(PyObject * /*self*/, PyObject *args,PyObject if (!PyArg_ParseTuple(args, "")) // convert args: Python->C return NULL; // NULL triggers exception - Py::String homedir(GetApplication().getHomePath()); + Py::String homedir(GetApplication().getHomePath(),"utf-8"); return Py::new_reference_to(homedir); } diff --git a/src/App/FreeCADInit.py b/src/App/FreeCADInit.py index d99892b14..4212d6913 100644 --- a/src/App/FreeCADInit.py +++ b/src/App/FreeCADInit.py @@ -52,7 +52,6 @@ def InitApplications(): HomeMod = os.path.realpath(HomeMod) MacroDir = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro").GetString("MacroPath") MacroMod = os.path.realpath(MacroDir+"/Mod") - ModPar = FreeCAD.ParamGet("System parameter:Modules") #print FreeCAD.getHomePath() if os.path.isdir(FreeCAD.getHomePath()+'src\\Tools'): @@ -88,13 +87,13 @@ def InitApplications(): FreeCAD.__path__ = ModDict.values() for Dir in ModDict.values(): if ((Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py')): - ModGrp = ModPar.GetGroup(Dir) sys.path.insert(0,Dir) PathExtension += Dir + os.pathsep InstallFile = os.path.join(Dir,"Init.py") if (os.path.exists(InstallFile)): try: - execfile(InstallFile) + #execfile(InstallFile) + exec open(InstallFile).read() except Exception, inst: Log('Init: Initializing ' + Dir + '... failed\n') Err('During initialization the error ' + str(inst) + ' occurred in ' + InstallFile + '\n') diff --git a/src/Gui/FreeCADGuiInit.py b/src/Gui/FreeCADGuiInit.py index ee8ea4b9f..0700b566d 100644 --- a/src/Gui/FreeCADGuiInit.py +++ b/src/Gui/FreeCADGuiInit.py @@ -104,13 +104,13 @@ def InitApplications(): ModDirs = FreeCAD.__path__ #print ModDirs Log('Init: Searching modules...\n') - ModPar = FreeCAD.ParamGet("System parameter:Modules") for Dir in ModDirs: if ((Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py')): InstallFile = os.path.join(Dir,"InitGui.py") if (os.path.exists(InstallFile)): try: - execfile(InstallFile) + #execfile(InstallFile) + exec open(InstallFile).read() except Exception, inst: Log('Init: Initializing ' + Dir + '... failed\n') Err('During initialization the error ' + str(inst) + ' occurred in ' + InstallFile + '\n') diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp index 5fbedd828..300084a3f 100644 --- a/src/Main/MainGui.cpp +++ b/src/Main/MainGui.cpp @@ -213,8 +213,6 @@ int main( int argc, char ** argv ) { QCoreApplication app(argc, argv); QStringList args = app.arguments(); - args.pop_front(); // remove 1st argument - argv_.push_back(argv[0]); for (QStringList::iterator it = args.begin(); it != args.end(); ++it) { data.push_back(it->toUtf8()); argv_.push_back(data.back().data());