ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
QuaZipNewInfo Struct Reference

Information about a file to be created. More...

#include <src/ckb/quazip/quazipnewinfo.h>

+ Collaboration diagram for QuaZipNewInfo:

Public Member Functions

 QuaZipNewInfo (const QString &name)
 Constructs QuaZipNewInfo instance. More...
 
 QuaZipNewInfo (const QString &name, const QString &file)
 Constructs QuaZipNewInfo instance. More...
 
 QuaZipNewInfo (const QuaZipFileInfo &existing)
 Initializes the new instance from existing file info. More...
 
 QuaZipNewInfo (const QuaZipFileInfo64 &existing)
 Initializes the new instance from existing file info. More...
 
void setFileDateTime (const QString &file)
 Sets the file timestamp from the existing file. More...
 
void setFilePermissions (const QString &file)
 Sets the file permissions from the existing file. More...
 
void setPermissions (QFile::Permissions permissions)
 Sets the file permissions. More...
 
void setFileNTFSTimes (const QString &fileName)
 Sets the NTFS times from an existing file. More...
 
void setFileNTFSmTime (const QDateTime &mTime, int fineTicks=0)
 Sets the NTFS modification time. More...
 
void setFileNTFSaTime (const QDateTime &aTime, int fineTicks=0)
 Sets the NTFS access time. More...
 
void setFileNTFScTime (const QDateTime &cTime, int fineTicks=0)
 Sets the NTFS creation time. More...
 

Data Fields

QString name
 File name. More...
 
QDateTime dateTime
 File timestamp. More...
 
quint16 internalAttr
 File internal attributes. More...
 
quint32 externalAttr
 File external attributes. More...
 
QString comment
 File comment. More...
 
QByteArray extraLocal
 File local extra field. More...
 
QByteArray extraGlobal
 File global extra field. More...
 
ulong uncompressedSize
 Uncompressed file size. More...
 

Detailed Description

This structure holds information about a file to be created inside ZIP archive. At least name should be set to something correct before passing this structure to QuaZipFile::open(OpenMode,const QuaZipNewInfo&,int,int,bool).

Zip64 support of this structure is slightly limited: in the raw mode (when a pre-compressed file is written into a ZIP file as-is), it is necessary to specify the uncompressed file size and the appropriate field is 32 bit. Since the raw mode is used extremely rare, there is no real need to have a separate QuaZipNewInfo64 structure like QuaZipFileInfo64. It may be added in the future though, if there is a demand for the raw mode with zip64 archives.

Definition at line 50 of file quazipnewinfo.h.

Constructor & Destructor Documentation

QuaZipNewInfo::QuaZipNewInfo ( const QString &  name)

Initializes name with name, dateTime with current date and time. Attributes are initialized with zeros, comment and extra field with null values.

Definition at line 79 of file quazipnewinfo.cpp.

79  :
80  name(name), dateTime(QDateTime::currentDateTime()), internalAttr(0), externalAttr(0),
82 {
83 }
quint16 internalAttr
File internal attributes.
Definition: quazipnewinfo.h:64
ulong uncompressedSize
Uncompressed file size.
Definition: quazipnewinfo.h:84
QDateTime dateTime
File timestamp.
Definition: quazipnewinfo.h:62
quint32 externalAttr
File external attributes.
Definition: quazipnewinfo.h:71
QString name
File name.
Definition: quazipnewinfo.h:55
QuaZipNewInfo::QuaZipNewInfo ( const QString &  name,
const QString &  file 
)

Initializes name with name. Timestamp and permissions are taken from the specified file. If the file does not exists or its timestamp is inaccessible (e. g. you do not have read permission for the directory file in), uses current time and zero permissions. Other attributes are initialized with zeros, comment and extra field with null values.

See Also
setFileDateTime()

Definition at line 85 of file quazipnewinfo.cpp.

References dateTime, and QuaZipNewInfo_setPermissions().

85  :
87 {
88  QFileInfo info(file);
89  QDateTime lm = info.lastModified();
90  if (!info.exists()) {
91  dateTime = QDateTime::currentDateTime();
92  } else {
93  dateTime = lm;
94  QuaZipNewInfo_setPermissions(this, info.permissions(), info.isDir());
95  }
96 }
quint16 internalAttr
File internal attributes.
Definition: quazipnewinfo.h:64
ulong uncompressedSize
Uncompressed file size.
Definition: quazipnewinfo.h:84
static void QuaZipNewInfo_setPermissions(QuaZipNewInfo *info, QFile::Permissions perm, bool isDir)
QDateTime dateTime
File timestamp.
Definition: quazipnewinfo.h:62
quint32 externalAttr
File external attributes.
Definition: quazipnewinfo.h:71
QString name
File name.
Definition: quazipnewinfo.h:55

+ Here is the call graph for this function:

QuaZipNewInfo::QuaZipNewInfo ( const QuaZipFileInfo existing)

Mainly used when copying files between archives.

Both extra fields are initialized to existing.extra. QuaZipNewInfo

Parameters
existing

Definition at line 69 of file quazipnewinfo.cpp.

References QuaZipNewInfo_init().

70 {
71  QuaZipNewInfo_init(*this, existing);
72 }
void QuaZipNewInfo_init(QuaZipNewInfo &self, const FileInfo &existing)

+ Here is the call graph for this function:

QuaZipNewInfo::QuaZipNewInfo ( const QuaZipFileInfo64 existing)

Mainly used when copying files between archives.

Both extra fields are initialized to existing.extra. QuaZipNewInfo

Parameters
existing

Definition at line 74 of file quazipnewinfo.cpp.

References QuaZipNewInfo_init().

75 {
76  QuaZipNewInfo_init(*this, existing);
77 }
void QuaZipNewInfo_init(QuaZipNewInfo &self, const FileInfo &existing)

+ Here is the call graph for this function:

Member Function Documentation

void QuaZipNewInfo::setFileDateTime ( const QString &  file)

Use this function to set the file timestamp from the existing file. Use it like this:

QFile file("file-to-add");
file.open(QIODevice::ReadOnly);
QuaZipNewInfo info("file-name-in-archive");
info.setFileDateTime("file-to-add"); // take the timestamp from file
zipFile.open(QIODevice::WriteOnly, info);

This function does not change dateTime if some error occured (e. g. file is inaccessible).

Definition at line 98 of file quazipnewinfo.cpp.

References dateTime.

99 {
100  QFileInfo info(file);
101  QDateTime lm = info.lastModified();
102  if (info.exists())
103  dateTime = lm;
104 }
QDateTime dateTime
File timestamp.
Definition: quazipnewinfo.h:62
void QuaZipNewInfo::setFileNTFSaTime ( const QDateTime &  aTime,
int  fineTicks = 0 
)

The time is written into the NTFS record in both the local and the global extra fields, updating the existing record if there is one, or creating a new one and appending it to the end of each extra field. When updating an existing record, all other fields are left intact.

Parameters
aTimeThe new access time.
fineTicksThe fractional part of milliseconds, in 100-nanosecond ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than 9999 will add milliseconds or even seconds, but this can be confusing and therefore is discouraged.

Definition at line 267 of file quazipnewinfo.cpp.

References extraGlobal, extraLocal, and setNTFSTime().

Referenced by setFileNTFSTimes().

268 {
269  setNTFSTime(extraLocal, aTime, 8, fineTicks);
270  setNTFSTime(extraGlobal, aTime, 8, fineTicks);
271 }
QByteArray extraLocal
File local extra field.
Definition: quazipnewinfo.h:77
static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position, int fineTicks)
QByteArray extraGlobal
File global extra field.
Definition: quazipnewinfo.h:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QuaZipNewInfo::setFileNTFScTime ( const QDateTime &  cTime,
int  fineTicks = 0 
)

The time is written into the NTFS record in both the local and the global extra fields, updating the existing record if there is one, or creating a new one and appending it to the end of each extra field. When updating an existing record, all other fields are left intact.

Parameters
cTimeThe new creation time.
fineTicksThe fractional part of milliseconds, in 100-nanosecond ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than 9999 will add milliseconds or even seconds, but this can be confusing and therefore is discouraged.

Definition at line 273 of file quazipnewinfo.cpp.

References extraGlobal, extraLocal, and setNTFSTime().

Referenced by setFileNTFSTimes().

274 {
275  setNTFSTime(extraLocal, cTime, 16, fineTicks);
276  setNTFSTime(extraGlobal, cTime, 16, fineTicks);
277 }
QByteArray extraLocal
File local extra field.
Definition: quazipnewinfo.h:77
static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position, int fineTicks)
QByteArray extraGlobal
File global extra field.
Definition: quazipnewinfo.h:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QuaZipNewInfo::setFileNTFSmTime ( const QDateTime &  mTime,
int  fineTicks = 0 
)

The time is written into the NTFS record in both the local and the global extra fields, updating the existing record if there is one, or creating a new one and appending it to the end of each extra field. When updating an existing record, all other fields are left intact.

Parameters
mTimeThe new modification time.
fineTicksThe fractional part of milliseconds, in 100-nanosecond ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than 9999 will add milliseconds or even seconds, but this can be confusing and therefore is discouraged.

Definition at line 261 of file quazipnewinfo.cpp.

References extraGlobal, extraLocal, and setNTFSTime().

Referenced by setFileNTFSTimes().

262 {
263  setNTFSTime(extraLocal, mTime, 0, fineTicks);
264  setNTFSTime(extraGlobal, mTime, 0, fineTicks);
265 }
QByteArray extraLocal
File local extra field.
Definition: quazipnewinfo.h:77
static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position, int fineTicks)
QByteArray extraGlobal
File global extra field.
Definition: quazipnewinfo.h:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void QuaZipNewInfo::setFileNTFSTimes ( const QString &  fileName)

If the file doesn't exist, a warning is printed to the stderr and nothing is done. Otherwise, all three times, as reported by QFileInfo::lastModified(), QFileInfo::lastRead() and QFileInfo::created(), are written to the NTFS extra field record.

The NTFS record is written to both the local and the global extra fields, updating the existing record if there is one, or creating a new one and appending it to the end of each extra field.

The microseconds will be zero, as they aren't reported by QFileInfo.

Parameters
fileName

Definition at line 118 of file quazipnewinfo.cpp.

References setFileNTFSaTime(), setFileNTFScTime(), and setFileNTFSmTime().

119 {
120  QFileInfo fi(fileName);
121  if (!fi.exists()) {
122  qWarning("QuaZipNewInfo::setFileNTFSTimes(): '%s' doesn't exist",
123  fileName.toUtf8().constData());
124  return;
125  }
126  setFileNTFSmTime(fi.lastModified());
127  setFileNTFSaTime(fi.lastRead());
128  setFileNTFScTime(fi.created());
129 }
void setFileNTFScTime(const QDateTime &cTime, int fineTicks=0)
Sets the NTFS creation time.
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.

+ Here is the call graph for this function:

void QuaZipNewInfo::setFilePermissions ( const QString &  file)

Takes permissions from the file and sets the high 16 bits of external attributes. Uses QFileInfo to get permissions on all platforms.

Definition at line 106 of file quazipnewinfo.cpp.

References QuaZipNewInfo_setPermissions().

107 {
108  QFileInfo info = QFileInfo(file);
109  QFile::Permissions perm = info.permissions();
110  QuaZipNewInfo_setPermissions(this, perm, info.isDir());
111 }
static void QuaZipNewInfo_setPermissions(QuaZipNewInfo *info, QFile::Permissions perm, bool isDir)

+ Here is the call graph for this function:

void QuaZipNewInfo::setPermissions ( QFile::Permissions  permissions)

Modifies the highest 16 bits of external attributes. The type part is set to dir if the name ends with a slash, and to regular file otherwise.

Definition at line 113 of file quazipnewinfo.cpp.

References name, and QuaZipNewInfo_setPermissions().

114 {
115  QuaZipNewInfo_setPermissions(this, permissions, name.endsWith('/'));
116 }
static void QuaZipNewInfo_setPermissions(QuaZipNewInfo *info, QFile::Permissions perm, bool isDir)
QString name
File name.
Definition: quazipnewinfo.h:55

+ Here is the call graph for this function:

Field Documentation

QString QuaZipNewInfo::comment

Will be encoded using QuaZip::getCommentCodec().

Definition at line 75 of file quazipnewinfo.h.

Referenced by QuaZipFile::open().

QDateTime QuaZipNewInfo::dateTime

This is the last file modification date and time. Will be stored in the archive central directory. It is a good practice to set it to the source file timestamp instead of archive creating time. Use setFileDateTime() or QuaZipNewInfo(const QString&, const QString&).

Definition at line 62 of file quazipnewinfo.h.

Referenced by QuaZipFile::open(), QuaZipNewInfo(), and setFileDateTime().

quint32 QuaZipNewInfo::externalAttr

The highest 16 bits contain Unix file permissions and type (dir or file). The constructor QuaZipNewInfo(const QString&, const QString&) takes permissions from the provided file.

Definition at line 71 of file quazipnewinfo.h.

Referenced by QuaZipFile::open(), and QuaZipNewInfo_setPermissions().

QByteArray QuaZipNewInfo::extraGlobal
QByteArray QuaZipNewInfo::extraLocal
quint16 QuaZipNewInfo::internalAttr

Definition at line 64 of file quazipnewinfo.h.

Referenced by QuaZipFile::open().

QString QuaZipNewInfo::name

This field holds file name inside archive, including path relative to archive root.

Definition at line 55 of file quazipnewinfo.h.

Referenced by QuaZipFile::open(), and setPermissions().

ulong QuaZipNewInfo::uncompressedSize

This is only needed if you are using raw file zipping mode, i. e. adding precompressed file in the zip archive.

Definition at line 84 of file quazipnewinfo.h.

Referenced by QuaZipFile::open().


The documentation for this struct was generated from the following files: