khanat-code-old/code/ryzom/tools/client/client_config_qt/main.cpp

158 lines
4.7 KiB
C++
Raw Normal View History

2016-01-24 16:08:32 +00:00
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// 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/>.
#include "stdpch.h"
#include "client_config_dialog.h"
#include "system.h"
2016-03-11 08:51:59 +00:00
#include "nel/misc/cmd_args.h"
2016-01-24 16:08:32 +00:00
#include <QSplashScreen>
#ifdef QT_STATICPLUGIN
#include <QtPlugin>
#if defined(Q_OS_WIN32)
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
#elif defined(Q_OS_MAC)
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
#elif defined(Q_OS_UNIX)
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
Q_IMPORT_PLUGIN(QXcbGlxIntegrationPlugin)
#endif
#endif
2016-03-12 13:49:35 +00:00
NLMISC::CCmdArgs Args;
2016-01-24 16:08:32 +00:00
int main(sint32 argc, char **argv)
{
QApplication app(argc, argv);
2016-03-29 12:00:04 +00:00
NLMISC::CApplicationContext applicationContext;
2016-03-11 08:51:59 +00:00
// parse command-line arguments
2016-03-12 13:49:35 +00:00
Args.setDescription("Ryzom Configuration");
Args.addArg("p", "profile", "id", "Use this profile to determine what directory to use by default");
2016-03-11 08:51:59 +00:00
2016-03-12 13:49:35 +00:00
if (!Args.parse(argc, argv)) return 1;
2016-03-11 08:51:59 +00:00
2016-01-24 16:08:32 +00:00
QApplication::setWindowIcon(QIcon(":/resources/welcome_icon.png"));
QPixmap pixmap(":/resources/splash_screen.png" );
QSplashScreen splash( pixmap );
splash.show();
2016-03-11 08:51:59 +00:00
QLocale locale = QLocale::system();
2016-01-24 16:08:32 +00:00
2016-03-11 08:51:59 +00:00
// load application translations
2016-01-24 16:08:32 +00:00
QTranslator localTranslator;
2016-03-11 08:51:59 +00:00
if (localTranslator.load(locale, "ryzom_configuration", "_", ":/translations"))
{
QApplication::installTranslator(&localTranslator);
}
// load Qt default translations
QTranslator qtTranslator;
if (qtTranslator.load(locale, "qt", "_", ":/translations"))
{
QApplication::installTranslator(&qtTranslator);
}
// Known cases:
// 1. Steam
// - Linux and Windows: all files in Steam folder
// - OS X: client.cfg in ~/Library/Application Support/Ryzom, client_default.cfg in Steam folder
// 2. Installer
// - Linux: client.cfg in ~/.ryzom/<config>/ client_default.cfg in ~/.ryzom/ryzom_live/
// - Windows: client.cfg in Roaming/Ryzom/<config>/ client_default.cfg in Local/Ryzom/ryzom_live/
// - OS X: client.cfg in ~/Library/Application Support/Ryzom/<config>/ client_default.cfg in ~/Library/Application Support/Ryzom/ryzom_live/
// default paths
std::string ryzomDir = NLMISC::CPath::standardizePath(NLMISC::CPath::getApplicationDirectory("Ryzom"));
2016-03-12 13:49:35 +00:00
std::string currentDir = Args.getStartupPath();
std::string executableDir = Args.getProgramPath();
2016-03-11 08:51:59 +00:00
std::string configFilename = "client.cfg";
std::string configPath;
// search client.cfg file in config directory (Ryzom Installer)
2016-03-12 13:49:35 +00:00
if (Args.haveArg("p"))
2016-03-11 08:51:59 +00:00
{
2016-03-12 13:49:35 +00:00
ryzomDir = NLMISC::CPath::standardizePath(ryzomDir + Args.getArg("p").front());
2016-03-11 08:51:59 +00:00
// client.cfg is always in profile directory if using -p argument
configPath = ryzomDir + configFilename;
}
else
{
#ifdef NL_OS_MAC
// client.cfg is in ~/Library/Application Support/Ryzom under OS X
configPath = ryzomDir + configFilename;
#else
// client.cfg is in current directory under other platforms
configPath = currentDir + configFilename;
#endif
}
// if file doesn't exist, create it
if (!NLMISC::CFile::fileExists(configPath))
2016-01-24 16:08:32 +00:00
{
2016-03-11 08:51:59 +00:00
// we need the full path to client_default.cfg
std::string defaultConfigFilename = "client_default.cfg";
std::string defaultConfigPath;
#ifdef NL_OS_MAC
// fix path inside bundle
defaultConfigPath = NLMISC::CPath::makePathAbsolute("../Resources", executableDir, true) + defaultConfigFilename;
#else
// same path as executables
defaultConfigPath = executableDir + defaultConfigFilename;
#endif
// test if default config exists in determined path
if (!NLMISC::CFile::fileExists(defaultConfigPath))
{
defaultConfigPath = currentDir + defaultConfigFilename;
// test if default config exists in current path
if (!NLMISC::CFile::fileExists(defaultConfigPath))
{
nlwarning("Unable to find %s", defaultConfigFilename.c_str());
return 1;
}
}
if (!CSystem::GetInstance().config.create(configPath, defaultConfigPath))
{
nlwarning("Unable to create %s", configPath.c_str());
return 1;
}
2016-01-24 16:08:32 +00:00
}
2016-03-11 08:51:59 +00:00
if (!CSystem::GetInstance().config.load(configPath))
{
nlwarning("Unable to load %s", configPath.c_str());
return 1;
}
2016-01-24 16:08:32 +00:00
CClientConfigDialog d;
d.show();
splash.finish( &d );
return app.exec();
}