From 265390a6c56527d61c6a628c9a8a01309821e6c6 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 20 Sep 2016 17:39:29 +0200 Subject: [PATCH] Changed: Create or update client.cfg, see #279 --- .../client/ryzom_installer/src/configfile.h | 2 + .../ryzom_installer/src/operationdialog.cpp | 3 ++ .../client/ryzom_installer/src/profile.cpp | 52 +++++++++++++++++++ .../client/ryzom_installer/src/profile.h | 2 + .../client/ryzom_installer/src/server.cpp | 5 ++ .../tools/client/ryzom_installer/src/server.h | 1 + 6 files changed, 65 insertions(+) diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.h b/code/ryzom/tools/client/ryzom_installer/src/configfile.h index 5c2a4dacc..998565dda 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.h +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.h @@ -54,6 +54,8 @@ public: CProfiles getBackupProfiles() const { return m_backupProfiles; } void backupProfiles(); + QString getLanguage() const { return m_language; } + int getProfilesCount() const; CProfile getProfile(int i = -1) const; CProfile getProfile(const QString &id) const; diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index 82c8c66a5..86d9cbfbf 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -888,6 +888,8 @@ bool COperationDialog::createDefaultProfile() config->addProfile(profile); config->save(); + profile.createClientConfig(); + emit done(); return true; @@ -1071,6 +1073,7 @@ void COperationDialog::addComponentsProfiles() const CProfile &profile = config->getProfile(profileId); profile.createShortcuts(); + profile.createClientConfig(); } } diff --git a/code/ryzom/tools/client/ryzom_installer/src/profile.cpp b/code/ryzom/tools/client/ryzom_installer/src/profile.cpp index 6f67495cc..ec0a95696 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profile.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profile.cpp @@ -118,3 +118,55 @@ void CProfile::updateShortcuts() const deleteShortcuts(); createShortcuts(); } + +bool CProfile::createClientConfig() const +{ + // where to search and put client.cfg + QString directory = getDirectory(); + QString filename = directory + "/client.cfg"; + + const CServer &s = CConfigFile::getInstance()->getServer(server); + + // create the 2 initial lines of client.cfg + QString rootConfigFilenameLine = QString("RootConfigFilename = \"%1\";").arg(s.getDefaultClientConfigFullPath()); + QString languageCodeline = QString("LanguageCode = \"%1\";\n").arg(CConfigFile::getInstance()->getLanguage()); + + QString content; + + QFile file(filename); + + if (file.open(QFile::ReadOnly)) + { + // read while content as UTF-8 text + content = QString::fromUtf8(file.readAll()); + + // search the end of the first line + int pos = content.indexOf('\n'); + + if (pos > 0) + { + // don't remove the \r under Windows + if (content[pos - 1] == '\r') pos--; + + // update RootConfigFilename to be sure it points on right client_default.cfg + content = content.mid(pos); + content.prepend(rootConfigFilenameLine); + } + + file.close(); + } + else + { + // create initial client.cfg + content += rootConfigFilenameLine + "\n"; + content += languageCodeline + "\n"; + } + + // write the new content of client.cfg + if (!file.open(QFile::WriteOnly)) return false; + + file.write(content.toUtf8()); + file.close(); + + return true; +} diff --git a/code/ryzom/tools/client/ryzom_installer/src/profile.h b/code/ryzom/tools/client/ryzom_installer/src/profile.h index df34788b1..1fa901c64 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profile.h +++ b/code/ryzom/tools/client/ryzom_installer/src/profile.h @@ -46,6 +46,8 @@ public: void createShortcuts() const; void deleteShortcuts() const; void updateShortcuts() const; + + bool createClientConfig() const; }; extern const CProfile NoProfile; diff --git a/code/ryzom/tools/client/ryzom_installer/src/server.cpp b/code/ryzom/tools/client/ryzom_installer/src/server.cpp index 9f6924c42..0a415d0fb 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/server.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/server.cpp @@ -42,3 +42,8 @@ QString CServer::getConfigurationFullPath() const return getDirectory() + "/" + configurationFilename; } + +QString CServer::getDefaultClientConfigFullPath() const +{ + return getDirectory() + "/client_default.cfg"; +} diff --git a/code/ryzom/tools/client/ryzom_installer/src/server.h b/code/ryzom/tools/client/ryzom_installer/src/server.h index 7a8f2d258..ee6da9f57 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/server.h +++ b/code/ryzom/tools/client/ryzom_installer/src/server.h @@ -47,6 +47,7 @@ public: QString getDirectory() const; QString getClientFullPath() const; QString getConfigurationFullPath() const; + QString getDefaultClientConfigFullPath() const; }; extern const CServer NoServer;