store ini file per default in the correct places of the different OSs

This commit is contained in:
Volker Fischer 2011-03-12 13:36:35 +00:00
parent fb736fc1be
commit 6f061342f8
3 changed files with 42 additions and 34 deletions

View file

@ -46,6 +46,9 @@
#define VERSION "3.1.3cvs"
#define APP_NAME "llcon"
// default name of the ini-file
#define DEFAULT_INI_FILE_NAME "llcon.ini"
// file name for logging file
#define DEFAULT_LOG_FILE_NAME "llconsrvlog.txt"

View file

@ -32,21 +32,9 @@ void CSettings::ReadIniFile ( const QString& sFileName )
bool bValue;
QDomDocument IniXMLDocument;
// load data from init-file
// prepare file name for loading initialization data from XML file
QString sCurFileName = sFileName;
if ( sCurFileName.isEmpty() )
{
// if no file name is available, use default file name
sCurFileName =
#if defined ( __APPLE__ ) || defined ( __MACOSX )
QApplication::applicationDirPath() + "/" +
#endif
LLCON_INIT_FILE_NAME;
}
// read data from file if possible
QFile file ( sCurFileName );
// prepare file name for loading initialization data from XML file and read
// data from file if possible
QFile file ( GetIniFileNameWithPath ( sFileName ) );
if ( file.open ( QIODevice::ReadOnly ) )
{
QTextStream in ( &file );
@ -276,20 +264,9 @@ void CSettings::WriteIniFile ( const QString& sFileName )
SetFlagIniSet ( IniXMLDocument, "client", "stereoaudio",
pClient->GetUseStereo() );
// prepare file name for storing initialization data in XML file
QString sCurFileName = sFileName;
if ( sCurFileName.isEmpty() )
{
// if no file name is available, use default file name
sCurFileName =
#if defined ( __APPLE__ ) || defined ( __MACOSX )
QApplication::applicationDirPath() + "/" +
#endif
LLCON_INIT_FILE_NAME;
}
// store XML data in file
QFile file ( sCurFileName );
// prepare file name for storing initialization data in XML file and store
// XML data in file
QFile file ( GetIniFileNameWithPath ( sFileName ) );
if ( file.open ( QIODevice::WriteOnly ) )
{
QTextStream out ( &file );
@ -297,6 +274,35 @@ void CSettings::WriteIniFile ( const QString& sFileName )
}
}
QString CSettings::GetIniFileNameWithPath ( const QString& sFileName )
{
// return the file name with complete path, take care if given file name is
// empty
QString sCurFileName = sFileName;
if ( sCurFileName.isEmpty() )
{
// we use the Qt default setting file paths for the different OSs by
// utilizing the QSettings class
const QSettings TempSettingsObject (
QSettings::IniFormat, QSettings::UserScope, APP_NAME, APP_NAME );
const QString sConfigDir =
QFileInfo ( TempSettingsObject.fileName() ).absolutePath();
// make sure the directory exists
if ( !QFile::exists ( sConfigDir ) )
{
QDir TempDirectoryObject;
TempDirectoryObject.mkpath ( sConfigDir );
}
// append the actual file name
sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME;
}
return sCurFileName;
}
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const int iValue )
{

View file

@ -27,16 +27,13 @@
#include <qdom.h>
#include <qfile.h>
#include <qsettings.h>
#include <qdir.h>
#include <qtextstream.h>
#include "global.h"
#include "client.h"
/* Definitions ****************************************************************/
// name of the init-file
#define LLCON_INIT_FILE_NAME "llcon.ini"
/* Classes ********************************************************************/
class CSettings
{
@ -50,6 +47,8 @@ protected:
void ReadIniFile ( const QString& sFileName );
void WriteIniFile ( const QString& sFileName );
QString GetIniFileNameWithPath ( const QString& sFileName );
// init file access function for read/write
void SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const int iValue = 0 );