Changed: More helpers
This commit is contained in:
parent
40073b4e57
commit
28e790481c
4 changed files with 106 additions and 41 deletions
|
@ -32,11 +32,52 @@ QString CServer::getDirectory() const
|
||||||
return CConfigFile::getInstance()->getInstallationDirectory() + "/" + id;
|
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
|
QString CProfile::getDirectory() const
|
||||||
{
|
{
|
||||||
return CConfigFile::getInstance()->getProfileDirectory() + "/" + id;
|
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::s_instance = NULL;
|
||||||
|
|
||||||
CConfigFile::CConfigFile(QObject *parent):QObject(parent), m_defaultServerIndex(0), m_defaultProfileIndex(0), m_use64BitsClient(false), m_shouldUninstallOldClient(true)
|
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()
|
bool CConfigFile::has64bitsOS()
|
||||||
{
|
{
|
||||||
return QSysInfo::currentCpuArchitecture() == "x86_64";
|
return QSysInfo::currentCpuArchitecture() == "x86_64";
|
||||||
|
@ -380,9 +431,28 @@ QString CConfigFile::getProfileDirectory() const
|
||||||
|
|
||||||
QString CConfigFile::getSrcProfileDirectory() 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
|
bool CConfigFile::use64BitsClient() const
|
||||||
|
@ -608,10 +678,12 @@ bool CConfigFile::foundTemporaryFiles(const QString &directory) const
|
||||||
|
|
||||||
bool CConfigFile::shouldCreateDesktopShortcut() const
|
bool CConfigFile::shouldCreateDesktopShortcut() const
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
const CProfile &profile = getProfile();
|
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
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -619,42 +691,29 @@ bool CConfigFile::shouldCreateDesktopShortcut() const
|
||||||
|
|
||||||
bool CConfigFile::shouldCreateMenuShortcut() const
|
bool CConfigFile::shouldCreateMenuShortcut() const
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
const CProfile &profile = getProfile();
|
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
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CConfigFile::getProfileClientFullPath(int profileIndex) const
|
QString CConfigFile::getInstallerFullPath() const
|
||||||
{
|
{
|
||||||
const CProfile &profile = getProfile(profileIndex);
|
return QApplication::applicationFilePath();
|
||||||
|
|
||||||
QString path = profile.executable;
|
|
||||||
|
|
||||||
if (!path.isEmpty()) return path;
|
|
||||||
|
|
||||||
return getServerClientFullPath(profile.server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CConfigFile::getServerClientFullPath(const QString &serverId) const
|
QString CConfigFile::getInstallerMenuLinkFullPath() const
|
||||||
{
|
{
|
||||||
const CServer &server = getServer(serverId);
|
#ifdef Q_OS_WIN32
|
||||||
|
return QString("%1/%2/%2 Installer.lnk").arg(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)).arg(QApplication::applicationName());
|
||||||
if (server.clientFilename.isEmpty()) return "";
|
#else
|
||||||
|
return "";
|
||||||
return server.getDirectory() + "/" + server.clientFilename;
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
QString CConfigFile::getServerConfigurationFullPath(const QString &serverId) const
|
|
||||||
{
|
|
||||||
const CServer &server = getServer(serverId);
|
|
||||||
|
|
||||||
if (server.configurationFilename.isEmpty()) return "";
|
|
||||||
|
|
||||||
return server.getDirectory() + "/" + server.configurationFilename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CConfigFile::getSrcServerClientBNPFullPath() const
|
QString CConfigFile::getSrcServerClientBNPFullPath() const
|
||||||
|
|
|
@ -45,6 +45,8 @@ public:
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
QString getDirectory() const;
|
QString getDirectory() const;
|
||||||
|
QString getClientFullPath() const;
|
||||||
|
QString getConfigurationFullPath() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const CServer NoServer;
|
extern const CServer NoServer;
|
||||||
|
@ -71,6 +73,9 @@ public:
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
QString getDirectory() const;
|
QString getDirectory() const;
|
||||||
|
QString getClientFullPath() const;
|
||||||
|
QString getClientDesktopLinkFullPath() const;
|
||||||
|
QString getClientMenuLinkFullPath() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const CProfile NoProfile;
|
extern const CProfile NoProfile;
|
||||||
|
@ -135,6 +140,9 @@ public:
|
||||||
QString getProfileDirectory() const;
|
QString getProfileDirectory() const;
|
||||||
QString getSrcProfileDirectory() const;
|
QString getSrcProfileDirectory() const;
|
||||||
|
|
||||||
|
QString getDesktopDirectory() const;
|
||||||
|
QString getMenuDirectory() const;
|
||||||
|
|
||||||
static bool has64bitsOS();
|
static bool has64bitsOS();
|
||||||
|
|
||||||
// default directories
|
// default directories
|
||||||
|
@ -166,9 +174,8 @@ public:
|
||||||
|
|
||||||
QString getClientArch() const;
|
QString getClientArch() const;
|
||||||
|
|
||||||
QString getProfileClientFullPath(int profileIndex = -1) const;
|
QString getInstallerFullPath() const;
|
||||||
QString getServerClientFullPath(const QString &serverId = "") const;
|
QString getInstallerMenuLinkFullPath() const;
|
||||||
QString getServerConfigurationFullPath(const QString &serverId = "") const;
|
|
||||||
|
|
||||||
QString getSrcServerClientBNPFullPath() const;
|
QString getSrcServerClientBNPFullPath() const;
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ void CMainWindow::onPlayClicked()
|
||||||
const CServer &server = config->getServer(profile.server);
|
const CServer &server = config->getServer(profile.server);
|
||||||
|
|
||||||
// get full path of client executable
|
// get full path of client executable
|
||||||
QString executable = config->getProfileClientFullPath(profileIndex);
|
QString executable = profile.getClientFullPath();
|
||||||
|
|
||||||
if (executable.isEmpty() || !QFile::exists(executable)) return;
|
if (executable.isEmpty() || !QFile::exists(executable)) return;
|
||||||
|
|
||||||
|
@ -121,8 +121,9 @@ void CMainWindow::onConfigureClicked()
|
||||||
CConfigFile *config = CConfigFile::getInstance();
|
CConfigFile *config = CConfigFile::getInstance();
|
||||||
|
|
||||||
const CProfile &profile = config->getProfile(profileIndex);
|
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;
|
if (executable.isEmpty() || !QFile::exists(executable)) return;
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ void CProfilesDialog::displayProfile(int index)
|
||||||
|
|
||||||
if (executable.isEmpty())
|
if (executable.isEmpty())
|
||||||
{
|
{
|
||||||
executable = CConfigFile::getInstance()->getServerClientFullPath(profile.server);
|
executable = profile.getClientFullPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString profileDirectory = profile.getDirectory();
|
QString profileDirectory = profile.getDirectory();
|
||||||
|
@ -216,7 +216,7 @@ void CProfilesDialog::updateExecutableVersion(int index)
|
||||||
// file empty, use default one
|
// file empty, use default one
|
||||||
if (executable.isEmpty())
|
if (executable.isEmpty())
|
||||||
{
|
{
|
||||||
executable += CConfigFile::getInstance()->getServerClientFullPath(profile.server);
|
executable += CConfigFile::getInstance()->getServer(profile.server).getClientFullPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
// file doesn't exist
|
// file doesn't exist
|
||||||
|
@ -264,18 +264,16 @@ void CProfilesDialog::onExecutableBrowseClicked()
|
||||||
CProfile &profile = m_model->getProfiles()[m_currentProfileIndex];
|
CProfile &profile = m_model->getProfiles()[m_currentProfileIndex];
|
||||||
|
|
||||||
QString executable = profile.executable;
|
QString executable = profile.executable;
|
||||||
|
QString defaultExecutable = CConfigFile::getInstance()->getServer(profile.server).getClientFullPath();
|
||||||
|
|
||||||
if (executable.isEmpty())
|
if (executable.isEmpty()) executable = defaultExecutable;
|
||||||
{
|
|
||||||
executable = CConfigFile::getInstance()->getServerClientFullPath(profile.server);
|
|
||||||
}
|
|
||||||
|
|
||||||
executable = QFileDialog::getOpenFileName(this, tr("Please choose Ryzom client executable to launch"), executable, tr("Executables (*.exe)"));
|
executable = QFileDialog::getOpenFileName(this, tr("Please choose Ryzom client executable to launch"), executable, tr("Executables (*.exe)"));
|
||||||
|
|
||||||
if (executable.isEmpty()) return;
|
if (executable.isEmpty()) return;
|
||||||
|
|
||||||
// don't need to save the new executable if the same as default one
|
// 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();
|
profile.executable.clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue