1
/***************************************************************************
2
* Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU Library General Public License (LGPL) *
8
* as published by the Free Software Foundation; either version 2 of *
9
* the License, or (at your option) any later version. *
10
* for detail see the LICENCE text file. *
12
* FreeCAD is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU Library General Public License for more details. *
17
* You should have received a copy of the GNU Library General Public *
18
* License along with FreeCAD; if not, write to the Free Software *
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22
***************************************************************************/
24
#include "../FCConfig.h"
36
#endif // HAVE_CONFIG_H
42
#include <Base/Console.h>
43
#include <Base/Exception.h>
44
#include <Base/Interpreter.h>
47
#include <App/Application.h>
51
using App::Application;
53
const char sBanner[] = "(c) Juergen Riegel, Werner Mayer, Yorik van Havre and others 2001-2024\n"\
54
"FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.\n"\
55
"FreeCAD wouldn't be possible without FreeCAD community.\n"\
56
" ##### #### ### #### \n" \
58
" # ## #### #### # # # # # \n" \
59
" #### # # # # # # # ##### # # \n" \
60
" # # #### #### # # # # # \n" \
61
" # # # # # # # # # ## ## ##\n" \
62
" # # #### #### ### # # #### ## ## ##\n\n" ;
66
int main( int argc, char ** argv )
68
// Make sure that we use '.' as decimal point
69
setlocale(LC_ALL, "");
70
setlocale(LC_NUMERIC, "C");
72
#if defined(__MINGW32__)
73
const char* mingw_prefix = getenv("MINGW_PREFIX");
74
const char* py_home = getenv("PYTHONHOME");
75
if (!py_home && mingw_prefix)
76
_putenv_s("PYTHONHOME", mingw_prefix);
79
// Name and Version of the Application
80
App::Application::Config()["ExeName"] = "FreeCAD";
81
App::Application::Config()["ExeVendor"] = "FreeCAD";
82
App::Application::Config()["AppDataSkipVendor"] = "true";
84
// set the banner (for logging and console)
85
App::Application::Config()["CopyrightInfo"] = sBanner;
88
// Init phase ===========================================================
89
// sets the default run mode for FC, starts with command prompt if not overridden in InitConfig...
90
App::Application::Config()["RunMode"] = "Exit";
91
App::Application::Config()["LoggingConsole"] = "1";
93
// Inits the Application
94
App::Application::init(argc,argv);
96
catch (const Base::UnknownProgramOption& e) {
97
std::cerr << e.what();
100
catch (const Base::ProgramInformation& e) {
101
std::cout << e.what();
104
catch (const Base::Exception& e) {
105
std::string appName = App::Application::Config()["ExeName"];
106
std::stringstream msg;
107
msg << "While initializing " << appName << " the following exception occurred: '" << e.what() << "'\n\n";
108
msg << "Python is searching for its runtime files in the following directories:\n" << Py_EncodeLocale(Py_GetPath(),nullptr) << "\n\n";
109
msg << "Python version information:\n" << Py_GetVersion() << "\n";
110
const char* pythonhome = getenv("PYTHONHOME");
112
msg << "\nThe environment variable PYTHONHOME is set to '" << pythonhome << "'.";
113
msg << "\nSetting this environment variable might cause Python to fail. Please contact your administrator to unset it on your system.\n\n";
116
msg << "\nPlease contact the application's support team for more information.\n\n";
119
printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str());
123
std::string appName = App::Application::Config()["ExeName"];
124
std::stringstream msg;
125
msg << "Unknown runtime error occurred while initializing " << appName <<".\n\n";
126
msg << "Please contact the application's support team for more information.\n\n";
127
printf("Initialization of %s failed:\n%s", appName.c_str(), msg.str().c_str());
131
// Run phase ===========================================================
133
Application::runApplication();
135
catch (const Base::SystemExitException &e) {
136
exit(e.getExitCode());
138
catch (const Base::Exception& e) {
143
Console().Error("Application unexpectedly terminated\n");
147
// Destruction phase ===========================================================
148
Console().Log("FreeCAD terminating...\n");
151
// close open documents
152
App::GetApplication().closeAllDocuments();
158
Application::destruct();
160
Console().Log("FreeCAD completely terminated\n");