From a1fab80cad7fa698d7cb017ab14cacfacdadbc00 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 17:28:54 +0200 Subject: [PATCH 01/12] Changed: Added more comments --HG-- branch : develop --- .../client/ryzom_installer/src/utils.cpp | 4 +++ .../tools/client/ryzom_installer/src/utils.h | 30 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp index 8fadb4610..40e4695f1 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp @@ -81,6 +81,7 @@ bool isDirectoryEmpty(const QString &directory, bool recursize) if (dir.exists()) { + // process all files and directories excepted parent and current ones QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot); for (int i = 0; i < list.size(); ++i) @@ -89,10 +90,12 @@ bool isDirectoryEmpty(const QString &directory, bool recursize) if (fileInfo.isDir()) { + // don't consider empty directories as files, but process it recursively if required if (recursize) if (!isDirectoryEmpty(fileInfo.absoluteFilePath(), true)) return false; } else { + // we found a file, directory is not empty return false; } } @@ -127,6 +130,7 @@ qint64 getDirectorySize(const QString &directory, bool recursize) if (dir.exists()) { + // process all files and directories excepted parent and current ones QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot); for (int i = 0; i < list.size(); ++i) diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.h b/code/ryzom/tools/client/ryzom_installer/src/utils.h index 296c439fd..1065a0872 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.h +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.h @@ -28,40 +28,62 @@ * \date 2016 */ +// convert a size in bytes to a QString with larger unit (KiB, MiB, etc...) QString qBytesToHumanReadable(qint64 bytes); QString nameToId(const QString &name); +// return true is the specified directory is empty (has no file inside) (and all its subdirectories if recursize is true) bool isDirectoryEmpty(const QString &directory, bool recursize); + +// check if specified directory is writable bool isDirectoryWritable(const QString &directory); +// return the total size in bytes of specified directtory (and all its subdirectories if recursize is true) qint64 getDirectorySize(const QString &directory, bool recursize); -// Convert a UTF-8 string to QString +// convert a UTF-8 string to QString QString qFromUtf8(const std::string &str); -// Convert a QString to UTF-8 string +// convert a QString to UTF-8 string std::string qToUtf8(const QString &str); -// Convert a UTF-16 string to QString +// convert an UTF-16 string to QString QString qFromUtf16(const ucstring &str); -// Convert a QString to UTF-16 string +// convert a QString to UTF-16 string ucstring qToUtf16(const QString &str); +// convert an wchar_t* to QString QString qFromWide(const wchar_t *str); +// convert an QString to wchar_t* wchar_t* qToWide(const QString &str); +// check if a shortcut already exists (the extension will be added) bool shortcutExists(const QString &shortcut); + +// create a shortcut with the native format of the current platform bool createShortcut(const QString &shortcut, const QString &name, const QString &executable, const QString &arguments, const QString &icon, const QString &workingDir); + +// remove a shortcut (the extension will be added) bool removeShortcut(const QString &shortcut); + +// return the real path of shortcut bool resolveShortcut(const QWidget &window, const QString &shortcut, QString &pathObj); + +// append the shortcut of current platform to specified path QString appendShortcutExtension(const QString &shortcut); +// launch an executable with --version parameter and parse version string QString getVersionFromExecutable(const QString &path); + +// write a resource in QRC to disk bool writeResource(const QString &resource, const QString &path); + +// write a resource in QRC to disk and replace all variables by specified values bool writeResourceWithTemplates(const QString &resource, const QString &path, const QMap &strings); +// a little helper class to unintialize COM after using it class CCOMHelper { bool m_mustUninit; From f0d591bca7be912b9282f984e00c79ea94448688 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 17:41:49 +0200 Subject: [PATCH 02/12] Changed: Remove nameToId --HG-- branch : develop --- .../client/ryzom_installer/src/utils.cpp | 30 ------------------- .../tools/client/ryzom_installer/src/utils.h | 1 - 2 files changed, 31 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp index 40e4695f1..9225285fc 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp @@ -41,36 +41,6 @@ QString qBytesToHumanReadable(qint64 bytes) return QString::fromUtf8(NLMISC::bytesToHumanReadableUnits(bytes, units).c_str()); } -QString nameToId(const QString &name) -{ - QString res; - - // only allows simple characters - QRegExp allowedCharacters("^[0-9a-zA-Z-]$"); - - for (int i = 0, len = name.length(); i < len; ++i) - { - if (allowedCharacters.indexIn(name.at(i)) > -1) - { - // allowed character - res += name[i]; - } - else - { - // not allowed, replace by a space - res += " "; - } - } - - // simplify all spaces - res = res.simplified(); - - // replace spaces by minus - res.replace(" ", "-"); - - return res; -} - bool isDirectoryEmpty(const QString &directory, bool recursize) { bool res = true; diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.h b/code/ryzom/tools/client/ryzom_installer/src/utils.h index 1065a0872..e3de8155b 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.h +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.h @@ -30,7 +30,6 @@ // convert a size in bytes to a QString with larger unit (KiB, MiB, etc...) QString qBytesToHumanReadable(qint64 bytes); -QString nameToId(const QString &name); // return true is the specified directory is empty (has no file inside) (and all its subdirectories if recursize is true) bool isDirectoryEmpty(const QString &directory, bool recursize); From 44ddae76b852d672f652d74203ef9db52112ec6a Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 17:42:46 +0200 Subject: [PATCH 03/12] Changed: Escape strings that will be in XML file --HG-- branch : develop --- code/ryzom/tools/client/ryzom_installer/src/utils.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp index 9225285fc..e735862a0 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp @@ -317,11 +317,11 @@ bool createShortcut(const QString &shortcut, const QString &name, const QString CConfigFile *config = CConfigFile::getInstance(); + // HTML escape values because they'll be in a XML file strings.clear(); - strings["NAME"] = name; - strings["COPYRIGHT"] = config->getProductPublisher(); + strings["NAME"] = name.toHtmlEscaped(); + strings["COPYRIGHT"] = config->getProductPublisher().toHtmlEscaped(); strings["VERSION"] = QApplication::applicationVersion(); - strings["IDENTIFIER"] = "com.winchgate.Ryzom-" + nameToId(name); // write Info.plist if (!writeResourceWithTemplates(":/templates/Info.plist", plistFile, strings)) return false; From f8155c116dd561fda700f81b747f68a8bc50f6f7 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 17:43:03 +0200 Subject: [PATCH 04/12] Changed: Little optimization --HG-- branch : develop --- code/ryzom/tools/client/ryzom_installer/src/utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp index e735862a0..9a08b4ac8 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp @@ -54,7 +54,7 @@ bool isDirectoryEmpty(const QString &directory, bool recursize) // process all files and directories excepted parent and current ones QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot); - for (int i = 0; i < list.size(); ++i) + for (int i = 0, len = list.size(); i < len; ++i) { QFileInfo fileInfo = list.at(i); From 2460943bea23ad0798e5c103cefccedaae77820e Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 17:43:53 +0200 Subject: [PATCH 05/12] Fixed: Check if profiles are correct before using them --HG-- branch : develop --- .../client/ryzom_installer/src/profile.cpp | 25 ++++++++++++++++++- .../client/ryzom_installer/src/profile.h | 2 ++ .../ryzom_installer/src/profilesdialog.cpp | 15 +++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/profile.cpp b/code/ryzom/tools/client/ryzom_installer/src/profile.cpp index 79aa74b25..90adb000c 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profile.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profile.cpp @@ -49,6 +49,29 @@ void CProfile::saveToSettings(QSettings &settings) const settings.setValue("menu_shortcut", menuShortcut); } +bool CProfile::isValid(QString &error) const +{ + QRegExp idReg("^[0-9a-z_]+$"); + + if (!idReg.exactMatch(id)) + { + error = QApplication::tr("Profile ID %1 is using invalid characters (only lowercase letters, numbers and underscore are allowed)").arg(id); + return false; + } + + QRegExp nameReg("[/\\\\<>?*:.%|\"]"); + + int pos = nameReg.indexIn(name); + + if (pos > -1) + { + error = QApplication::tr("Profile name %1 is using invalid character %2 at position %3").arg(name).arg(name[pos]).arg(pos); + return false; + } + + return true; +} + QString CProfile::getDirectory() const { return CConfigFile::getInstance()->getProfileDirectory() + "/" + id; @@ -105,7 +128,7 @@ void CProfile::createShortcuts() const // create desktop shortcut if (!createShortcut(shortcut, name, exe, profileArguments, icon, workingDir)) { - qDebug() << "Unable to create desktop directory"; + qDebug() << "Unable to create desktop shortcut"; } } diff --git a/code/ryzom/tools/client/ryzom_installer/src/profile.h b/code/ryzom/tools/client/ryzom_installer/src/profile.h index 774d55193..5b7f8158f 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profile.h +++ b/code/ryzom/tools/client/ryzom_installer/src/profile.h @@ -40,6 +40,8 @@ public: void loadFromSettings(const QSettings &settings); void saveToSettings(QSettings &settings) const; + bool isValid(QString &error) const; + // helpers QString getDirectory() const; QString getClientFullPath() const; diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp index 5bbeb86b2..4aa0b2f27 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp @@ -56,6 +56,21 @@ void CProfilesDialog::accept() { saveProfile(m_currentProfileIndex); + const CProfiles &profiles = m_model->getProfiles(); + + // check if profiles are valid + foreach(const CProfile &profile, profiles) + { + QString error; + + if (!profile.isValid(error)) + { + // display an error message + QMessageBox::critical(this, tr("Error"), error); + return; + } + } + m_model->save(); QDialog::accept(); From fdf69c006de7a0b767bf02f69bb49fe5f1745d4e Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 17:45:39 +0200 Subject: [PATCH 06/12] Changed: Remove useless information in Info.plist --HG-- branch : develop --- .../client/ryzom_installer/res/Info.plist | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/res/Info.plist b/code/ryzom/tools/client/ryzom_installer/res/Info.plist index 0f34722db..c8e811f43 100644 --- a/code/ryzom/tools/client/ryzom_installer/res/Info.plist +++ b/code/ryzom/tools/client/ryzom_installer/res/Info.plist @@ -10,18 +10,8 @@ $NAME CFBundleIconFile ryzom.icns - CFBundleIdentifier - $IDENTIFIER CFBundleInfoDictionaryVersion 6.0 - CFBundleLocalizations - - en - fr - de - ru - es - CFBundleLongVersionString $VERSION CFBundleName @@ -38,16 +28,8 @@ CFBundleVersion 1.0 - CSResourcesFileMapped - LSApplicationCategoryType public.app-category.role-playing-games - LSFileQuarantineEnabled - - LSMinimumSystemVersion - 10.6 - LSRequiresCarbon - NSHumanReadableCopyright $COPYRIGHT From 27550081daa542e5cb37900d7c40020d6f88097f Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 17:46:05 +0200 Subject: [PATCH 07/12] Changed: Put real identifier for Ryzom Installer under OS X --HG-- branch : develop --- code/ryzom/tools/client/ryzom_installer/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/tools/client/ryzom_installer/CMakeLists.txt b/code/ryzom/tools/client/ryzom_installer/CMakeLists.txt index b76b0e20d..a8783ed66 100644 --- a/code/ryzom/tools/client/ryzom_installer/CMakeLists.txt +++ b/code/ryzom/tools/client/ryzom_installer/CMakeLists.txt @@ -45,7 +45,7 @@ SOURCE_GROUP("Translation Files" FILES ${CLIENT_INSTALL_TRANS} ${CLIENT_INSTALL_ if(APPLE) SET(MACOSX_BUNDLE_INFO_STRING "Ryzom Installer") SET(MACOSX_BUNDLE_ICON_FILE "ryzom.icns") - SET(MACOSX_BUNDLE_GUI_IDENTIFIER "") + SET(MACOSX_BUNDLE_GUI_IDENTIFIER "com.winchgate.RyzomInstaller") SET(MACOSX_BUNDLE_LONG_VERSION_STRING ${RYZOM_VERSION}) SET(MACOSX_BUNDLE_BUNDLE_NAME "Ryzom Installer") SET(MACOSX_BUNDLE_SHORT_VERSION_STRING ${RYZOM_VERSION}) From 0087f4aec97366ab120cc58a3116beea17353f7c Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 18:02:20 +0200 Subject: [PATCH 08/12] Changed: Abort if operation failed --HG-- branch : develop --- .../ryzom_installer/src/operationdialog.cpp | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index 4213bec73..a1b8d813d 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -558,12 +558,7 @@ void COperationDialog::extractDownloadedData() extractor.setSourceFile(config->getInstallationDirectory() + "/" + server.dataDownloadFilename); extractor.setDestinationDirectory(dest); - if (extractor.exec()) - { - } - else - { - } + if (!extractor.exec()) return; emit done(); } @@ -593,12 +588,7 @@ void COperationDialog::extractDownloadedClient() extractor.setSourceFile(config->getInstallationDirectory() + "/" + config->expandVariables(server.clientDownloadFilename)); extractor.setDestinationDirectory(destinationDirectory); - if (extractor.exec()) - { - } - else - { - } + if (!extractor.exec()) return; launchUpgradeScript(destinationDirectory, server.clientFilename); @@ -626,12 +616,7 @@ void COperationDialog::copyDataFiles() copier.setDestinationDirectory(server.getDirectory()); copier.setIncludeFilter(serverFiles); - if (copier.exec()) - { - } - else - { - } + if (!copier.exec()) return; emit done(); } @@ -661,12 +646,7 @@ void COperationDialog::copyProfileFiles() copier.setDestinationDirectory(profile.getDirectory()); copier.setIncludeFilter(profileFiles); - if (copier.exec()) - { - } - else - { - } + if (!copier.exec()) return; // correct path to client_default.cfg profile.createClientConfig(); @@ -688,7 +668,8 @@ void COperationDialog::extractBnpClient() CFilesExtractor extractor(this); extractor.setSourceFile(config->getSrcServerClientBNPFullPath()); extractor.setDestinationDirectory(destinationDirectory); - extractor.exec(); + + if (!extractor.exec()) return; launchUpgradeScript(destinationDirectory, server.clientFilename); From d2edc7d418cd33a32559d8a0dcd01b671285141a Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 18:02:34 +0200 Subject: [PATCH 09/12] Changed: Remove unused code --HG-- branch : develop --- .../tools/client/ryzom_installer/src/operationdialog.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index a1b8d813d..cc2c09109 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -126,12 +126,6 @@ void COperationDialog::processInstallNextStep() { CConfigFile *config = CConfigFile::getInstance(); - // default server - const CServer &server = config->getServer(); - - // default profile - const CProfile &configuration = config->getProfile(); - // long operations are done in a thread OperationStep step = config->getInstallNextStep(); From bc45604e46051e9125c378f4e8561f5fcc4e0713 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 18:02:55 +0200 Subject: [PATCH 10/12] Changed: Only return if downloading data --HG-- branch : develop --- .../tools/client/ryzom_installer/src/operationdialog.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index cc2c09109..9fc47dde3 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -346,8 +346,10 @@ void COperationDialog::processUpdateProfilesNextStep() if (server.clientDownloadUrl == defaultServer.clientDownloadUrl) { if (QFile::exists("")) + { downloadData(); - return; + return; + } } } else From cc8a200156f2f71284e2b635acea8cbb84bf7d02 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 18:03:26 +0200 Subject: [PATCH 11/12] Changed: Better error message --HG-- branch : develop --- code/ryzom/tools/client/ryzom_installer/src/filesextractor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/filesextractor.cpp b/code/ryzom/tools/client/ryzom_installer/src/filesextractor.cpp index 28b04f82b..535b43b76 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/filesextractor.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/filesextractor.cpp @@ -502,7 +502,7 @@ bool CFilesExtractor::extract7z() break; case SZ_ERROR_INPUT_EOF: - error = QApplication::tr("Errors in 7z file"); + error = QApplication::tr("File %1 is corrupted, unable to uncompress it").arg(m_sourceFile); break; case SZ_ERROR_FAIL: From 9744b44b6e19acae8802d1cd66e668549d1e4571 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 18:04:01 +0200 Subject: [PATCH 12/12] Changed: Specify server to use (the one of default profile) --HG-- branch : develop --- code/ryzom/tools/client/ryzom_installer/src/main.cpp | 2 ++ code/ryzom/tools/client/ryzom_installer/src/operationdialog.h | 1 + 2 files changed, 3 insertions(+) diff --git a/code/ryzom/tools/client/ryzom_installer/src/main.cpp b/code/ryzom/tools/client/ryzom_installer/src/main.cpp index 9e4bdf8a0..a4ec462d9 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/main.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/main.cpp @@ -216,6 +216,7 @@ int main(int argc, char *argv[]) COperationDialog dialog; + dialog.setCurrentServerId(config.getProfile().server); dialog.setOperation(OperationUninstall); dialog.setUninstallComponents(components); @@ -244,6 +245,7 @@ int main(int argc, char *argv[]) if (step != Done) { COperationDialog dialog; + dialog.setCurrentServerId(config.getProfile().server); dialog.setOperation(config.getSrcServerDirectory().isEmpty() ? OperationInstall:OperationMigrate); if (!dialog.exec()) return 1; diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h index 037cfb016..50f6d761b 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h @@ -40,6 +40,7 @@ public: void setOperation(OperationType operation); void setUninstallComponents(const SComponents &components); + void setCurrentServerId(const QString &serverId) { m_currentServerId = serverId; } public slots: void onAbortClicked();