+ support of home path with non-ASCII chars
This commit is contained in:
parent
eb89cb422c
commit
5912342e3f
|
@ -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<const ushort *>(homePath.c_str()));
|
||||
#else
|
||||
QString str = QString::fromStdWString(homePath);
|
||||
#endif
|
||||
return str.toStdString();
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue
Block a user