pmt: initial 1.8.0 update

This commit is contained in:
2024-04-25 22:04:33 +03:00
committed by GitHub
parent 076774d9f4
commit 0157c886ae

View File

@@ -1,7 +1,7 @@
/* By YZBruh */ /* By YZBruh */
/* /*
* Copyright 2024 YZBruh - Partition Manager * Copyright 2024 Partition Manager
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ extern "C" {
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include "include/pmt.h" #include "include/pmt.h"
@@ -40,24 +41,30 @@ extern bool pmt_force_mode;
void backup(char *target_backup_partition, char *backup_partition_style) void backup(char *target_backup_partition, char *backup_partition_style)
{ {
static char backupper_path[200]; static char backupper_path[200];
if (strstr(backup_partition_style, "classic") != NULL) { if (strstr(backup_partition_style, "classic") != NULL)
if (pmt_use_cust_cxt) { {
if (pmt_use_cust_cxt)
{
sprintf(backupper_path, "%s/%s", cust_cxt, target_backup_partition); sprintf(backupper_path, "%s/%s", cust_cxt, target_backup_partition);
} else { } else {
sprintf(backupper_path, "/dev/block/by-name/%s", target_backup_partition); sprintf(backupper_path, "/dev/block/by-name/%s", target_backup_partition);
} }
} else if (strstr(backup_partition_style, "logical") != NULL) { } else if (strstr(backup_partition_style, "logical") != NULL)
{
sprintf(backupper_path, "/dev/block/mapper/%s", target_backup_partition); sprintf(backupper_path, "/dev/block/mapper/%s", target_backup_partition);
} else { } else {
if (!pmt_force_mode) { if (!pmt_force_mode)
{
error("İnvalid partition type!\n", 28); error("İnvalid partition type!\n", 28);
} else { } else {
exit(28); exit(28);
} }
} }
if (access(backupper_path, F_OK) == -1) { if (access(backupper_path, F_OK) == -1)
if (!pmt_force_mode) { {
if (!pmt_force_mode)
{
error("Partition not found!\n", 29); error("Partition not found!\n", 29);
} else { } else {
exit(29); exit(29);
@@ -65,35 +72,43 @@ void backup(char *target_backup_partition, char *backup_partition_style)
} }
static char backupper_cmd[256]; static char backupper_cmd[256];
if (outdir != NULL) { if (outdir != NULL)
if (out != NULL) { {
if (out != NULL)
{
sprintf(backupper_cmd, "dd if=%s of=%s/%s.img status=none", backupper_path, outdir, out); sprintf(backupper_cmd, "dd if=%s of=%s/%s.img status=none", backupper_path, outdir, out);
} else { } else {
sprintf(backupper_cmd, "dd if=%s of=%s/%s.img status=none", backupper_path, outdir, target_backup_partition); sprintf(backupper_cmd, "dd if=%s of=%s/%s.img status=none", backupper_path, outdir, target_backup_partition);
} }
} else { } else {
if (out != NULL) { if (out != NULL)
{
sprintf(backupper_cmd, "dd if=%s of=/storage/emulated/0/%s.img status=none", backupper_path, out); sprintf(backupper_cmd, "dd if=%s of=/storage/emulated/0/%s.img status=none", backupper_path, out);
} else { } else {
sprintf(backupper_cmd, "dd if=%s of=/storage/emulated/0/%s.img status=none", backupper_path, target_backup_partition); sprintf(backupper_cmd, "dd if=%s of=/storage/emulated/0/%s.img status=none", backupper_path, target_backup_partition);
} }
} }
if (system(backupper_cmd) != 0) { if (system(backupper_cmd) != 0)
if (!pmt_force_mode) { {
if (!pmt_force_mode)
{
error("Failed!\n", 99); error("Failed!\n", 99);
} else { } else {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
if (outdir != NULL) { if (outdir != NULL)
if (out != NULL) { {
if (out != NULL)
{
printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, out, ANSI_RESET); printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, out, ANSI_RESET);
} else { } else {
printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, target_backup_partition, ANSI_RESET); printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, target_backup_partition, ANSI_RESET);
} }
} else { } else {
if (out != NULL) { if (out != NULL)
{
printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, out, ANSI_RESET); printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, out, ANSI_RESET);
} else { } else {
printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, target_backup_partition, ANSI_RESET); printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, target_backup_partition, ANSI_RESET);