MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / createTestArchive

Function createTestArchive

lib/QuaZip/qztest/qztest.cpp:108–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108bool createTestArchive(QuaZip &zip, const QString &zipName,
109 const QStringList &fileNames,
110 QTextCodec *codec,
111 const QString &dir)
112{
113 if (codec != NULL) {
114 zip.setFileNameCodec(codec);
115 }
116 if (!zip.open(QuaZip::mdCreate)) {
117 qWarning("Couldn't open %s", zipName.toUtf8().constData());
118 return false;
119 }
120 int i = 0;
121 QDateTime dt1;
122 foreach (QString fileName, fileNames) {
123 QuaZipFile zipFile(&zip);
124 QString filePath = QDir(dir).filePath(fileName);
125 QFileInfo fileInfo(filePath);
126 QuaZipNewInfo newInfo(fileName, filePath);
127 if (i == 0) // to test code that needs different timestamps
128 newInfo.dateTime = newInfo.dateTime.addSecs(-60);
129 else if (i == 1) // will use for the next file too
130 dt1 = newInfo.dateTime;
131 else if (i == 2) // to test identical timestamps
132 newInfo.dateTime = dt1;
133 if (!zipFile.open(QIODevice::WriteOnly,
134 newInfo, NULL, 0,
135 fileInfo.isDir() ? 0 : 8)) {
136 qWarning("Couldn't open %s in %s", fileName.toUtf8()
137 .constData(), zipName.toUtf8().constData());
138 return false;
139 }
140 if (!fileInfo.isDir()) {
141 QFile file(filePath);
142 if (!file.open(QIODevice::ReadOnly)) {
143 qWarning("Couldn't open %s", filePath.toUtf8()
144 .constData());
145 return false;
146 }
147 while (!file.atEnd()) {
148 char buf[4096];
149 qint64 l = file.read(buf, 4096);
150 if (l <= 0) {
151 qWarning("Couldn't read %s", filePath.toUtf8()
152 .constData());
153 return false;
154 }
155 if (zipFile.write(buf, l) != l) {
156 qWarning("Couldn't write to %s in %s",
157 filePath.toUtf8().constData(),
158 zipName.toUtf8().constData());
159 return false;
160 }
161 }
162 file.close();
163 }
164 zipFile.close();
165 ++i;

Callers 14

getFileListMethod · 0.85
addMethod · 0.85
setFileNameCodecMethod · 0.85
testQIODeviceAPIMethod · 0.85
extractFileMethod · 0.85
extractDirMethod · 0.85
entryListMethod · 0.85
cdMethod · 0.85
entryInfoListMethod · 0.85
operatorsMethod · 0.85
filePathMethod · 0.85
setZipNameMethod · 0.85

Calls 5

setCommentMethod · 0.80
existsMethod · 0.80
setFileNameCodecMethod · 0.45
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected