Improved initialization of config directory.
This commit is contained in:
parent
ec8db207f5
commit
992133d1e2
@ -2682,17 +2682,17 @@
|
||||
<context>
|
||||
<name>QApplication</name>
|
||||
<message>
|
||||
<location filename="../../src/Global.cpp" line="670"/>
|
||||
<location filename="../../src/Global.cpp" line="671"/>
|
||||
<source>Executable '%1' doesn't support Windows compatibility mode.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../src/Global.cpp" line="757"/>
|
||||
<location filename="../../src/Global.cpp" line="758"/>
|
||||
<source>Executable '%1' requires Qt v%2, but found Qt v%3.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../src/Global.cpp" line="785"/>
|
||||
<location filename="../../src/Global.cpp" line="767"/>
|
||||
<source>Executable '%1' requires Windows 2000 or later.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -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
|
||||
|
@ -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<int>(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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -130,11 +130,12 @@ public:
|
||||
|
||||
//Misc
|
||||
void validate(void);
|
||||
|
||||
|
||||
private:
|
||||
QSettings *m_settings;
|
||||
QString *m_defaultLanguage;
|
||||
QString defaultLanguage(void);
|
||||
QString initDirectory(const QString &path);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user