Files
qelectrotech-source-mirror/sources/container/qetzip.h
T
ispyisail c240e4e6f7 Fix the dates of the files inside a .qetz project
miniz is built with MINIZ_NO_TIME so that saving the same project twice
gives the same bytes. Without a clock it writes 0 as each entry's DOS
date: day 0 of month 0, 1980, which is not a date. Unzip tools show it
as 30 Nov 1979, others fail the conversion and show 13 Dec 1901
(reported on PR #1462).

Write 1 Jan 1980 00:00, the first valid DOS date, into the local and
central header of every entry once the archive is built. The bytes stay
reproducible, and miniz stays unmodified. Using the save time instead
was rejected: two saves would no longer give the same file, and miniz
converts through the local time zone, so even a fixed time_t would
differ between machines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 21:49:34 +13:00

56 lines
2.0 KiB
C++

/*
Copyright 2006-2026 The QElectroTech Team
This file is part of QElectroTech.
QElectroTech is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
QElectroTech is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef QETZIP_H
#define QETZIP_H
#include <QByteArray>
#include <QList>
#include <QString>
/**
@brief The QetZip namespace
Reads and writes the zip file a .qetz project is stored in: plain ZIP,
Deflate, as ODF and OOXML documents are, so any unzip tool opens it.
A whole archive is read into, or written from, memory -- projects are
megabytes, not gigabytes -- and written through QSaveFile, so a failed
save leaves the previous file as it was.
Every entry is dated 1 Jan 1980 00:00, not the time of saving: saving
the same project twice gives the same bytes.
*/
namespace QetZip
{
struct Entry
{
QString name; ///< path inside the archive, '/'-separated
QByteArray data;
bool compress = true; ///< false: stored (pictures, the mimetype entry)
};
/// Largest archive read(): uncompressed total and entry count
constexpr qint64 MaxUncompressedSize = qint64(2) * 1024 * 1024 * 1024;
constexpr int MaxEntries = 100000;
bool write(const QString &path, const QList<Entry> &entries, QString *error = nullptr);
QByteArray toBytes(const QList<Entry> &entries, QString *error = nullptr);
bool read(const QString &path, QList<Entry> *entries, QString *error = nullptr);
bool fromBytes(const QByteArray &zip, QList<Entry> *entries, QString *error = nullptr);
}
#endif // QETZIP_H