2012-05-29 13:31:11 +00:00
|
|
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
// Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// Project includes
|
|
|
|
#include "extension_system/iplugin_spec.h"
|
|
|
|
#include "extension_system/plugin_manager.h"
|
|
|
|
|
|
|
|
// NeL includes
|
|
|
|
#include <nel/misc/types_nl.h>
|
|
|
|
#include <nel/misc/app_context.h>
|
|
|
|
#include <nel/misc/debug.h>
|
|
|
|
#include <nel/misc/common.h>
|
|
|
|
#include <nel/misc/file.h>
|
|
|
|
#include <nel/misc/dynloadlib.h>
|
|
|
|
#include <nel/misc/path.h>
|
|
|
|
#include <nel/misc/command.h>
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
#include <QtCore/QTranslator>
|
|
|
|
#include <QtCore/QLibraryInfo>
|
|
|
|
#include <QtCore/QLocale>
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
#include <QtGui/QMessageBox>
|
|
|
|
#include <QtGui/QApplication>
|
2014-06-04 20:09:11 +00:00
|
|
|
//#include <QtGui/QSplashScreen>
|
2012-05-29 13:31:11 +00:00
|
|
|
#include <QtGui/QFileDialog>
|
|
|
|
#include <QtGui/QInputDialog>
|
|
|
|
|
2015-02-09 16:54:27 +00:00
|
|
|
#include "startup_settings_dlg.h"
|
2014-06-04 20:09:11 +00:00
|
|
|
#include "splash_screen.h"
|
2014-06-04 23:57:13 +00:00
|
|
|
#include "pm_watcher.h"
|
2014-05-26 19:04:05 +00:00
|
|
|
|
2012-09-24 12:02:33 +00:00
|
|
|
#ifdef HAVE_OVQT_CONFIG_H
|
|
|
|
#include "ovqt_config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-05-26 19:04:05 +00:00
|
|
|
static const char *appNameC = "RyzomCoreStudio";
|
2012-05-29 13:31:11 +00:00
|
|
|
|
|
|
|
// nel_qt log file name
|
|
|
|
#define NLQT_LOG_FILE "nel_qt.log"
|
|
|
|
|
|
|
|
// clear nel_qt log before use
|
|
|
|
#define NLQT_ERASE_LOG true
|
|
|
|
|
|
|
|
#if !defined (NLQT_USE_LOG_LOG)
|
|
|
|
# define NLQT_USE_LOG_LOG true
|
|
|
|
#endif
|
|
|
|
#if !defined (NLQT_USE_LOG)
|
|
|
|
# define NLQT_USE_LOG 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace NLQT
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
NLMISC::CFileDisplayer *s_FileDisplayer = NULL;
|
|
|
|
} /* anonymous namespace */
|
|
|
|
|
|
|
|
} /* namespace NLQT */
|
|
|
|
|
|
|
|
#ifndef DATA_DIR
|
|
|
|
# define DATA_DIR "."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
# ifdef _UNICODE
|
|
|
|
# define tstring wstring
|
|
|
|
# else
|
|
|
|
# define tstring string
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
|
|
|
|
static void displayError(const QString &t) // No console on Windows.
|
|
|
|
{
|
|
|
|
QMessageBox::critical(0, QLatin1String(appNameC), t);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static void displayError(const QString &t)
|
|
|
|
{
|
|
|
|
qCritical("%s", qPrintable(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline QString msgCoreLoadFailure(const QString &why)
|
|
|
|
{
|
|
|
|
return QCoreApplication::translate("Application", "Failed to load Core plugin: %1").arg(why);
|
|
|
|
}
|
|
|
|
|
2014-06-04 23:57:13 +00:00
|
|
|
|
2014-01-21 11:50:23 +00:00
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
int __stdcall WinMain(void *hInstance, void *hPrevInstance, void *lpCmdLine, int nShowCmd)
|
|
|
|
#else // NL_OS_WINDOWS
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
#endif // NL_OS_WINDOWS
|
2012-05-29 13:31:11 +00:00
|
|
|
{
|
|
|
|
// go nel!
|
|
|
|
new NLMISC::CApplicationContext;
|
|
|
|
{
|
|
|
|
// use log.log if NEL_LOG_IN_FILE and NLQT_USE_LOG_LOG defined as 1
|
|
|
|
NLMISC::createDebug(NULL, NLQT_USE_LOG_LOG, false);
|
|
|
|
#if NLQT_USE_LOG
|
|
|
|
// create NLQT_LOG_FILE
|
|
|
|
// filedisplayer only deletes the 001 etc
|
|
|
|
if (NLQT_ERASE_LOG && NLMISC::CFile::isExists(NLQT_LOG_FILE))
|
|
|
|
NLMISC::CFile::deleteFile(NLQT_LOG_FILE);
|
|
|
|
// initialize the log file
|
|
|
|
NLQT::s_FileDisplayer = new NLMISC::CFileDisplayer();
|
|
|
|
NLQT::s_FileDisplayer->setParam(NLQT_LOG_FILE, NLQT_ERASE_LOG);
|
|
|
|
NLMISC::DebugLog->addDisplayer(NLQT::s_FileDisplayer);
|
|
|
|
NLMISC::InfoLog->addDisplayer(NLQT::s_FileDisplayer);
|
|
|
|
NLMISC::WarningLog->addDisplayer(NLQT::s_FileDisplayer);
|
|
|
|
NLMISC::AssertLog->addDisplayer(NLQT::s_FileDisplayer);
|
|
|
|
NLMISC::ErrorLog->addDisplayer(NLQT::s_FileDisplayer);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nlinfo("Welcome to NeL Object Viewer Qt!");
|
|
|
|
}
|
|
|
|
QApplication::setGraphicsSystem("raster");
|
2014-01-21 11:50:23 +00:00
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
QApplication app(__argc, __argv);
|
|
|
|
#else // NL_OS_WINDOWS
|
2012-05-29 13:31:11 +00:00
|
|
|
QApplication app(argc, argv);
|
2014-01-21 11:50:23 +00:00
|
|
|
#endif // NL_OS_WINDOWS
|
2014-05-26 19:04:05 +00:00
|
|
|
|
2014-06-04 20:09:11 +00:00
|
|
|
SplashScreen *splash = new SplashScreen();
|
2014-05-25 20:45:34 +00:00
|
|
|
splash->setPixmap(QPixmap(":/images/studio_splash.png"));
|
2014-06-04 20:09:11 +00:00
|
|
|
splash->setProgressBarEnabled( true );
|
|
|
|
splash->setText( "Starting up..." );
|
|
|
|
splash->setProgress( 0 );
|
2012-05-29 13:31:11 +00:00
|
|
|
splash->show();
|
|
|
|
|
|
|
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
|
|
|
QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
|
|
|
|
QLatin1String("RyzomCore"), QLatin1String(appNameC));
|
|
|
|
|
2014-05-26 19:04:05 +00:00
|
|
|
bool firstRun = settings->value( "FirstRun", true ).toBool();
|
|
|
|
if( firstRun )
|
|
|
|
{
|
|
|
|
settings->setValue( "FirstRun", false );
|
|
|
|
|
2015-02-09 16:54:27 +00:00
|
|
|
StartupSettingsDlg sd;
|
2014-05-26 19:04:05 +00:00
|
|
|
sd.setSettings( settings );
|
|
|
|
sd.load();
|
|
|
|
sd.exec();
|
|
|
|
}
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
QTranslator translator;
|
|
|
|
QTranslator qtTranslator;
|
|
|
|
QString locale = settings->value("Language", QLocale::system().name()).toString();
|
|
|
|
QString qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
|
|
|
// translator.load("object_viewer_qt_" + locale, ":/");
|
|
|
|
qtTranslator.load("qt_" + locale, qtTrPath);
|
|
|
|
app.installTranslator(&translator);
|
|
|
|
app.installTranslator(&qtTranslator);
|
|
|
|
|
2014-06-04 23:57:13 +00:00
|
|
|
splash->setText( "Loading plugins..." );
|
|
|
|
splash->setProgress( 20 );
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
#if defined(NL_OS_MAC)
|
|
|
|
QDir::setCurrent(qApp->applicationDirPath() + QString("/../Resources"));
|
2012-10-28 12:34:58 +00:00
|
|
|
NLMISC::CLibrary::addLibPath((qApp->applicationDirPath() + QString("/../PlugIns/nel")).toUtf8().constData());
|
2012-05-29 13:31:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ExtensionSystem::PluginManager pluginManager;
|
|
|
|
pluginManager.setSettings(settings);
|
|
|
|
QStringList pluginPaths;
|
2012-09-24 06:25:47 +00:00
|
|
|
#if defined(NL_OS_MAC)
|
2014-05-19 00:08:03 +00:00
|
|
|
pluginPaths << settings->value("PluginPath", qApp->applicationDirPath() + QString("/../PlugIns/studio")).toString();
|
2012-09-24 06:25:47 +00:00
|
|
|
#else
|
|
|
|
pluginPaths << settings->value("PluginPath", QString("%1/plugins").arg(DATA_DIR)).toString();
|
2012-05-29 13:31:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
pluginManager.setPluginPaths(pluginPaths);
|
2014-06-04 23:57:13 +00:00
|
|
|
|
|
|
|
PluginManagerWatcher watcher;
|
|
|
|
watcher.setPluginManager( &pluginManager );
|
|
|
|
watcher.setSplashScreen( splash );
|
|
|
|
watcher.connect();
|
|
|
|
|
2012-05-29 13:31:11 +00:00
|
|
|
pluginManager.loadPlugins();
|
|
|
|
|
2014-06-04 23:57:13 +00:00
|
|
|
watcher.disconnect();
|
2012-05-29 13:31:11 +00:00
|
|
|
splash->hide();
|
|
|
|
|
|
|
|
ExtensionSystem::IPluginSpec *corePlugin = pluginManager.pluginByName("Core");
|
|
|
|
|
|
|
|
if (!corePlugin)
|
|
|
|
{
|
|
|
|
QDir absolutePluginPaths(pluginPaths.join(QLatin1String(",")));
|
|
|
|
QString absolutePaths = absolutePluginPaths.absolutePath();
|
2014-05-19 00:08:03 +00:00
|
|
|
const QString reason = QCoreApplication::translate("Application", "Could not find studio_plugin_core in %1").arg(absolutePaths);
|
2012-05-29 13:31:11 +00:00
|
|
|
displayError(msgCoreLoadFailure(reason));
|
|
|
|
|
|
|
|
QString newPath = QFileDialog::getExistingDirectory(0, QCoreApplication::translate("Application", "Change the plugins path"), QDir::homePath());
|
|
|
|
bool ok;
|
|
|
|
QString text = QInputDialog::getText(0, QCoreApplication::translate("Application", "Enter the plugins path"),
|
|
|
|
QCoreApplication::translate("Application", "Plugin path:"), QLineEdit::Normal,
|
|
|
|
newPath, &ok);
|
|
|
|
if (ok && !text.isEmpty())
|
|
|
|
settings->setValue("PluginPath", text);
|
|
|
|
settings->sync();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (corePlugin->hasError())
|
|
|
|
{
|
|
|
|
displayError(msgCoreLoadFailure(corePlugin->errorString()));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList errors;
|
|
|
|
Q_FOREACH (ExtensionSystem::IPluginSpec *spec, pluginManager.plugins())
|
|
|
|
if (spec->hasError())
|
|
|
|
errors.append(spec->fileName() + " : " + spec->errorString());
|
|
|
|
|
|
|
|
if (!errors.isEmpty())
|
2014-05-19 00:08:03 +00:00
|
|
|
QMessageBox::warning(0, QCoreApplication::translate("Application", "Studio - Plugin loader messages"),
|
2012-05-29 13:31:11 +00:00
|
|
|
errors.join(QString::fromLatin1("\n\n")));
|
|
|
|
|
|
|
|
int result = app.exec();
|
|
|
|
return result;
|
2012-09-24 12:02:33 +00:00
|
|
|
}
|