2023-08-19 07:53:29 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-08-18 14:52:06 -04:00
|
|
|
#include "utility.h"
|
2023-10-08 18:02:02 -04:00
|
|
|
#include "astra_http_log.h"
|
2023-08-18 14:52:06 -04:00
|
|
|
|
2023-12-17 13:05:37 -05:00
|
|
|
#include <QSslConfiguration>
|
2023-08-18 14:52:06 -04:00
|
|
|
#include <QStandardPaths>
|
|
|
|
|
2023-12-17 12:01:28 -05:00
|
|
|
using namespace Qt::StringLiterals;
|
|
|
|
|
2023-08-18 14:52:06 -04:00
|
|
|
QString Utility::toWindowsPath(const QDir &dir)
|
|
|
|
{
|
2023-12-17 12:01:28 -05:00
|
|
|
return QStringLiteral("Z:") + dir.absolutePath().replace('/'_L1, '\\'_L1);
|
2023-08-18 14:52:06 -04:00
|
|
|
}
|
2023-10-08 18:02:02 -04:00
|
|
|
|
|
|
|
void Utility::printRequest(const QString &type, const QNetworkRequest &request)
|
|
|
|
{
|
|
|
|
qDebug(ASTRA_HTTP) << type.toUtf8().constData() << request.url().toDisplayString();
|
|
|
|
}
|
2023-12-17 12:01:28 -05:00
|
|
|
|
|
|
|
void Utility::createPathIfNeeded(const QDir &dir)
|
|
|
|
{
|
|
|
|
if (!QDir().exists(dir.absolutePath())) {
|
|
|
|
QDir().mkpath(dir.absolutePath());
|
|
|
|
}
|
2023-12-17 13:05:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Utility::setSSL(QNetworkRequest &request)
|
|
|
|
{
|
|
|
|
QSslConfiguration config;
|
|
|
|
config.setProtocol(QSsl::AnyProtocol);
|
|
|
|
config.setPeerVerifyMode(QSslSocket::VerifyNone);
|
|
|
|
|
|
|
|
request.setSslConfiguration(config);
|
2023-12-21 20:28:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Utility::readVersion(const QString &path)
|
|
|
|
{
|
|
|
|
QFile file(path);
|
|
|
|
file.open(QFile::ReadOnly | QFile::Text);
|
|
|
|
|
|
|
|
return QString::fromUtf8(file.readAll());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Utility::writeVersion(const QString &path, const QString &version)
|
|
|
|
{
|
|
|
|
QFile verFile(path);
|
|
|
|
verFile.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
|
|
verFile.write(version.toUtf8());
|
|
|
|
verFile.close();
|
2023-12-17 12:01:28 -05:00
|
|
|
}
|