summaryrefslogtreecommitdiffstats
path: root/kdat/Archive.h
blob: 9f42684a56d7c9fcf32e8758832bd6e10bc9a05a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// KDat - a tar-based DAT archiver
// Copyright (C) 1998-2000  Sean Vyain, svyain@mail.tds.net
// Copyright (C) 2001-2002  Lawrence Widman, kdat@cardiothink.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#ifndef _Archive_h_
#define _Archive_h_

#include <stdio.h>

#include <tqptrlist.h>
#include <tqstring.h>

#include "File.h"

class Tape;

/**
 * @short This class represents a single tar archive.
 */
class Archive {
    bool _stubbed;

    int         _endBlock;
    int         _ctime;
    FILE*       _fptr;
    int         _offset;
    TQString     _name;
    TQPtrList<File> _children;
    RangeList   _ranges;
    Tape*       _tape;
public:
    /**
     * Create a new archive.
     *
     * @param tape       The tape containing this archive.
     * @param ctime      The create time of the archive.
     * @param name       The name given to this archive by the user.
     */
    Archive( Tape* tape, int ctime, const TQString & name );

    /**
     * Create a new stubbed instance of an archive.  The file pointer and
     * offset specify where the actual instance data can be found.  The real
     * data is read on demand when one of the accessor functions is called.
     *
     * @param tape   The tape containing this archive.
     * @param fptr   The open index file containing this archive entry.  The file
     *               must be left open so that the archive entry information can
     *               be read at a later time.
     * @param offset The offset that will be seeked to when reading the archive
     *               entry information.
     */
    Archive( Tape* tape, FILE* fptr, int offset );

    /**
     * Destroy the archive entry and all of its children.
     */
    ~Archive();

    /**
     * Insure that all of the data fields for this archive entry have been read
     * in.  If the archive entry is a stub then the actual data is read from the
     * index file.  If the archive entry is not a stub then no action is taken.
     *
     * @param version The version of the old tape index.
     */
    void read( int version = KDAT_INDEX_FILE_VERSION );

    /**
     * Recursively read the instance data for this archive entry and all of its
     * children.  This method is used when converting from an older index format.
     *
     * @param version The version of the old tape index.
     */
    void readAll( int version );

    /**
     * Write out the archive entry to the open file.  Entries for each of its
     * children will also be written.
     */
    void write( FILE* fptr );

    /**
     * Get the creation time for this archive.
     *
     * @return The creation time in seconds since the Epoch.
     */
    int getCTime();

    /**
     * Get the last tape block of this archive.
     *
     * @return The last tape block used by this archive.
     */
    int getEndBlock();

    /**
     * Get the name of this archive.
     *
     * @return The name of this archive.
     */
    TQString getName();

    /**
     * Get the tape that contains this archive.
     *
     * @return A pointer to the tape containing this archive.
     */
    Tape* getTape();
    
    /**
     * Get the list of top-level files in this archive.
     *
     * @return A list of the immediate children of this archive.
     */
    const TQPtrList<File>& getChildren();

    /**
     * Get the list of ranges of this file and all of its children.
     *
     * @return A list of ranges.
     */
    const TQPtrList<Range>& getRanges();

    /**
     * Set the ending tape block for this archive.
     *
     * @param endBlock The last tape block used by this archive.
     */
    void setEndBlock( int endBlock );

    /**
     * Set the name of this archive.
     *
     * @param name The new archive name.
     */
    void setName( const TQString & name );

    /**
     * Add a new top level file as a child of this archive.
     *
     * @param file The file to add.
     */
    void addChild( File* file );

    /**
     * Create a new file entry, and add it to the archive.  Based on the
     * full path name of the file, an appropriate parent is found.  The parent
     * may be this archive or another file entry.  File entries will be created
     * on demand if some or all of the file's path does not yet exist in this
     * archive.
     *
     * @param size        The size, in bytes, of the file.
     * @param mtime       The last modification time for the file, in seconds since
     *                    the Epoch.
     * @param startRecord The first tar record number of this file.
     * @param endRecord   The last tar record number of this file.
     * @param name        The full path name for the file.
     *
     * @return A pointer to the newly created file entry.
     */
    File* addFile( int size, int mtime, int startRecord, int endRecord, const TQString & filename );

    /**
     * Recursively calculate the list of ranges for all of the archive's children.
     */
    void calcRanges();
};

#endif