Changed: More helpers

This commit is contained in:
kervala 2016-06-19 21:04:00 +02:00
parent 40073b4e57
commit 28e790481c
4 changed files with 106 additions and 41 deletions

View file

@ -32,11 +32,52 @@ QString CServer::getDirectory() const
return CConfigFile::getInstance()->getInstallationDirectory() + "/" + id;
}
QString CServer::getClientFullPath() const
{
if (clientFilename.isEmpty()) return "";
return getDirectory() + "/" + clientFilename;
}
QString CServer::getConfigurationFullPath() const
{
if (configurationFilename.isEmpty()) return "";
return getDirectory() + "/" + configurationFilename;
}
QString CProfile::getDirectory() const
{
return CConfigFile::getInstance()->getProfileDirectory() + "/" + id;
}
QString CProfile::getClientFullPath() const
{
if (!executable.isEmpty()) return executable;
const CServer &s = CConfigFile::getInstance()->getServer(server);
return s.getClientFullPath();
}
QString CProfile::getClientDesktopLinkFullPath() const
{
#ifdef Q_OS_WIN32
return CConfigFile::getInstance()->getDesktopDirectory() + "/" + name + ".lnk";
#else
return "";
#endif
}
QString CProfile::getClientMenuLinkFullPath() const
{
#ifdef Q_OS_WIN32
return CConfigFile::getInstance()->getMenuDirectory() + "/" + name + ".lnk";
#else
return "";
#endif
}
CConfigFile *CConfigFile::s_instance = NULL;
CConfigFile::CConfigFile(QObject *parent):QObject(parent), m_defaultServerIndex(0), m_defaultProfileIndex(0), m_use64BitsClient(false), m_shouldUninstallOldClient(true)
@ -323,6 +364,16 @@ void CConfigFile::removeProfile(const QString &id)
}
}
QString CConfigFile::getDesktopDirectory() const
{
return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
}
QString CConfigFile::getMenuDirectory() const
{
return QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/" + QApplication::applicationName();
}
bool CConfigFile::has64bitsOS()
{
return QSysInfo::currentCpuArchitecture() == "x86_64";
@ -380,9 +431,28 @@ QString CConfigFile::getProfileDirectory() const
QString CConfigFile::getSrcProfileDirectory() const
{
if (QFile::exists(getSrcServerDirectory() + "/client.cfg")) return getSrcServerDirectory();
QString filename = "client.cfg";
return qFromUtf8(NLMISC::CPath::getApplicationDirectory("Ryzom"));
QStringList paths;
// same path as client
paths << getSrcServerDirectory();
// profile path root
paths << getProfileDirectory();
#if !defined(Q_OS_WIN32) && !defined(Q_OS_MAC)
// specific path under Linux
paths << QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.ryzom";
#endif
// search config file in these locations
foreach(const QString &path, paths)
{
if (QFile::exists(path + "/" + filename)) return path;
}
return "";
}
bool CConfigFile::use64BitsClient() const
@ -608,10 +678,12 @@ bool CConfigFile::foundTemporaryFiles(const QString &directory) const
bool CConfigFile::shouldCreateDesktopShortcut() const
{
#ifdef Q_OS_WIN32
const CProfile &profile = getProfile();
return profile.desktopShortcut && !NLMISC::CFile::isExists(qToUtf8(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk"));
if (!profile.desktopShortcut) return false;
#ifdef Q_OS_WIN32
return !NLMISC::CFile::isExists(qToUtf8(profile.getClientDesktopLinkFullPath()));
#else
return false;
#endif
@ -619,42 +691,29 @@ bool CConfigFile::shouldCreateDesktopShortcut() const
bool CConfigFile::shouldCreateMenuShortcut() const
{
#ifdef Q_OS_WIN32
const CProfile &profile = getProfile();
return profile.menuShortcut && !NLMISC::CFile::isExists(qToUtf8(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/Ryzom/Ryzom.lnk"));
if (!profile.menuShortcut) return false;
#ifdef Q_OS_WIN32
return !NLMISC::CFile::isExists(qToUtf8(profile.getClientMenuLinkFullPath()));
#else
return false;
#endif
}
QString CConfigFile::getProfileClientFullPath(int profileIndex) const
QString CConfigFile::getInstallerFullPath() const
{
const CProfile &profile = getProfile(profileIndex);
QString path = profile.executable;
if (!path.isEmpty()) return path;
return getServerClientFullPath(profile.server);
return QApplication::applicationFilePath();
}
QString CConfigFile::getServerClientFullPath(const QString &serverId) const
QString CConfigFile::getInstallerMenuLinkFullPath() const
{
const CServer &server = getServer(serverId);
if (server.clientFilename.isEmpty()) return "";
return server.getDirectory() + "/" + server.clientFilename;
}
QString CConfigFile::getServerConfigurationFullPath(const QString &serverId) const
{
const CServer &server = getServer(serverId);
if (server.configurationFilename.isEmpty()) return "";
return server.getDirectory() + "/" + server.configurationFilename;
#ifdef Q_OS_WIN32
return QString("%1/%2/%2 Installer.lnk").arg(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)).arg(QApplication::applicationName());
#else
return "";
#endif
}
QString CConfigFile::getSrcServerClientBNPFullPath() const

View file

@ -45,6 +45,8 @@ public:
// helpers
QString getDirectory() const;
QString getClientFullPath() const;
QString getConfigurationFullPath() const;
};
extern const CServer NoServer;
@ -71,6 +73,9 @@ public:
// helpers
QString getDirectory() const;
QString getClientFullPath() const;
QString getClientDesktopLinkFullPath() const;
QString getClientMenuLinkFullPath() const;
};
extern const CProfile NoProfile;
@ -135,6 +140,9 @@ public:
QString getProfileDirectory() const;
QString getSrcProfileDirectory() const;
QString getDesktopDirectory() const;
QString getMenuDirectory() const;
static bool has64bitsOS();
// default directories
@ -166,9 +174,8 @@ public:
QString getClientArch() const;
QString getProfileClientFullPath(int profileIndex = -1) const;
QString getServerClientFullPath(const QString &serverId = "") const;
QString getServerConfigurationFullPath(const QString &serverId = "") const;
QString getInstallerFullPath() const;
QString getInstallerMenuLinkFullPath() const;
QString getSrcServerClientBNPFullPath() const;

View file

@ -95,7 +95,7 @@ void CMainWindow::onPlayClicked()
const CServer &server = config->getServer(profile.server);
// get full path of client executable
QString executable = config->getProfileClientFullPath(profileIndex);
QString executable = profile.getClientFullPath();
if (executable.isEmpty() || !QFile::exists(executable)) return;
@ -121,8 +121,9 @@ void CMainWindow::onConfigureClicked()
CConfigFile *config = CConfigFile::getInstance();
const CProfile &profile = config->getProfile(profileIndex);
const CServer &server = config->getServer(profile.server);
QString executable = config->getServerConfigurationFullPath(profile.server);
QString executable = server.getConfigurationFullPath();
if (executable.isEmpty() || !QFile::exists(executable)) return;

View file

@ -103,7 +103,7 @@ void CProfilesDialog::displayProfile(int index)
if (executable.isEmpty())
{
executable = CConfigFile::getInstance()->getServerClientFullPath(profile.server);
executable = profile.getClientFullPath();
}
QString profileDirectory = profile.getDirectory();
@ -216,7 +216,7 @@ void CProfilesDialog::updateExecutableVersion(int index)
// file empty, use default one
if (executable.isEmpty())
{
executable += CConfigFile::getInstance()->getServerClientFullPath(profile.server);
executable += CConfigFile::getInstance()->getServer(profile.server).getClientFullPath();
}
// file doesn't exist
@ -264,18 +264,16 @@ void CProfilesDialog::onExecutableBrowseClicked()
CProfile &profile = m_model->getProfiles()[m_currentProfileIndex];
QString executable = profile.executable;
QString defaultExecutable = CConfigFile::getInstance()->getServer(profile.server).getClientFullPath();
if (executable.isEmpty())
{
executable = CConfigFile::getInstance()->getServerClientFullPath(profile.server);
}
if (executable.isEmpty()) executable = defaultExecutable;
executable = QFileDialog::getOpenFileName(this, tr("Please choose Ryzom client executable to launch"), executable, tr("Executables (*.exe)"));
if (executable.isEmpty()) return;
// don't need to save the new executable if the same as default one
if (executable == CConfigFile::getInstance()->getServerClientFullPath(profile.server))
if (executable == defaultExecutable)
{
profile.executable.clear();
}