Fix game:addSpawnShapesByZone
[ryzomcore.git] / studio / src / main.cpp
blob787e579306969083d2a40a74a9f00864bf751ea1
1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
6 // Copyright (C) 2014-2015 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // Copyright (C) 2014-2015 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
8 //
9 // This program is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU Affero General Public License as
11 // published by the Free Software Foundation, either version 3 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Affero General Public License for more details.
19 // You should have received a copy of the GNU Affero General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 // Project includes
23 #include "extension_system/iplugin_spec.h"
24 #include "extension_system/plugin_manager.h"
26 // NeL includes
27 #include <nel/misc/types_nl.h>
28 #include <nel/misc/app_context.h>
29 #include <nel/misc/debug.h>
30 #include <nel/misc/common.h>
31 #include <nel/misc/file.h>
32 #include <nel/misc/dynloadlib.h>
33 #include <nel/misc/path.h>
34 #include <nel/misc/command.h>
36 // Qt includes
37 #include <QtCore/QDir>
38 #include <QtCore/QTranslator>
39 #include <QtCore/QLibraryInfo>
40 #include <QtCore/QLocale>
41 #include <QtCore/QSettings>
42 #include <QtGui/QMessageBox>
43 #include <QtGui/QApplication>
44 //#include <QtGui/QSplashScreen>
45 #include <QtGui/QFileDialog>
46 #include <QtGui/QInputDialog>
48 #include "startup_settings_dlg.h"
49 #include "splash_screen.h"
50 #include "pm_watcher.h"
52 #ifdef HAVE_OVQT_CONFIG_H
53 #include "ovqt_config.h"
54 #endif
56 static const char *appNameC = "RyzomCoreStudio";
58 // nel_qt log file name
59 #define NLQT_LOG_FILE "nel_qt.log"
61 // clear nel_qt log before use
62 #define NLQT_ERASE_LOG true
64 #if !defined (NLQT_USE_LOG_LOG)
65 # define NLQT_USE_LOG_LOG true
66 #endif
67 #if !defined (NLQT_USE_LOG)
68 # define NLQT_USE_LOG 1
69 #endif
71 namespace NLQT
74 namespace
76 NLMISC::CFileDisplayer *s_FileDisplayer = NULL;
77 } /* anonymous namespace */
79 } /* namespace NLQT */
81 #ifndef DATA_DIR
82 # define DATA_DIR "."
83 #endif
86 #ifdef NL_OS_WINDOWS
87 # ifdef _UNICODE
88 # define tstring wstring
89 # else
90 # define tstring string
91 # endif
92 #endif
94 #ifdef Q_OS_WIN
96 static void displayError(const QString &t) // No console on Windows.
98 QMessageBox::critical(0, QLatin1String(appNameC), t);
101 #else
103 static void displayError(const QString &t)
105 qCritical("%s", qPrintable(t));
108 #endif
110 static inline QString msgCoreLoadFailure(const QString &why)
112 return QCoreApplication::translate("Application", "Failed to load Core plugin: %1").arg(why);
116 #ifdef NL_OS_WINDOWS
117 int __stdcall WinMain(void *hInstance, void *hPrevInstance, void *lpCmdLine, int nShowCmd)
118 #else // NL_OS_WINDOWS
119 int main(int argc, char **argv)
120 #endif // NL_OS_WINDOWS
122 // go nel!
123 new NLMISC::CApplicationContext;
125 // use log.log if NEL_LOG_IN_FILE and NLQT_USE_LOG_LOG defined as 1
126 NLMISC::createDebug(NULL, NLQT_USE_LOG_LOG, false);
127 NLMISC::INelContext::getInstance().setWindowedApplication(true);
128 #if NLQT_USE_LOG
129 // create NLQT_LOG_FILE
130 // filedisplayer only deletes the 001 etc
131 if (NLQT_ERASE_LOG && NLMISC::CFile::isExists(NLQT_LOG_FILE))
132 NLMISC::CFile::deleteFile(NLQT_LOG_FILE);
133 // initialize the log file
134 NLQT::s_FileDisplayer = new NLMISC::CFileDisplayer();
135 NLQT::s_FileDisplayer->setParam(NLQT_LOG_FILE, NLQT_ERASE_LOG);
136 NLMISC::DebugLog->addDisplayer(NLQT::s_FileDisplayer);
137 NLMISC::InfoLog->addDisplayer(NLQT::s_FileDisplayer);
138 NLMISC::WarningLog->addDisplayer(NLQT::s_FileDisplayer);
139 NLMISC::AssertLog->addDisplayer(NLQT::s_FileDisplayer);
140 NLMISC::ErrorLog->addDisplayer(NLQT::s_FileDisplayer);
141 #endif
143 nlinfo("Welcome to NeL Object Viewer Qt!");
145 QApplication::setGraphicsSystem("raster");
146 #ifdef NL_OS_WINDOWS
147 QApplication app(__argc, __argv);
148 #else // NL_OS_WINDOWS
149 QApplication app(argc, argv);
150 #endif // NL_OS_WINDOWS
152 SplashScreen *splash = new SplashScreen();
153 splash->setPixmap(QPixmap(":/images/studio_splash.png"));
154 splash->setProgressBarEnabled( true );
155 splash->setText( "Starting up..." );
156 splash->setProgress( 0 );
157 splash->show();
159 QSettings::setDefaultFormat(QSettings::IniFormat);
160 QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
161 QLatin1String("RyzomCore"), QLatin1String(appNameC));
163 bool firstRun = settings->value( "FirstRun", true ).toBool();
164 if( firstRun )
166 settings->setValue( "FirstRun", false );
168 StartupSettingsDlg sd;
169 sd.setSettings( settings );
170 sd.load();
171 sd.exec();
174 QTranslator translator;
175 QTranslator qtTranslator;
176 QString locale = settings->value("Language", QLocale::system().name()).toString();
177 QString qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
178 // translator.load("object_viewer_qt_" + locale, ":/");
179 qtTranslator.load("qt_" + locale, qtTrPath);
180 app.installTranslator(&translator);
181 app.installTranslator(&qtTranslator);
183 splash->setText( "Loading plugins..." );
184 splash->setProgress( 20 );
186 #if defined(NL_OS_MAC)
187 QDir::setCurrent(qApp->applicationDirPath() + QString("/../Resources"));
188 NLMISC::CLibrary::addLibPath((qApp->applicationDirPath() + QString("/../PlugIns/nel")).toUtf8().constData());
189 #endif
191 ExtensionSystem::PluginManager pluginManager;
192 pluginManager.setSettings(settings);
193 QStringList pluginPaths;
194 #if defined(NL_OS_MAC)
195 pluginPaths << settings->value("PluginPath", qApp->applicationDirPath() + QString("/../PlugIns/studio")).toString();
196 #else
197 pluginPaths << settings->value("PluginPath", QString("%1/plugins").arg(DATA_DIR)).toString();
198 #endif
200 pluginManager.setPluginPaths(pluginPaths);
202 PluginManagerWatcher watcher;
203 watcher.setPluginManager( &pluginManager );
204 watcher.setSplashScreen( splash );
205 watcher.connect();
207 pluginManager.loadPlugins();
209 watcher.disconnect();
210 splash->hide();
212 ExtensionSystem::IPluginSpec *corePlugin = pluginManager.pluginByName("Core");
214 if (!corePlugin)
216 QDir absolutePluginPaths(pluginPaths.join(QLatin1String(",")));
217 QString absolutePaths = absolutePluginPaths.absolutePath();
218 const QString reason = QCoreApplication::translate("Application", "Could not find studio_plugin_core in %1").arg(absolutePaths);
219 displayError(msgCoreLoadFailure(reason));
221 QString newPath = QFileDialog::getExistingDirectory(0, QCoreApplication::translate("Application", "Change the plugins path"), QDir::homePath());
222 bool ok;
223 QString text = QInputDialog::getText(0, QCoreApplication::translate("Application", "Enter the plugins path"),
224 QCoreApplication::translate("Application", "Plugin path:"), QLineEdit::Normal,
225 newPath, &ok);
226 if (ok && !text.isEmpty())
227 settings->setValue("PluginPath", text);
228 settings->sync();
229 return 1;
231 if (corePlugin->hasError())
233 displayError(msgCoreLoadFailure(corePlugin->errorString()));
234 return 1;
237 QStringList errors;
238 Q_FOREACH (ExtensionSystem::IPluginSpec *spec, pluginManager.plugins())
239 if (spec->hasError())
240 errors.append(spec->fileName() + " : " + spec->errorString());
242 if (!errors.isEmpty())
243 QMessageBox::warning(0, QCoreApplication::translate("Application", "Studio - Plugin loader messages"),
244 errors.join(QString::fromLatin1("\n\n")));
246 int result = app.exec();
247 return result;