| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <FCConfig.h>
|
| |
|
| | #if defined(FC_OS_WIN32)
|
| | # include <windows.h>
|
| | #endif
|
| |
|
| | #ifdef FC_OS_MACOSX
|
| | # include <mach-o/dyld.h>
|
| | # include <string>
|
| | #endif
|
| |
|
| | #if HAVE_CONFIG_H
|
| | # include <config.h>
|
| | #endif
|
| |
|
| | #include <cstdio>
|
| | #include <iostream>
|
| | #include <QByteArray>
|
| |
|
| |
|
| | #include <Base/ConsoleObserver.h>
|
| | #include <Base/Exception.h>
|
| | #include <Base/PyObjectBase.h>
|
| | #include <Base/Sequencer.h>
|
| | #include <App/Application.h>
|
| |
|
| | #if defined(FC_OS_WIN32)
|
| |
|
| | |
| |
|
| | BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID )
|
| | {
|
| | switch (ul_reason_for_call) {
|
| | case DLL_PROCESS_ATTACH: {
|
| |
|
| |
|
| | char szFileName[MAX_PATH];
|
| | GetModuleFileNameA((HMODULE)hModule, szFileName, MAX_PATH - 1);
|
| | App::Application::Config()["AppHomePath"] = szFileName;
|
| | } break;
|
| | default:
|
| | break;
|
| | }
|
| |
|
| | return true;
|
| | }
|
| | #elif defined(FC_OS_LINUX) || defined(FC_OS_BSD)
|
| | # ifndef GNU_SOURCE
|
| | # define GNU_SOURCE
|
| | # endif
|
| | # include <dlfcn.h>
|
| | #elif defined(FC_OS_CYGWIN)
|
| | # include <windows.h>
|
| | #endif
|
| |
|
| | PyMOD_INIT_FUNC(FreeCAD)
|
| | {
|
| |
|
| | App::Application::Config()["ExeName"] = "FreeCAD";
|
| | App::Application::Config()["ExeVendor"] = "FreeCAD";
|
| | App::Application::Config()["AppDataSkipVendor"] = "true";
|
| |
|
| | QByteArray path;
|
| |
|
| | #if defined(FC_OS_WIN32)
|
| | path = App::Application::Config()["AppHomePath"].c_str();
|
| | #elif defined(FC_OS_CYGWIN)
|
| | HMODULE hModule = GetModuleHandle("FreeCAD.dll");
|
| | char szFileName[MAX_PATH];
|
| | GetModuleFileNameA(hModule, szFileName, MAX_PATH - 1);
|
| | path = szFileName;
|
| | #elif defined(FC_OS_LINUX) || defined(FC_OS_BSD)
|
| | putenv("LANG=C");
|
| | putenv("LC_ALL=C");
|
| |
|
| | Dl_info info;
|
| | int ret = dladdr((void*)PyInit_FreeCAD, &info);
|
| | if ((ret == 0) || (!info.dli_fname)) {
|
| | PyErr_SetString(PyExc_ImportError, "Cannot get path of the FreeCAD module!");
|
| | return nullptr;
|
| | }
|
| |
|
| | path = info.dli_fname;
|
| |
|
| | #elif defined(FC_OS_MACOSX)
|
| |
|
| |
|
| |
|
| |
|
| | const static char libName[] = "/FreeCAD.so";
|
| | const static char upDir[] = "/../";
|
| |
|
| | PyObject* pySysPath = PySys_GetObject("path");
|
| | if (PyList_Check(pySysPath)) {
|
| | int i;
|
| |
|
| |
|
| |
|
| | for (i = PyList_Size(pySysPath) - 1; i >= 0; --i) {
|
| | const char* basePath;
|
| | PyObject* pyPath = PyList_GetItem(pySysPath, i);
|
| | long sz = 0;
|
| |
|
| | if (PyUnicode_Check(pyPath)) {
|
| |
|
| | basePath = PyUnicode_AsUTF8AndSize(pyPath, &sz);
|
| | }
|
| | else {
|
| | continue;
|
| | }
|
| |
|
| | if (sz + sizeof(libName) > PATH_MAX) {
|
| | continue;
|
| | }
|
| |
|
| | path = basePath;
|
| |
|
| |
|
| | if (access(path + libName, R_OK | X_OK) == 0) {
|
| |
|
| |
|
| |
|
| | path += upDir;
|
| | break;
|
| | }
|
| | }
|
| | }
|
| |
|
| | if (path.isEmpty()) {
|
| | PyErr_SetString(PyExc_ImportError, "Cannot get path of the FreeCAD module!");
|
| | return nullptr;
|
| | }
|
| |
|
| | #else
|
| | # error "Implement: Retrieve the path of the module for your platform."
|
| | #endif
|
| | int argc = 1;
|
| | std::vector<char*> argv;
|
| | argv.push_back(path.data());
|
| |
|
| | try {
|
| |
|
| | App::Application::init(argc, argv.data());
|
| | }
|
| | catch (const Base::Exception& e) {
|
| | std::string appName = App::Application::Config()["ExeName"];
|
| | std::cout << "While initializing " << appName << " the following exception occurred: '"
|
| | << e.what() << "'\n\n";
|
| | std::cout << "Please contact the application's support team for more information."
|
| | << std::endl;
|
| | }
|
| |
|
| | Base::EmptySequencer* seq = new Base::EmptySequencer();
|
| | (void)seq;
|
| | static Base::RedirectStdOutput stdcout;
|
| | static Base::RedirectStdLog stdclog;
|
| | static Base::RedirectStdError stdcerr;
|
| | std::cout.rdbuf(&stdcout);
|
| | std::clog.rdbuf(&stdclog);
|
| | std::cerr.rdbuf(&stdcerr);
|
| |
|
| | PyObject* modules = PyImport_GetModuleDict();
|
| | PyObject* module = PyDict_GetItemString(modules, "FreeCAD");
|
| | if (!module) {
|
| | PyErr_SetString(PyExc_ImportError, "Failed to load FreeCAD module!");
|
| | }
|
| | return module;
|
| | }
|
| |
|