blob: e71f3dcb4ff9932cad1a95408de7c97eae79164d [file] [log] [blame]
nebrassyfe1c2372021-05-20 13:03:30 +02001/*
2 Copyright 2014 to 2020 TeamWin
3 This file is part of TWRP/TeamWin Recovery Project.
4
5 TWRP is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TWRP is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with TWRP. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <string>
20#include "partitions.hpp"
21
22#ifndef TWRP_REPACKER
23#define TWRP_REPACKER
24
25enum Repack_Type {
26 REPLACE_NONE = 0,
27 REPLACE_RAMDISK = 1,
28 REPLACE_KERNEL = 2,
29 REPLACE_RAMDISK_UNPACKED = 3,
30};
31
32struct Repack_Options_struct {
33 Repack_Type Type;
34 bool Backup_First;
35 bool Disable_Verity;
36 bool Disable_Force_Encrypt;
37};
38
39class twrpRepacker {
40 public:
41 bool Backup_Image_For_Repack(TWPartition* Part, const std::string& Temp_Folder_Destination, const bool Create_Backup, const std::string& Backup_Name); // Prepares an image for repacking by unpacking it to the temp folder destination
42 std::string Unpack_Image(const std::string& Source_Path, const std::string& Temp_Folder_Destination, const bool Copy_Source, const bool Create_Destination = true); // Prepares an image for repacking by unpacking it to the temp folder destination and return the ramdisk format
43 bool Repack_Image_And_Flash(const std::string& Target_Image, const struct Repack_Options_struct& Repack_Options); // Repacks the boot image with a new kernel or a new ramdisk
44 bool Flash_Current_Twrp();
45 private:
46 bool Prepare_Empty_Folder(const std::string& Folder); // Creates an empty folder at Folder. If the folder already exists, the folder is deleted, then created
47 std::string original_ramdisk_format; // Ramdisk format of boot partition
48 std::string image_ramdisk_format; // Ramdisk format of boot image to repack from
49};
50#endif // TWRP_REPACKER