ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
quazipfileinfo.cpp
Go to the documentation of this file.
1 /*
2 Copyright (C) 2005-2014 Sergey A. Tachenov
3 
4 This file is part of QuaZIP.
5 
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 
11 QuaZIP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public License
17 along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
18 
19 See COPYING file for the full LGPL text.
20 
21 Original ZIP package is copyrighted by Gilles Vollant and contributors,
22 see quazip/(un)zip.h files for details. Basically it's the zlib license.
23 */
24 
25 #include "quazipfileinfo.h"
26 
27 static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr) {
28  quint32 uPerm = (externalAttr & 0xFFFF0000u) >> 16;
29 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
30  QFile::Permissions perm{};
31 #else
32  QFile::Permissions perm = 0;
33 #endif
34  if ((uPerm & 0400) != 0) perm |= QFile::ReadOwner;
35  if ((uPerm & 0200) != 0) perm |= QFile::WriteOwner;
36  if ((uPerm & 0100) != 0) perm |= QFile::ExeOwner;
37  if ((uPerm & 0040) != 0) perm |= QFile::ReadGroup;
38  if ((uPerm & 0020) != 0) perm |= QFile::WriteGroup;
39  if ((uPerm & 0010) != 0) perm |= QFile::ExeGroup;
40  if ((uPerm & 0004) != 0) perm |= QFile::ReadOther;
41  if ((uPerm & 0002) != 0) perm |= QFile::WriteOther;
42  if ((uPerm & 0001) != 0) perm |= QFile::ExeOther;
43  return perm;
44 }
45 
46 QFile::Permissions QuaZipFileInfo::getPermissions() const {
48 }
49 
50 QFile::Permissions QuaZipFileInfo64::getPermissions() const {
52 }
53 
55  bool noOverflow = true;
56  info.name = name;
59  info.flags = flags;
60  info.method = method;
61  info.dateTime = dateTime;
62  info.crc = crc;
63  if (compressedSize > 0xFFFFFFFFu) {
64  info.compressedSize = 0xFFFFFFFFu;
65  noOverflow = false;
66  } else {
68  }
69  if (uncompressedSize > 0xFFFFFFFFu) {
70  info.uncompressedSize = 0xFFFFFFFFu;
71  noOverflow = false;
72  } else {
74  }
78  info.comment = comment;
79  info.extra = extra;
80  return noOverflow;
81 }
82 
83 static QDateTime getNTFSTime(const QByteArray &extra,
84  int position,
85  int *fineTicks) {
86  QDateTime dateTime;
87  for (int i = 0; i <= extra.size() - 4;) {
88  unsigned type =
89  static_cast<unsigned>(static_cast<unsigned char>(extra.at(i))) |
90  (static_cast<unsigned>(
91  static_cast<unsigned char>(extra.at(i + 1)))
92  << 8);
93  i += 2;
94  unsigned length =
95  static_cast<unsigned>(static_cast<unsigned char>(extra.at(i))) |
96  (static_cast<unsigned>(
97  static_cast<unsigned char>(extra.at(i + 1)))
98  << 8);
99  i += 2;
100  if (type == QUAZIP_EXTRA_NTFS_MAGIC && length >= 32) {
101  i += 4; // reserved
102  while (i <= extra.size() - 4) {
103  unsigned tag =
104  static_cast<unsigned>(
105  static_cast<unsigned char>(extra.at(i))) |
106  (static_cast<unsigned>(
107  static_cast<unsigned char>(extra.at(i + 1)))
108  << 8);
109  i += 2;
110  int tagsize = static_cast<unsigned>(
111  static_cast<unsigned char>(extra.at(i))) |
112  (static_cast<unsigned>(static_cast<unsigned char>(
113  extra.at(i + 1)))
114  << 8);
115  i += 2;
116  if (tag == QUAZIP_EXTRA_NTFS_TIME_MAGIC &&
117  tagsize >= position + 8) {
118  i += position;
119  quint64 mtime =
120  static_cast<quint64>(
121  static_cast<unsigned char>(extra.at(i))) |
122  (static_cast<quint64>(static_cast<unsigned char>(
123  extra.at(i + 1)))
124  << 8) |
125  (static_cast<quint64>(static_cast<unsigned char>(
126  extra.at(i + 2)))
127  << 16) |
128  (static_cast<quint64>(static_cast<unsigned char>(
129  extra.at(i + 3)))
130  << 24) |
131  (static_cast<quint64>(static_cast<unsigned char>(
132  extra.at(i + 4)))
133  << 32) |
134  (static_cast<quint64>(static_cast<unsigned char>(
135  extra.at(i + 5)))
136  << 40) |
137  (static_cast<quint64>(static_cast<unsigned char>(
138  extra.at(i + 6)))
139  << 48) |
140  (static_cast<quint64>(static_cast<unsigned char>(
141  extra.at(i + 7)))
142  << 56);
143  // the NTFS time is measured from 1601 for whatever reason
144  QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
145  dateTime = base.addMSecs(mtime / 10000);
146  if (fineTicks != NULL) {
147  *fineTicks = static_cast<int>(mtime % 10000);
148  }
149  i += tagsize - position;
150  } else {
151  i += tagsize;
152  }
153  }
154  } else {
155  i += length;
156  }
157  }
158  if (fineTicks != NULL && dateTime.isNull()) {
159  *fineTicks = 0;
160  }
161  return dateTime;
162 }
163 
164 QDateTime QuaZipFileInfo64::getNTFSmTime(int *fineTicks) const {
165  return getNTFSTime(extra, 0, fineTicks);
166 }
167 
168 QDateTime QuaZipFileInfo64::getNTFSaTime(int *fineTicks) const {
169  return getNTFSTime(extra, 8, fineTicks);
170 }
171 
172 QDateTime QuaZipFileInfo64::getNTFScTime(int *fineTicks) const {
173  return getNTFSTime(extra, 16, fineTicks);
174 }
char type
math::float3 position
#define NULL
__host__ __device__ float length(float2 v)
Definition: cutil_math.h:1162
#define QUAZIP_EXTRA_NTFS_TIME_MAGIC
Definition: quazip_global.h:57
#define QUAZIP_EXTRA_NTFS_MAGIC
Definition: quazip_global.h:56
static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr)
static QDateTime getNTFSTime(const QByteArray &extra, int position, int *fineTicks)
QDateTime getNTFSaTime(int *fineTicks=NULL) const
Returns the NTFS access time.
QDateTime getNTFSmTime(int *fineTicks=NULL) const
Returns the NTFS modification time.
quint16 versionNeeded
Version needed to extract.
QString name
File name.
quint32 externalAttr
External file attributes.
quint16 method
Compression method.
QDateTime getNTFScTime(int *fineTicks=NULL) const
Returns the NTFS creation time.
QDateTime dateTime
Last modification date and time.
quint64 uncompressedSize
Uncompressed file size.
quint16 flags
General purpose flags.
quint16 versionCreated
Version created by.
bool toQuaZipFileInfo(QuaZipFileInfo &info) const
Converts to QuaZipFileInfo.
QString comment
Comment.
quint16 diskNumberStart
Disk number start.
QByteArray extra
Extra field.
quint64 compressedSize
Compressed file size.
quint16 internalAttr
Internal file attributes.
QFile::Permissions getPermissions() const
Get the file permissions.
Information about a file inside archive.
quint32 uncompressedSize
Uncompressed file size.
QString name
File name.
quint16 internalAttr
Internal file attributes.
quint16 versionCreated
Version created by.
quint16 flags
General purpose flags.
quint16 versionNeeded
Version needed to extract.
quint16 diskNumberStart
Disk number start.
QFile::Permissions getPermissions() const
Get the file permissions.
quint32 crc
CRC.
QDateTime dateTime
Last modification date and time.
QString comment
Comment.
quint16 method
Compression method.
quint32 compressedSize
Compressed file size.
quint32 externalAttr
External file attributes.
QByteArray extra
Extra field.