Prevent accidental usage of /usr/bin/data
Clementine detects a data directory in the same directory as the executable to determine portable configuration. But there are some packages that create /usr/bin/data, causing Clementine to run in portable mode. Use a more unique data directory name, clementine-data, as the portable data directory. For backwards compatibility, use the legacy data directory if the already exists there.
This commit is contained in:
parent
e1c8726661
commit
bb736d1156
|
@ -66,6 +66,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool Application::kIsPortable = false;
|
bool Application::kIsPortable = false;
|
||||||
|
const char* Application::kLegacyPortableDataDir = "data";
|
||||||
|
const char* Application::kDefaultPortableDataDir = "clementine-data";
|
||||||
|
const char* Application::kPortableDataDir = nullptr;
|
||||||
|
|
||||||
class ApplicationImpl {
|
class ApplicationImpl {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -63,6 +63,10 @@ class Application : public QObject {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool kIsPortable;
|
static bool kIsPortable;
|
||||||
|
static const char* kPortableDataDir;
|
||||||
|
static const char* kLegacyPortableDataDir;
|
||||||
|
static const char* kDefaultPortableDataDir;
|
||||||
|
static bool IsPortable() { return kIsPortable; }
|
||||||
|
|
||||||
explicit Application(QObject* parent = nullptr);
|
explicit Application(QObject* parent = nullptr);
|
||||||
~Application();
|
~Application();
|
||||||
|
|
|
@ -342,8 +342,9 @@ QString ColorToRgba(const QColor& c) {
|
||||||
QString GetConfigPath(ConfigPath config) {
|
QString GetConfigPath(ConfigPath config) {
|
||||||
switch (config) {
|
switch (config) {
|
||||||
case Path_Root: {
|
case Path_Root: {
|
||||||
if (Application::kIsPortable) {
|
if (Application::IsPortable()) {
|
||||||
return QString("%1/data").arg(QCoreApplication::applicationDirPath());
|
QDir d(QCoreApplication::applicationDirPath());
|
||||||
|
return d.filePath(Application::kPortableDataDir);
|
||||||
}
|
}
|
||||||
#ifdef Q_OS_DARWIN
|
#ifdef Q_OS_DARWIN
|
||||||
return mac::GetApplicationSupportPath() + "/" +
|
return mac::GetApplicationSupportPath() + "/" +
|
||||||
|
|
26
src/main.cpp
26
src/main.cpp
|
@ -197,15 +197,33 @@ void ParseAProto() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckPortable() {
|
void CheckPortable() {
|
||||||
QFile f(QApplication::applicationDirPath() + QDir::separator() + "data");
|
QDir appDir(QApplication::applicationDirPath());
|
||||||
if (f.exists()) {
|
// First look for legacy data location.
|
||||||
|
QDir d(appDir.filePath(Application::kLegacyPortableDataDir));
|
||||||
|
// Key off of database file since config name may vary depending on platform.
|
||||||
|
if (d.exists("clementine.db")) {
|
||||||
// We are portable. Set the bool and change the qsettings path
|
// We are portable. Set the bool and change the qsettings path
|
||||||
|
qLog(Info) << "Using legacy portable data location:" << d.path();
|
||||||
Application::kIsPortable = true;
|
Application::kIsPortable = true;
|
||||||
|
Application::kPortableDataDir = Application::kLegacyPortableDataDir;
|
||||||
|
|
||||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||||
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope,
|
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, d.path());
|
||||||
f.fileName());
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d = appDir.filePath(Application::kDefaultPortableDataDir);
|
||||||
|
if (d.exists()) {
|
||||||
|
// We are portable. Set the bool and change the qsettings path
|
||||||
|
qLog(Info) << "Using portable data location:" << d.path();
|
||||||
|
Application::kIsPortable = true;
|
||||||
|
Application::kPortableDataDir = Application::kDefaultPortableDataDir;
|
||||||
|
|
||||||
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||||
|
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, d.path());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qLog(Info) << "Using default config locations.";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in New Issue