General improvements and bug fixes

This commit is contained in:
driftingsun 2020-12-26 23:17:20 +03:00
parent 15730b470e
commit 43028953e2
19 changed files with 208 additions and 114 deletions

View file

@ -1,4 +1,5 @@
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QProcess>
#include <QStandardPaths>
@ -11,14 +12,49 @@ QString Utils::toString(bool value)
return value ? "true" : "false";
}
QString Utils::systemLogPath()
QString Utils::serverName()
{
return systemDataLocationPath() + "/log";
#ifdef Q_OS_WIN
return SERVICE_NAME;
#else
return QString("/tmp/%1").arg(SERVICE_NAME);
#endif
}
QString Utils::systemConfigPath()
QString Utils::defaultVpnConfigFileName()
{
return systemDataLocationPath() + "/config";
return configPath() + QString("/%1.ovpn").arg(APPLICATION_NAME);
}
QString Utils::systemLogPath()
{
#ifdef Q_OS_WIN
QStringList locationList = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
QString primaryLocation = "ProgramData";
foreach (const QString& location, locationList) {
if (location.contains(primaryLocation)) {
return QString("%1/%2/log").arg(location).arg(APPLICATION_NAME);
}
}
return QString();
#else
return QString("/var/log/%1").arg(APPLICATION_NAME);
#endif
}
bool Utils::initializePath(const QString& path)
{
QDir dir;
if (!dir.mkpath(path)) {
qWarning().noquote() << QString("Cannot initialize path: '%1'").arg(path);
return false;
}
return true;
}
QString Utils::configPath()
{
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/config";
}
bool Utils::createEmptyFile(const QString& path)
@ -27,25 +63,6 @@ bool Utils::createEmptyFile(const QString& path)
return f.open(QIODevice::WriteOnly | QIODevice::Truncate);
}
QString Utils::systemDataLocationPath()
{
QStringList locationList = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
QString primaryLocation;
#ifdef Q_OS_WIN
primaryLocation = "ProgramData";
#elif defined Q_OS_MAC
primaryLocation = "Users";
#endif
foreach (const QString& location, locationList) {
if (location.contains(primaryLocation)) {
return QString("%1/%2").arg(location).arg(APPLICATION_NAME);
}
}
return QString();
}
QString Utils::executable(const QString& baseName, bool absPath)
{
QString ext;