blob: 3ee6028a5696d839fe993b557b952e5bf6623fde [file] [log] [blame]
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001/*
2 Copyright 2012 bigbiff/Dees_Troy 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
19extern "C" {
20 #include "libtar/libtar.h"
21}
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <string.h>
25#include <errno.h>
26#include <fcntl.h>
27#include <fstream>
28#include <string>
29#include <vector>
30
31using namespace std;
32
33class twrpTar {
34 public:
bigbiff bigbiff3bf2b0e2013-01-21 21:26:43 -050035 int extract();
bigbiff bigbiff9c754052013-01-09 09:09:08 -050036 int compress(string fn);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050037 int uncompress(string fn);
38 int addFilesToExistingTar(vector <string> files, string tarFile);
bigbiff bigbiff3bf2b0e2013-01-21 21:26:43 -050039 int createTar();
bigbiff bigbiff9c754052013-01-09 09:09:08 -050040 int addFile(string fn, bool include_root);
n0d33b511632013-03-06 21:14:15 +020041 int entryExists(string entry);
bigbiff bigbiff3bf2b0e2013-01-21 21:26:43 -050042 int closeTar(bool gzip);
bigbiff bigbiffe6594ab2013-02-17 20:18:31 -050043 int createTarGZFork();
44 int createTarFork();
45 int extractTarFork();
46 int splitArchiveFork();
bigbiff bigbiff3bf2b0e2013-01-21 21:26:43 -050047 void setfn(string fn);
48 void setdir(string dir);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050049 private:
bigbiff bigbiff3bf2b0e2013-01-21 21:26:43 -050050 int createTGZ();
51 int create();
52 int Split_Archive();
bigbiff bigbiff9c754052013-01-09 09:09:08 -050053 int removeEOT(string tarFile);
bigbiff bigbiff3bf2b0e2013-01-21 21:26:43 -050054 int extractTar();
55 int tarDirs(bool include_root);
56 int Generate_Multiple_Archives(string Path);
57 string Strip_Root_Dir(string Path);
58 int extractTGZ();
59 int openTar(bool gzip);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050060 int has_data_media;
61 int Archive_File_Count;
62 unsigned long long Archive_Current_Size;
n0d33b511632013-03-06 21:14:15 +020063 int getArchiveType(); // 1 for compressed - 0 for uncompressed
bigbiff bigbiff9c754052013-01-09 09:09:08 -050064 TAR *t;
65 FILE* p;
66 int fd;
bigbiff bigbiff3bf2b0e2013-01-21 21:26:43 -050067 string tardir;
68 string tarfn;
69 string basefn;
bigbiff bigbiff9c754052013-01-09 09:09:08 -050070};