From 6e169732a1a3cdbad56decdbdbe9b5ae262254c1 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 25 Jul 2016 18:31:11 +0200 Subject: [PATCH] Changed: Create all profiles shortcuts at once, see #279 --- .../client/ryzom_installer/src/configfile.cpp | 93 ++++++++++++++----- .../client/ryzom_installer/src/configfile.h | 8 +- .../client/ryzom_installer/src/operation.h | 3 +- .../ryzom_installer/src/operationdialog.cpp | 63 ++----------- .../ryzom_installer/src/operationdialog.h | 3 +- 5 files changed, 86 insertions(+), 84 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp index 2167707c9..07529f4c7 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp @@ -60,24 +60,84 @@ QString CProfile::getClientFullPath() const return s.getClientFullPath(); } -QString CProfile::getClientDesktopLinkFullPath() const +QString CProfile::getClientDesktopShortcutFullPath() const { #ifdef Q_OS_WIN32 return CConfigFile::getInstance()->getDesktopDirectory() + "/" + name + ".lnk"; -#else +#elif defined(Q_OS_MAC) return ""; +#else + return CConfigFile::getInstance()->getDesktopDirectory() + "/" + name + ".desktop"; #endif } -QString CProfile::getClientMenuLinkFullPath() const +QString CProfile::getClientMenuShortcutFullPath() const { #ifdef Q_OS_WIN32 return CConfigFile::getInstance()->getMenuDirectory() + "/" + name + ".lnk"; -#else +#elif defined(Q_OS_MAC) return ""; +#else + return CConfigFile::getInstance()->getMenuDirectory() + "/" + name + ".desktop"; #endif } +void CProfile::createShortcuts() const +{ + const CServer &s = CConfigFile::getInstance()->getServer(server); + + QString executable = getClientFullPath(); + QString workingDir = s.getDirectory(); + + QString arguments = QString("--profile %1").arg(id); + + // append custom arguments + if (!arguments.isEmpty()) arguments += QString(" %1").arg(arguments); + + QString icon; + +#ifdef Q_OS_WIN32 + icon = executable; +#else + // TODO: Linux icon +#endif + + if (desktopShortcut) + { + QString shortcut = getClientDesktopShortcutFullPath(); + + // create desktop shortcut + createLink(shortcut, name, executable, arguments, icon, workingDir); + } + + if (menuShortcut) + { + QString shortcut = getClientMenuShortcutFullPath(); + + // create menu shortcut + createLink(shortcut, name, executable, arguments, icon, workingDir); + } +} + +void CProfile::deleteShortcuts() const +{ + // delete desktop shortcut + QString link = getClientDesktopShortcutFullPath(); + + if (QFile::exists(link)) QFile::remove(link); + + // delete menu shortcut + link = getClientMenuShortcutFullPath(); + + if (QFile::exists(link)) QFile::remove(link); +} + +void CProfile::updateShortcuts() const +{ + deleteShortcuts(); + createShortcuts(); +} + CConfigFile *CConfigFile::s_instance = NULL; CConfigFile::CConfigFile(QObject *parent):QObject(parent), m_defaultServerIndex(0), m_defaultProfileIndex(0), m_use64BitsClient(false), m_shouldUninstallOldClient(true) @@ -692,11 +752,9 @@ bool CConfigFile::shouldCreateDesktopShortcut() const if (!profile.desktopShortcut) return false; -#ifdef Q_OS_WIN32 - return !NLMISC::CFile::isExists(qToUtf8(profile.getClientDesktopLinkFullPath())); -#else - return false; -#endif + QString shortcut = profile.getClientDesktopShortcutFullPath(); + + return !shortcut.isEmpty() && !NLMISC::CFile::isExists(qToUtf8(shortcut)); } bool CConfigFile::shouldCreateMenuShortcut() const @@ -705,11 +763,9 @@ bool CConfigFile::shouldCreateMenuShortcut() const if (!profile.menuShortcut) return false; -#ifdef Q_OS_WIN32 - return !NLMISC::CFile::isExists(qToUtf8(profile.getClientMenuLinkFullPath())); -#else - return false; -#endif + QString shortcut = profile.getClientMenuShortcutFullPath(); + + return !shortcut.isEmpty() && !NLMISC::CFile::isExists(qToUtf8(shortcut)); } QString CConfigFile::getInstallerFullPath() const @@ -876,14 +932,9 @@ OperationStep CConfigFile::getInstallNextStep() const return CopyProfileFiles; } - if (shouldCreateDesktopShortcut()) + if (shouldCreateDesktopShortcut() || shouldCreateMenuShortcut()) { - return CreateDesktopShortcut; - } - - if (shouldCreateMenuShortcut()) - { - return CreateMenuShortcut; + return CreateProfileShortcuts; } #ifdef Q_OS_WIN diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.h b/code/ryzom/tools/client/ryzom_installer/src/configfile.h index cc4c02b79..ed1768c6c 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.h +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.h @@ -74,8 +74,12 @@ public: // helpers QString getDirectory() const; QString getClientFullPath() const; - QString getClientDesktopLinkFullPath() const; - QString getClientMenuLinkFullPath() const; + QString getClientDesktopShortcutFullPath() const; + QString getClientMenuShortcutFullPath() const; + + void createShortcuts() const; + void deleteShortcuts() const; + void updateShortcuts() const; }; extern const CProfile NoProfile; diff --git a/code/ryzom/tools/client/ryzom_installer/src/operation.h b/code/ryzom/tools/client/ryzom_installer/src/operation.h index 5ea4326e1..5cf03f3e1 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operation.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operation.h @@ -64,8 +64,7 @@ enum OperationStep CopyInstaller, UninstallOldClient, CreateProfile, - CreateDesktopShortcut, - CreateMenuShortcut, + CreateProfileShortcuts, CreateAddRemoveEntry, Done }; diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index b82b46b5d..d402476e3 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -175,12 +175,8 @@ void COperationDialog::processInstallNextStep() createDefaultProfile(); break; - case CreateDesktopShortcut: - createClientDesktopShortcut(0); - break; - - case CreateMenuShortcut: - createClientMenuShortcut(0); + case CreateProfileShortcuts: + createProfileShortcuts(0); break; case CreateAddRemoveEntry: @@ -869,60 +865,15 @@ bool COperationDialog::createDefaultProfile() return true; } -bool COperationDialog::createClientDesktopShortcut(const QString &profileId) +bool COperationDialog::createProfileShortcuts(const QString &profileId) { CConfigFile *config = CConfigFile::getInstance(); const CProfile &profile = config->getProfile(profileId); - const CServer &server = config->getServer(profile.server); - m_currentOperation = tr("Create desktop shortcut for profile %1").arg(profile.id); + m_currentOperation = tr("Create shortcuts for profile %1").arg(profile.id); -#ifdef Q_OS_WIN32 - if (profile.desktopShortcut) - { - QString executable = profile.getClientFullPath(); - QString shortcut = profile.getClientDesktopLinkFullPath(); - QString workingDir = server.getDirectory(); - - QString arguments = QString("--profile %1").arg(profile.id); - - // append custom arguments - if (!profile.arguments.isEmpty()) arguments += QString(" %1").arg(profile.arguments); - - createLink(executable, shortcut, arguments, workingDir, profile.comments); - } -#endif - - emit done(); - - return true; -} - -bool COperationDialog::createClientMenuShortcut(const QString &profileId) -{ - CConfigFile *config = CConfigFile::getInstance(); - - const CProfile &profile = config->getProfile(profileId); - const CServer &server = config->getServer(profile.server); - - m_currentOperation = tr("Create menu shortcut for profile %1").arg(profile.id); - -#ifdef Q_OS_WIN32 - if (profile.menuShortcut) - { - QString executable = profile.getClientFullPath(); - QString shortcut = profile.getClientMenuLinkFullPath(); - QString workingDir = server.getDirectory(); - - QString arguments = QString("--profile %1").arg(profile.id); - - // append custom arguments - if (!profile.arguments.isEmpty()) arguments += QString(" %1").arg(profile.arguments); - - createLink(executable, shortcut, arguments, workingDir, profile.comments); - } -#endif + profile.createShortcuts(); emit done(); @@ -1080,9 +1031,7 @@ void COperationDialog::addComponentsProfiles() { const CProfile &profile = config->getProfile(profileId); - if (profile.desktopShortcut) createClientDesktopShortcut(profile.id); - - if (profile.menuShortcut) createClientMenuShortcut(profile.id); + profile.createShortcuts(); } } diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h index 091b77278..e9966c4d2 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h @@ -103,8 +103,7 @@ protected: void uninstallOldClient(); bool createDefaultProfile(); - bool createClientDesktopShortcut(const QString &profileId); - bool createClientMenuShortcut(const QString &profileId); + bool createProfileShortcuts(const QString &profileId); bool createAddRemoveEntry(); bool updateAddRemoveEntry();