Improved initialization of config directory.

This commit is contained in:
LoRd_MuldeR 2011-08-26 16:32:25 +02:00
parent ec8db207f5
commit 992133d1e2
5 changed files with 62 additions and 15 deletions

View File

@ -2682,17 +2682,17 @@
<context> <context>
<name>QApplication</name> <name>QApplication</name>
<message> <message>
<location filename="../../src/Global.cpp" line="670"/> <location filename="../../src/Global.cpp" line="671"/>
<source>Executable &apos;%1&apos; doesn&apos;t support Windows compatibility mode.</source> <source>Executable &apos;%1&apos; doesn&apos;t support Windows compatibility mode.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Global.cpp" line="757"/> <location filename="../../src/Global.cpp" line="758"/>
<source>Executable &apos;%1&apos; requires Qt v%2, but found Qt v%3.</source> <source>Executable &apos;%1&apos; requires Qt v%2, but found Qt v%3.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../../src/Global.cpp" line="785"/> <location filename="../../src/Global.cpp" line="767"/>
<source>Executable &apos;%1&apos; requires Windows 2000 or later.</source> <source>Executable &apos;%1&apos; requires Windows 2000 or later.</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View File

@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 3 #define VER_LAMEXP_MINOR_LO 3
#define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 15 #define VER_LAMEXP_PATCH 15
#define VER_LAMEXP_BUILD 669 #define VER_LAMEXP_BUILD 672
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Tools versions // Tools versions

View File

@ -762,6 +762,10 @@ bool lamexp_init_qt(int argc, char* argv[])
//Check the Windows version //Check the Windows version
switch(QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) 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: case QSysInfo::WV_2000:
qDebug("Running on Windows 2000 (not officially supported!).\n"); qDebug("Running on Windows 2000 (not officially supported!).\n");
lamexp_check_compatibility_mode("GetNativeSystemInfo", executableName); lamexp_check_compatibility_mode("GetNativeSystemInfo", executableName);
@ -783,7 +787,7 @@ bool lamexp_init_qt(int argc, char* argv[])
lamexp_check_compatibility_mode(NULL, executableName); lamexp_check_compatibility_mode(NULL, executableName);
break; break;
default: 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<int>(QSysInfo::windowsVersion() & QSysInfo::WV_NT_based));
break; break;
} }
@ -803,7 +807,7 @@ bool lamexp_init_qt(int argc, char* argv[])
application->setApplicationName("LameXP - Audio Encoder Front-End"); application->setApplicationName("LameXP - Audio Encoder Front-End");
application->setApplicationVersion(QString().sprintf("%d.%02d.%04d", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build())); application->setApplicationVersion(QString().sprintf("%d.%02d.%04d", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build()));
application->setOrganizationName("LoRd_MuldeR"); 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")); application->setWindowIcon((date.month() == 12 && date.day() >= 24 && date.day() <= 26) ? QIcon(":/MainIcon2.png") : QIcon(":/MainIcon.png"));
//Load plugins from application directory //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) bool lamexp_portable_mode(void)
{ {
QString baseName = QFileInfo(QApplication::applicationFilePath()).completeBaseName(); 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);
} }
/* /*

View File

@ -131,22 +131,38 @@ SettingsModel::SettingsModel(void)
: :
m_defaultLanguage(NULL) m_defaultLanguage(NULL)
{ {
QString configPath; QString configPath = "LameXP.ini";
if(!lamexp_portable_mode()) if(!lamexp_portable_mode())
{ {
QString dataPath = QDir(QDesktopServices::storageLocation(QDesktopServices::DataLocation)).canonicalPath(); QString dataPath = initDirectory(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
if(dataPath.isEmpty()) dataPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation); if(!dataPath.isEmpty())
QDir(dataPath).mkpath("."); {
configPath = QString("%1/config.ini").arg(dataPath); 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 else
{ {
qDebug("LameXP is running in \"portable\" mode -> config in application dir!\n"); qDebug("LameXP is running in \"portable\" mode -> config in application dir!\n");
QString appPath = QFileInfo(QApplication::applicationFilePath()).canonicalFilePath(); QString appPath = QFileInfo(QApplication::applicationFilePath()).canonicalFilePath();
if(appPath.isEmpty()) appPath = QApplication::applicationFilePath(); 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()); configPath = QString("%1/%2.ini").arg(QFileInfo(appPath).absolutePath(), QFileInfo(appPath).completeBaseName());
} }
}
m_settings = new QSettings(configPath, QSettings::IniFormat); m_settings = new QSettings(configPath, QSettings::IniFormat);
const QString groupKey = QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build()); const QString groupKey = QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build());
@ -267,6 +283,30 @@ QString SettingsModel::defaultLanguage(void)
return LAMEXP_DEFAULT_LANGID; 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 // Getter and Setter
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -135,6 +135,7 @@ private:
QSettings *m_settings; QSettings *m_settings;
QString *m_defaultLanguage; QString *m_defaultLanguage;
QString defaultLanguage(void); QString defaultLanguage(void);
QString initDirectory(const QString &path);
}; };
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////