1 #ifndef MYTAR_H
2 #define MYTAR_H
3 
4 #include <wx/string.h>
5 #include <wx/dynarray.h>
6 
7 class wxArrayString;
8 
9 struct Replacers
10 {
11     wxString from;
12     wxString to;
13 };
14 WX_DECLARE_OBJARRAY(Replacers, ReplacersArray);
15 
16 class TAR
17 {
18     public:
19         struct Header
20         {
21             char name[100];
22             char mode[8];
23             char uid[8];
24             char gid[8];
25             char size[12];
26             char mtime[12];
27             char chksum[8];
28             char typeflag;
29             char linkname[100];
30             char magic[6];
31             char version[2];
32             char uname[32];
33             char gname[32];
34             char devmajor[8];
35             char devminor[8];
36             char prefix[155];
37             char padding[12];
38 //            char *gnu_longname;
39 //            char *gnu_longlink;
40         } __attribute__((__packed__));
41 
42         enum FileType
43         {
44             ftNormal,          // Regular file
45             ftLink,            // Link to another, previously archived, file (LinkName)
46             ftSymbolicLink,    // Symbolic link to another file              (LinkName)
47             ftCharacter,       // Character special files
48             ftBlock,           // Block special files
49             ftDirectory,       // Directory entry. Size is zero (unlimited) or max. number of bytes
50             ftFifo,            // FIFO special file. No data stored in the archive.
51             ftContiguous,      // Contiguous file, if supported by OS
52             ftDumpDir,         // List of files
53             ftMultiVolume,     // Multi-volume file part
54             ftVolumeHeader,    // Volume header. Can appear only as first record in the archive
55             ftLongName,
56             ftLongLink
57         };
58 
59         struct Record
60         {
61             wxString name;
62             int size;
63             size_t pos;
64             FileType ft;
65         };
66 
67         TAR(const wxString& filename = wxEmptyString);
68         ~TAR();
69 
70         bool Open(const wxString& filename);
71         void Close();
72         void Reset();
73 
74         bool Next(Record* rec);
75         bool ExtractAll(const wxString& dirname, wxString& status, wxArrayString* files = 0);
76         bool ExtractFile(Record* rec, const wxString& dirname, wxString& status, wxString* convertedFile = 0);
77         Record* FindFile(const wxString& filename);
78 
79         void ClearReplacers();
80         void AddReplacer(const wxString& from, const wxString& to);
81     protected:
82         int OctToInt(const char* oct);
83         size_t OffsetRecords(size_t bytes);
84         void ReplaceThings(wxString& path);
85         FILE* m_pFile;
86         size_t m_SkipBytes;
87         size_t m_Size;
88         ReplacersArray m_Replacers;
89 };
90 
91 #endif // MYTAR_H
92