quazipnewinfo.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #ifndef QUA_ZIPNEWINFO_H
  2. #define QUA_ZIPNEWINFO_H
  3. /*
  4. Copyright (C) 2005-2014 Sergey A. Tachenov
  5. This file is part of QuaZIP.
  6. QuaZIP is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published by
  8. the Free Software Foundation, either version 2.1 of the License, or
  9. (at your option) any later version.
  10. QuaZIP 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 Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
  16. See COPYING file for the full LGPL text.
  17. Original ZIP package is copyrighted by Gilles Vollant, see
  18. quazip/(un)zip.h files for details, basically it's zlib license.
  19. **/
  20. #include <QDateTime>
  21. #include <QFile>
  22. #include <QString>
  23. #include "quazip_global.h"
  24. #include "quazipfileinfo.h"
  25. /// Information about a file to be created.
  26. /** This structure holds information about a file to be created inside
  27. * ZIP archive. At least name should be set to something correct before
  28. * passing this structure to
  29. * QuaZipFile::open(OpenMode,const QuaZipNewInfo&,int,int,bool).
  30. *
  31. * Zip64 support of this structure is slightly limited: in the raw mode (when
  32. * a pre-compressed file is written into a ZIP file as-is), it is necessary
  33. * to specify the uncompressed file size and the appropriate field is 32 bit.
  34. * Since the raw mode is used extremely rare, there is no real need to have
  35. * a separate QuaZipNewInfo64 structure like QuaZipFileInfo64. It may be added
  36. * in the future though, if there is a demand for the raw mode with zip64
  37. * archives.
  38. **/
  39. struct QUAZIP_EXPORT QuaZipNewInfo {
  40. /// File name.
  41. /** This field holds file name inside archive, including path relative
  42. * to archive root.
  43. **/
  44. QString name;
  45. /// File timestamp.
  46. /** This is the last file modification date and time. Will be stored
  47. * in the archive central directory. It is a good practice to set it
  48. * to the source file timestamp instead of archive creating time. Use
  49. * setFileDateTime() or QuaZipNewInfo(const QString&, const QString&).
  50. **/
  51. QDateTime dateTime;
  52. /// File internal attributes.
  53. quint16 internalAttr;
  54. /// File external attributes.
  55. /**
  56. The highest 16 bits contain Unix file permissions and type (dir or
  57. file). The constructor QuaZipNewInfo(const QString&, const QString&)
  58. takes permissions from the provided file.
  59. */
  60. quint32 externalAttr;
  61. /// File comment.
  62. /** Will be encoded using QuaZip::getCommentCodec().
  63. **/
  64. QString comment;
  65. /// File local extra field.
  66. QByteArray extraLocal;
  67. /// File global extra field.
  68. QByteArray extraGlobal;
  69. /// Uncompressed file size.
  70. /** This is only needed if you are using raw file zipping mode, i. e.
  71. * adding precompressed file in the zip archive.
  72. **/
  73. ulong uncompressedSize;
  74. /// Constructs QuaZipNewInfo instance.
  75. /** Initializes name with \a name, dateTime with current date and
  76. * time. Attributes are initialized with zeros, comment and extra
  77. * field with null values.
  78. **/
  79. QuaZipNewInfo(const QString& name);
  80. /// Constructs QuaZipNewInfo instance.
  81. /** Initializes name with \a name. Timestamp and permissions are taken
  82. * from the specified file. If the \a file does not exists or its timestamp
  83. * is inaccessible (e. g. you do not have read permission for the
  84. * directory file in), uses current time and zero permissions. Other attributes are
  85. * initialized with zeros, comment and extra field with null values.
  86. *
  87. * \sa setFileDateTime()
  88. **/
  89. QuaZipNewInfo(const QString& name, const QString& file);
  90. /// Initializes the new instance from existing file info.
  91. /** Mainly used when copying files between archives.
  92. *
  93. * Both extra fields are initialized to existing.extra.
  94. * @brief QuaZipNewInfo
  95. * @param existing
  96. */
  97. QuaZipNewInfo(const QuaZipFileInfo &existing);
  98. /// Initializes the new instance from existing file info.
  99. /** Mainly used when copying files between archives.
  100. *
  101. * Both extra fields are initialized to existing.extra.
  102. * @brief QuaZipNewInfo
  103. * @param existing
  104. */
  105. QuaZipNewInfo(const QuaZipFileInfo64 &existing);
  106. /// Sets the file timestamp from the existing file.
  107. /** Use this function to set the file timestamp from the existing
  108. * file. Use it like this:
  109. * \code
  110. * QuaZipFile zipFile(&zip);
  111. * QFile file("file-to-add");
  112. * file.open(QIODevice::ReadOnly);
  113. * QuaZipNewInfo info("file-name-in-archive");
  114. * info.setFileDateTime("file-to-add"); // take the timestamp from file
  115. * zipFile.open(QIODevice::WriteOnly, info);
  116. * \endcode
  117. *
  118. * This function does not change dateTime if some error occured (e. g.
  119. * file is inaccessible).
  120. **/
  121. void setFileDateTime(const QString& file);
  122. /// Sets the file permissions from the existing file.
  123. /**
  124. Takes permissions from the file and sets the high 16 bits of
  125. external attributes. Uses QFileInfo to get permissions on all
  126. platforms.
  127. */
  128. void setFilePermissions(const QString &file);
  129. /// Sets the file permissions.
  130. /**
  131. Modifies the highest 16 bits of external attributes. The type part
  132. is set to dir if the name ends with a slash, and to regular file
  133. otherwise.
  134. */
  135. void setPermissions(QFile::Permissions permissions);
  136. /// Sets the NTFS times from an existing file.
  137. /**
  138. * If the file doesn't exist, a warning is printed to the stderr and nothing
  139. * is done. Otherwise, all three times, as reported by
  140. * QFileInfo::lastModified(), QFileInfo::lastRead() and QFileInfo::created(),
  141. * are written to the NTFS extra field record.
  142. *
  143. * The NTFS record is written to
  144. * both the local and the global extra fields, updating the existing record
  145. * if there is one, or creating a new one and appending it to the end
  146. * of each extra field.
  147. *
  148. * The microseconds will be zero, as they aren't reported by QFileInfo.
  149. * @param fileName
  150. */
  151. void setFileNTFSTimes(const QString &fileName);
  152. /// Sets the NTFS modification time.
  153. /**
  154. * The time is written into the NTFS record in
  155. * both the local and the global extra fields, updating the existing record
  156. * if there is one, or creating a new one and appending it to the end
  157. * of each extra field. When updating an existing record, all other fields
  158. * are left intact.
  159. * @param mTime The new modification time.
  160. * @param fineTicks The fractional part of milliseconds, in 100-nanosecond
  161. * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than
  162. * 9999 will add milliseconds or even seconds, but this can be
  163. * confusing and therefore is discouraged.
  164. */
  165. void setFileNTFSmTime(const QDateTime &mTime, int fineTicks = 0);
  166. /// Sets the NTFS access time.
  167. /**
  168. * The time is written into the NTFS record in
  169. * both the local and the global extra fields, updating the existing record
  170. * if there is one, or creating a new one and appending it to the end
  171. * of each extra field. When updating an existing record, all other fields
  172. * are left intact.
  173. * @param aTime The new access time.
  174. * @param fineTicks The fractional part of milliseconds, in 100-nanosecond
  175. * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than
  176. * 9999 will add milliseconds or even seconds, but this can be
  177. * confusing and therefore is discouraged.
  178. */
  179. void setFileNTFSaTime(const QDateTime &aTime, int fineTicks = 0);
  180. /// Sets the NTFS creation time.
  181. /**
  182. * The time is written into the NTFS record in
  183. * both the local and the global extra fields, updating the existing record
  184. * if there is one, or creating a new one and appending it to the end
  185. * of each extra field. When updating an existing record, all other fields
  186. * are left intact.
  187. * @param cTime The new creation time.
  188. * @param fineTicks The fractional part of milliseconds, in 100-nanosecond
  189. * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than
  190. * 9999 will add milliseconds or even seconds, but this can be
  191. * confusing and therefore is discouraged.
  192. */
  193. void setFileNTFScTime(const QDateTime &cTime, int fineTicks = 0);
  194. };
  195. #endif