Rearranged when to load skeleton files.

master
Tomatix 5 years ago
parent 4299f3ebad
commit 947587c68d
  1. 67
      IdealIRC/IdealIRC.cpp
  2. 70
      IdealIRC/main.cpp

@ -30,66 +30,6 @@
// Used externally. Initialized in the IdealIRC constructor.
IdealIRC* IIRC_MainWindow_Ptr{ nullptr };
namespace {
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;
}
}
} // Anonymous namespace
IdealIRC::IdealIRC(QWidget* parent)
: QMainWindow(parent)
, ui(new Ui::IdealIRC)
@ -111,13 +51,6 @@ IdealIRC::IdealIRC(QWidget* parent)
addToolBar(Qt::RightToolBarArea, ui->windowButtons);
}
qInfo() << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
qInfo() << " IdealIRC version" << VERSION_STRING << "started.";
qInfo() << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
runtimeEnvironmentSetup();
qDebug() << "Global path:" << GLOBAL_PATH;
qDebug() << "Local path:" << LOCAL_PATH;
const QString title = QString("%1 %2")
.arg(windowTitle())
.arg(VERSION_STRING_NO_APPEND);

@ -18,16 +18,82 @@
*/
#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;
QApplication a(argc, argv);
IdealIRC w;
w.show();

Loading…
Cancel
Save