Changed: Create or update client.cfg, see #279

This commit is contained in:
kervala 2016-09-20 17:39:29 +02:00
parent 1b4997ccd7
commit c98bf6f44f
6 changed files with 65 additions and 0 deletions

View file

@ -54,6 +54,8 @@ public:
CProfiles getBackupProfiles() const { return m_backupProfiles; } CProfiles getBackupProfiles() const { return m_backupProfiles; }
void backupProfiles(); void backupProfiles();
QString getLanguage() const { return m_language; }
int getProfilesCount() const; int getProfilesCount() const;
CProfile getProfile(int i = -1) const; CProfile getProfile(int i = -1) const;
CProfile getProfile(const QString &id) const; CProfile getProfile(const QString &id) const;

View file

@ -888,6 +888,8 @@ bool COperationDialog::createDefaultProfile()
config->addProfile(profile); config->addProfile(profile);
config->save(); config->save();
profile.createClientConfig();
emit done(); emit done();
return true; return true;
@ -1071,6 +1073,7 @@ void COperationDialog::addComponentsProfiles()
const CProfile &profile = config->getProfile(profileId); const CProfile &profile = config->getProfile(profileId);
profile.createShortcuts(); profile.createShortcuts();
profile.createClientConfig();
} }
} }

View file

@ -118,3 +118,55 @@ void CProfile::updateShortcuts() const
deleteShortcuts(); deleteShortcuts();
createShortcuts(); 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;
}

View file

@ -46,6 +46,8 @@ public:
void createShortcuts() const; void createShortcuts() const;
void deleteShortcuts() const; void deleteShortcuts() const;
void updateShortcuts() const; void updateShortcuts() const;
bool createClientConfig() const;
}; };
extern const CProfile NoProfile; extern const CProfile NoProfile;

View file

@ -42,3 +42,8 @@ QString CServer::getConfigurationFullPath() const
return getDirectory() + "/" + configurationFilename; return getDirectory() + "/" + configurationFilename;
} }
QString CServer::getDefaultClientConfigFullPath() const
{
return getDirectory() + "/client_default.cfg";
}

View file

@ -47,6 +47,7 @@ public:
QString getDirectory() const; QString getDirectory() const;
QString getClientFullPath() const; QString getClientFullPath() const;
QString getConfigurationFullPath() const; QString getConfigurationFullPath() const;
QString getDefaultClientConfigFullPath() const;
}; };
extern const CServer NoServer; extern const CServer NoServer;