1 // KDat - a tar-based DAT archiver
2 // Copyright (C) 1998-2000 Sean Vyain, svyain@mail.tds.net
3 // Copyright (C) 2001-2002 Lawrence Widman, kdat@cardiothink.com
5 // This program 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 2 of the License, or
8 // (at your option) any later version.
10 // This program 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.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <q3ptrlist.h>
31 * @short This class represents a single file or directory in a tar file.
49 Q3PtrList
<File
> _children
;
53 * Create a new file entry.
55 * @param parent The directory file entry that contains this file.
56 * @param size The size of the file in bytes.
57 * @param mtime The last modification time of the file in seconds since
59 * @param startRecord The first tar record number in the file.
60 * @param endRecord The last tar record number in the file.
61 * @param name The file name. If the file name ends with a '/' then it
62 * is assumed to be a directory name. Only the last part of
63 * the file's path name should be passed in. The rest of the
64 * path is determined by this file entry's ancestors.
66 File( File
* parent
, int size
, int mtime
, int startRecord
, int endRecord
, const QString
& name
);
69 * Create a new stubbed instance of a file entry. The file pointer and
70 * offset specify where the actual instance data can be found. The real
71 * data is read on demand when one of the accessor functions is called.
73 * @param parent The directory file entry that contains this file.
74 * @param fptr The open index file containing this file entry. The file
75 * must be left open so that the file entry information can
76 * be read at a later time.
77 * @param offset The offset that will be seeked to when reading the file
80 File( File
* parent
, FILE* fptr
, int offset
);
83 * Destroy the file entry and all of its children.
88 * Insure that all of the data fields for this file entry have been read
89 * in. If the file entry is a stub then the actual data is read from the
90 * index file. If the file entry is not a stub then no action is taken.
92 * @param version The version of the old tape index.
94 void read( int version
= KDAT_INDEX_FILE_VERSION
);
97 * Recursively read the instance for this file entry and all of it's
98 * children. This method is used when converting from an older index format.
100 * @param version The version of the old tape index.
102 void readAll( int version
);
105 * Write out the file entry to the open file. Entries for each of its
106 * children will also be written.
108 void write( FILE* fptr
);
111 * Determine whether this file entry represents a directory. If the file
112 * name ends in a '/' then it is assumed that it is a directory.
114 * @return TRUE if the file represents a directory, or FALSE if it is an
120 * Get the size of the file.
122 * @return The size, in bytes, of the file.
127 * Get the last modification time for the file.
129 * @ return The last time the file was modified, in seconds since the Epoch.
134 * Get the tar record number for the file. This is the number of 512-byte
135 * tar blocks that must be read before getting to this file.
137 * @return The tar record number for the file.
139 int getStartRecord();
142 * Get the tar record number that is just past the end of the file. This
143 * number minus the start record gives the number of 512-byte tar blocks
144 * that this file occupies in the archive.
146 * @return The last tar record number for the file.
151 * Get the name of this file. Only the last component of the full path
154 * @return The file's name.
159 * Get the full path name of the file.
161 * @return The full path to the file.
163 QString
getFullPathName();
166 * Get the file entry's parent. A NULL parent indicates that this is one
167 * of (possibly) many top level directories within the tar archive.
169 * @return A pointer to the file entry that contains this file entry.
174 * Get the children of this file entry. A normal file will never have any
175 * children. A directory may or may not have children.
177 * @return A list of the immediate children of this file entry.
179 const Q3PtrList
<File
>& getChildren();
182 * Get the list of ranges of this file and all of its children.
184 * @return A list of ranges.
186 const Q3PtrList
<Range
>& getRanges();
189 * Add a new file entry as a child of this file entry.
191 * @param file The file to add.
193 void addChild( File
* file
);
196 * Recursively calculate the list of ranges for all of the file's children.