1
0
Fork 0
forked from blue/squawk

downloaded files now stored with squawk:// prefix, that way I can move downloads folder without messing up the database

This commit is contained in:
Blue 2022-02-19 00:27:09 +03:00
parent 243edff8bd
commit d8b5ccb2da
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
14 changed files with 75 additions and 44 deletions

View file

@ -1,4 +0,0 @@
target_sources(squawk PRIVATE
pathcheck.h
pathcheck.cpp
)

View file

@ -1,47 +0,0 @@
#include "pathcheck.h"
QString Utils::downloadsPathCheck()
{
QSettings settings;
QVariant dpv = settings.value("downloadsPath");
QString path;
if (!dpv.isValid()) {
path = defaultDownloadsPath();
qDebug() << "no downloadsPath variable in config, using default" << path;
path = getCanonicalWritablePath(path);
return path;
} else {
path = dpv.toString();
path = getCanonicalWritablePath(path);
if (path.size() == 0) {
path = defaultDownloadsPath();
qDebug() << "falling back to the default downloads path" << path;
path = getCanonicalWritablePath(path);
}
return path;
}
}
QString Utils::defaultDownloadsPath()
{
return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + QApplication::applicationName();
}
QString Utils::getCanonicalWritablePath(const QString& path)
{
QDir location(path);
if (!location.exists()) {
bool res = location.mkpath(location.canonicalPath());
if (!res) {
qDebug() << "couldn't create directory" << path;
return "";
}
}
QFileInfo info(location.canonicalPath());
if (info.isWritable()) {
return location.canonicalPath();
} else {
qDebug() << "directory" << path << "is not writable";
return "";
}
}

View file

@ -1,21 +0,0 @@
#ifndef PATHCHECK_H
#define PATHCHECK_H
#include <QString>
#include <QStandardPaths>
#include <QSettings>
#include <QApplication>
#include <QDir>
#include <QFileInfo>
#include <QDebug>
namespace Utils {
QString downloadsPathCheck();
QString defaultDownloadsPath();
QString getCanonicalWritablePath(const QString& path);
}
#endif // PATHCHECK_H