32 QFile::Permissions perm,
bool isDir)
34 quint32 uPerm = isDir ? 0040000 : 0100000;
35 if ((perm & QFile::ReadOwner) != 0)
37 if ((perm & QFile::WriteOwner) != 0)
39 if ((perm & QFile::ExeOwner) != 0)
41 if ((perm & QFile::ReadGroup) != 0)
43 if ((perm & QFile::WriteGroup) != 0)
45 if ((perm & QFile::ExeGroup) != 0)
47 if ((perm & QFile::ReadOther) != 0)
49 if ((perm & QFile::WriteOther) != 0)
51 if ((perm & QFile::ExeOther) != 0)
56 template<
typename FileInfo>
59 self.name = existing.name;
60 self.dateTime = existing.dateTime;
61 self.internalAttr = existing.internalAttr;
62 self.externalAttr = existing.externalAttr;
63 self.comment = existing.comment;
64 self.extraLocal = existing.extra;
65 self.extraGlobal = existing.extra;
66 self.uncompressedSize = existing.uncompressedSize;
80 name(name), dateTime(QDateTime::currentDateTime()), internalAttr(0), externalAttr(0),
86 name(name), internalAttr(0), externalAttr(0), uncompressedSize(0)
89 QDateTime lm = info.lastModified();
91 dateTime = QDateTime::currentDateTime();
100 QFileInfo info(file);
101 QDateTime lm = info.lastModified();
108 QFileInfo info = QFileInfo(file);
109 QFile::Permissions perm = info.permissions();
120 QFileInfo fi(fileName);
122 qWarning(
"QuaZipNewInfo::setFileNTFSTimes(): '%s' doesn't exist",
123 fileName.toUtf8().constData());
131 static void setNTFSTime(QByteArray &extra,
const QDateTime &time,
int position,
133 int ntfsPos = -1, timesPos = -1;
134 unsigned ntfsLength = 0, ntfsTimesLength = 0;
135 for (
int i = 0; i <= extra.size() - 4; ) {
136 unsigned type =
static_cast<unsigned>(
static_cast<unsigned char>(
138 | (
static_cast<unsigned>(
static_cast<unsigned char>(
139 extra.at(i + 1))) << 8);
141 unsigned length =
static_cast<unsigned>(
static_cast<unsigned char>(
143 | (
static_cast<unsigned>(
static_cast<unsigned char>(
144 extra.at(i + 1))) << 8);
153 while (i <= extra.size() - 4) {
154 unsigned tag =
static_cast<unsigned>(
155 static_cast<unsigned char>(extra.at(i)))
156 | (
static_cast<unsigned>(
157 static_cast<unsigned char>(extra.at(i + 1)))
160 unsigned tagsize =
static_cast<unsigned>(
161 static_cast<unsigned char>(extra.at(i)))
162 | (
static_cast<unsigned>(
163 static_cast<unsigned char>(extra.at(i + 1)))
168 ntfsTimesLength = tagsize;
181 ntfsPos = extra.size();
183 extra.resize(extra.size() + 4 + ntfsLength);
187 extra[ntfsPos + 2] = 32;
188 extra[ntfsPos + 3] = 0;
190 memset(extra.data() + ntfsPos + 4, 0, 32);
191 timesPos = ntfsPos + 8;
197 extra[timesPos + 2] = 24;
198 extra[timesPos + 3] = 0;
199 ntfsTimesLength = 24;
201 if (timesPos == -1) {
203 timesPos = ntfsPos + 4 + ntfsLength;
204 extra.resize(extra.size() + 28);
209 memmove(extra.data() + timesPos + 28, extra.data() + timesPos,
210 extra.size() - 28 - timesPos);
217 extra[timesPos + 2] = 24;
218 extra[timesPos + 3] = 0;
220 memset(extra.data() + timesPos + 4, 0, 24);
221 ntfsTimesLength = 24;
223 if (ntfsTimesLength < 24) {
225 size_t timesEnd = timesPos + 4 + ntfsTimesLength;
226 extra.resize(extra.size() + (24 - ntfsTimesLength));
230 memmove(extra.data() + timesEnd + (24 - ntfsTimesLength),
231 extra.data() + timesEnd,
232 extra.size() - (24 - ntfsTimesLength) - timesEnd);
234 ntfsLength += (24 - ntfsTimesLength);
235 ntfsTimesLength = 24;
236 extra[ntfsPos + 2] =
static_cast<char>(ntfsLength);
237 extra[ntfsPos + 3] =
static_cast<char>(ntfsLength >> 8);
238 extra[timesPos + 2] =
static_cast<char>(ntfsTimesLength);
239 extra[timesPos + 3] =
static_cast<char>(ntfsTimesLength >> 8);
241 QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
242 #if (QT_VERSION >= 0x040700)
243 quint64 ticks = base.msecsTo(time) * 10000 + fineTicks;
245 QDateTime utc = time.toUTC();
246 quint64 ticks = (
static_cast<qint64
>(base.date().daysTo(utc.date()))
247 * Q_INT64_C(86400000)
248 +
static_cast<qint64
>(base.time().msecsTo(utc.time())))
249 * Q_INT64_C(10000) + fineTicks;
251 extra[timesPos + 4 + position] =
static_cast<char>(ticks);
252 extra[timesPos + 5 + position] =
static_cast<char>(ticks >> 8);
253 extra[timesPos + 6 + position] =
static_cast<char>(ticks >> 16);
254 extra[timesPos + 7 + position] =
static_cast<char>(ticks >> 24);
255 extra[timesPos + 8 + position] =
static_cast<char>(ticks >> 32);
256 extra[timesPos + 9 + position] =
static_cast<char>(ticks >> 40);
257 extra[timesPos + 10 + position] =
static_cast<char>(ticks >> 48);
258 extra[timesPos + 11 + position] =
static_cast<char>(ticks >> 56);
#define QUAZIP_EXTRA_NTFS_MAGIC
Information about a file to be created.
QByteArray extraLocal
File local extra field.
static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position, int fineTicks)
void setFileNTFScTime(const QDateTime &cTime, int fineTicks=0)
Sets the NTFS creation time.
void setPermissions(QFile::Permissions permissions)
Sets the file permissions.
Information about a file inside archive.
static void QuaZipNewInfo_setPermissions(QuaZipNewInfo *info, QFile::Permissions perm, bool isDir)
#define QUAZIP_EXTRA_NTFS_TIME_MAGIC
QuaZipNewInfo(const QString &name)
Constructs QuaZipNewInfo instance.
QDateTime dateTime
File timestamp.
QByteArray extraGlobal
File global extra field.
Information about a file inside archive (with zip64 support).
quint32 externalAttr
File external attributes.
void setFilePermissions(const QString &file)
Sets the file permissions from the existing file.
void setFileNTFSTimes(const QString &fileName)
Sets the NTFS times from an existing file.
void QuaZipNewInfo_init(QuaZipNewInfo &self, const FileInfo &existing)
void setFileNTFSmTime(const QDateTime &mTime, int fineTicks=0)
Sets the NTFS modification time.
void setFileNTFSaTime(const QDateTime &aTime, int fineTicks=0)
Sets the NTFS access time.
void setFileDateTime(const QString &file)
Sets the file timestamp from the existing file.