File indexing completed on 2025-01-26 04:24:54
0001 #ifndef QUA_ZIPNEWINFO_H 0002 #define QUA_ZIPNEWINFO_H 0003 0004 /* 0005 Copyright (C) 2005-2014 Sergey A. Tachenov 0006 0007 This file is part of QuaZIP. 0008 0009 QuaZIP is free software: you can redistribute it and/or modify 0010 it under the terms of the GNU Lesser General Public License as published by 0011 the Free Software Foundation, either version 2.1 of the License, or 0012 (at your option) any later version. 0013 0014 QuaZIP is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU Lesser General Public License for more details. 0018 0019 You should have received a copy of the GNU Lesser General Public License 0020 along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. 0021 0022 See COPYING file for the full LGPL text. 0023 0024 Original ZIP package is copyrighted by Gilles Vollant, see 0025 quazip/(un)zip.h files for details, basically it's zlib license. 0026 **/ 0027 0028 #include <QDateTime> 0029 #include <QFile> 0030 #include <QString> 0031 0032 #include "quazip_global.h" 0033 0034 #include "quazipfileinfo.h" 0035 0036 /// Information about a file to be created. 0037 /** This structure holds information about a file to be created inside 0038 * ZIP archive. At least name should be set to something correct before 0039 * passing this structure to 0040 * QuaZipFile::open(OpenMode,const QuaZipNewInfo&,int,int,bool). 0041 * 0042 * Zip64 support of this structure is slightly limited: in the raw mode (when 0043 * a pre-compressed file is written into a ZIP file as-is), it is necessary 0044 * to specify the uncompressed file size and the appropriate field is 32 bit. 0045 * Since the raw mode is used extremely rare, there is no real need to have 0046 * a separate QuaZipNewInfo64 structure like QuaZipFileInfo64. It may be added 0047 * in the future though, if there is a demand for the raw mode with zip64 0048 * archives. 0049 **/ 0050 struct QUAZIP_EXPORT QuaZipNewInfo { 0051 /// File name. 0052 /** This field holds file name inside archive, including path relative 0053 * to archive root. 0054 **/ 0055 QString name; 0056 /// File timestamp. 0057 /** This is the last file modification date and time. Will be stored 0058 * in the archive central directory. It is a good practice to set it 0059 * to the source file timestamp instead of archive creating time. Use 0060 * setFileDateTime() or QuaZipNewInfo(const QString&, const QString&). 0061 **/ 0062 QDateTime dateTime; 0063 /// File internal attributes. 0064 quint16 internalAttr; 0065 /// File external attributes. 0066 /** 0067 The highest 16 bits contain Unix file permissions and type (dir or 0068 file). The constructor QuaZipNewInfo(const QString&, const QString&) 0069 takes permissions from the provided file. 0070 */ 0071 quint32 externalAttr; 0072 /// File comment. 0073 /** Will be encoded using QuaZip::getCommentCodec(). 0074 **/ 0075 QString comment; 0076 /// File local extra field. 0077 QByteArray extraLocal; 0078 /// File global extra field. 0079 QByteArray extraGlobal; 0080 /// Uncompressed file size. 0081 /** This is only needed if you are using raw file zipping mode, i. e. 0082 * adding precompressed file in the zip archive. 0083 **/ 0084 ulong uncompressedSize; 0085 /// Constructs QuaZipNewInfo instance. 0086 /** Initializes name with \a name, dateTime with current date and 0087 * time. Attributes are initialized with zeros, comment and extra 0088 * field with null values. 0089 **/ 0090 QuaZipNewInfo(const QString& name); 0091 /// Constructs QuaZipNewInfo instance. 0092 /** Initializes name with \a name. Timestamp and permissions are taken 0093 * from the specified file. If the \a file does not exists or its timestamp 0094 * is inaccessible (e. g. you do not have read permission for the 0095 * directory file in), uses current time and zero permissions. Other attributes are 0096 * initialized with zeros, comment and extra field with null values. 0097 * 0098 * \sa setFileDateTime() 0099 **/ 0100 QuaZipNewInfo(const QString& name, const QString& file); 0101 /// Initializes the new instance from existing file info. 0102 /** Mainly used when copying files between archives. 0103 * 0104 * Both extra fields are initialized to existing.extra. 0105 * @brief QuaZipNewInfo 0106 * @param existing 0107 */ 0108 QuaZipNewInfo(const QuaZipFileInfo &existing); 0109 /// Initializes the new instance from existing file info. 0110 /** Mainly used when copying files between archives. 0111 * 0112 * Both extra fields are initialized to existing.extra. 0113 * @brief QuaZipNewInfo 0114 * @param existing 0115 */ 0116 QuaZipNewInfo(const QuaZipFileInfo64 &existing); 0117 /// Sets the file timestamp from the existing file. 0118 /** Use this function to set the file timestamp from the existing 0119 * file. Use it like this: 0120 * \code 0121 * QuaZipFile zipFile(&zip); 0122 * QFile file("file-to-add"); 0123 * file.open(QIODevice::ReadOnly); 0124 * QuaZipNewInfo info("file-name-in-archive"); 0125 * info.setFileDateTime("file-to-add"); // take the timestamp from file 0126 * zipFile.open(QIODevice::WriteOnly, info); 0127 * \endcode 0128 * 0129 * This function does not change dateTime if some error occured (e. g. 0130 * file is inaccessible). 0131 **/ 0132 void setFileDateTime(const QString& file); 0133 /// Sets the file permissions from the existing file. 0134 /** 0135 Takes permissions from the file and sets the high 16 bits of 0136 external attributes. Uses QFileInfo to get permissions on all 0137 platforms. 0138 */ 0139 void setFilePermissions(const QString &file); 0140 /// Sets the file permissions. 0141 /** 0142 Modifies the highest 16 bits of external attributes. The type part 0143 is set to dir if the name ends with a slash, and to regular file 0144 otherwise. 0145 */ 0146 void setPermissions(QFile::Permissions permissions); 0147 /// Sets the NTFS times from an existing file. 0148 /** 0149 * If the file doesn't exist, a warning is printed to the stderr and nothing 0150 * is done. Otherwise, all three times, as reported by 0151 * QFileInfo::lastModified(), QFileInfo::lastRead() and QFileInfo::created(), 0152 * are written to the NTFS extra field record. 0153 * 0154 * The NTFS record is written to 0155 * both the local and the global extra fields, updating the existing record 0156 * if there is one, or creating a new one and appending it to the end 0157 * of each extra field. 0158 * 0159 * The microseconds will be zero, as they aren't reported by QFileInfo. 0160 * @param fileName 0161 */ 0162 void setFileNTFSTimes(const QString &fileName); 0163 /// Sets the NTFS modification time. 0164 /** 0165 * The time is written into the NTFS record in 0166 * both the local and the global extra fields, updating the existing record 0167 * if there is one, or creating a new one and appending it to the end 0168 * of each extra field. When updating an existing record, all other fields 0169 * are left intact. 0170 * @param mTime The new modification time. 0171 * @param fineTicks The fractional part of milliseconds, in 100-nanosecond 0172 * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than 0173 * 9999 will add milliseconds or even seconds, but this can be 0174 * confusing and therefore is discouraged. 0175 */ 0176 void setFileNTFSmTime(const QDateTime &mTime, int fineTicks = 0); 0177 /// Sets the NTFS access time. 0178 /** 0179 * The time is written into the NTFS record in 0180 * both the local and the global extra fields, updating the existing record 0181 * if there is one, or creating a new one and appending it to the end 0182 * of each extra field. When updating an existing record, all other fields 0183 * are left intact. 0184 * @param aTime The new access time. 0185 * @param fineTicks The fractional part of milliseconds, in 100-nanosecond 0186 * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than 0187 * 9999 will add milliseconds or even seconds, but this can be 0188 * confusing and therefore is discouraged. 0189 */ 0190 void setFileNTFSaTime(const QDateTime &aTime, int fineTicks = 0); 0191 /// Sets the NTFS creation time. 0192 /** 0193 * The time is written into the NTFS record in 0194 * both the local and the global extra fields, updating the existing record 0195 * if there is one, or creating a new one and appending it to the end 0196 * of each extra field. When updating an existing record, all other fields 0197 * are left intact. 0198 * @param cTime The new creation time. 0199 * @param fineTicks The fractional part of milliseconds, in 100-nanosecond 0200 * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than 0201 * 9999 will add milliseconds or even seconds, but this can be 0202 * confusing and therefore is discouraged. 0203 */ 0204 void setFileNTFScTime(const QDateTime &cTime, int fineTicks = 0); 0205 }; 0206 0207 #endif