forked from AdrianTM/mx-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 11
/
batchprocessing.cpp
118 lines (105 loc) · 4.55 KB
/
batchprocessing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**********************************************************************
* batchprocessing.cpp
**********************************************************************
* Copyright (C) 2020-2024 MX Authors
*
* Authors: Adrian
* MX Linux <http://mxlinux.org>
*
* This file is part of MX Snapshot.
*
* MX Snapshot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MX Snapshot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MX Snapshot. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************/
#include "batchprocessing.h"
#include <QDebug>
#include <QRegularExpression>
#include <chrono>
#include "work.h"
using namespace std::chrono_literals;
Batchprocessing::Batchprocessing(const QCommandLineParser &arg_parser, QObject *parent)
: QObject(parent),
Settings(arg_parser),
work(this)
{
connect(qApp, &QCoreApplication::aboutToQuit, this, [this] { work.cleanUp(); });
setConnections();
if (!checkCompression()) {
qCritical().noquote() << tr("Error")
<< tr("Current kernel doesn't support selected compression algorithm, "
"please edit the configuration file and select a different algorithm.");
return;
}
QString path = snapshot_dir;
qDebug() << "Free space:" << getFreeSpaceStrings(path.remove(QRegularExpression("/snapshot$")));
if (!arg_parser.isSet("month") && !arg_parser.isSet("override-size")) {
qDebug() << "Unused space:" << getUsedSpace();
}
work.started = true;
work.e_timer.start();
if (!checkSnapshotDir() || !checkTempDir()) {
work.cleanUp();
return;
}
otherExclusions();
work.setupEnv();
if (!arg_parser.isSet("month") && !arg_parser.isSet("override-size")) {
work.checkEnoughSpace();
}
work.copyNewIso();
work.savePackageList(snapshot_name);
if (edit_boot_menu) {
qDebug() << tr("The program will pause the build and open the boot menu in your text editor.");
QString cmd = getEditor() + " \"" + work_dir + "/iso-template/boot/isolinux/isolinux.cfg\"";
Cmd().run(cmd);
}
disconnect(&timer, &QTimer::timeout, nullptr, nullptr);
work.createIso(snapshot_name);
}
void Batchprocessing::setConnections()
{
connect(&timer, &QTimer::timeout, this, &Batchprocessing::progress);
connect(&work.shell, &Cmd::started, this, [this] { timer.start(500ms); });
connect(&work.shell, &Cmd::done, this, [this] { timer.stop(); });
connect(&work.shell, &Cmd::outputAvailable, this, [](const QString &out) { qDebug().noquote() << out; });
connect(&work.shell, &Cmd::errorAvailable, this, [](const QString &out) { qWarning().noquote() << out; });
connect(&work, &Work::message, [](const QString &out) { qDebug().noquote() << out; });
connect(&work, &Work::messageBox,
[](BoxType /*unused*/, const QString &title, const QString &msg) { qDebug().noquote() << title << msg; });
}
void Batchprocessing::progress()
{
static bool toggle = false;
qDebug() << "\033[2KProcessing command" << (toggle ? "...\r" : "\r");
toggle = !toggle;
}
void Batchprocessing::checkNvidiaGraphicsCard()
{
if (work.shell.run("glxinfo | grep -q NVIDIA")) {
qDebug() << tr("This computer uses an NVIDIA graphics card. Are you planning to use the "
"resulting ISO on the same computer or another computer with an NVIDIA card?")
+ " yes/no";
QString response;
QTextStream stdinStream(stdin);
stdinStream >> response;
response = response.toLower();
if (response == "yes" || response == "y") {
boot_options += " xorg=nvidia";
qDebug() << tr("Note: If you use the resulting ISO on a computer without an NVIDIA card, "
"you will likely need to remove 'xorg=nvidia' from the boot options.");
} else {
qDebug() << tr("Note: If you use the resulting ISO on a computer with an NVIDIA card, "
"you may need to add 'xorg=nvidia' to the boot options.");
}
}
}