From 364efba09d3afe3078294f6882ff7c623731ac30 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 17 Oct 2016 11:35:24 +0200 Subject: [PATCH] Merge with develop --- .../ryzom_installer/res/ryzom_installer.ini | 4 +- .../client/ryzom_installer/src/configfile.cpp | 60 +++++---- .../client/ryzom_installer/src/configfile.h | 1 - .../ryzom_installer/src/filescopier.cpp | 116 ++++++++---------- .../client/ryzom_installer/src/filescopier.h | 4 +- .../tools/client/ryzom_installer/src/main.cpp | 2 +- .../ryzom_installer/src/migratedialog.cpp | 2 +- .../ryzom_installer/src/operationdialog.cpp | 17 ++- 8 files changed, 104 insertions(+), 102 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/res/ryzom_installer.ini b/code/ryzom/tools/client/ryzom_installer/res/ryzom_installer.ini index e18a58d19..feae1b62e 100644 --- a/code/ryzom/tools/client/ryzom_installer/res/ryzom_installer.ini +++ b/code/ryzom/tools/client/ryzom_installer/res/ryzom_installer.ini @@ -1,9 +1,9 @@ -version=3 +version=4 [common] installation_directory= installer_filename_windows=ryzom_installer_qt_r.exe -installer_filename_osx=RyzomInstaller.app/Contents/MacOS/RyzomInstaller +installer_filename_osx="Ryzom Installer.app/Contents/MacOS/Ryzom Installer" installer_filename_linux=ryzom_installer_qt [product] diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp index 839c85272..b09fa4e44 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp @@ -106,22 +106,25 @@ bool CConfigFile::load(const QString &filename) m_productHelpUrl = settings.value("url_help").toString(); m_productComments = settings.value("comments").toString(); settings.endGroup(); + } - settings.beginGroup("servers"); - int serversCount = settings.value("size").toInt(); - m_defaultServerIndex = settings.value("default").toInt(); + settings.beginGroup("servers"); + int serversCount = settings.value("size").toInt(); + m_defaultServerIndex = settings.value("default").toInt(); + settings.endGroup(); + + // only resize if added servers in local ryzom_installer.ini + int oldServersCount = m_servers.size(); + + if (serversCount > oldServersCount) m_servers.resize(serversCount); + + for (int i = oldServersCount; i < serversCount; ++i) + { + CServer &server = m_servers[i]; + + settings.beginGroup(QString("server_%1").arg(i)); + server.loadFromSettings(settings); settings.endGroup(); - - m_servers.resize(serversCount); - - for (int i = 0; i < serversCount; ++i) - { - CServer &server = m_servers[i]; - - settings.beginGroup(QString("server_%1").arg(i)); - server.loadFromSettings(settings); - settings.endGroup(); - } } // custom choices, always keep them @@ -492,11 +495,6 @@ QString CConfigFile::getParentDirectory() return current.absolutePath(); } -QString CConfigFile::getApplicationDirectory() -{ - return QApplication::applicationDirPath(); -} - QString CConfigFile::getOldInstallationDirectory() { // HKEY_CURRENT_USER/SOFTWARE/Nevrax/RyzomInstall/InstallId=1917716796 (string) @@ -757,7 +755,19 @@ QString CConfigFile::getInstallerCurrentFilePath() const QString CConfigFile::getInstallerCurrentDirPath() const { // installer is always run from TEMP under Windows - return QApplication::applicationDirPath(); + QString appDir = QApplication::applicationDirPath(); + +#ifdef Q_OS_MAC + QDir dir(appDir); + dir.cdUp(); // .. = Contents + dir.cdUp(); // .. = .app + dir.cdUp(); // .. = + + // return absolute path + appDir = dir.absolutePath(); +#endif + + return appDir; } QString CConfigFile::getInstallerInstalledFilePath() const @@ -818,7 +828,7 @@ QStringList CConfigFile::getInstallerRequiredFiles() const #endif // include current executable - files << QFileInfo(QApplication::applicationFilePath()).fileName(); + files << QFileInfo(getInstallerCurrentFilePath()).fileName(); #elif defined(Q_OS_MAC) // everything is in a directory files << "Ryzom Installer.app"; @@ -827,7 +837,7 @@ QStringList CConfigFile::getInstallerRequiredFiles() const files << "ryzom_installer.png"; // include current executable - files << QFileInfo(QApplication::applicationFilePath()).fileName(); + files << QFileInfo(getInstallerCurrentFilePath()).fileName(); #endif return files; @@ -875,7 +885,7 @@ OperationStep CConfigFile::getInstallNextStep() const if (!isRyzomInstalledIn(currentDirectory)) { // Ryzom is in the same directory as Ryzom Installer - currentDirectory = getApplicationDirectory(); + currentDirectory = getInstallerCurrentDirPath(); if (!isRyzomInstalledIn(currentDirectory)) { @@ -972,8 +982,8 @@ OperationStep CConfigFile::getInstallNextStep() const // current installer older, launch the more recent installer case -1: return LaunchInstalledInstaller; - // continue only if 0 - default: break; + // continue only if 0 and launched Installer is the installed one + default: if (getInstallerCurrentDirPath() != getInstallerInstalledFilePath() && QFile::exists(getInstallerInstalledFilePath())) return LaunchInstalledInstaller; } // no default profile diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.h b/code/ryzom/tools/client/ryzom_installer/src/configfile.h index a7b2a8919..1f71ad56b 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.h +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.h @@ -90,7 +90,6 @@ public: // default directories static QString getCurrentDirectory(); static QString getParentDirectory(); - static QString getApplicationDirectory(); static QString getOldInstallationDirectory(); static QString getNewInstallationDirectory(); static QString getOldInstallationLanguage(); diff --git a/code/ryzom/tools/client/ryzom_installer/src/filescopier.cpp b/code/ryzom/tools/client/ryzom_installer/src/filescopier.cpp index 069de1283..470790d4a 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/filescopier.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/filescopier.cpp @@ -63,71 +63,62 @@ bool CFilesCopier::exec() FilesToCopy files; + // create the list of files to copy CFilesCopier::getFilesList(files); + // copy them return copyFiles(files); } -void CFilesCopier::getFilesList(FilesToCopy &files) +void CFilesCopier::getFile(const QFileInfo &fileInfo, const QDir &srcDir, FilesToCopy &files) const { - QDir dir(m_sourceDirectory); + // full path to file + QString fullPath = fileInfo.absoluteFilePath(); - QFileInfoList entries = dir.entryInfoList(m_includeFilter); + // full path where to copy file + QString dstPath = m_destinationDirectory + "/" + srcDir.relativeFilePath(fullPath); + + if (fileInfo.isDir()) + { + // create directory + QDir().mkpath(dstPath); + + QDir subDir(fullPath); + + // get list of all files in directory + QFileInfoList entries = subDir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot); + + // proces seach file recursively + foreach(const QFileInfo &entry, entries) + { + getFile(entry, srcDir, files); + } + } + else + { + // add the file to list with all useful information + FileToCopy file; + file.filename = fileInfo.fileName(); + file.src = fileInfo.filePath(); + file.dst = dstPath; + file.size = fileInfo.size(); + file.date = fileInfo.lastModified().toTime_t(); + file.permissions = fileInfo.permissions(); + + files << file; + } +} + +void CFilesCopier::getFilesList(FilesToCopy &files) const +{ + QDir srcDir(m_sourceDirectory); + + // only copy all files from filter + QFileInfoList entries = srcDir.entryInfoList(m_includeFilter); foreach(const QFileInfo &entry, entries) { - QString fullPath = entry.absoluteFilePath(); - - QString dstPath = m_destinationDirectory + "/" + dir.relativeFilePath(fullPath); - - if (entry.isDir()) - { - QDir().mkpath(dstPath); - - QDir subDir(fullPath); - - QDirIterator it(subDir, QDirIterator::Subdirectories); - - while (it.hasNext()) - { - fullPath = it.next(); - - if (it.fileName().startsWith('.')) continue; - - QFileInfo fileInfo = it.fileInfo(); - - dstPath = m_destinationDirectory + "/" + dir.relativeFilePath(fullPath); - - if (fileInfo.isDir()) - { - QDir().mkpath(dstPath); - } - else - { - FileToCopy file; - file.filename = it.fileName(); - file.src = it.filePath(); - file.dst = dstPath; - file.size = it.fileInfo().size(); - file.date = it.fileInfo().lastModified().toTime_t(); - file.permissions = it.fileInfo().permissions(); - - files << file; - } - } - } - else - { - FileToCopy file; - file.filename = entry.fileName(); - file.src = entry.filePath(); - file.dst = dstPath; - file.size = entry.size(); - file.date = entry.lastModified().toTime_t(); - file.permissions = entry.permissions(); - - files << file; - } + getFile(entry, srcDir, files); } // copy additional files @@ -135,18 +126,7 @@ void CFilesCopier::getFilesList(FilesToCopy &files) { QFileInfo fileInfo(fullpath); - if (fileInfo.isFile()) - { - FileToCopy file; - file.filename = fileInfo.fileName(); - file.src = fileInfo.filePath(); - file.dst = m_destinationDirectory + "/" + fileInfo.fileName(); - file.size = fileInfo.size(); - file.date = fileInfo.lastModified().toTime_t(); - file.permissions = fileInfo.permissions(); - - files << file; - } + getFile(fileInfo, srcDir, files); } } @@ -186,7 +166,7 @@ bool CFilesCopier::copyFiles(const FilesToCopy &files) if (!QFile::copy(file.src, file.dst)) { - if (m_listener) m_listener->operationFail(QApplication::tr("Unable to copy file %1").arg(file.src)); + if (m_listener) m_listener->operationFail(QApplication::tr("Unable to copy file %1 to %2").arg(file.src).arg(file.dst)); return false; } diff --git a/code/ryzom/tools/client/ryzom_installer/src/filescopier.h b/code/ryzom/tools/client/ryzom_installer/src/filescopier.h index 8b505fb68..f0f2651a8 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/filescopier.h +++ b/code/ryzom/tools/client/ryzom_installer/src/filescopier.h @@ -54,7 +54,9 @@ protected: typedef QList FilesToCopy; - void getFilesList(FilesToCopy &files); + void getFile(const QFileInfo &info, const QDir &srcDir, FilesToCopy &files) const; + void getFilesList(FilesToCopy &files) const; + bool copyFiles(const FilesToCopy &files); IOperationProgressListener *m_listener; diff --git a/code/ryzom/tools/client/ryzom_installer/src/main.cpp b/code/ryzom/tools/client/ryzom_installer/src/main.cpp index 9b587c0b2..5e0bea7a9 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/main.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/main.cpp @@ -180,7 +180,7 @@ int main(int argc, char *argv[]) // copy installer and required files to TEMP directory if (QDir().mkdir(tempPath) && copyInstallerFiles(config.getInstallerRequiredFiles(), tempPath)) { - QString tempFile = tempPath + "/" + QFileInfo(QApplication::applicationFilePath()).fileName(); + QString tempFile = tempPath + "/" + QFileInfo(getInstallerCurrentFilePath()).fileName(); // launch copy in TEMP directory with same arguments if (QProcess::startDetached(tempFile, QApplication::arguments())) return 0; diff --git a/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp index 2315d38ec..92c4da4e6 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp @@ -38,7 +38,7 @@ CMigrateDialog::CMigrateDialog():QDialog() if (!CConfigFile::getInstance()->isRyzomInstalledIn(m_currentDirectory)) { // Ryzom is in the same directory as Ryzom Installer - m_currentDirectory = CConfigFile::getInstance()->getApplicationDirectory(); + m_currentDirectory = CConfigFile::getInstance()->getInstallerCurrentDirPath(); if (!CConfigFile::getInstance()->isRyzomInstalledIn(m_currentDirectory)) { diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index 25bbd9b17..702b445fe 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -729,18 +729,28 @@ void COperationDialog::copyInstaller() // rename old client to installer - QString oldInstallerFullPath = QApplication::applicationFilePath(); + QString oldInstallerFullPath = config->getInstallerCurrentFilePath(); QString newInstallerFullPath = config->getInstallerInstalledFilePath(); if (!newInstallerFullPath.isEmpty()) { + QString srcDir = config->getSrcServerDirectory(); + + if (srcDir.isEmpty()) srcDir = config->getInstallerCurrentDirPath(); + // always copy new installers CFilesCopier copier(this); copier.setIncludeFilter(config->getInstallerRequiredFiles()); +#ifdef Q_OS_WIN32 copier.addFile(oldInstallerFullPath); - copier.setSourceDirectory(config->getSrcServerDirectory().isEmpty() ? QApplication::applicationDirPath():config->getSrcServerDirectory()); +#endif + copier.setSourceDirectory(srcDir); copier.setDestinationDirectory(config->getInstallationDirectory()); - copier.exec(); + + if (!copier.exec()) return; + +#ifdef Q_OS_WIN32 + // only happens under Windows in Debug or when migrating // copied file oldInstallerFullPath = config->getInstallationDirectory() + "/" + QFileInfo(oldInstallerFullPath).fileName(); @@ -754,6 +764,7 @@ void COperationDialog::copyInstaller() // rename new installer with final name QFile::rename(oldInstallerFullPath, newInstallerFullPath); } +#endif // create menu directory if defined QString path = config->getMenuDirectory();