colormanager: implement default config

This commit is contained in:
itsmattkc
2020-04-22 05:08:33 +10:00
parent 141ac8b12f
commit ccb02d30aa
45 changed files with 721897 additions and 196 deletions
+3 -1
View File
@@ -37,10 +37,12 @@
#include <execinfo.h>
#endif
#include "common/filefunctions.h"
OLIVE_NAMESPACE_ENTER
void crash_handler(int sig) {
QString log_path = QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).filePath(QStringLiteral("olive_crash"));
QString log_path = QDir(FileFunctions::GetTempPath()).filePath(QStringLiteral("olive_crash"));
QFile output(log_path);
output.open(QFile::WriteOnly);
+55 -7
View File
@@ -31,7 +31,7 @@
OLIVE_NAMESPACE_ENTER
QString GetUniqueFileIdentifier(const QString &filename)
QString FileFunctions::GetUniqueFileIdentifier(const QString &filename)
{
QFileInfo info(filename);
@@ -50,7 +50,7 @@ QString GetUniqueFileIdentifier(const QString &filename)
return QString(result.toHex());
}
QString GetMediaIndexLocation()
QString FileFunctions::GetMediaIndexLocation()
{
QDir local_appdata_dir(Config::Current()["DiskCachePath"].toString());
@@ -62,12 +62,12 @@ QString GetMediaIndexLocation()
return media_index_dir.absolutePath();
}
QString GetMediaIndexFilename(const QString &filename)
QString FileFunctions::GetMediaIndexFilename(const QString &filename)
{
return QDir(GetMediaIndexLocation()).filePath(filename);
}
QString GetMediaCacheLocation()
QString FileFunctions::GetMediaCacheLocation()
{
QDir local_appdata_dir(Config::Current()["DiskCachePath"].toString());
@@ -79,7 +79,7 @@ QString GetMediaCacheLocation()
return media_cache_dir.absolutePath();
}
QString GetConfigurationLocation()
QString FileFunctions::GetConfigurationLocation()
{
if (IsPortable()) {
return GetApplicationPath();
@@ -88,14 +88,62 @@ QString GetConfigurationLocation()
}
}
bool IsPortable()
bool FileFunctions::IsPortable()
{
return QFileInfo::exists(QDir(GetApplicationPath()).filePath("portable"));
}
QString GetApplicationPath()
QString FileFunctions::GetApplicationPath()
{
return QCoreApplication::applicationDirPath();
}
QString FileFunctions::GetTempPath()
{
QString temp_path = QDir(QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation))
.filePath(QCoreApplication::organizationName()))
.filePath(QCoreApplication::applicationName());
// Ensure it exists
QDir(temp_path).mkpath(".");
return temp_path;
}
void FileFunctions::CopyDirectory(const QString &source, const QString &dest)
{
QDir d(source);
if (!d.exists()) {
qCritical() << "Failed to copy directory, source" << source << "didn't exist";
return;
}
QDir dest_dir(dest);
if (!dest_dir.mkpath(QStringLiteral("."))) {
qCritical() << "Failed to create destination directory" << dest;
return;
}
QFileInfoList l = d.entryInfoList();
foreach (const QFileInfo& info, l) {
// QDir::NoDotAndDotDot continues to not work, so we have to check manually
if (info.fileName() == QStringLiteral(".") || info.fileName() == QStringLiteral("..")) {
continue;
}
QString dest_file_path = dest_dir.filePath(info.fileName());
if (info.isDir()) {
// Copy dir
CopyDirectory(info.absoluteFilePath(), dest_file_path);
} else {
// Copy file
QFile::copy(info.absoluteFilePath(), dest_file_path);
}
}
}
OLIVE_NAMESPACE_EXIT
+25 -7
View File
@@ -27,19 +27,37 @@
OLIVE_NAMESPACE_ENTER
bool IsPortable();
/**
* @brief A collection of static file and directory functions
*/
class FileFunctions {
public:
/**
* @brief Returns true if the application is running in portable mode
*
* In portable mode, any persistent configuration files should be made in a path relative to the application rather
* than in the user's home folder.
*/
static bool IsPortable();
QString GetUniqueFileIdentifier(const QString& filename);
static QString GetUniqueFileIdentifier(const QString& filename);
QString GetMediaIndexLocation();
static QString GetMediaIndexLocation();
QString GetMediaIndexFilename(const QString& filename);
static QString GetMediaIndexFilename(const QString& filename);
QString GetMediaCacheLocation();
static QString GetMediaCacheLocation();
static QString GetConfigurationLocation();
static QString GetApplicationPath();
static QString GetTempPath();
static void CopyDirectory(const QString& source, const QString& dest);
};
QString GetConfigurationLocation();
QString GetApplicationPath();
OLIVE_NAMESPACE_EXIT