SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / kdat / File.h
blob125c32a9c6598c513199131bf4bf84d5f9394453
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
4 //
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.
9 //
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
19 #ifndef File_H
20 #define File_H
22 #include <stdio.h>
24 #include <q3ptrlist.h>
27 #include "Range.h"
28 #include "kdat.h"
30 /**
31 * @short This class represents a single file or directory in a tar file.
33 class File {
34 bool _stubbed;
35 union {
36 struct {
37 int _size;
38 int _mtime;
39 int _startRecord;
40 int _endRecord;
41 } _data;
42 struct {
43 FILE* _fptr;
44 int _offset;
45 } _stub;
46 } _union;
47 QString _name;
48 File* _parent;
49 Q3PtrList<File> _children;
50 RangeList _ranges;
51 public:
52 /**
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
58 * the Epoch.
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 );
68 /**
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
78 * entry information.
80 File( File* parent, FILE* fptr, int offset );
82 /**
83 * Destroy the file entry and all of its children.
85 ~File();
87 /**
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 );
96 /**
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
115 * ordinary file.
117 bool isDirectory();
120 * Get the size of the file.
122 * @return The size, in bytes, of the file.
124 int getSize();
127 * Get the last modification time for the file.
129 * @ return The last time the file was modified, in seconds since the Epoch.
131 int getMTime();
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.
148 int getEndRecord();
151 * Get the name of this file. Only the last component of the full path
152 * name is returned.
154 * @return The file's name.
156 QString getName();
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.
171 File* getParent();
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.
198 void calcRanges();
201 #endif