mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-17 13:01:41 +00:00
Changed: Create or update client.cfg, see #279
This commit is contained in:
parent
51fcee657b
commit
265390a6c5
6 changed files with 65 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ public:
|
|||
void createShortcuts() const;
|
||||
void deleteShortcuts() const;
|
||||
void updateShortcuts() const;
|
||||
|
||||
bool createClientConfig() const;
|
||||
};
|
||||
|
||||
extern const CProfile NoProfile;
|
||||
|
|
|
@ -42,3 +42,8 @@ QString CServer::getConfigurationFullPath() const
|
|||
|
||||
return getDirectory() + "/" + configurationFilename;
|
||||
}
|
||||
|
||||
QString CServer::getDefaultClientConfigFullPath() const
|
||||
{
|
||||
return getDirectory() + "/client_default.cfg";
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
QString getDirectory() const;
|
||||
QString getClientFullPath() const;
|
||||
QString getConfigurationFullPath() const;
|
||||
QString getDefaultClientConfigFullPath() const;
|
||||
};
|
||||
|
||||
extern const CServer NoServer;
|
||||
|
|
Loading…
Reference in a new issue