The complete source code of IdealIRC http://www.idealirc.org/
 
 
 
 
idealirc/IdealIRC/main.cpp

89 lines
2.6 KiB

/*
* IdealIRC - Internet Relay Chat client
* Copyright (C) 2021 Tom-Andre Barstad.
* This software is licensed under the Software Attribution License.
* See LICENSE for more information.
*/
#include "IdealIRC.h"
#include "config.h"
#include <QApplication>
#include <QDebug>
#include <QDir>
void copyRecursively(const QString& from, const QString& to)
{
QDir srcDir(from);
if (!srcDir.exists()) {
qWarning() << "Unable to copy" << from << "to" << to;
return;
}
QDir destDir(to);
if (!destDir.exists()) {
if (destDir.mkdir(to))
qInfo() << "Created new directory:" << to;
else {
qWarning() << "Unable to create new directory:" << to;
return;
}
}
auto sep = QDir::separator();
QStringList files = srcDir.entryList(QDir::Files);
for (const QString& fileName : files) {
QString srcName = from + sep + fileName;
QString destName = to + sep + fileName;
if (QFile::copy(srcName, destName))
qInfo() << "Copied" << srcName << "to" << destName;
else
qWarning() << "Unable to copy" << srcName << "to" << destName;
}
files = srcDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
for (const QString& fileName : files) {
QString srcName = from + sep + fileName;
QString destName = to + sep + fileName;
copyRecursively(srcName, destName);
}
}
void runtimeEnvironmentSetup()
{
if constexpr (BUILD_TYPE == BuildType::packaged) {
QDir destination(LOCAL_PATH);
if (!destination.exists()) {
qInfo() << "Creating configuration directory:" << LOCAL_PATH;
destination.mkdir(LOCAL_PATH);
QDir skelDir(GLOBAL_PATH+"/skel");
if (skelDir.exists()) {
qInfo() << "Copying configuration skeleton from" << skelDir;
copyRecursively(skelDir.path(), destination.path());
}
else
qWarning() << "No configuration skeleton found";
}
else
qInfo() << "Using existing configuration directory:" << LOCAL_PATH;
}
}
int main(int argc, char *argv[])
{
qSetMessagePattern("[%{time}] %{file}:%{line} %{message}");
Q_INIT_RESOURCE(resources);
QApplication a(argc, argv);
qInfo() << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
qInfo() << " IdealIRC version" << VERSION_STRING << "started.";
qInfo() << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
runtimeEnvironmentSetup();
qDebug() << "Global path:" << GLOBAL_PATH;
qDebug() << "Local path:" << LOCAL_PATH;
IdealIRC w;
w.show();
return a.exec();
}