pmt: add interrupt signal handler etc.

This commit is contained in:
2025-08-18 22:24:42 +03:00
parent 58330fddf4
commit 366bb28612
3 changed files with 25 additions and 16 deletions

View File

@@ -16,12 +16,13 @@
#include "functions/functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#include <unistd.h>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <csignal>
#include <generated/buildInfo.hpp>
#include <string>
#include <unistd.h>
namespace PartitionManager {
@@ -30,10 +31,16 @@ void init() {
Helper::LoggingProperties::setLogFile("/sdcard/Documents/last_pmt_logs.log");
}
static void sigHandler(const int sig) {
// Even if only SIGINT is to be captured for now, this is still a more appropriate code
if (sig == SIGINT) println("\n%sInterrupted.%s", YELLOW, STYLE_RESET);
exit(sig);
}
auto Variables = std::make_unique<VariableTable>();
basic_variables::basic_variables()
: logFile("/sdcard/Documents/last_pmt_logs.log"), onLogical(false),
: logFile(Helper::LoggingProperties::FILE), onLogical(false),
quietProcess(false), verboseMode(false), viewVersion(false),
forceProcess(false) {
try {
@@ -45,6 +52,15 @@ basic_variables::basic_variables()
int Main(int argc, char **argv) {
try {
// try-catch start
if (argc < 2) {
println(
"Usage: %s [OPTIONS] [SUBCOMMAND]\nUse --help for more information.",
argv[0]);
return EXIT_FAILURE;
}
signal(SIGINT, sigHandler);
CLI::App AppMain{"Partition Manager Tool"};
FunctionManager FuncManager;
@@ -77,13 +93,6 @@ int Main(int argc, char **argv) {
AppMain.add_flag("-v,--version", Variables->viewVersion,
"Print version and exit");
if (argc < 2) {
println(
"Usage: %s [OPTIONS] [SUBCOMMAND]\nUse --help for more information.",
argv[0]);
return EXIT_FAILURE;
}
FuncManager.registerFunction(std::make_unique<backupFunction>(), AppMain);
FuncManager.registerFunction(std::make_unique<flashFunction>(), AppMain);
FuncManager.registerFunction(std::make_unique<eraseFunction>(), AppMain);

View File

@@ -42,7 +42,7 @@ struct _entry {
* The main type of the library. The Builder class is designed
* to be easily manipulated and modified only on this class.
*/
class basic_partition_map final {
class basic_partition_map {
private:
void _resize_map();