From 74fa115d205b320f2d259efcd5bc54416bc18153 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Mon, 5 May 2014 06:07:41 -0500 Subject: [PATCH] fixed check for missing ini files --- apps/opencs/model/settings/settingmanager.cpp | 7 +-- apps/opencs/model/settings/usersettings.cpp | 44 ++++++++++--------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/apps/opencs/model/settings/settingmanager.cpp b/apps/opencs/model/settings/settingmanager.cpp index e48dd6e26..afb80c206 100644 --- a/apps/opencs/model/settings/settingmanager.cpp +++ b/apps/opencs/model/settings/settingmanager.cpp @@ -21,6 +21,7 @@ CSMSettings::SettingManager::SettingManager(QObject *parent) : } + CSMSettings::Setting *CSMSettings::SettingManager::createSetting (CSMSettings::SettingType typ, const QString &page, const QString &name) { @@ -113,7 +114,7 @@ CSMSettings::Setting *CSMSettings::SettingManager::findSetting { foreach (Setting *setting, mSettings) { - if (settingName.isEmpty() || (setting->name() == settingName)) + if (setting->name() == settingName) { if (setting->page() == pageName) return setting; @@ -121,7 +122,7 @@ CSMSettings::Setting *CSMSettings::SettingManager::findSetting } return 0; } -/* + QList CSMSettings::SettingManager::findSettings (const QString &pageName) { @@ -134,7 +135,7 @@ QList CSMSettings::SettingManager::findSettings } return settings; } -*/ + CSMSettings::SettingPageMap CSMSettings::SettingManager::settingPageMap() const { SettingPageMap pageMap; diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index bd24b7df0..7764cc2c2 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -288,44 +288,48 @@ CSMSettings::UserSettings::~UserSettings() void CSMSettings::UserSettings::loadSettings (const QString &fileName) { mUserFilePath = QString::fromUtf8 - (mCfgMgr.getUserConfigPath().string().c_str()) + fileName.toUtf8(); + (mCfgMgr.getUserConfigPath().string().c_str()); - QString global = QString::fromUtf8 - (mCfgMgr.getGlobalPath().string().c_str()) + fileName.toUtf8(); + QString globalFilePath = QString::fromUtf8 + (mCfgMgr.getGlobalPath().string().c_str()); - QString local = QString::fromUtf8 - (mCfgMgr.getLocalPath().string().c_str()) + fileName.toUtf8(); + QString localFilePath = QString::fromUtf8 + (mCfgMgr.getLocalPath().string().c_str()); - //open user and global streams - //QTextStream *userStream = openFilestream (mUserFilePath, true); - // QTextStream *otherStream = openFilestream (global, true); + bool isUser = QFile (mUserFilePath + fileName).exists(); + bool isSystem = QFile (globalFilePath + fileName).exists(); - //failed stream, try for local - // if (!otherStream) - // otherStream = openFilestream (local, true); + QString otherFilePath = globalFilePath; + + //test for local only if global fails (uninstalled copy) + if (!isSystem) + { + isSystem = QFile (localFilePath + fileName).exists(); + otherFilePath = localFilePath; + } //error condition - notify and return - // if (!otherStream || !userStream) - /* { + if (!isUser || !isSystem) + { QString message = QObject::tr("
An error was encountered loading \ user settings files.

One or several files could not \ be read. This may be caused by a missing configuration file, \ incorrect file permissions or a corrupted installation of \ OpenCS.
"); - message += QObject::tr("
Global filepath: ") + global; - message += QObject::tr("
Local filepath: ") + local; + message += QObject::tr("
Global filepath: ") + globalFilePath; + message += QObject::tr("
Local filepath: ") + localFilePath; message += QObject::tr("
User filepath: ") + mUserFilePath; displayFileErrorMessage ( message, true); return; } -*/ - //QSETTINGS TEST - qDebug() << mCfgMgr.getUserConfigPath().string().c_str() << ',' << mCfgMgr.getGlobalPath().string().c_str(); - QSettings::setPath (QSettings::IniFormat, QSettings::UserScope, mCfgMgr.getUserConfigPath().string().c_str()); - QSettings::setPath (QSettings::IniFormat, QSettings::SystemScope, mCfgMgr.getGlobalPath().string().c_str()); + QSettings::setPath + (QSettings::IniFormat, QSettings::UserScope, mUserFilePath); + + QSettings::setPath + (QSettings::IniFormat, QSettings::SystemScope, otherFilePath); if (mSettings) delete mSettings;