From 992133d1e2dff713c52e95a74d5cab6f8cf352c2 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Fri, 26 Aug 2011 16:32:25 +0200 Subject: [PATCH] Improved initialization of config directory. --- etc/Translation/Blank.ts | 6 ++--- src/Config.h | 2 +- src/Global.cpp | 12 ++++++--- src/Model_Settings.cpp | 54 ++++++++++++++++++++++++++++++++++------ src/Model_Settings.h | 3 ++- 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index ab5ded59..ed4d0ec5 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -2682,17 +2682,17 @@ QApplication - + Executable '%1' doesn't support Windows compatibility mode. - + Executable '%1' requires Qt v%2, but found Qt v%3. - + Executable '%1' requires Windows 2000 or later. diff --git a/src/Config.h b/src/Config.h index bcf8669d..887df99f 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 3 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 15 -#define VER_LAMEXP_BUILD 669 +#define VER_LAMEXP_BUILD 672 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Global.cpp b/src/Global.cpp index b38e4ec1..de198f87 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -762,6 +762,10 @@ bool lamexp_init_qt(int argc, char* argv[]) //Check the Windows version switch(QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) { + case 0: + case QSysInfo::WV_NT: + qFatal("%s", QApplication::tr("Executable '%1' requires Windows 2000 or later.").arg(QString::fromLatin1(executableName)).toLatin1().constData()); + break; case QSysInfo::WV_2000: qDebug("Running on Windows 2000 (not officially supported!).\n"); lamexp_check_compatibility_mode("GetNativeSystemInfo", executableName); @@ -783,7 +787,7 @@ bool lamexp_init_qt(int argc, char* argv[]) lamexp_check_compatibility_mode(NULL, executableName); break; default: - qWarning("%s", QApplication::tr("Executable '%1' requires Windows 2000 or later.").arg(QString::fromLatin1(executableName)).toLatin1().constData()); + qWarning("Running on an unknown/unsupported OS (%d).\n", static_cast(QSysInfo::windowsVersion() & QSysInfo::WV_NT_based)); break; } @@ -803,7 +807,7 @@ bool lamexp_init_qt(int argc, char* argv[]) application->setApplicationName("LameXP - Audio Encoder Front-End"); application->setApplicationVersion(QString().sprintf("%d.%02d.%04d", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build())); application->setOrganizationName("LoRd_MuldeR"); - application->setOrganizationDomain("mulder.dummwiedeutsch.de"); + application->setOrganizationDomain("mulder.at.gg"); application->setWindowIcon((date.month() == 12 && date.day() >= 24 && date.day() <= 26) ? QIcon(":/MainIcon2.png") : QIcon(":/MainIcon.png")); //Load plugins from application directory @@ -982,7 +986,9 @@ void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize) bool lamexp_portable_mode(void) { QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName(); - return baseName.contains("lamexp", Qt::CaseInsensitive) && baseName.contains("portable", Qt::CaseInsensitive); + int idx1 = baseName.indexOf("lamexp", 0, Qt::CaseInsensitive); + int idx2 = baseName.lastIndexOf("portable", -1, Qt::CaseInsensitive); + return (idx1 >= 0) && (idx2 >= 0) && (idx1 < idx2); } /* diff --git a/src/Model_Settings.cpp b/src/Model_Settings.cpp index 9cf51861..c0692e33 100644 --- a/src/Model_Settings.cpp +++ b/src/Model_Settings.cpp @@ -131,21 +131,37 @@ SettingsModel::SettingsModel(void) : m_defaultLanguage(NULL) { - QString configPath; + QString configPath = "LameXP.ini"; if(!lamexp_portable_mode()) { - QString dataPath = QDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation)).canonicalPath(); - if(dataPath.isEmpty()) dataPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation); - QDir(dataPath).mkpath("."); - configPath = QString("%1/config.ini").arg(dataPath); + QString dataPath = initDirectory(QDesktopServices::storageLocation(QDesktopServices::DataLocation)); + if(!dataPath.isEmpty()) + { + configPath = QString("%1/config.ini").arg(QDir(dataPath).canonicalPath()); + } + else + { + qWarning("SettingsModel: DataLocation could not be initialized!"); + dataPath = initDirectory(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)); + if(!dataPath.isEmpty()) + { + configPath = QString("%1/LameXP.ini").arg(QDir(dataPath).canonicalPath()); + } + } } else { qDebug("LameXP is running in \"portable\" mode -> config in application dir!\n"); QString appPath = QFileInfo(QApplication::applicationFilePath()).canonicalFilePath(); - if(appPath.isEmpty()) appPath = QApplication::applicationFilePath(); - configPath = QString("%1/%2.ini").arg(QFileInfo(appPath).absolutePath(), QFileInfo(appPath).completeBaseName()); + if(appPath.isEmpty()) + { + appPath = QFileInfo(QApplication::applicationFilePath()).absoluteFilePath(); + } + if(QFileInfo(appPath).exists() && QFileInfo(appPath).isFile()) + { + configPath = QString("%1/%2.ini").arg(QFileInfo(appPath).absolutePath(), QFileInfo(appPath).completeBaseName()); + } } m_settings = new QSettings(configPath, QSettings::IniFormat); @@ -267,6 +283,30 @@ QString SettingsModel::defaultLanguage(void) return LAMEXP_DEFAULT_LANGID; } +QString SettingsModel::initDirectory(const QString &path) +{ + if(path.isEmpty()) + { + return QString(); + } + + if(!QDir(path).exists()) + { + for(int i = 0; i < 32; i++) + { + if(QDir(path).mkpath(".")) break; + Sleep(1); + } + } + + if(!QDir(path).exists()) + { + return QString(); + } + + return QDir(path).canonicalPath(); +} + //////////////////////////////////////////////////////////// // Getter and Setter //////////////////////////////////////////////////////////// diff --git a/src/Model_Settings.h b/src/Model_Settings.h index ffa63df1..bb6d9689 100644 --- a/src/Model_Settings.h +++ b/src/Model_Settings.h @@ -130,11 +130,12 @@ public: //Misc void validate(void); - + private: QSettings *m_settings; QString *m_defaultLanguage; QString defaultLanguage(void); + QString initDirectory(const QString &path); }; ///////////////////////////////////////////////////////////////////////////////