Upgrade to Qt6

This commit is contained in:
Phillip Stephens 2021-01-23 16:26:28 -08:00
parent 1acd71dc46
commit 76966831b0
60 changed files with 1654 additions and 914 deletions

View File

@ -4,7 +4,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
find_package(Qt5 COMPONENTS Network Widgets Xml Gui REQUIRED PATHS /usr/local/opt/qt) find_package(Qt6 COMPONENTS Core5Compat Network Widgets Xml Gui REQUIRED PATHS /usr/local/opt/qt)
file(GLOB QUAZIP_SRCS quazip/quazip/*.c quazip/quazip/*.cpp quazip/quazip/*.h) file(GLOB QUAZIP_SRCS quazip/quazip/*.c quazip/quazip/*.cpp quazip/quazip/*.h)
list(REMOVE_ITEM QUAZIP_SRCS list(REMOVE_ITEM QUAZIP_SRCS
@ -74,11 +74,12 @@ target_compile_definitions(hecl-gui PRIVATE
) )
target_link_libraries(hecl-gui PRIVATE target_link_libraries(hecl-gui PRIVATE
Qt5::Core Qt6::Core
Qt5::Gui Qt6::Core5Compat
Qt5::Network Qt6::Gui
Qt5::Widgets Qt6::Network
Qt5::Xml Qt6::Widgets
Qt6::Xml
hecl-light hecl-light
zeus zeus

View File

@ -64,13 +64,12 @@ void ParseEscapeSequence(int attribute, QListIterator<QString>& i, QTextCharForm
case 17: case 17:
case 18: case 18:
case 19: { case 19: {
QFontDatabase fontDatabase;
QString fontFamily = textCharFormat.fontFamily(); QString fontFamily = textCharFormat.fontFamily();
QStringList fontStyles = fontDatabase.styles(fontFamily); QStringList fontStyles = QFontDatabase::styles(fontFamily);
int fontStyleIndex = attribute - 11; int fontStyleIndex = attribute - 11;
if (fontStyleIndex < fontStyles.length()) { if (fontStyleIndex < fontStyles.length()) {
textCharFormat.setFont( textCharFormat.setFont(
fontDatabase.font(fontFamily, fontStyles.at(fontStyleIndex), textCharFormat.font().pointSize())); QFontDatabase::font(fontFamily, fontStyles.at(fontStyleIndex), textCharFormat.font().pointSize()));
} }
break; break;
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
class QStringList; #include <QStringList>
class QuaZip; class QuaZip;
class QString; class QString;

View File

@ -4,6 +4,9 @@
#include <QMessageBox> #include <QMessageBox>
#include <QComboBox> #include <QComboBox>
#include <QLabel> #include <QLabel>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QtCore5Compat>
#endif
#include "EscapeSequenceParser.hpp" #include "EscapeSequenceParser.hpp"
#include "FileDirDialog.hpp" #include "FileDirDialog.hpp"
#include "ExtractZip.hpp" #include "ExtractZip.hpp"
@ -537,6 +540,7 @@ void MainWindow::setTextTermFormatting(const QString& text) {
m_inContinueNote = false; m_inContinueNote = false;
m_cursor.beginEditBlock(); m_cursor.beginEditBlock();
// TODO: Migrate QRegExp to QRegularExpression
QRegExp const escapeSequenceExpression(QStringLiteral(R"(\x1B\[([\d;\?FA]+)([mlh]?))")); QRegExp const escapeSequenceExpression(QStringLiteral(R"(\x1B\[([\d;\?FA]+)([mlh]?))"));
QTextCharFormat defaultTextCharFormat = m_cursor.charFormat(); QTextCharFormat defaultTextCharFormat = m_cursor.charFormat();
int offset = escapeSequenceExpression.indexIn(text); int offset = escapeSequenceExpression.indexIn(text);

View File

@ -34,7 +34,7 @@ int main(int argc, char* argv[]) {
QApplication::setOrganizationName(QStringLiteral("AxioDL")); QApplication::setOrganizationName(QStringLiteral("AxioDL"));
QApplication::setApplicationName(QStringLiteral("HECL")); QApplication::setApplicationName(QStringLiteral("HECL"));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif #endif

View File

@ -1,64 +1,68 @@
cmake_minimum_required(VERSION 2.6) # require 3.15 for GNUInstallDirs
project(QuaZip) cmake_minimum_required(VERSION 3.15...3.18)
# CMP0042: Explicitly acknowledge MACOSX_RPATH project(QuaZip VERSION 1.1)
# (introduced in CMake 2.8.12, enabled by default in CMake 3.0,
# and producing a warning when unset since 3.7.1)
cmake_policy(SET CMP0042 NEW)
option(BUILD_WITH_QT4 "Build QuaZip with Qt4 no matter if Qt5 was found" OFF) set(CMAKE_CXX_STANDARD 14)
if(NOT BUILD_WITH_QT4) set(QUAZIP_LIB_VERSION ${QuaZip_VERSION})
# try Qt5 first, and prefer that if found set(QUAZIP_LIB_SOVERSION 1.0.0)
find_package(Qt5Core QUIET)
option(BUILD_SHARED_LIBS "" ON)
set(QUAZIP_QT_MAJOR_VERSION 5 CACHE STRING "Qt version to use (4 or 5), defaults to 5")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE)
endif() endif()
if(Qt5Core_FOUND) enable_testing()
set(CMAKE_CXX_STANDARD 11) set(CMAKE_AUTOMOC ON)
set(QTCORE_LIBRARIES ${Qt5Core_LIBRARIES}) set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(QUAZIP_LIB_VERSION_SUFFIX 5) set(CMAKE_DEBUG_POSTFIX d)
# if there is no QT_ROOT, try to deduce it from Qt QtCore include
if("${QT_ROOT}" STREQUAL "") set(QUAZIP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(QT_ROOT ${QT_QTCORE_INCLUDE_DIR}/../..) set(QUAZIP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(QUAZIP_LIB_FILE_NAME quazip${QuaZip_VERSION_MAJOR}-qt${QUAZIP_QT_MAJOR_VERSION})
set(QUAZIP_LIB_TARGET_NAME QuaZip)
set(QUAZIP_DIR_NAME QuaZip-Qt${QUAZIP_QT_MAJOR_VERSION}-${QUAZIP_LIB_VERSION})
set(QUAZIP_PACKAGE_NAME QuaZip-Qt${QUAZIP_QT_MAJOR_VERSION})
set(QUAZIP_ENABLE_TESTS OFF)
if(QUAZIP_QT_MAJOR_VERSION EQUAL 6)
find_package(Qt6 REQUIRED COMPONENTS Core Core5Compat
OPTIONAL_COMPONENTS Network Test)
set(QUAZIP_LIB_QT_LIBRARIES Qt6::Core Qt6::Core5Compat)
set(QUAZIP_TEST_QT_LIBRARIES Qt6::Core Qt6::Core5Compat Qt6::Network Qt6::Test)
set(QUAZIP_PKGCONFIG_REQUIRES Qt6Core)
if (Qt6Network_FOUND AND Qt6Test_FOUND)
set(QUAZIP_ENABLE_TESTS ON)
endif() endif()
include_directories(${Qt5Core_INCLUDE_DIRS}) elseif(QUAZIP_QT_MAJOR_VERSION EQUAL 5)
find_package(Qt5 REQUIRED COMPONENTS Core
macro(qt_wrap_cpp) OPTIONAL_COMPONENTS Network Test)
qt5_wrap_cpp(${ARGN}) set(QUAZIP_LIB_QT_LIBRARIES Qt5::Core)
endmacro() set(QUAZIP_TEST_QT_LIBRARIES Qt5::Core Qt5::Network Qt5::Test)
else() set(QUAZIP_PKGCONFIG_REQUIRES Qt5Core)
set(qt_min_version "4.5.0") if (Qt5Network_FOUND AND Qt5Test_FOUND)
find_package(Qt4 REQUIRED) set(QUAZIP_ENABLE_TESTS ON)
set(QT_USE_QTGUI false)
include(${QT_USE_FILE})
include_directories(${QT_INCLUDES})
set(QTCORE_LIBRARIES ${QT_QTCORE_LIBRARY})
macro(qt_wrap_cpp)
qt4_wrap_cpp(${ARGN})
endmacro()
endif()
# Use system zlib on unix and Qt ZLIB on Windows
if(UNIX OR MINGW)
find_package(ZLIB REQUIRED)
else()
set(ZLIB_INCLUDE_DIRS "${QT_ROOT}/src/3rdparty/zlib" CACHE STRING "Path to ZLIB headers of Qt")
set(ZLIB_LIBRARIES "")
if(NOT EXISTS "${ZLIB_INCLUDE_DIRS}/zlib.h")
message("Please specify a valid zlib include dir")
endif() endif()
elseif(QUAZIP_QT_MAJOR_VERSION EQUAL 4)
find_package(Qt4 4.5.0 REQUIRED COMPONENTS QtCore
OPTIONAL_COMPONENTS QtNetwork QtTest)
set(QUAZIP_LIB_QT_LIBRARIES Qt4::QtCore)
set(QUAZIP_TEST_QT_LIBRARIES Qt4::QtCore Qt4::QtNetwork Qt4::QtTest)
set(QUAZIP_PKGCONFIG_REQUIRES QtCore)
if (QT_QTNETWORK_FOUND AND QT_QTTEST_FOUND)
set(QUAZIP_ENABLE_TESTS ON)
endif()
else()
message(FATAL_ERROR "Qt version ${QUAZIP_QT_MAJOR_VERSION} is not supported")
endif() endif()
# All build libraries are moved to this directory find_package(ZLIB REQUIRED)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)")
set(LIB_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE STRING "Library directory name" FORCE)
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig" CACHE STRING "Installation directory for pkgconfig (.pc) files" FORCE)
set(QUAZIP_LIB_TARGET_NAME quazip${QUAZIP_LIB_VERSION_SUFFIX} CACHE
INTERNAL "Target name of libquazip" FORCE)
add_subdirectory(quazip) add_subdirectory(quazip)
install(FILES QuaZipConfig.cmake DESTINATION ${LIB_DESTINATION}/cmake/QuaZip${QUAZIP_LIB_VERSION_SUFFIX} RENAME QuaZip${QUAZIP_LIB_VERSION_SUFFIX}Config.cmake) if(QUAZIP_ENABLE_TESTS)
add_subdirectory(qztest EXCLUDE_FROM_ALL)
endif()

View File

@ -1,6 +1,23 @@
The QuaZIP library is licensed under the GNU Lesser General Public This file contains information about licensing information for the
QuaZip library. It is the definitive source of such information, and
takes priority over any copyright notices that might be found in the
source code. All of those copyright notices are there just to reference
this file, which they all should do, except the notices in the original
ZIP/UNZIP package (MiniZip), which is included in the QuaZip library in
a modified state, as its license permits.
If some source file contains a copyright notice that neither marks that
file as clearly belonging to the MiniZip project nor references this
file, then it's a bug and should be reported to
https://github.com/stachenov/quazip/issues
The QuaZip library is licensed under the GNU Lesser General Public
License V2.1 plus a static linking exception. License V2.1 plus a static linking exception.
The original ZIP/UNZIP package (MiniZip) is copyrighted by Gilles
Vollant and contributors, see quazip/(un)zip.h files for details.
Basically it's the zlib license.
STATIC LINKING EXCEPTION STATIC LINKING EXCEPTION
The copyright holders give you permission to link this library with The copyright holders give you permission to link this library with

View File

@ -1,4 +1,19 @@
QuaZIP changes QuaZip changes
* 2020-10-11 1.1
* Fixed Unix symlink handling in JlCompress compression
* Implemented Unix symlink handling in JlCompress extraction
* Added 1.x migration guide
* 2020-10-05 1.0
* Preliminary Qt 6 support
* Consistent naming of binaries (libquazip1-qt5 style)
* Modern CMake support
* Ditched qmake support
* 2020-04-29 0.9
* Support for extended timestamps
* Various contributed CMake fixes
* 2019-05-27 0.8.1 * 2019-05-27 0.8.1
* CMake regression fix * CMake regression fix

View File

@ -1,8 +1,8 @@
QuaZIP is the C++ wrapper for Gilles Vollant's ZIP/UNZIP package QuaZip is the C++ wrapper for Gilles Vollant's ZIP/UNZIP package
(AKA Minizip) using Trolltech's Qt library. (AKA Minizip) using Trolltech's Qt library.
If you need to write files to a ZIP archive or read files from one If you need to write files to a ZIP archive or read files from one
using QIODevice API, QuaZIP is exactly the kind of tool you need. using QIODevice API, QuaZip is exactly the kind of tool you need.
See [the documentation](https://stachenov.github.io/quazip/) for details. See [the documentation](https://stachenov.github.io/quazip/) for details.
@ -10,9 +10,11 @@ Want to report a bug or ask for a feature? Open an [issue](https://github.com/st
Want to fix a bug or implement a new feature? See [CONTRIBUTING.md](CONTRIBUTING.md). Want to fix a bug or implement a new feature? See [CONTRIBUTING.md](CONTRIBUTING.md).
You're a package maintainer and want to update to QuaZip 1.0? Read [the migration guide](https://github.com/stachenov/quazip/blob/master/QuaZip-1.x-migration.md).
Copyright notice: Copyright notice:
Copyright (C) 2005-2018 Sergey A. Tachenov Copyright (C) 2005-2020 Sergey A. Tachenov and contributors
Distributed under LGPL, full details in the COPYING file. Distributed under LGPL, full details in the COPYING file.

View File

@ -1,36 +1,97 @@
file(GLOB SRCS "*.c" "*.cpp") project(QuaZip_Library VERSION ${QUAZIP_LIB_VERSION})
file(GLOB PUBLIC_HEADERS "*.h")
set(QUAZIP_LIB_VERSION 1.0.0) include(GNUInstallDirs) # configurable CMAKE_INSTALL_*DIR
set(QUAZIP_LIB_SOVERSION 1)
# Must be added to enable export macro set(QUAZIP_HEADERS
ADD_DEFINITIONS(-DQUAZIP_BUILD) JlCompress.h
ioapi.h
minizip_crypt.h
quaadler32.h
quachecksum32.h
quacrc32.h
quagzipfile.h
quaziodevice.h
quazip.h
quazip_global.h
quazip_qt_compat.h
quazipdir.h
quazipfile.h
quazipfileinfo.h
quazipnewinfo.h
unzip.h
zip.h
)
qt_wrap_cpp(MOC_SRCS ${PUBLIC_HEADERS}) set(QUAZIP_SOURCES
set(SRCS ${SRCS} ${MOC_SRCS}) ${QUAZIP_HEADERS}
unzip.c
zip.c
JlCompress.cpp
qioapi.cpp
quaadler32.cpp
quachecksum32.cpp
quacrc32.cpp
quagzipfile.cpp
quaziodevice.cpp
quazip.cpp
quazipdir.cpp
quazipfile.cpp
quazipfileinfo.cpp
quazipnewinfo.cpp
)
add_library(${QUAZIP_LIB_TARGET_NAME} SHARED ${SRCS}) set(QUAZIP_INCLUDE_PATH ${QUAZIP_DIR_NAME}/quazip)
add_library(quazip_static STATIC ${SRCS}) set(QUAZIP_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake)
set(QUAZIP_PKGCONFIG_NAME quazip${QuaZip_VERSION_MAJOR}-qt${QUAZIP_QT_MAJOR_VERSION})
# Windows uses .lib extension for both static and shared library add_library(${QUAZIP_LIB_TARGET_NAME} ${QUAZIP_SOURCES})
# *nix systems use different extensions for SHARED and STATIC library and by convention both libraries have the same name add_library(QuaZip::QuaZip ALIAS ${QUAZIP_LIB_TARGET_NAME})
if (NOT WIN32)
set_target_properties(quazip_static PROPERTIES OUTPUT_NAME quazip${QUAZIP_LIB_VERSION_SUFFIX})
endif ()
target_include_directories(${QUAZIP_LIB_TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${ZLIB_INCLUDE_DIRS}) set_target_properties(${QUAZIP_LIB_TARGET_NAME} PROPERTIES
target_include_directories(quazip_static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${ZLIB_INCLUDE_DIRS}) VERSION ${QUAZIP_LIB_VERSION}
set_target_properties(${QUAZIP_LIB_TARGET_NAME} quazip_static PROPERTIES VERSION ${QUAZIP_LIB_VERSION} SOVERSION ${QUAZIP_LIB_SOVERSION} DEBUG_POSTFIX d) SOVERSION ${QUAZIP_LIB_SOVERSION}
OUTPUT_NAME ${QUAZIP_LIB_FILE_NAME}
# Link against ZLIB_LIBRARIES if needed (on Windows this variable is empty) PUBLIC_HEADER "${QUAZIP_HEADERS}"
target_link_libraries(${QUAZIP_LIB_TARGET_NAME} ${QT_QTMAIN_LIBRARY} ${QTCORE_LIBRARIES} ${ZLIB_LIBRARIES}) )
target_link_libraries(quazip_static ${QT_QTMAIN_LIBRARY} ${QTCORE_LIBRARIES} ${ZLIB_LIBRARIES}) target_include_directories(${QUAZIP_LIB_TARGET_NAME} PUBLIC
$<BUILD_INTERFACE:${QUAZIP_SOURCE_DIR}>
if(UNIX AND NOT APPLE) $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
configure_file( ${CMAKE_SOURCE_DIR}/quazip.pc.cmakein $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QUAZIP_DIR_NAME}>
${CMAKE_BINARY_DIR}/quazip.pc @ONLY) $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QUAZIP_INCLUDE_PATH}>
install(FILES ${CMAKE_BINARY_DIR}/quazip.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}") )
target_link_libraries(${QUAZIP_LIB_TARGET_NAME} ${QUAZIP_LIB_QT_LIBRARIES} ZLIB::ZLIB)
if(BUILD_SHARED_LIBS)
target_compile_definitions(${QUAZIP_LIB_TARGET_NAME} PRIVATE QUAZIP_BUILD) # dllexport
else()
target_compile_definitions(${QUAZIP_LIB_TARGET_NAME} PUBLIC QUAZIP_STATIC) # suppress dllimport
endif() endif()
install(FILES ${PUBLIC_HEADERS} DESTINATION include/quazip${QUAZIP_LIB_VERSION_SUFFIX})
install(TARGETS ${QUAZIP_LIB_TARGET_NAME} quazip_static LIBRARY DESTINATION ${LIB_DESTINATION} ARCHIVE DESTINATION ${LIB_DESTINATION} RUNTIME DESTINATION ${LIB_DESTINATION}) include(CMakePackageConfigHelpers)
if(BUILD_SHARED_LIBS)
set(Flavor Shared)
else()
set(Flavor Static)
endif()
set(QUAZIP_EXPORT_SET ${QUAZIP_PACKAGE_NAME}_${Flavor}Targets)
write_basic_package_version_file(${PROJECT_BINARY_DIR}/${QUAZIP_PACKAGE_NAME}ConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(QuaZipConfig.cmake.in ${QUAZIP_PACKAGE_NAME}Config.cmake
INSTALL_DESTINATION ${QUAZIP_INSTALL_CONFIGDIR}/${QUAZIP_DIR_NAME}
)
install(TARGETS ${QUAZIP_LIB_TARGET_NAME}
EXPORT ${QUAZIP_EXPORT_SET}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${QUAZIP_INCLUDE_PATH}
)
install(EXPORT ${QUAZIP_EXPORT_SET}
NAMESPACE QuaZip::
DESTINATION ${QUAZIP_INSTALL_CONFIGDIR}/${QUAZIP_DIR_NAME}
)
install(FILES ${PROJECT_BINARY_DIR}/${QUAZIP_PACKAGE_NAME}Config.cmake
${PROJECT_BINARY_DIR}/${QUAZIP_PACKAGE_NAME}ConfigVersion.cmake
DESTINATION ${QUAZIP_INSTALL_CONFIGDIR}/${QUAZIP_DIR_NAME}
)
configure_file(quazip.pc.cmakein ${QUAZIP_PKGCONFIG_NAME}.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${QUAZIP_PKGCONFIG_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

View File

@ -2,20 +2,20 @@
Copyright (C) 2010 Roberto Pompermaier Copyright (C) 2010 Roberto Pompermaier
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -24,7 +24,6 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include "JlCompress.h" #include "JlCompress.h"
#include <QDebug>
static bool copyData(QIODevice &inFile, QIODevice &outFile) static bool copyData(QIODevice &inFile, QIODevice &outFile)
{ {
@ -50,24 +49,31 @@ bool JlCompress::compressFile(QuaZip* zip, QString fileName, QString fileDest) {
zip->getMode()!=QuaZip::mdAppend && zip->getMode()!=QuaZip::mdAppend &&
zip->getMode()!=QuaZip::mdAdd) return false; zip->getMode()!=QuaZip::mdAdd) return false;
// Apro il file originale
QFile inFile;
inFile.setFileName(fileName);
if(!inFile.open(QIODevice::ReadOnly)) return false;
// Apro il file risulato // Apro il file risulato
QuaZipFile outFile(zip); QuaZipFile outFile(zip);
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileDest, inFile.fileName()))) return false; if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileDest, fileName))) return false;
// Copio i dati QFileInfo input(fileName);
if (!copyData(inFile, outFile) || outFile.getZipError()!=UNZ_OK) { if (quazip_is_symlink(input)) {
// Not sure if we should use any specialized codecs here.
// After all, a symlink IS just a byte array. And
// this is mostly for Linux, where UTF-8 is ubiquitous these days.
QString path = quazip_symlink_target(input);
QString relativePath = input.dir().relativeFilePath(path);
outFile.write(QFile::encodeName(relativePath));
} else {
QFile inFile;
inFile.setFileName(fileName);
if (!inFile.open(QIODevice::ReadOnly))
return false; return false;
if (!copyData(inFile, outFile) || outFile.getZipError()!=UNZ_OK)
return false;
inFile.close();
} }
// Chiudo i file // Chiudo i file
outFile.close(); outFile.close();
if (outFile.getZipError()!=UNZ_OK) return false; if (outFile.getZipError()!=UNZ_OK) return false;
inFile.close();
return true; return true;
} }
@ -92,7 +98,7 @@ bool JlCompress::compressSubDir(QuaZip* zip, QString dir, QString origDir, bool
if (dir != origDir) { if (dir != origDir) {
QuaZipFile dirZipFile(zip); QuaZipFile dirZipFile(zip);
if (!dirZipFile.open(QIODevice::WriteOnly, if (!dirZipFile.open(QIODevice::WriteOnly,
QuaZipNewInfo(origDirectory.relativeFilePath(dir) + QLatin1String("/"), dir), 0, 0, 0)) { QuaZipNewInfo(origDirectory.relativeFilePath(dir) + QLatin1String("/"), dir), nullptr, 0, 0)) {
return false; return false;
} }
dirZipFile.close(); dirZipFile.close();
@ -105,10 +111,8 @@ bool JlCompress::compressSubDir(QuaZip* zip, QString dir, QString origDir, bool
QFileInfoList files = directory.entryInfoList(QDir::AllDirs|QDir::NoDotAndDotDot|filters); QFileInfoList files = directory.entryInfoList(QDir::AllDirs|QDir::NoDotAndDotDot|filters);
for (int index = 0; index < files.size(); ++index ) { for (int index = 0; index < files.size(); ++index ) {
const QFileInfo & file( files.at( index ) ); const QFileInfo & file( files.at( index ) );
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 4) if (!file.isDir()) // needed for Qt < 4.7 because it doesn't understand AllDirs
if (!file.isDir())
continue; continue;
#endif
// Comprimo la sotto cartella // Comprimo la sotto cartella
if(!compressSubDir(zip,file.absoluteFilePath(),origDir,recursive,filters)) return false; if(!compressSubDir(zip,file.absoluteFilePath(),origDir,recursive,filters)) return false;
} }
@ -170,6 +174,13 @@ bool JlCompress::extractFile(QuaZip* zip, QString fileName, QString fileDest) {
return true; return true;
} }
if (info.isSymbolicLink()) {
QString target = QFile::decodeName(inFile.readAll());
if (!QFile::link(target, fileDest))
return false;
return true;
}
// Apro il file risultato // Apro il file risultato
QFile outFile; QFile outFile;
outFile.setFileName(fileDest); outFile.setFileName(fileDest);
@ -262,7 +273,7 @@ bool JlCompress::compressFiles(QString fileCompressed, QStringList files) {
} }
bool JlCompress::compressDir(QString fileCompressed, QString dir, bool recursive) { bool JlCompress::compressDir(QString fileCompressed, QString dir, bool recursive) {
return compressDir(fileCompressed, dir, recursive, 0); return compressDir(fileCompressed, dir, recursive, QDir::Filters());
} }
bool JlCompress::compressDir(QString fileCompressed, QString dir, bool JlCompress::compressDir(QString fileCompressed, QString dir,
@ -353,12 +364,18 @@ QStringList JlCompress::extractFiles(QuaZip &zip, const QStringList &files, cons
return extracted; return extracted;
} }
QStringList JlCompress::extractDir(QString fileCompressed, QString dir) { QStringList JlCompress::extractDir(QString fileCompressed, QTextCodec* fileNameCodec, QString dir) {
// Apro lo zip // Apro lo zip
QuaZip zip(fileCompressed); QuaZip zip(fileCompressed);
if (fileNameCodec)
zip.setFileNameCodec(fileNameCodec);
return extractDir(zip, dir); return extractDir(zip, dir);
} }
QStringList JlCompress::extractDir(QString fileCompressed, QString dir) {
return extractDir(fileCompressed, nullptr, dir);
}
QStringList JlCompress::extractDir(QuaZip &zip, const QString &dir) QStringList JlCompress::extractDir(QuaZip &zip, const QString &dir)
{ {
if(!zip.open(QuaZip::mdUnzip)) { if(!zip.open(QuaZip::mdUnzip)) {
@ -429,12 +446,19 @@ QStringList JlCompress::getFileList(QuaZip *zip)
return lst; return lst;
} }
QStringList JlCompress::extractDir(QIODevice *ioDevice, QString dir) QStringList JlCompress::extractDir(QIODevice* ioDevice, QTextCodec* fileNameCodec, QString dir)
{ {
QuaZip zip(ioDevice); QuaZip zip(ioDevice);
if (fileNameCodec)
zip.setFileNameCodec(fileNameCodec);
return extractDir(zip, dir); return extractDir(zip, dir);
} }
QStringList JlCompress::extractDir(QIODevice *ioDevice, QString dir)
{
return extractDir(ioDevice, nullptr, dir);
}
QStringList JlCompress::getFileList(QIODevice *ioDevice) QStringList JlCompress::getFileList(QIODevice *ioDevice)
{ {
QuaZip *zip = new QuaZip(ioDevice); QuaZip *zip = new QuaZip(ioDevice);

View File

@ -5,20 +5,20 @@
Copyright (C) 2010 Roberto Pompermaier Copyright (C) 2010 Roberto Pompermaier
Copyright (C) 2005-2016 Sergey A. Tachenov Copyright (C) 2005-2016 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -29,10 +29,11 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "quazip.h" #include "quazip.h"
#include "quazipfile.h" #include "quazipfile.h"
#include "quazipfileinfo.h" #include "quazipfileinfo.h"
#include <QString> #include "quazip_qt_compat.h"
#include <QDir> #include <QtCore/QString>
#include <QFileInfo> #include <QtCore/QDir>
#include <QFile> #include <QtCore/QFileInfo>
#include <QtCore/QFile>
/// Utility class for typical operations. /// Utility class for typical operations.
/** /**
@ -152,6 +153,15 @@ public:
\return The list of the full paths of the files extracted, empty on failure. \return The list of the full paths of the files extracted, empty on failure.
*/ */
static QStringList extractDir(QString fileCompressed, QString dir = QString()); static QStringList extractDir(QString fileCompressed, QString dir = QString());
/// Extract a whole archive.
/**
\param fileCompressed The name of the archive.
\param fileNameCodec The codec to use for file names.
\param dir The directory to extract to, the current directory if
left empty.
\return The list of the full paths of the files extracted, empty on failure.
*/
static QStringList extractDir(QString fileCompressed, QTextCodec* fileNameCodec, QString dir = QString());
/// Get the file list. /// Get the file list.
/** /**
\return The list of the files in the archive, or, more precisely, the \return The list of the files in the archive, or, more precisely, the
@ -185,6 +195,15 @@ public:
\return The list of the full paths of the files extracted, empty on failure. \return The list of the full paths of the files extracted, empty on failure.
*/ */
static QStringList extractDir(QIODevice *ioDevice, QString dir = QString()); static QStringList extractDir(QIODevice *ioDevice, QString dir = QString());
/// Extract a whole archive.
/**
\param ioDevice pointer to device with compressed data.
\param fileNameCodec The codec to use for file names.
\param dir The directory to extract to, the current directory if
left empty.
\return The list of the full paths of the files extracted, empty on failure.
*/
static QStringList extractDir(QIODevice* ioDevice, QTextCodec* fileNameCodec, QString dir = QString());
/// Get the file list. /// Get the file list.
/** /**
\return The list of the files in the archive, or, more precisely, the \return The list of the files in the archive, or, more precisely, the

View File

@ -1,19 +1,39 @@
/** /**
\page faq QuaZIP FAQ \page faq %QuaZip FAQ
<!-- <!--
\ref faq-QuaZip-name "Q. QuaZIP, QuaZip, Quazip, quazip... what's with these names?"
\ref faq-non-QIODevice "Q. Is there any way to use QuaZipFile in Qt where you are supposed to use normal (non-zipped) file, but not through QIODevice API?" \ref faq-non-QIODevice "Q. Is there any way to use QuaZipFile in Qt where you are supposed to use normal (non-zipped) file, but not through QIODevice API?"
\ref faq-zip64 "Q. Can QuaZIP handle files larger than 4GB? What about zip64 standard?" \ref faq-zip64 "Q. Can QuaZip handle files larger than 4GB? What about zip64 standard?"
\ref faq-seekable "Q. Can QuaZIP write archives to a sequential QIODevice like QTcpSocket?" \ref faq-seekable "Q. Can QuaZip write archives to (or read from) a sequential QIODevice like QTcpSocket?"
\ref faq-thread-safe "Q. Is QuaZip thread safe? Reentrant?"
--> -->
\anchor faq-non-QIODevice Q. Is there any way to use QuaZipFile in Qt \anchor faq-QuaZip-name <b>Q. QuaZIP, %QuaZip, Quazip, quazip... what's with these names?</b>
In QuaZIP 0.x, there was this rule that QuaZIP is the library name, while %QuaZip is
a class in this library. Since %QuaZip 1.0, it's now obsolete, and both are %QuaZip
now to avoid confusion. The lowercase version is used in places where lowercase
is the convention, such as some file names. Quazip is not used anywhere except maybe
by mistake.
One reason using QuaZIP actually made some sense is that Doxygen (used to generate
this documentation) is very insistent on linking every mention of a class name
to its documentation, meaning every %QuaZip became QuaZip (linked to the QuaZip class docs).
This can be avoided by proper escaping, but it's pretty annoying to do it every time.
Too bad I realized it \em after I'd renamed QuaZIP to %QuaZip, so if you see
too many links to the QuaZip class in places where they don't belong, well... you now
know the reason.
\anchor faq-non-QIODevice <b>Q. Is there any way to use QuaZipFile in Qt
where you are supposed to use normal (non-zipped) file, but not where you are supposed to use normal (non-zipped) file, but not
through QIODevice API? through QIODevice API?</b>
A. Usually not. For example, if you are passing file name to some A. Usually not. For example, if you are passing file name to some
database driver (like SQLite), Qt usually just passes this name down database driver (like SQLite), Qt usually just passes this name down
@ -26,25 +46,48 @@ pointer. Then you would be able to pass QuaZipFile as well as many
other nice things such as QBuffer or QProcess. Of course, that's only other nice things such as QBuffer or QProcess. Of course, that's only
possible if you have control over the sources of the particular class. possible if you have control over the sources of the particular class.
\anchor faq-zip64 Q. Can QuaZIP handle files larger than 4GB? What \anchor faq-zip64 <b>Q. Can %QuaZip handle files larger than 4GB? What
about zip64 standard? about zip64 standard?</b>
A. Starting with version 0.6, QuaZIP uses Minizip 1.1 with zip64 A. Starting with version 0.6, %QuaZip uses Minizip 1.1 with zip64
support which should handle large files perfectly. The zip64 support support which should handle large files perfectly. The zip64 support
in Minizip looks like it's not 100% conforming to the standard, but in Minizip looks like it's not 100% conforming to the standard, but
3rd party tools seem to have no problem with the resulting archives. 3rd party tools seem to have no problem with the resulting archives.
\anchor faq-seekable Q. Can QuaZIP write archives to a sequential QIODevice like QTcpSocket? \anchor faq-seekable <b>Q. Can %QuaZip write archives to a sequential QIODevice like QTcpSocket?</b>
A. Yes, it's possible since QuaZIP v0.7. It's only possible in A. Writing is possible since %QuaZip v0.7. It's only possible in
mdCreate mode, no mdAppend support. mdCreate mode, no mdAppend support. Reading is not supported either.
\anchor faq-Minizip-update Q. Can I use another version of Minizip in QuaZIP, not the bundled one? \anchor faq-Minizip-update <b>Q. Can I use another version of Minizip in %QuaZip, not the bundled one?</b>
A. No, unfortunately not. To support reading/writing ZIP archives from/to QIODevice objects, A. No, unfortunately not. To support reading/writing ZIP archives from/to QIODevice objects,
some modifications were needed to Minizip. Now that there is a Minizip fork on GitHub, it is some modifications were needed to Minizip. Now that there is a Minizip fork on GitHub, it is
theoretically possible to backport these modifications into Minizip in a backward-compatible theoretically possible to backport these modifications into Minizip in a backward-compatible
manner to ensure seamless integration with QuaZIP, but it hasn't been done yet, and there manner to ensure seamless integration with %QuaZip, but it hasn't been done yet, and there
are no short-term plans, only a long-term goal. are no short-term plans, only a long-term goal.
\anchor faq-thread-safe <b>Q. Is %QuaZip thread safe? Reentrant?</b>
A. This is actually two questions: is Minizip thread safe or reentrant, and is %QuaZip thread safe or reentrant?
The answer is that Minizip and %QuaZip are mostly just regular I/O libraries using some data structures to
store the current I/O state. This means that most of the library is reentrant, but not thread-safe,
as is the usual case with most regular libraries. That is, using different unrelated instances of the same class
is mostly safe. “Unrelated” means that QuaZip / QuaZipFile pairs should be treated as single objects
as they are tightly coupled together (and should have been a single class in the first place).
Since it's an I/O library, to achieve reentrancy it is required to avoid OS-level conflicts. This
means that concurrent writing to the same ZIP file is impossible, no matter how careful you are
with class instances. Concurrent reading using different instances is possible.
An attentive reader would probably notice by this point all these “mostly safe”, “mostly regular libraries”.
This is, of course, about static (global) variables. %QuaZip has just a few, and they are only available
through obviously named static setters, like QuaZip::setDefaultOsCode() and QuaZip::setDefaultFileNameCodec().
If you need to use these, be sure to call them before starting any other threads.
As far as Minizip goes, it is mostly safe I/O library, but the crypting part contains some code
that is definitely not thread safe, namely srand() and rand() (not even rand_r()) calls.
This code is used for encryption only, so decryption is safe.
*/ */

View File

@ -1,5 +1,5 @@
/** /**
\mainpage QuaZIP - Qt/C++ wrapper for Minizip \mainpage %QuaZip - %Qt/C++ wrapper for Minizip
\section overview Overview \section overview Overview
@ -7,7 +7,7 @@
Gilles Vollant's ZIP/UNZIP package</a> is a simple C library Gilles Vollant's ZIP/UNZIP package</a> is a simple C library
for creating, appending and reading ZIP archives. for creating, appending and reading ZIP archives.
<a href="http://qt.io/">Qt</a> is a very powerful cross-platform C++ <a href="http://qt.io/">%Qt</a> is a very powerful cross-platform C++
library with a lot of useful modules and classes. With %Qt, you can library with a lot of useful modules and classes. With %Qt, you can
create rich GUIs, perform networking activities, accessing databases create rich GUIs, perform networking activities, accessing databases
and much much more. If Java is “write once, run everywhere”, %Qt and much much more. If Java is “write once, run everywhere”, %Qt
@ -17,20 +17,20 @@ One thing %Qt can't do out-of-the-box is write and read ZIP archives.
Of course, you can do it with Minizip, but Minizip has its own Of course, you can do it with Minizip, but Minizip has its own
interface which isn't exactly compatible with %Qt. Namely, in %Qt interface which isn't exactly compatible with %Qt. Namely, in %Qt
there is an abstract class called QIODevice, which there is an abstract class called QIODevice, which
is Qt-speak for “input/output stream”. There are a lot of classes is %Qt-speak for “input/output stream”. There are a lot of classes
that accept QIODevice to write some useful things to it—you could that accept QIODevice to write some useful things to it—you could
serialize XML to a QIODevice, for example. Therefore, wouldn't it serialize XML to a QIODevice, for example. Therefore, wouldn't it
be useful if you could open a QIODevice that would write directly be useful if you could open a QIODevice that would write directly
to a file in a ZIP archive? Or read from one? That's exactly where to a file in a ZIP archive? Or read from one? That's exactly where
QuaZIP comes into the picture. %QuaZip comes into the picture.
Technically speaking, QuaZIP is a simple C++ wrapper around Minizip. Technically speaking, %QuaZip is a simple C++ wrapper around Minizip.
Or you could call it an implementation of the Adapter pattern. With Or you could call it an implementation of the Adapter pattern. With
QuaZIP, both ZIP files and files inside ZIP archives can be accessed %QuaZip, both ZIP files and files inside ZIP archives can be accessed
with QIODevice API. You can even write ZIP files to a sequential devices with QIODevice API. You can even write ZIP files to a sequential devices
like TCP sockets, although some limitations apply in this case. like TCP sockets, although some limitations apply in this case.
\section download Download QuaZIP \section download Download QuaZip
The latest downloads are available from the The latest downloads are available from the
<a href="https://github.com/stachenov/quazip/releases">GitHub page</a>. <a href="https://github.com/stachenov/quazip/releases">GitHub page</a>.
@ -42,121 +42,127 @@ installed, you can still read offline docs in the “quazip/doc”
subdir and in the header files. Don't confuse those dirs: subdir and in the header files. Don't confuse those dirs:
- “doc” in the project's root is where Doxygen \em output is. - “doc” in the project's root is where Doxygen \em output is.
- “quazip/doc” is where Doxygen \em input is, along with the header - “quazip/doc” is where Doxygen \em input is, the part of it that
files. doesn't belong to any particular header files.
Older downloads are available from Older downloads are available from
<a href="http://sourceforge.net/projects/quazip/">QuaZIP project's page at SourceForge.net</a>. <a href="http://sourceforge.net/projects/quazip/">%QuaZip project's page at SourceForge.net</a>.
\section platforms Platforms supported \section platforms Platforms supported
QuaZIP is regularly tested on the following platforms: %QuaZip 1.1 was tested on:
- linux-g++ (Ubuntu 16.04 LTS, %Qt 5.5.1) - %Qt 5.15.0 MinGW 8.1 x32
- linux-g++ (CentOS 6.9, %Qt 4.6.2) - %Qt 5.12.9 MinGW 7.3 x32
- win32-msvc (MS VS/VC 2013 64-bit, %Qt 5.9.2) - %Qt 5.9.7 CentOS 7 x64
- %Qt 4.8.7 CentOS 7 x64
- %Qt 5.11.0 Astra Linux CE 1.6 x64
It should work fine on any platform supported by %Qt 4.6.2 or later. It should work fine on any platform supported by %Qt 4.8.7 or later.
In theory, older versions might work as well, but aren't guaranteed In theory, even versions as old as %Qt 4.6.2 might work as well, but
to. aren't guaranteed to.
\section whats-new What is new in this version of QuaZIP? Preliminary %Qt 6 support is available as well, but not tested at all.
\section whats-new What is new in this version of QuaZip?
See the NEWS.txt file supplied with the distribution. See the NEWS.txt file supplied with the distribution.
\section Dependencies \section Dependencies
Just <a href="http://www.zlib.org/">zlib</a> and %Qt 4/5. Sometimes Just <a href="http://www.zlib.org/">zlib</a> and %Qt 4/5/6. Sometimes
you can get away with using zlib library bundled into %Qt, but you can get away with using zlib library bundled into %Qt, but
usually you need at least its headers. usually you need at least its headers.
CMake-wise, you need \c ZLIB::ZLIB and one of the following:
\li \c Qt5::Core
\li \c Qt6::Core and \c Qt6::Core5Compat
\li \c Qt4::QtCore
To build and run tests, the appropriate Test and Network submodules are needed as well.
Make sure that you have %Qt installed with all required headers and
utilities (that is, including the 'dev' or 'devel' package on some Linux distros).
\section building Building, testing and installing \section building Building, testing and installing
%QuaZip uses CMake since 1.0. If you used qmake to build it,
you'll have to switch to CMake now, and it's a good thing because
two build systems made everything confusing and inconsistent. CMake
may be confusing, badly designed and lack good tutorials, but
it's \em the build system at the time of the writing. Some Linux
distros are shipped with incredibly outdated CMake versions,
but the good news is, there are official self-contained binary
distributions, so just grab the newest version, unpack it
somewhere, set up PATH (or symlinks) and you're all set.
CMake minimum version 3.15 is required to build %QuaZip 1.0.
\note Instructions given in this section assume that you are \note Instructions given in this section assume that you are
using some UNIX dialect, but the build process should be very similar using some UNIX dialect, but the build process should be very similar
on win32-g++ platform too. On other platforms it's essentially the on MinGW x32 too. On other platforms it's essentially the
same process, maybe with some qmake adjustments not specific to same process, maybe with some CMake adjustments not specific to
QuaZIP itself. %QuaZip itself.
To build the library, run: To build the library, run:
\verbatim \verbatim
$ cd /wherever/quazip/source/is/quazip-x.y.z/quazip $ cd /wherever/quazip/source/is/quazip-x.y.z
$ qmake <qmake args> [PREFIX=where-to-install] $ cmake -S . -B wherever/you/want/your/build/to/be -D QUAZIP_QT_MAJOR_VERSION=4, 5 or 6
$ make $ cmake --build wherever/you/want/your/build/to/be
\endverbatim \endverbatim
Make sure that you have %Qt 4/5 installed with all required headers and \c QUAZIP_QT_MAJOR_VERSION is just one number, and it defaults to 5, so if building with %Qt 5, it is optional.
utilities (that is, including the 'dev' or 'devel' package on Linux)
and that you run qmake utility of the %Qt 4/5, not some other version
you may have already installed (you may need to type full path to
qmake like /usr/local/qt4/bin/qmake).
To reconfigure (with another PREFIX, for example), just run On Windows, it may be required to use <tt>-G "MinGW Makefiles"</tt> or something like that to convince
CMake that you really want to use, say, MinGW and not Visual Studio, for example.
To install, run
\verbatim \verbatim
qmake distclean $ cmake --build wherever/you/want/your/build/to/be --target install -D CMAKE_INSTALL_PREFIX=/wherever/you/want/to/install
\endverbatim
and then qmake with the appropriate arguments again.
Usually, it is needed to specify additional include path or libraries
in qmake args (see qmake reference in the %Qt documentation). For
example:
\verbatim
$ qmake LIBS+=-L/usr/local/zlib/lib INCLUDEPATH+=/usr/local/zlib/include
\endverbatim
(note abscence of “-I” before the include path and the presence of “-L”
before the lib path)
Also note that you may or may not need to define ZLIB_WINAPI (qmake
DEFINES+=ZLIB_WINAPI) when linking to zlib on Windows, depending on
how zlib was built (generally, if using zlibwapi.dll, this define is
needed).
To install compiled library:
\verbatim
$ make install
\endverbatim \endverbatim
By default, QuaZIP compiles as a DLL/SO, but you have other %QuaZip installs as CMake package QuaZip-QtX, where X is the major
options: version of %Qt. For example, QuaZip-Qt5. Different major versions of
- Just copy appropriate source files to your project and use them, %QuaZip have different binary names (libquazip1-qt5, for example),
but you need to define QUAZIP_STATIC before including any QuaZIP which allows to install them in parallel.
headers (best done as a compiler option). This will save you from
possible side effects of importing/exporting QuaZIP symbols. To reconfigure (for another %Qt version or release/debug, or anything else), just nuke the whole build directory
- Compile it as a static library using CONFIG += staticlib qmake and repeat everything.
option. QUAZIP_STATIC is defined automatically by qmake in this case.
By default, %QuaZip compiles as a DLL/SO, but respects the standard BUILD_SHARED_LIBS CMake option, adjusting
its imports/exports accordingly.
Binary compatibility is guaranteed between minor releases starting Binary compatibility is guaranteed between minor releases starting
with version 0.5, thanks to the Pimpl idiom. That is, the next binary with version 1.0, thanks to the Pimpl idiom. That is, the next binary
incompatible version will be 1.x in the worst case. incompatible version will be 2.x in the worst case.
\section test Testing \section test Testing
To check if QuaZIP's basic features work OK on your platform, you may To test, run:
wish to compile the test suite provided in test directory:
\verbatim \verbatim
$ cd /wherever/quazip/source/is/quazip-x.y.z/qztest $ cmake --build wherever/you/want/your/build/to/be --target check
$ qmake
$ make
$ ./qztest
\endverbatim \endverbatim
Note that the test suite looks for the quazip library in the “quazip” Note that tests are not included in the \c all target, so if you want
folder of the project (“../quazip”), but you may wish to use LIBS to build and test with %Qt Creator, add another build step and select
for some systems (Windows often puts the library in the separate the \c qztest target. Then set up run configuration to launch
“debug” or “release” directory). If you wish to use the quazip the qztest binary.
version that's already installed, provide the appropriate path.
On Windows, you need to set its working directory
to the \c quazip subdirectory of the build tree. The default
is the \c qztest directory, which lead to mysterious crashes
because qztest can't find the %QuaZip DLL there.
On some systems you may need to set PATH, LD_LIBRARY_PATH or On some systems you may need to set PATH, LD_LIBRARY_PATH or
SHLIB_PATH to get “qztest” to actually run and to use the right SHLIB_PATH to get “qztest” to actually run and to use the version of %QuaZip you've just built,
version. especially if you already have some version of %QuaZip installed somewhere.
If everything went fine, the test suite should report a lot of PASS If everything went fine, the test suite should report a lot of PASS
messages. If something goes wrong, it will provide details and a messages and the “All tests executed successfully” message.
If something goes wrong, it will provide details and a
warning that some tests failed. warning that some tests failed.
\section using Using \section using Using
See \ref usage “usage page”. See the \ref usage "Usage Page".
\section contacts Authors and contacts \section contacts Authors and contacts
@ -164,17 +170,17 @@ This wrapper has been written by Sergei Tachenov.
This is my first open source project, and it's pretty old, but it This is my first open source project, and it's pretty old, but it
works and many people are happily using it, including myself. works and many people are happily using it, including myself.
If you have anything to say to me about QuaZIP library, feel free to If you have anything to say to me about %QuaZip library, feel free to
do so (read the \ref faq first, though). I can not promise, do so (read the \ref faq first, though). I can not promise,
though, that I fix all the bugs you report in, add any features you though, that I fix all the bugs you report in, add any features you
want, or respond to your critics, or respond to your feedback at all. want, or respond to your critics, or respond to your feedback at all.
I may be busy, I may be tired of working on QuaZIP, I may be even I may be busy, I may be tired of working on %QuaZip, I may be even
dead already (you never know...). dead already (you never know...).
To report bugs or to post ideas about what should be done, use To report bugs or to post ideas about what should be done, use
<a href="https://github.com/stachenov/quazip">GitHub</a>. It's an <a href="https://github.com/stachenov/quazip">GitHub</a>. It's an
awesome site, where you can report bugs or register yourself an awesome site, where you can report bugs or register yourself an
account, fork QuaZIP (don't hesitate to do so), create a new branch, account, fork %QuaZip (don't hesitate to do so), create a new branch,
make some changes and issue a make some changes and issue a
<a href="https://help.github.com/articles/about-pull-requests/">pull <a href="https://help.github.com/articles/about-pull-requests/">pull
request</a>, which is GitHub's way of offering patches. See CONTRIBUTING.md request</a>, which is GitHub's way of offering patches. See CONTRIBUTING.md
@ -191,5 +197,5 @@ Old bugs may still be available at
<a href="https://sourceforge.net/projects/quazip/">SourceForge</a> <a href="https://sourceforge.net/projects/quazip/">SourceForge</a>
for reference. for reference.
Copyright (C) 2005-2018 Sergei Tachenov and contributors Copyright (C) 2005-2020 Sergei Tachenov and contributors
*/ */

View File

@ -1,33 +1,104 @@
/** \page usage Usage /** \page usage Usage
This page provides general information on QuaZIP usage. See classes This page provides general information on %QuaZip usage. See classes
QuaZip and QuaZipFile for the detailed documentation on what can QuaZip and QuaZipFile for the detailed documentation on what can
QuaZIP do and what it can not. Also, reading comments in the zip.h and %QuaZip do and what it can't do. Also, reading comments in the zip.h and
unzip.h files (taken from the original ZIP/UNZIP package) is always a unzip.h files (taken from the original ZIP/UNZIP package) is always a
good idea too. After all, QuaZIP is just a wrapper with a few good idea too. After all, %QuaZip is just a wrapper with a few
convenience extensions and reimplementations. convenience extensions and reimplementations.
QuaZip is a class representing ZIP archive, QuaZipFile represents a \section CMake
file inside archive and subclasses QIODevice as well. One limitation
is that there can be only one instance of QuaZipFile per QuaZip
instance, which kind of makes it confusing why there are two classes
instead of one. This is actually no more than an API design mistake
kept for backwards compatibility.
The JlCompress class provides some high-level convenience static To get started, as it is usual with modern CMake, you just need
methods which may be very useful if all you need is just to “unzip something like this in your CMakeLists.txt:
a file” or something like that.
\verbatim
find_package(QuaZip-Qt5)
target_link_libraries(whatever-your-target-is QuaZip::QuaZip)
\endverbatim
Or, if you prefer to add %QuaZip sources directly to your project
(e. g. as a Git submodule):
\verbatim
add_subdirectory(quazip)
target_link_libraries(whatever-your-target-is QuaZip::QuaZip)
\endverbatim
In the latter case, you may want to set BUILD_SHARED_LIBS to NO
to link statically.
In all cases, if %QuaZip is linked statically, it automatically
defines QUAZIP_STATIC whenever your link to it, which disables
dllimports that would lead to confusing errors (at least on Windows)
otherwise.
If, for some weird reason, you decide to add %QuaZip sources to your
project directly (skipping CMake), or link it statically and then
link it to your project without CMake, you may need to define
QUAZIP_STATIC manually to avoid problems with dllimports.
%QuaZip uses SameMajorVersion compatibility mode, so you can have,
say, %QuaZip 1.x and %QuaZip 2.x (in some future, when there is such a thing)
installed in parallel, and then pass the required version to
\c find_package. As long as the major version matches, it will be found.
\section Flatpak
%Quazip can be used in Flatpak YAML manifests as such:
\verbatim
modules:
- name: quazip
buildsystem: cmake-ninja
builddir: true
config-opts:
- -DCMAKE_BUILD_TYPE=MinSizeRel
sources:
- type: archive
url: https://github.com/stachenov/quazip/archive/v1.1.tar.gz
sha256: 54edce9c11371762bd4f0003c2937b5d8806a2752dd9c0fd9085e90792612ad0
- type: shell
commands:
- sed -i 's|${CMAKE_ROOT}/Modules|share/cmake|' CMakeLists.txt
\endverbatim
or on older JSON manifests:
\verbatim
"modules": [
{
"name": "quazip",
"buildsystem": "cmake-ninja",
"builddir": true,
"config-opts": [
"-DCMAKE_BUILD_TYPE=MinSizeRel"
],
"sources": [
{
"type": "archive",
"url": "https://github.com/stachenov/quazip/archive/v1.1.tar.gz",
"sha256": "54edce9c11371762bd4f0003c2937b5d8806a2752dd9c0fd9085e90792612ad0"
},
{
"type": "shell",
"commands": [
"sed -i 's|${CMAKE_ROOT}/Modules|share/cmake|' CMakeLists.txt"
]
}
]
}
]
\endverbatim
\section terminology Terminology \section terminology Terminology
“QuaZIP” means the whole library, while “QuaZip” (note the %QuaZip” means the whole library or the \c QuaZip class, depending
lower case) is just one class in it. on the context.
“ZIP/UNZIP API” or “Minizip” means the original API of the Gilles “ZIP/UNZIP API” or “Minizip” means the original API of the Gilles
Vollant's ZIP/UNZIP package. It was slightly modified to better Vollant's ZIP/UNZIP package. It was slightly modified to better
integrate with Qt. These modifications are not source or binary integrate with Qt. These modifications are not source or binary
compatible with the official Minizip release, which means you can't compatible with the official Minizip release, which means you can't
just drop the newer Minizip version into QuaZIP sources and make it just drop the newer Minizip version into %QuaZip sources and make it
work. work.
“ZIP”, “ZIP archive” or “ZIP file” means any ZIP archive. Typically “ZIP”, “ZIP archive” or “ZIP file” means any ZIP archive. Typically
@ -38,6 +109,19 @@ QTcpSocket).
“A file inside archive”, “a file inside ZIP” or something like that “A file inside archive”, “a file inside ZIP” or something like that
means file either being read or written from/to some ZIP archive. means file either being read or written from/to some ZIP archive.
\section API
The main classes are QuaZip and QuaZipFile, and there's JlCompress
that contains a lot of high-level utility methods (think of it
as the Facade Pattern for the most common uses).
QuaZip is a class representing ZIP archive, QuaZipFile represents a
file inside archive and subclasses QIODevice as well. One limitation
is that there can be only one instance of QuaZipFile per QuaZip
instance, which kind of makes it confusing why there are two classes
instead of one. This is actually no more than an API design mistake
kept for backwards compatibility.
\section general-usage General usage \section general-usage General usage
In general, the process looks like this: In general, the process looks like this:
@ -47,7 +131,7 @@ In general, the process looks like this:
-# Perform reading or writing. -# Perform reading or writing.
-# Close the QuaZipFile instance. -# Close the QuaZipFile instance.
-# Repeat steps 24 for other files if needed. -# Repeat steps 24 for other files if needed.
-# Close the QuaZIP instance. -# Close the QuaZip instance.
See the “qztest” subdirectory for examples. TestQuaZipFile::zipUnzip() See the “qztest” subdirectory for examples. TestQuaZipFile::zipUnzip()
is a good place to start. is a good place to start.
@ -57,16 +141,16 @@ is a good place to start.
Almost any call to ZIP/UNZIP API return some error code. Most of the Almost any call to ZIP/UNZIP API return some error code. Most of the
original API's error checking could be done in this wrapper as well, original API's error checking could be done in this wrapper as well,
but it would cause unnecessary code bloating without any benefit. So, but it would cause unnecessary code bloating without any benefit. So,
QuaZIP only checks for situations that ZIP/UNZIP API can not check %QuaZip only checks for situations that ZIP/UNZIP API can not check
for. For example, ZIP/UNZIP API has no “ZIP open mode” concept for. For example, ZIP/UNZIP API has no “ZIP open mode” concept
because read and write modes are completely separated. On the other because read and write modes are completely separated. On the other
hand, to avoid creating classes like “QuaZipReader”, “QuaZipWriter” hand, to avoid creating classes like “QuaZipReader”, “QuaZipWriter”
or something like that, QuaZIP introduces “ZIP open mode” concept or something like that, %QuaZip introduces “ZIP open mode” concept
instead, thus making it possible to use one class (QuaZip) for both instead, thus making it possible to use one class (QuaZip) for both
reading and writing. But this leads to additional open mode checks reading and writing. But this leads to additional open mode checks
which are not done in ZIP/UNZIP package. which are not done in ZIP/UNZIP package.
Therefore, error checking is two-level (QuaZIP's level and ZIP/UNZIP Therefore, error checking is two-level (%QuaZip's level and ZIP/UNZIP
API level), which sometimes can be confusing, so here are some API level), which sometimes can be confusing, so here are some
advices on how the error checking should be properly done: advices on how the error checking should be properly done:
@ -92,5 +176,7 @@ advices on how the error checking should be properly done:
on when it should not be called. on when it should not be called.
I know that this is somewhat messy, but I could not find a better way I know that this is somewhat messy, but I could not find a better way
to do all the error handling. to do all the error handling back in 2005, and it's too late to change
anything now. A major API redesign is needed, but not planned in any
foreseeable future yet.
*/ */

View File

@ -15,13 +15,8 @@
#include "ioapi.h" #include "ioapi.h"
#include "quazip_global.h" #include "quazip_global.h"
#include <QIODevice> #include <QtCore/QIODevice>
#if (QT_VERSION >= 0x050100) #include "quazip_qt_compat.h"
#define QUAZIP_QSAVEFILE_BUG_WORKAROUND
#endif
#ifdef QUAZIP_QSAVEFILE_BUG_WORKAROUND
#include <QSaveFile>
#endif
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
@ -39,7 +34,7 @@
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode) voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode)
{ {
if (pfilefunc->zfile_func64.zopen64_file != NULL) if (pfilefunc->zfile_func64.zopen64_file != nullptr)
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,file,mode); return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,file,mode);
else else
{ {
@ -49,7 +44,7 @@ voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mod
int call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) int call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
{ {
if (pfilefunc->zfile_func64.zseek64_file != NULL) if (pfilefunc->zfile_func64.zseek64_file != nullptr)
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
else else
{ {
@ -63,7 +58,7 @@ int call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPO
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
{ {
if (pfilefunc->zfile_func64.zseek64_file != NULL) if (pfilefunc->zfile_func64.zseek64_file != nullptr)
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
else else
{ {
@ -105,7 +100,7 @@ voidpf ZCALLBACK qiodevice_open_file_func (
&& iodevice->isSequential()) { && iodevice->isSequential()) {
// We can use sequential devices only for writing. // We can use sequential devices only for writing.
delete d; delete d;
return NULL; return nullptr;
} else { } else {
if ((desiredMode & QIODevice::WriteOnly) != 0) { if ((desiredMode & QIODevice::WriteOnly) != 0) {
// open for writing, need to seek existing device // open for writing, need to seek existing device
@ -119,7 +114,7 @@ voidpf ZCALLBACK qiodevice_open_file_func (
return iodevice; return iodevice;
} else { } else {
delete d; delete d;
return NULL; return nullptr;
} }
} }
iodevice->open(desiredMode); iodevice->open(desiredMode);
@ -128,13 +123,13 @@ voidpf ZCALLBACK qiodevice_open_file_func (
// We can use sequential devices only for writing. // We can use sequential devices only for writing.
iodevice->close(); iodevice->close();
delete d; delete d;
return NULL; return nullptr;
} else { } else {
return iodevice; return iodevice;
} }
} else { } else {
delete d; delete d;
return NULL; return nullptr;
} }
} }
@ -287,17 +282,7 @@ int ZCALLBACK qiodevice_close_file_func (
QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque); QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
delete d; delete d;
QIODevice *device = reinterpret_cast<QIODevice*>(stream); QIODevice *device = reinterpret_cast<QIODevice*>(stream);
#ifdef QUAZIP_QSAVEFILE_BUG_WORKAROUND return quazip_close(device) ? 0 : -1;
// QSaveFile terribly breaks the is-a idiom:
// it IS a QIODevice, but it is NOT compatible with it: close() is private
QSaveFile *file = qobject_cast<QSaveFile*>(device);
if (file != NULL) {
// We have to call the ugly commit() instead:
return file->commit() ? 0 : -1;
}
#endif
device->close();
return 0;
} }
int ZCALLBACK qiodevice_fakeclose_file_func ( int ZCALLBACK qiodevice_fakeclose_file_func (
@ -347,17 +332,17 @@ void fill_qiodevice64_filefunc (
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
{ {
p_filefunc64_32->zfile_func64.zopen64_file = NULL; p_filefunc64_32->zfile_func64.zopen64_file = nullptr;
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
p_filefunc64_32->zfile_func64.ztell64_file = NULL; p_filefunc64_32->zfile_func64.ztell64_file = nullptr;
p_filefunc64_32->zfile_func64.zseek64_file = NULL; p_filefunc64_32->zfile_func64.zseek64_file = nullptr;
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
p_filefunc64_32->zfile_func64.zfakeclose_file = NULL; p_filefunc64_32->zfile_func64.zfakeclose_file = nullptr;
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
} }

View File

@ -2,20 +2,20 @@
Copyright (C) 2010 Adam Walczak Copyright (C) 2010 Adam Walczak
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.

View File

@ -5,20 +5,20 @@
Copyright (C) 2010 Adam Walczak Copyright (C) 2010 Adam Walczak
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -26,7 +26,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QByteArray> #include <QtCore/QByteArray>
#include "quachecksum32.h" #include "quachecksum32.h"

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QByteArray> #include <QtCore/QByteArray>
#include "quazip_global.h" #include "quazip_global.h"
/// Checksum interface. /// Checksum interface.
@ -53,6 +53,7 @@ class QUAZIP_EXPORT QuaChecksum32
{ {
public: public:
virtual ~QuaChecksum32();
///Calculates the checksum for data. ///Calculates the checksum for data.
/** \a data source data /** \a data source data
* \return data checksum * \return data checksum

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -22,7 +22,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QFile> #include <QtCore/QFile>
#include "quagzipfile.h" #include "quagzipfile.h"
@ -31,9 +31,9 @@ class QuaGzipFilePrivate {
friend class QuaGzipFile; friend class QuaGzipFile;
QString fileName; QString fileName;
gzFile gzd; gzFile gzd;
inline QuaGzipFilePrivate(): gzd(NULL) {} inline QuaGzipFilePrivate(): gzd(nullptr) {}
inline QuaGzipFilePrivate(const QString &fileName): inline QuaGzipFilePrivate(const QString &fileName):
fileName(fileName), gzd(NULL) {} fileName(fileName), gzd(nullptr) {}
template<typename FileId> bool open(FileId id, template<typename FileId> bool open(FileId id,
QIODevice::OpenMode mode, QString &error); QIODevice::OpenMode mode, QString &error);
gzFile open(int fd, const char *modeString); gzFile open(int fd, const char *modeString);
@ -76,7 +76,7 @@ bool QuaGzipFilePrivate::open(FileId id, QIODevice::OpenMode mode,
return false; return false;
} }
gzd = open(id, modeString); gzd = open(id, modeString);
if (gzd == NULL) { if (gzd == nullptr) {
error = QuaGzipFile::tr("Could not gzopen() file"); error = QuaGzipFile::tr("Could not gzopen() file");
return false; return false;
} }

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QIODevice> #include <QtCore/QIODevice>
#include "quazip_global.h" #include "quazip_global.h"
#include <zlib.h> #include <zlib.h>
@ -55,7 +55,7 @@ public:
\param fileName The name of the GZIP file. \param fileName The name of the GZIP file.
\param parent The parent object, as per QObject logic. \param parent The parent object, as per QObject logic.
*/ */
QuaGzipFile(const QString &fileName, QObject *parent = NULL); QuaGzipFile(const QString &fileName, QObject *parent = nullptr);
/// Destructor. /// Destructor.
virtual ~QuaGzipFile(); virtual ~QuaGzipFile();
/// Sets the name of the GZIP file to be opened. /// Sets the name of the GZIP file to be opened.

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -51,21 +51,21 @@ class QuaZIODevicePrivate {
QuaZIODevicePrivate::QuaZIODevicePrivate(QIODevice *io, QuaZIODevice *q): QuaZIODevicePrivate::QuaZIODevicePrivate(QIODevice *io, QuaZIODevice *q):
io(io), io(io),
q(q), q(q),
inBuf(NULL), inBuf(nullptr),
inBufPos(0), inBufPos(0),
inBufSize(0), inBufSize(0),
outBuf(NULL), outBuf(nullptr),
outBufPos(0), outBufPos(0),
outBufSize(0), outBufSize(0),
zBufError(false), zBufError(false),
atEnd(false) atEnd(false)
{ {
zins.zalloc = (alloc_func) NULL; zins.zalloc = (alloc_func) nullptr;
zins.zfree = (free_func) NULL; zins.zfree = (free_func) nullptr;
zins.opaque = NULL; zins.opaque = nullptr;
zouts.zalloc = (alloc_func) NULL; zouts.zalloc = (alloc_func) nullptr;
zouts.zfree = (free_func) NULL; zouts.zfree = (free_func) nullptr;
zouts.opaque = NULL; zouts.opaque = nullptr;
inBuf = new char[QUAZIO_INBUFSIZE]; inBuf = new char[QUAZIO_INBUFSIZE];
outBuf = new char[QUAZIO_OUTBUFSIZE]; outBuf = new char[QUAZIO_OUTBUFSIZE];
#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT #ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT
@ -86,9 +86,9 @@ QuaZIODevicePrivate::~QuaZIODevicePrivate()
#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT #ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT
indebug.close(); indebug.close();
#endif #endif
if (inBuf != NULL) if (inBuf != nullptr)
delete[] inBuf; delete[] inBuf;
if (outBuf != NULL) if (outBuf != nullptr)
delete[] outBuf; delete[] outBuf;
} }
@ -155,11 +155,11 @@ int QuaZIODevicePrivate::doFlush(QString &error)
// #define QUAZIP_ZIODEVICE_DEBUG_OUTPUT // #define QUAZIP_ZIODEVICE_DEBUG_OUTPUT
// #define QUAZIP_ZIODEVICE_DEBUG_INPUT // #define QUAZIP_ZIODEVICE_DEBUG_INPUT
#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT #ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT
#include <QFile> #include <QtCore/QFile>
static QFile debug; static QFile debug;
#endif #endif
#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT #ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT
#include <QFile> #include <QtCore/QFile>
static QFile indebug; static QFile indebug;
#endif #endif

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QIODevice> #include <QtCore/QIODevice>
#include "quazip_global.h" #include "quazip_global.h"
#include <zlib.h> #include <zlib.h>
@ -47,7 +47,7 @@ public:
\param io The QIODevice to read/write. \param io The QIODevice to read/write.
\param parent The parent object, as per QObject logic. \param parent The parent object, as per QObject logic.
*/ */
QuaZIODevice(QIODevice *io, QObject *parent = NULL); QuaZIODevice(QIODevice *io, QObject *parent = nullptr);
/// Destructor. /// Destructor.
~QuaZIODevice(); ~QuaZIODevice();
/// Flushes data waiting to be written. /// Flushes data waiting to be written.
@ -66,7 +66,7 @@ public:
sock->flush(); // this actually sends data to network sock->flush(); // this actually sends data to network
\endcode \endcode
This may change in the future versions of QuaZIP by implementing an This may change in the future versions of %QuaZip by implementing an
ugly hack: trying to cast the QIODevice using qobject_cast to known ugly hack: trying to cast the QIODevice using qobject_cast to known
flush()-supporting subclasses, and calling flush if the resulting flush()-supporting subclasses, and calling flush if the resulting
pointer is not zero. pointer is not zero.

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -22,9 +22,9 @@ Original ZIP package is copyrighted by Gilles Vollant, see
quazip/(un)zip.h files for details, basically it's zlib license. quazip/(un)zip.h files for details, basically it's zlib license.
**/ **/
#include <QFile> #include <QtCore/QFile>
#include <QFlags> #include <QtCore/QFlags>
#include <QHash> #include <QtCore/QHash>
#include "quazip.h" #include "quazip.h"
@ -78,7 +78,7 @@ class QuaZipPrivate {
uint osCode; uint osCode;
inline QTextCodec *getDefaultFileNameCodec() inline QTextCodec *getDefaultFileNameCodec()
{ {
if (defaultFileNameCodec == NULL) { if (defaultFileNameCodec == nullptr) {
return QTextCodec::codecForLocale(); return QTextCodec::codecForLocale();
} else { } else {
return defaultFileNameCodec; return defaultFileNameCodec;
@ -89,7 +89,7 @@ class QuaZipPrivate {
q(q), q(q),
fileNameCodec(getDefaultFileNameCodec()), fileNameCodec(getDefaultFileNameCodec()),
commentCodec(QTextCodec::codecForLocale()), commentCodec(QTextCodec::codecForLocale()),
ioDevice(NULL), ioDevice(nullptr),
mode(QuaZip::mdNotOpen), mode(QuaZip::mdNotOpen),
hasCurrentFile_f(false), hasCurrentFile_f(false),
zipError(UNZ_OK), zipError(UNZ_OK),
@ -99,8 +99,8 @@ class QuaZipPrivate {
utf8(false), utf8(false),
osCode(defaultOsCode) osCode(defaultOsCode)
{ {
unzFile_f = NULL; unzFile_f = nullptr;
zipFile_f = NULL; zipFile_f = nullptr;
lastMappedDirectoryEntry.num_of_file = 0; lastMappedDirectoryEntry.num_of_file = 0;
lastMappedDirectoryEntry.pos_in_zip_directory = 0; lastMappedDirectoryEntry.pos_in_zip_directory = 0;
} }
@ -110,7 +110,7 @@ class QuaZipPrivate {
fileNameCodec(getDefaultFileNameCodec()), fileNameCodec(getDefaultFileNameCodec()),
commentCodec(QTextCodec::codecForLocale()), commentCodec(QTextCodec::codecForLocale()),
zipName(zipName), zipName(zipName),
ioDevice(NULL), ioDevice(nullptr),
mode(QuaZip::mdNotOpen), mode(QuaZip::mdNotOpen),
hasCurrentFile_f(false), hasCurrentFile_f(false),
zipError(UNZ_OK), zipError(UNZ_OK),
@ -120,8 +120,8 @@ class QuaZipPrivate {
utf8(false), utf8(false),
osCode(defaultOsCode) osCode(defaultOsCode)
{ {
unzFile_f = NULL; unzFile_f = nullptr;
zipFile_f = NULL; zipFile_f = nullptr;
lastMappedDirectoryEntry.num_of_file = 0; lastMappedDirectoryEntry.num_of_file = 0;
lastMappedDirectoryEntry.pos_in_zip_directory = 0; lastMappedDirectoryEntry.pos_in_zip_directory = 0;
} }
@ -140,8 +140,8 @@ class QuaZipPrivate {
utf8(false), utf8(false),
osCode(defaultOsCode) osCode(defaultOsCode)
{ {
unzFile_f = NULL; unzFile_f = nullptr;
zipFile_f = NULL; zipFile_f = nullptr;
lastMappedDirectoryEntry.num_of_file = 0; lastMappedDirectoryEntry.num_of_file = 0;
lastMappedDirectoryEntry.pos_in_zip_directory = 0; lastMappedDirectoryEntry.pos_in_zip_directory = 0;
} }
@ -160,7 +160,7 @@ class QuaZipPrivate {
static uint defaultOsCode; static uint defaultOsCode;
}; };
QTextCodec *QuaZipPrivate::defaultFileNameCodec = NULL; QTextCodec *QuaZipPrivate::defaultFileNameCodec = nullptr;
uint QuaZipPrivate::defaultOsCode = QUAZIP_OS_UNIX; uint QuaZipPrivate::defaultOsCode = QUAZIP_OS_UNIX;
void QuaZipPrivate::clearDirectoryMap() void QuaZipPrivate::clearDirectoryMap()
@ -241,7 +241,7 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
return false; return false;
} }
QIODevice *ioDevice = p->ioDevice; QIODevice *ioDevice = p->ioDevice;
if (ioDevice == NULL) { if (ioDevice == nullptr) {
if (p->zipName.isEmpty()) { if (p->zipName.isEmpty()) {
qWarning("QuaZip::open(): set either ZIP file name or IO device first"); qWarning("QuaZip::open(): set either ZIP file name or IO device first");
return false; return false;
@ -252,14 +252,14 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
unsigned flags = 0; unsigned flags = 0;
switch(mode) { switch(mode) {
case mdUnzip: case mdUnzip:
if (ioApi == NULL) { if (ioApi == nullptr) {
if (p->autoClose) if (p->autoClose)
flags |= UNZ_AUTO_CLOSE; flags |= UNZ_AUTO_CLOSE;
p->unzFile_f=unzOpenInternal(ioDevice, NULL, 1, flags); p->unzFile_f=unzOpenInternal(ioDevice, nullptr, 1, flags);
} else { } else {
// QuaZIP pre-zip64 compatibility mode // QuaZip pre-zip64 compatibility mode
p->unzFile_f=unzOpen2(ioDevice, ioApi); p->unzFile_f=unzOpen2(ioDevice, ioApi);
if (p->unzFile_f != NULL) { if (p->unzFile_f != nullptr) {
if (p->autoClose) { if (p->autoClose) {
unzSetFlags(p->unzFile_f, UNZ_AUTO_CLOSE); unzSetFlags(p->unzFile_f, UNZ_AUTO_CLOSE);
} else { } else {
@ -267,7 +267,7 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
} }
} }
} }
if(p->unzFile_f!=NULL) { if(p->unzFile_f!=nullptr) {
if (ioDevice->isSequential()) { if (ioDevice->isSequential()) {
unzClose(p->unzFile_f); unzClose(p->unzFile_f);
if (!p->zipName.isEmpty()) if (!p->zipName.isEmpty())
@ -289,7 +289,7 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
case mdCreate: case mdCreate:
case mdAppend: case mdAppend:
case mdAdd: case mdAdd:
if (ioApi == NULL) { if (ioApi == nullptr) {
if (p->autoClose) if (p->autoClose)
flags |= ZIP_AUTO_CLOSE; flags |= ZIP_AUTO_CLOSE;
if (p->dataDescriptorWritingEnabled) if (p->dataDescriptorWritingEnabled)
@ -300,23 +300,23 @@ bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
mode==mdCreate?APPEND_STATUS_CREATE: mode==mdCreate?APPEND_STATUS_CREATE:
mode==mdAppend?APPEND_STATUS_CREATEAFTER: mode==mdAppend?APPEND_STATUS_CREATEAFTER:
APPEND_STATUS_ADDINZIP, APPEND_STATUS_ADDINZIP,
NULL, NULL, flags); nullptr, nullptr, flags);
} else { } else {
// QuaZIP pre-zip64 compatibility mode // QuaZip pre-zip64 compatibility mode
p->zipFile_f=zipOpen2(ioDevice, p->zipFile_f=zipOpen2(ioDevice,
mode==mdCreate?APPEND_STATUS_CREATE: mode==mdCreate?APPEND_STATUS_CREATE:
mode==mdAppend?APPEND_STATUS_CREATEAFTER: mode==mdAppend?APPEND_STATUS_CREATEAFTER:
APPEND_STATUS_ADDINZIP, APPEND_STATUS_ADDINZIP,
NULL, nullptr,
ioApi); ioApi);
if (p->zipFile_f != NULL) { if (p->zipFile_f != nullptr) {
zipSetFlags(p->zipFile_f, flags); zipSetFlags(p->zipFile_f, flags);
} }
} }
if(p->zipFile_f!=NULL) { if(p->zipFile_f!=nullptr) {
if (ioDevice->isSequential()) { if (ioDevice->isSequential()) {
if (mode != mdCreate) { if (mode != mdCreate) {
zipClose(p->zipFile_f, NULL); zipClose(p->zipFile_f, nullptr);
qWarning("QuaZip::open(): " qWarning("QuaZip::open(): "
"only mdCreate can be used with " "only mdCreate can be used with "
"sequential devices"); "sequential devices");
@ -357,7 +357,7 @@ void QuaZip::close()
case mdCreate: case mdCreate:
case mdAppend: case mdAppend:
case mdAdd: case mdAdd:
p->zipError=zipClose(p->zipFile_f, p->comment.isNull() ? NULL : isUtf8Enabled() p->zipError=zipClose(p->zipFile_f, p->comment.isNull() ? nullptr : isUtf8Enabled()
? p->comment.toUtf8().constData() ? p->comment.toUtf8().constData()
: p->commentCodec->fromUnicode(p->comment).constData()); : p->commentCodec->fromUnicode(p->comment).constData());
break; break;
@ -368,7 +368,7 @@ void QuaZip::close()
// opened by name, need to delete the internal IO device // opened by name, need to delete the internal IO device
if (!p->zipName.isEmpty()) { if (!p->zipName.isEmpty()) {
delete p->ioDevice; delete p->ioDevice;
p->ioDevice = NULL; p->ioDevice = nullptr;
} }
p->clearDirectoryMap(); p->clearDirectoryMap();
if(p->zipError==UNZ_OK) if(p->zipError==UNZ_OK)
@ -382,7 +382,7 @@ void QuaZip::setZipName(const QString& zipName)
return; return;
} }
p->zipName=zipName; p->zipName=zipName;
p->ioDevice = NULL; p->ioDevice = nullptr;
} }
void QuaZip::setIoDevice(QIODevice *ioDevice) void QuaZip::setIoDevice(QIODevice *ioDevice)
@ -442,7 +442,7 @@ bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs)
return true; return true;
} }
// Unicode-aware reimplementation of the unzLocateFile function // Unicode-aware reimplementation of the unzLocateFile function
if(p->unzFile_f==NULL) { if(p->unzFile_f==nullptr) {
p->zipError=UNZ_PARAMERROR; p->zipError=UNZ_PARAMERROR;
return false; return false;
} }
@ -517,7 +517,7 @@ bool QuaZip::goToNextFile()
bool QuaZip::getCurrentFileInfo(QuaZipFileInfo *info)const bool QuaZip::getCurrentFileInfo(QuaZipFileInfo *info)const
{ {
QuaZipFileInfo64 info64; QuaZipFileInfo64 info64;
if (info == NULL) { // Very unlikely because of the overloads if (info == nullptr) { // Very unlikely because of the overloads
return false; return false;
} }
if (getCurrentFileInfo(&info64)) { if (getCurrentFileInfo(&info64)) {
@ -540,14 +540,14 @@ bool QuaZip::getCurrentFileInfo(QuaZipFileInfo64 *info)const
QByteArray fileName; QByteArray fileName;
QByteArray extra; QByteArray extra;
QByteArray comment; QByteArray comment;
if(info==NULL) return false; if(info==nullptr) return false;
if(!isOpen()||!hasCurrentFile()) return false; if(!isOpen()||!hasCurrentFile()) return false;
if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &info_z, NULL, 0, NULL, 0, NULL, 0))!=UNZ_OK) if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &info_z, nullptr, 0, nullptr, 0, nullptr, 0))!=UNZ_OK)
return false; return false;
fileName.resize(info_z.size_filename); fileName.resize(info_z.size_filename);
extra.resize(info_z.size_file_extra); extra.resize(info_z.size_file_extra);
comment.resize(info_z.size_file_comment); comment.resize(info_z.size_file_comment);
if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, NULL, if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, nullptr,
fileName.data(), fileName.size(), fileName.data(), fileName.size(),
extra.data(), extra.size(), extra.data(), extra.size(),
comment.data(), comment.size()))!=UNZ_OK) comment.data(), comment.size()))!=UNZ_OK)
@ -585,7 +585,7 @@ QString QuaZip::getCurrentFileName()const
QByteArray fileName(MAX_FILE_NAME_LENGTH, 0); QByteArray fileName(MAX_FILE_NAME_LENGTH, 0);
unz_file_info64 file_info; unz_file_info64 file_info;
if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &file_info, fileName.data(), fileName.size(), if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &file_info, fileName.data(), fileName.size(),
NULL, 0, NULL, 0))!=UNZ_OK) nullptr, 0, nullptr, 0))!=UNZ_OK)
return QString(); return QString();
fileName.resize(file_info.size_filename); fileName.resize(file_info.size_filename);
QString result = (file_info.flag & UNZ_ENCODING_UTF8) QString result = (file_info.flag & UNZ_ENCODING_UTF8)
@ -645,7 +645,7 @@ QString QuaZip::getZipName() const
QIODevice *QuaZip::getIoDevice() const QIODevice *QuaZip::getIoDevice() const
{ {
if (!p->zipName.isEmpty()) // opened by name, using an internal QIODevice if (!p->zipName.isEmpty()) // opened by name, using an internal QIODevice
return NULL; return nullptr;
return p->ioDevice; return p->ioDevice;
} }

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,9 +25,9 @@ Original ZIP package is copyrighted by Gilles Vollant, see
quazip/(un)zip.h files for details, basically it's zlib license. quazip/(un)zip.h files for details, basically it's zlib license.
**/ **/
#include <QString> #include <QtCore/QString>
#include <QStringList> #include <QtCore/QStringList>
#include <QTextCodec> #include "quazip_qt_compat.h"
#include "zip.h" #include "zip.h"
#include "unzip.h" #include "unzip.h"
@ -116,7 +116,7 @@ class QUAZIP_EXPORT QuaZip {
csSensitive=1, ///< Case sensitive. csSensitive=1, ///< Case sensitive.
csInsensitive=2 ///< Case insensitive. csInsensitive=2 ///< Case insensitive.
}; };
/// Returns the actual case sensitivity for the specified QuaZIP one. /// Returns the actual case sensitivity for the specified QuaZip one.
/** /**
\param cs The value to convert. \param cs The value to convert.
\returns If CaseSensitivity::csDefault, then returns the default \returns If CaseSensitivity::csDefault, then returns the default
@ -153,17 +153,17 @@ class QUAZIP_EXPORT QuaZip {
* *
* If the ZIP file is accessed via explicitly set QIODevice, then * If the ZIP file is accessed via explicitly set QIODevice, then
* this device is opened in the necessary mode. If the device was * this device is opened in the necessary mode. If the device was
* already opened by some other means, then QuaZIP checks if the * already opened by some other means, then QuaZip checks if the
* open mode is compatible to the mode needed for the requested operation. * open mode is compatible to the mode needed for the requested operation.
* If necessary, seeking is performed to position the device properly. * If necessary, seeking is performed to position the device properly.
* *
* \return \c true if successful, \c false otherwise. * \return \c true if successful, \c false otherwise.
* *
* \note ZIP/UNZIP API open calls do not return error code - they * \note ZIP/UNZIP API open calls do not return error code - they
* just return \c NULL indicating an error. But to make things * just return \c null indicating an error. But to make things
* easier, quazip.h header defines additional error code \c * easier, quazip.h header defines additional error code \c
* UNZ_ERROROPEN and getZipError() will return it if the open call * UNZ_ERROROPEN and getZipError() will return it if the open call
* of the ZIP/UNZIP API returns \c NULL. * of the ZIP/UNZIP API returns \c null.
* *
* Argument \a ioApi specifies IO function set for ZIP/UNZIP * Argument \a ioApi specifies IO function set for ZIP/UNZIP
* package to use. See unzip.h, zip.h and ioapi.h for details. Note * package to use. See unzip.h, zip.h and ioapi.h for details. Note
@ -177,12 +177,12 @@ class QUAZIP_EXPORT QuaZip {
* QIODevice instead of file name, but also has a nice side effect * QIODevice instead of file name, but also has a nice side effect
* of raising the file size limit from 2G to 4G (in non-zip64 archives). * of raising the file size limit from 2G to 4G (in non-zip64 archives).
* *
* \note If the zip64 support is needed, the ioApi argument \em must be NULL * \note If the zip64 support is needed, the ioApi argument \em must be null
* because due to the backwards compatibility issues it can be used to * because due to the backwards compatibility issues it can be used to
* provide a 32-bit API only. * provide a 32-bit API only.
* *
* \note If the \ref QuaZip::setAutoClose() "no-auto-close" feature is used, * \note If the \ref QuaZip::setAutoClose() "no-auto-close" feature is used,
* then the \a ioApi argument \em should be NULL because the old API * then the \a ioApi argument \em should be null because the old API
* doesn't support the 'fake close' operation, causing slight memory leaks * doesn't support the 'fake close' operation, causing slight memory leaks
* and other possible troubles (like closing the output device in case * and other possible troubles (like closing the output device in case
* when an error occurs during opening). * when an error occurs during opening).
@ -190,7 +190,7 @@ class QUAZIP_EXPORT QuaZip {
* In short: just forget about the \a ioApi argument and you'll be * In short: just forget about the \a ioApi argument and you'll be
* fine. * fine.
**/ **/
bool open(Mode mode, zlib_filefunc_def *ioApi =NULL); bool open(Mode mode, zlib_filefunc_def *ioApi =nullptr);
/// Closes ZIP file. /// Closes ZIP file.
/** Call getZipError() to determine if the close was successful. /** Call getZipError() to determine if the close was successful.
* *
@ -206,7 +206,7 @@ class QUAZIP_EXPORT QuaZip {
* by making close() private and crashing the application if it is called * by making close() private and crashing the application if it is called
* from the base class where it is public. It is an excellent example * from the base class where it is public. It is an excellent example
* of poor design that illustrates why you should never ever break * of poor design that illustrates why you should never ever break
* an is-a relationship between the base class and a subclass. QuaZIP * an is-a relationship between the base class and a subclass. QuaZip
* works around this bug by checking if the QIODevice is an instance * works around this bug by checking if the QIODevice is an instance
* of QSaveFile, using qobject_cast<>, and if it is, calls * of QSaveFile, using qobject_cast<>, and if it is, calls
* QSaveFile::commit() instead of close(). It is a really ugly hack, * QSaveFile::commit() instead of close(). It is a really ugly hack,
@ -427,7 +427,7 @@ class QUAZIP_EXPORT QuaZip {
According to the ZIP format specification, a file inside archive According to the ZIP format specification, a file inside archive
may have a data descriptor immediately following the file may have a data descriptor immediately following the file
data. This is reflected by a special flag in the local file header data. This is reflected by a special flag in the local file header
and in the central directory. By default, QuaZIP sets this flag and in the central directory. By default, QuaZip sets this flag
and writes the data descriptor unless both method and level were and writes the data descriptor unless both method and level were
set to 0, in which case it operates in 1.0-compatible mode and set to 0, in which case it operates in 1.0-compatible mode and
never writes data descriptors. never writes data descriptors.
@ -539,14 +539,14 @@ class QUAZIP_EXPORT QuaZip {
bool isAutoClose() const; bool isAutoClose() const;
/// Sets or unsets the auto-close flag. /// Sets or unsets the auto-close flag.
/** /**
By default, QuaZIP opens the underlying QIODevice when open() is called, By default, QuaZip opens the underlying QIODevice when open() is called,
and closes it when close() is called. In some cases, when the device and closes it when close() is called. In some cases, when the device
is set explicitly using setIoDevice(), it may be desirable to is set explicitly using setIoDevice(), it may be desirable to
leave the device open. If the auto-close flag is unset using this method, leave the device open. If the auto-close flag is unset using this method,
then the device isn't closed automatically if it was set explicitly. then the device isn't closed automatically if it was set explicitly.
If it is needed to clear this flag, it is recommended to do so before If it is needed to clear this flag, it is recommended to do so before
opening the archive because otherwise QuaZIP may close the device opening the archive because otherwise QuaZip may close the device
during the open() call if an error is encountered after the device during the open() call if an error is encountered after the device
is opened. is opened.
@ -567,7 +567,7 @@ class QUAZIP_EXPORT QuaZip {
* The codec specified here can be overriden by calling setFileNameCodec(). * The codec specified here can be overriden by calling setFileNameCodec().
* If neither function is called, QTextCodec::codecForLocale() will be used * If neither function is called, QTextCodec::codecForLocale() will be used
* to decode or encode file names. Use this function with caution if * to decode or encode file names. Use this function with caution if
* the application uses other libraries that depend on QuaZIP. Those * the application uses other libraries that depend on QuaZip. Those
* libraries can either call this function by themselves, thus overriding * libraries can either call this function by themselves, thus overriding
* your setting or can rely on the default encoding, thus failing * your setting or can rely on the default encoding, thus failing
* mysteriously if you change it. For these reasons, it isn't recommended * mysteriously if you change it. For these reasons, it isn't recommended
@ -576,7 +576,7 @@ class QUAZIP_EXPORT QuaZip {
* encoding. * encoding.
* *
* In most cases, using setFileNameCodec() instead is the right choice. * In most cases, using setFileNameCodec() instead is the right choice.
* However, if you depend on third-party code that uses QuaZIP, then the * However, if you depend on third-party code that uses QuaZip, then the
* reasons stated above can actually become a reason to use this function * reasons stated above can actually become a reason to use this function
* in case the third-party code in question fails because it doesn't * in case the third-party code in question fails because it doesn't
* understand the encoding you need and doesn't provide a way to specify it. * understand the encoding you need and doesn't provide a way to specify it.
@ -587,7 +587,7 @@ class QUAZIP_EXPORT QuaZip {
* setDefaultFileNameCodec() when you don't have access to the QuaZip * setDefaultFileNameCodec() when you don't have access to the QuaZip
* instance. * instance.
* *
* @param codec The codec to use by default. If NULL, resets to default. * @param codec The codec to use by default. If null, resets to default.
*/ */
static void setDefaultFileNameCodec(QTextCodec *codec); static void setDefaultFileNameCodec(QTextCodec *codec);
/** /**

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QtCore/qglobal.h> #include <QtCore/QtGlobal>
/** /**
This is automatically defined when building a static library, but when This is automatically defined when building a static library, but when
@ -55,5 +55,9 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#define QUAZIP_EXTRA_NTFS_MAGIC 0x000Au #define QUAZIP_EXTRA_NTFS_MAGIC 0x000Au
#define QUAZIP_EXTRA_NTFS_TIME_MAGIC 0x0001u #define QUAZIP_EXTRA_NTFS_TIME_MAGIC 0x0001u
#define QUAZIP_EXTRA_EXT_TIME_MAGIC 0x5455u
#define QUAZIP_EXTRA_EXT_MOD_TIME_FLAG 1
#define QUAZIP_EXTRA_EXT_AC_TIME_FLAG 2
#define QUAZIP_EXTRA_EXT_CR_TIME_FLAG 4
#endif // QUAZIP_GLOBAL_H #endif // QUAZIP_GLOBAL_H

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -23,9 +23,10 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include "quazipdir.h" #include "quazipdir.h"
#include "quazip_qt_compat.h"
#include <QSet> #include <QtCore/QSet>
#include <QSharedData> #include <QtCore/QSharedData>
/// \cond internal /// \cond internal
class QuaZipDirPrivate: public QSharedData { class QuaZipDirPrivate: public QSharedData {
@ -103,9 +104,9 @@ bool QuaZipDir::cd(const QString &directoryName)
if (!dir.cd(QLatin1String("/"))) if (!dir.cd(QLatin1String("/")))
return false; return false;
} }
QStringList path = dirName.split(QLatin1String("/"), QString::SkipEmptyParts); QStringList path = dirName.split(QLatin1String("/"), SkipEmptyParts);
for (QStringList::const_iterator i = path.constBegin(); for (QStringList::const_iterator i = path.constBegin();
i != path.end(); i != path.constEnd();
++i) { ++i) {
const QString &step = *i; const QString &step = *i;
#ifdef QUAZIP_QUAZIPDIR_DEBUG #ifdef QUAZIP_QUAZIPDIR_DEBUG
@ -390,11 +391,7 @@ bool QuaZipDirPrivate::entryInfoList(QStringList nameFilters,
== Qt::CaseInsensitive) == Qt::CaseInsensitive)
srt |= QDir::IgnoreCase; srt |= QDir::IgnoreCase;
QuaZipDirComparator lessThan(srt); QuaZipDirComparator lessThan(srt);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) quazip_sort(list.begin(), list.end(), lessThan);
std::sort(list.begin(), list.end(), lessThan);
#else
qSort(list.begin(), list.end(), lessThan);
#endif
} }
QuaZipDir_convertInfoList(list, result); QuaZipDir_convertInfoList(list, result);
return true; return true;

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -29,9 +29,9 @@ class QuaZipDirPrivate;
#include "quazip.h" #include "quazip.h"
#include "quazipfileinfo.h" #include "quazipfileinfo.h"
#include <QDir> #include <QtCore/QDir>
#include <QList> #include <QtCore/QList>
#include <QSharedDataPointer> #include <QtCore/QSharedDataPointer>
/// Provides ZIP archive navigation. /// Provides ZIP archive navigation.
/** /**

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -24,6 +24,8 @@ quazip/(un)zip.h files for details, basically it's zlib license.
#include "quazipfile.h" #include "quazipfile.h"
#include "quazipfileinfo.h"
using namespace std; using namespace std;
#define QUAZIP_VERSION_MADE_BY 0x1Eu #define QUAZIP_VERSION_MADE_BY 0x1Eu
@ -80,7 +82,7 @@ class QuaZipFilePrivate {
/// The constructor for the corresponding QuaZipFile constructor. /// The constructor for the corresponding QuaZipFile constructor.
inline QuaZipFilePrivate(QuaZipFile *q): inline QuaZipFilePrivate(QuaZipFile *q):
q(q), q(q),
zip(NULL), zip(nullptr),
caseSensitivity(QuaZip::csDefault), caseSensitivity(QuaZip::csDefault),
raw(false), raw(false),
writePos(0), writePos(0),
@ -175,18 +177,18 @@ QuaZipFile::~QuaZipFile()
QString QuaZipFile::getZipName() const QString QuaZipFile::getZipName() const
{ {
return p->zip==NULL ? QString() : p->zip->getZipName(); return p->zip==nullptr ? QString() : p->zip->getZipName();
} }
QuaZip *QuaZipFile::getZip() const QuaZip *QuaZipFile::getZip() const
{ {
return p->internal ? NULL : p->zip; return p->internal ? nullptr : p->zip;
} }
QString QuaZipFile::getActualFileName()const QString QuaZipFile::getActualFileName()const
{ {
p->setZipError(UNZ_OK); p->setZipError(UNZ_OK);
if (p->zip == NULL || (openMode() & WriteOnly)) if (p->zip == nullptr || (openMode() & WriteOnly))
return QString(); return QString();
QString name=p->zip->getCurrentFileName(); QString name=p->zip->getCurrentFileName();
if(name.isNull()) if(name.isNull())
@ -200,7 +202,7 @@ void QuaZipFile::setZipName(const QString& zipName)
qWarning("QuaZipFile::setZipName(): file is already open - can not set ZIP name"); qWarning("QuaZipFile::setZipName(): file is already open - can not set ZIP name");
return; return;
} }
if(p->zip!=NULL && p->internal) if(p->zip!=nullptr && p->internal)
delete p->zip; delete p->zip;
p->zip=new QuaZip(zipName); p->zip=new QuaZip(zipName);
p->internal=true; p->internal=true;
@ -212,7 +214,7 @@ void QuaZipFile::setZip(QuaZip *zip)
qWarning("QuaZipFile::setZip(): file is already open - can not set ZIP"); qWarning("QuaZipFile::setZip(): file is already open - can not set ZIP");
return; return;
} }
if(p->zip!=NULL && p->internal) if(p->zip!=nullptr && p->internal)
delete p->zip; delete p->zip;
p->zip=zip; p->zip=zip;
p->fileName=QString(); p->fileName=QString();
@ -221,7 +223,7 @@ void QuaZipFile::setZip(QuaZip *zip)
void QuaZipFile::setFileName(const QString& fileName, QuaZip::CaseSensitivity cs) void QuaZipFile::setFileName(const QString& fileName, QuaZip::CaseSensitivity cs)
{ {
if(p->zip==NULL) { if(p->zip==nullptr) {
qWarning("QuaZipFile::setFileName(): call setZipName() first"); qWarning("QuaZipFile::setFileName(): call setZipName() first");
return; return;
} }
@ -251,7 +253,7 @@ void QuaZipFilePrivate::setZipError(int zipError) const
bool QuaZipFile::open(OpenMode mode) bool QuaZipFile::open(OpenMode mode)
{ {
return open(mode, NULL); return open(mode, nullptr);
} }
bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const char *password) bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const char *password)
@ -277,8 +279,8 @@ bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const ch
return false; return false;
} }
} else { } else {
if(p->zip==NULL) { if(p->zip==nullptr) {
qWarning("QuaZipFile::open(): zip is NULL"); qWarning("QuaZipFile::open(): zip is null");
return false; return false;
} }
if(p->zip->getMode()!=QuaZip::mdUnzip) { if(p->zip->getMode()!=QuaZip::mdUnzip) {
@ -319,8 +321,8 @@ bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
qWarning("QuaZipFile::open(): write mode is incompatible with internal QuaZip approach"); qWarning("QuaZipFile::open(): write mode is incompatible with internal QuaZip approach");
return false; return false;
} }
if(p->zip==NULL) { if(p->zip==nullptr) {
qWarning("QuaZipFile::open(): zip is NULL"); qWarning("QuaZipFile::open(): zip is null");
return false; return false;
} }
if(p->zip->getMode()!=QuaZip::mdCreate&&p->zip->getMode()!=QuaZip::mdAppend&&p->zip->getMode()!=QuaZip::mdAdd) { if(p->zip->getMode()!=QuaZip::mdCreate&&p->zip->getMode()!=QuaZip::mdAppend&&p->zip->getMode()!=QuaZip::mdAdd) {
@ -380,7 +382,7 @@ bool QuaZipFile::isSequential()const
qint64 QuaZipFile::pos()const qint64 QuaZipFile::pos()const
{ {
if(p->zip==NULL) { if(p->zip==nullptr) {
qWarning("QuaZipFile::pos(): call setZipName() or setZip() first"); qWarning("QuaZipFile::pos(): call setZipName() or setZip() first");
return -1; return -1;
} }
@ -399,7 +401,7 @@ qint64 QuaZipFile::pos()const
bool QuaZipFile::atEnd()const bool QuaZipFile::atEnd()const
{ {
if(p->zip==NULL) { if(p->zip==nullptr) {
qWarning("QuaZipFile::atEnd(): call setZipName() or setZip() first"); qWarning("QuaZipFile::atEnd(): call setZipName() or setZip() first");
return false; return false;
} }
@ -431,8 +433,8 @@ qint64 QuaZipFile::csize()const
{ {
unz_file_info64 info_z; unz_file_info64 info_z;
p->setZipError(UNZ_OK); p->setZipError(UNZ_OK);
if(p->zip==NULL||p->zip->getMode()!=QuaZip::mdUnzip) return -1; if(p->zip==nullptr||p->zip->getMode()!=QuaZip::mdUnzip) return -1;
p->setZipError(unzGetCurrentFileInfo64(p->zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0)); p->setZipError(unzGetCurrentFileInfo64(p->zip->getUnzFile(), &info_z, nullptr, 0, nullptr, 0, nullptr, 0));
if(p->zipError!=UNZ_OK) if(p->zipError!=UNZ_OK)
return -1; return -1;
return info_z.compressed_size; return info_z.compressed_size;
@ -442,8 +444,8 @@ qint64 QuaZipFile::usize()const
{ {
unz_file_info64 info_z; unz_file_info64 info_z;
p->setZipError(UNZ_OK); p->setZipError(UNZ_OK);
if(p->zip==NULL||p->zip->getMode()!=QuaZip::mdUnzip) return -1; if(p->zip==nullptr||p->zip->getMode()!=QuaZip::mdUnzip) return -1;
p->setZipError(unzGetCurrentFileInfo64(p->zip->getUnzFile(), &info_z, NULL, 0, NULL, 0, NULL, 0)); p->setZipError(unzGetCurrentFileInfo64(p->zip->getUnzFile(), &info_z, nullptr, 0, nullptr, 0, nullptr, 0));
if(p->zipError!=UNZ_OK) if(p->zipError!=UNZ_OK)
return -1; return -1;
return info_z.uncompressed_size; return info_z.uncompressed_size;
@ -462,7 +464,7 @@ bool QuaZipFile::getFileInfo(QuaZipFileInfo *info)
bool QuaZipFile::getFileInfo(QuaZipFileInfo64 *info) bool QuaZipFile::getFileInfo(QuaZipFileInfo64 *info)
{ {
if(p->zip==NULL||p->zip->getMode()!=QuaZip::mdUnzip) return false; if(p->zip==nullptr||p->zip->getMode()!=QuaZip::mdUnzip) return false;
p->zip->getCurrentFileInfo(info); p->zip->getCurrentFileInfo(info);
p->setZipError(p->zip->getZipError()); p->setZipError(p->zip->getZipError());
return p->zipError==UNZ_OK; return p->zipError==UNZ_OK;
@ -471,7 +473,7 @@ bool QuaZipFile::getFileInfo(QuaZipFileInfo64 *info)
void QuaZipFile::close() void QuaZipFile::close()
{ {
p->resetZipError(); p->resetZipError();
if(p->zip==NULL||!p->zip->isOpen()) return; if(p->zip==nullptr||!p->zip->isOpen()) return;
if(!isOpen()) { if(!isOpen()) {
qWarning("QuaZipFile::close(): file isn't open"); qWarning("QuaZipFile::close(): file isn't open");
return; return;
@ -539,3 +541,30 @@ qint64 QuaZipFile::bytesAvailable() const
{ {
return size() - pos(); return size() - pos();
} }
QByteArray QuaZipFile::getLocalExtraField()
{
int size = unzGetLocalExtrafield(p->zip->getUnzFile(), nullptr, 0);
QByteArray extra(size, '\0');
int err = unzGetLocalExtrafield(p->zip->getUnzFile(), extra.data(), static_cast<uint>(extra.size()));
if (err < 0) {
p->setZipError(err);
return QByteArray();
}
return extra;
}
QDateTime QuaZipFile::getExtModTime()
{
return QuaZipFileInfo64::getExtTime(getLocalExtraField(), QUAZIP_EXTRA_EXT_MOD_TIME_FLAG);
}
QDateTime QuaZipFile::getExtAcTime()
{
return QuaZipFileInfo64::getExtTime(getLocalExtraField(), QUAZIP_EXTRA_EXT_AC_TIME_FLAG);
}
QDateTime QuaZipFile::getExtCrTime()
{
return QuaZipFileInfo64::getExtTime(getLocalExtraField(), QUAZIP_EXTRA_EXT_CR_TIME_FLAG);
}

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant, see
quazip/(un)zip.h files for details, basically it's zlib license. quazip/(un)zip.h files for details, basically it's zlib license.
**/ **/
#include <QIODevice> #include <QtCore/QIODevice>
#include "quazip_global.h" #include "quazip_global.h"
#include "quazip.h" #include "quazip.h"
@ -39,7 +39,7 @@ class QuaZipFilePrivate;
* interface to the ZIP/UNZIP package, but also integrates it with Qt by * interface to the ZIP/UNZIP package, but also integrates it with Qt by
* subclassing QIODevice. This makes possible to access files inside ZIP * subclassing QIODevice. This makes possible to access files inside ZIP
* archive using QTextStream or QDataStream, for example. Actually, this * archive using QTextStream or QDataStream, for example. Actually, this
* is the main purpose of the whole QuaZIP library. * is the main purpose of the whole QuaZip library.
* *
* You can either use existing QuaZip instance to create instance of * You can either use existing QuaZip instance to create instance of
* this class or pass ZIP archive file name to this class, in which case * this class or pass ZIP archive file name to this class, in which case
@ -107,7 +107,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
* QuaZipFile constructed by this constructor can be used for read * QuaZipFile constructed by this constructor can be used for read
* only access. Use QuaZipFile(QuaZip*,QObject*) for writing. * only access. Use QuaZipFile(QuaZip*,QObject*) for writing.
**/ **/
QuaZipFile(const QString& zipName, QObject *parent =NULL); QuaZipFile(const QString& zipName, QObject *parent =nullptr);
/// Constructs a QuaZipFile instance. /// Constructs a QuaZipFile instance.
/** \a parent argument specifies this object's parent object, \a /** \a parent argument specifies this object's parent object, \a
* zipName specifies ZIP archive file name and \a fileName and \a cs * zipName specifies ZIP archive file name and \a fileName and \a cs
@ -119,7 +119,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
* \sa QuaZip::setCurrentFile() * \sa QuaZip::setCurrentFile()
**/ **/
QuaZipFile(const QString& zipName, const QString& fileName, QuaZipFile(const QString& zipName, const QString& fileName,
QuaZip::CaseSensitivity cs =QuaZip::csDefault, QObject *parent =NULL); QuaZip::CaseSensitivity cs =QuaZip::csDefault, QObject *parent =nullptr);
/// Constructs a QuaZipFile instance. /// Constructs a QuaZipFile instance.
/** \a parent argument specifies this object's parent object. /** \a parent argument specifies this object's parent object.
* *
@ -169,7 +169,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
* zip.close(); * zip.close();
* \endcode * \endcode
**/ **/
QuaZipFile(QuaZip *zip, QObject *parent =NULL); QuaZipFile(QuaZip *zip, QObject *parent =nullptr);
/// Destroys a QuaZipFile instance. /// Destroys a QuaZipFile instance.
/** Closes file if open, destructs internal QuaZip object (if it /** Closes file if open, destructs internal QuaZip object (if it
* exists and \em is internal, of course). * exists and \em is internal, of course).
@ -296,7 +296,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
* it is NULL then this function behaves just like open(OpenMode). * it is NULL then this function behaves just like open(OpenMode).
**/ **/
inline bool open(OpenMode mode, const char *password) inline bool open(OpenMode mode, const char *password)
{return open(mode, NULL, NULL, false, password);} {return open(mode, nullptr, nullptr, false, password);}
/// Opens a file for reading. /// Opens a file for reading.
/** \overload /** \overload
* Argument \a password specifies a password to decrypt the file. * Argument \a password specifies a password to decrypt the file.
@ -309,7 +309,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
* \a method should not be \c NULL. \a level can be \c NULL if you * \a method should not be \c NULL. \a level can be \c NULL if you
* don't want to know the compression level. * don't want to know the compression level.
**/ **/
bool open(OpenMode mode, int *method, int *level, bool raw, const char *password =NULL); bool open(OpenMode mode, int *method, int *level, bool raw, const char *password =nullptr);
/// Opens a file for writing. /// Opens a file for writing.
/** \a info argument specifies information about file. It should at /** \a info argument specifies information about file. It should at
* least specify a correct file name. Also, it is a good idea to * least specify a correct file name. Also, it is a good idea to
@ -339,7 +339,7 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
* algorithms tuning. See deflateInit2() in zlib. * algorithms tuning. See deflateInit2() in zlib.
**/ **/
bool open(OpenMode mode, const QuaZipNewInfo& info, bool open(OpenMode mode, const QuaZipNewInfo& info,
const char *password =NULL, quint32 crc =0, const char *password =nullptr, quint32 crc =0,
int method =Z_DEFLATED, int level =Z_DEFAULT_COMPRESSION, bool raw =false, int method =Z_DEFLATED, int level =Z_DEFAULT_COMPRESSION, bool raw =false,
int windowBits =-MAX_WBITS, int memLevel =DEF_MEM_LEVEL, int strategy =Z_DEFAULT_STRATEGY); int windowBits =-MAX_WBITS, int memLevel =DEF_MEM_LEVEL, int strategy =Z_DEFAULT_STRATEGY);
/// Returns \c true, but \ref quazipfile-sequential "beware"! /// Returns \c true, but \ref quazipfile-sequential "beware"!
@ -451,6 +451,58 @@ class QUAZIP_EXPORT QuaZipFile: public QIODevice {
int getZipError() const; int getZipError() const;
/// Returns the number of bytes available for reading. /// Returns the number of bytes available for reading.
virtual qint64 bytesAvailable() const; virtual qint64 bytesAvailable() const;
/// Returns the local extra field
/**
There are two (optional) local extra fields associated with a file.
One is located in the central header and is available along
with the rest of the file information in @ref QuaZipFileInfo64::extra.
Another is located before the file itself,
and is returned by this function. The file must be open first.
@return the local extra field, or an empty array if there is none
(or file is not open)
*/
QByteArray getLocalExtraField();
/// Returns the extended modification timestamp
/**
* The getExt*Time() functions only work if there is an extended timestamp
* extra field (ID 0x5455) present. Otherwise, they all return invalid null
* timestamps.
*
* Modification time, but not other times, can also be accessed through
* @ref QuaZipFileInfo64 without the need to open the file first.
*
* @sa dateTime
* @sa QuaZipFileInfo64::getExtModTime()
* @sa getExtAcTime()
* @sa getExtCrTime()
* @return The extended modification time, UTC
*/
QDateTime getExtModTime();
/// Returns the extended access timestamp
/**
* The getExt*Time() functions only work if there is an extended timestamp
* extra field (ID 0x5455) present. Otherwise, they all return invalid null
* timestamps.
* @sa dateTime
* @sa QuaZipFileInfo64::getExtModTime()
* @sa getExtModTime()
* @sa getExtCrTime()
* @return The extended access time, UTC
*/
QDateTime getExtAcTime();
/// Returns the extended creation timestamp
/**
* The getExt*Time() functions only work if there is an extended timestamp
* extra field (ID 0x5455) present. Otherwise, they all return invalid null
* timestamps.
* @sa dateTime
* @sa QuaZipFileInfo64::getExtModTime()
* @sa getExtModTime()
* @sa getExtAcTime()
* @return The extended creation time, UTC
*/
QDateTime getExtCrTime();
}; };
#endif #endif

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -24,9 +24,11 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "quazipfileinfo.h" #include "quazipfileinfo.h"
#include <QtCore/QDataStream>
static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr) { static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr) {
quint32 uPerm = (externalAttr & 0xFFFF0000u) >> 16; quint32 uPerm = (externalAttr & 0xFFFF0000u) >> 16;
QFile::Permissions perm = 0; QFile::Permissions perm;
if ((uPerm & 0400) != 0) if ((uPerm & 0400) != 0)
perm |= QFile::ReadOwner; perm |= QFile::ReadOwner;
if ((uPerm & 0200) != 0) if ((uPerm & 0200) != 0)
@ -59,6 +61,12 @@ QFile::Permissions QuaZipFileInfo64::getPermissions() const
return permissionsFromExternalAttr(externalAttr); return permissionsFromExternalAttr(externalAttr);
} }
bool QuaZipFileInfo64::isSymbolicLink() const
{
quint32 uPerm = (externalAttr & 0xFFFF0000u) >> 16;
return (uPerm & 0170000) == 0120000;
}
bool QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo &info) const bool QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo &info) const
{ {
bool noOverflow = true; bool noOverflow = true;
@ -93,69 +101,32 @@ static QDateTime getNTFSTime(const QByteArray &extra, int position,
int *fineTicks) int *fineTicks)
{ {
QDateTime dateTime; QDateTime dateTime;
for (int i = 0; i <= extra.size() - 4; ) { QuaExtraFieldHash extraHash = QuaZipFileInfo64::parseExtraField(extra);
unsigned type = static_cast<unsigned>(static_cast<unsigned char>( QList<QByteArray> ntfsExtraFields = extraHash[QUAZIP_EXTRA_NTFS_MAGIC];
extra.at(i))) if (ntfsExtraFields.isEmpty())
| (static_cast<unsigned>(static_cast<unsigned char>( return dateTime;
extra.at(i + 1))) << 8); QByteArray ntfsExtraField = ntfsExtraFields.at(0);
i += 2; if (ntfsExtraField.length() <= 4)
unsigned length = static_cast<unsigned>(static_cast<unsigned char>( return dateTime;
extra.at(i))) QByteArray ntfsAttributes = ntfsExtraField.mid(4);
| (static_cast<unsigned>(static_cast<unsigned char>( QuaExtraFieldHash ntfsHash = QuaZipFileInfo64::parseExtraField(ntfsAttributes);
extra.at(i + 1))) << 8); QList<QByteArray> ntfsTimeAttributes = ntfsHash[QUAZIP_EXTRA_NTFS_TIME_MAGIC];
i += 2; if (ntfsTimeAttributes.isEmpty())
if (type == QUAZIP_EXTRA_NTFS_MAGIC && length >= 32) { return dateTime;
i += 4; // reserved QByteArray ntfsTimes = ntfsTimeAttributes.at(0);
while (i <= extra.size() - 4) { if (ntfsTimes.size() < 24)
unsigned tag = static_cast<unsigned>( return dateTime;
static_cast<unsigned char>(extra.at(i))) QDataStream timeReader(ntfsTimes);
| (static_cast<unsigned>( timeReader.setByteOrder(QDataStream::LittleEndian);
static_cast<unsigned char>(extra.at(i + 1))) timeReader.device()->seek(position);
<< 8); quint64 time;
i += 2; timeReader >> time;
int tagsize = static_cast<unsigned>( if (time == 0)
static_cast<unsigned char>(extra.at(i))) return dateTime;
| (static_cast<unsigned>(
static_cast<unsigned char>(extra.at(i + 1)))
<< 8);
i += 2;
if (tag == QUAZIP_EXTRA_NTFS_TIME_MAGIC
&& tagsize >= position + 8) {
i += position;
quint64 mtime = static_cast<quint64>(
static_cast<unsigned char>(extra.at(i)))
| (static_cast<quint64>(static_cast<unsigned char>(
extra.at(i + 1))) << 8)
| (static_cast<quint64>(static_cast<unsigned char>(
extra.at(i + 2))) << 16)
| (static_cast<quint64>(static_cast<unsigned char>(
extra.at(i + 3))) << 24)
| (static_cast<quint64>(static_cast<unsigned char>(
extra.at(i + 4))) << 32)
| (static_cast<quint64>(static_cast<unsigned char>(
extra.at(i + 5))) << 40)
| (static_cast<quint64>(static_cast<unsigned char>(
extra.at(i + 6))) << 48)
| (static_cast<quint64>(static_cast<unsigned char>(
extra.at(i + 7))) << 56);
// the NTFS time is measured from 1601 for whatever reason
QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
dateTime = base.addMSecs(mtime / 10000); dateTime = base.addMSecs(time / 10000);
if (fineTicks != NULL) { if (fineTicks != nullptr) {
*fineTicks = static_cast<int>(mtime % 10000); *fineTicks = static_cast<int>(time % 10000);
}
i += tagsize - position;
} else {
i += tagsize;
}
}
} else {
i += length;
}
}
if (fineTicks != NULL && dateTime.isNull()) {
*fineTicks = 0;
} }
return dateTime; return dateTime;
} }
@ -174,3 +145,60 @@ QDateTime QuaZipFileInfo64::getNTFScTime(int *fineTicks) const
{ {
return getNTFSTime(extra, 16, fineTicks); return getNTFSTime(extra, 16, fineTicks);
} }
QDateTime QuaZipFileInfo64::getExtTime(const QByteArray &extra, int flag)
{
QDateTime dateTime;
QuaExtraFieldHash extraHash = QuaZipFileInfo64::parseExtraField(extra);
QList<QByteArray> extTimeFields = extraHash[QUAZIP_EXTRA_EXT_TIME_MAGIC];
if (extTimeFields.isEmpty())
return dateTime;
QByteArray extTimeField = extTimeFields.at(0);
if (extTimeField.length() < 1)
return dateTime;
QDataStream input(extTimeField);
input.setByteOrder(QDataStream::LittleEndian);
quint8 flags;
input >> flags;
int flagsRemaining = flags;
while (!input.atEnd()) {
int nextFlag = flagsRemaining & -flagsRemaining;
flagsRemaining &= flagsRemaining - 1;
qint32 time;
input >> time;
if (nextFlag == flag) {
QDateTime base(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC);
dateTime = base.addSecs(time);
return dateTime;
}
}
return dateTime;
}
QDateTime QuaZipFileInfo64::getExtModTime() const
{
return getExtTime(extra, 1);
}
QuaExtraFieldHash QuaZipFileInfo64::parseExtraField(const QByteArray &extraField)
{
QDataStream input(extraField);
input.setByteOrder(QDataStream::LittleEndian);
QHash<quint16, QList<QByteArray> > result;
while (!input.atEnd()) {
quint16 id, size;
input >> id;
if (input.status() == QDataStream::ReadPastEnd)
return result;
input >> size;
if (input.status() == QDataStream::ReadPastEnd)
return result;
QByteArray data;
data.resize(size);
int read = input.readRawData(data.data(), data.size());
if (read < data.size())
return result;
result[id] << data;
}
return result;
}

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,12 +25,16 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QByteArray> #include <QtCore/QByteArray>
#include <QDateTime> #include <QtCore/QDateTime>
#include <QFile> #include <QtCore/QFile>
#include <QtCore/QHash>
#include "quazip_global.h" #include "quazip_global.h"
/// The typedef to store extra field parse results
typedef QHash<quint16, QList<QByteArray> > QuaExtraFieldHash;
/// Information about a file inside archive. /// Information about a file inside archive.
/** /**
* \deprecated Use QuaZipFileInfo64 instead. Not only it supports large files, * \deprecated Use QuaZipFileInfo64 instead. Not only it supports large files,
@ -120,6 +124,12 @@ struct QUAZIP_EXPORT QuaZipFileInfo64 {
QFile::Permissions. QFile::Permissions.
*/ */
QFile::Permissions getPermissions() const; QFile::Permissions getPermissions() const;
/// Checks whether the file is a symbolic link.
/**
Returns true iff the highest 16 bits of the external attributes
indicate that the file is a symbolic link according to Unix file mode.
*/
bool isSymbolicLink() const;
/// Converts to QuaZipFileInfo /// Converts to QuaZipFileInfo
/** /**
If any of the fields are greater than 0xFFFFFFFFu, they are set to If any of the fields are greater than 0xFFFFFFFFu, they are set to
@ -136,7 +146,7 @@ struct QUAZIP_EXPORT QuaZipFileInfo64 {
/** /**
* The getNTFS*Time() functions only work if there is an NTFS extra field * The getNTFS*Time() functions only work if there is an NTFS extra field
* present. Otherwise, they all return invalid null timestamps. * present. Otherwise, they all return invalid null timestamps.
* @param fineTicks If not NULL, the fractional part of milliseconds returned * @param fineTicks If not null, the fractional part of milliseconds returned
* there, measured in 100-nanosecond ticks. Will be set to * there, measured in 100-nanosecond ticks. Will be set to
* zero if there is no NTFS extra field. * zero if there is no NTFS extra field.
* @sa dateTime * @sa dateTime
@ -144,12 +154,12 @@ struct QUAZIP_EXPORT QuaZipFileInfo64 {
* @sa getNTFScTime() * @sa getNTFScTime()
* @return The NTFS modification time, UTC * @return The NTFS modification time, UTC
*/ */
QDateTime getNTFSmTime(int *fineTicks = NULL) const; QDateTime getNTFSmTime(int *fineTicks = nullptr) const;
/// Returns the NTFS access time /// Returns the NTFS access time
/** /**
* The getNTFS*Time() functions only work if there is an NTFS extra field * The getNTFS*Time() functions only work if there is an NTFS extra field
* present. Otherwise, they all return invalid null timestamps. * present. Otherwise, they all return invalid null timestamps.
* @param fineTicks If not NULL, the fractional part of milliseconds returned * @param fineTicks If not null, the fractional part of milliseconds returned
* there, measured in 100-nanosecond ticks. Will be set to * there, measured in 100-nanosecond ticks. Will be set to
* zero if there is no NTFS extra field. * zero if there is no NTFS extra field.
* @sa dateTime * @sa dateTime
@ -157,12 +167,12 @@ struct QUAZIP_EXPORT QuaZipFileInfo64 {
* @sa getNTFScTime() * @sa getNTFScTime()
* @return The NTFS access time, UTC * @return The NTFS access time, UTC
*/ */
QDateTime getNTFSaTime(int *fineTicks = NULL) const; QDateTime getNTFSaTime(int *fineTicks = nullptr) const;
/// Returns the NTFS creation time /// Returns the NTFS creation time
/** /**
* The getNTFS*Time() functions only work if there is an NTFS extra field * The getNTFS*Time() functions only work if there is an NTFS extra field
* present. Otherwise, they all return invalid null timestamps. * present. Otherwise, they all return invalid null timestamps.
* @param fineTicks If not NULL, the fractional part of milliseconds returned * @param fineTicks If not null, the fractional part of milliseconds returned
* there, measured in 100-nanosecond ticks. Will be set to * there, measured in 100-nanosecond ticks. Will be set to
* zero if there is no NTFS extra field. * zero if there is no NTFS extra field.
* @sa dateTime * @sa dateTime
@ -170,9 +180,53 @@ struct QUAZIP_EXPORT QuaZipFileInfo64 {
* @sa getNTFSaTime() * @sa getNTFSaTime()
* @return The NTFS creation time, UTC * @return The NTFS creation time, UTC
*/ */
QDateTime getNTFScTime(int *fineTicks = NULL) const; QDateTime getNTFScTime(int *fineTicks = nullptr) const;
/// Returns the extended modification timestamp
/**
* The getExt*Time() functions only work if there is an extended timestamp
* extra field (ID 0x5455) present. Otherwise, they all return invalid null
* timestamps.
*
* QuaZipFileInfo64 only contains the modification time because it's extracted
* from @ref extra, which contains the global extra field, and access and
* creation time are in the local header which can be accessed through
* @ref QuaZipFile.
*
* @sa dateTime
* @sa QuaZipFile::getExtModTime()
* @sa QuaZipFile::getExtAcTime()
* @sa QuaZipFile::getExtCrTime()
* @return The extended modification time, UTC
*/
QDateTime getExtModTime() const;
/// Checks whether the file is encrypted. /// Checks whether the file is encrypted.
bool isEncrypted() const {return (flags & 1) != 0;} bool isEncrypted() const {return (flags & 1) != 0;}
/// Parses extra field
/**
* The returned hash table contains a list of data blocks for every header ID
* in the provided extra field. The number of data blocks in a hash table value
* equals to the number of occurrences of the appropriate header id. In most cases,
* a block with a specific header ID only occurs once, and therefore the returned
* hash table will contain a list consisting of a single element for that header ID.
*
* @param extraField extra field to parse
* @return header id to list of data block hash
*/
static QuaExtraFieldHash parseExtraField(const QByteArray &extraField);
/// Extracts extended time from the extra field
/**
* Utility function used by various getExt*Time() functions, but can be used directly
* if the extra field is obtained elsewhere (from a third party library, for example).
*
* @param extra the extra field for a file
* @param flag 1 - modification time, 2 - access time, 4 - creation time
* @return the extracted time or null QDateTime if not present
* @sa getExtModTime()
* @sa QuaZipFile::getExtModTime()
* @sa QuaZipFile::getExtAcTime()
* @sa QuaZipFile::getExtCrTime()
*/
static QDateTime getExtTime(const QByteArray &extra, int flag);
}; };
#endif #endif

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -22,9 +22,10 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QFileInfo> #include <QtCore/QFileInfo>
#include "quazipnewinfo.h" #include "quazipnewinfo.h"
#include "quazip_qt_compat.h"
#include <string.h> #include <string.h>
@ -100,7 +101,7 @@ QuaZipNewInfo::QuaZipNewInfo(const QString& name, const QString& file):
dateTime = QDateTime::currentDateTime(); dateTime = QDateTime::currentDateTime();
} else { } else {
dateTime = lm; dateTime = lm;
QuaZipNewInfo_setPermissions(this, info.permissions(), info.isDir(), info.isSymLink()); QuaZipNewInfo_setPermissions(this, info.permissions(), info.isDir(), quazip_is_symlink(info));
} }
} }
@ -116,7 +117,7 @@ void QuaZipNewInfo::setFilePermissions(const QString &file)
{ {
QFileInfo info = QFileInfo(file); QFileInfo info = QFileInfo(file);
QFile::Permissions perm = info.permissions(); QFile::Permissions perm = info.permissions();
QuaZipNewInfo_setPermissions(this, perm, info.isDir(), info.isSymLink()); QuaZipNewInfo_setPermissions(this, perm, info.isDir(), quazip_is_symlink(info));
} }
void QuaZipNewInfo::setPermissions(QFile::Permissions permissions) void QuaZipNewInfo::setPermissions(QFile::Permissions permissions)
@ -134,11 +135,7 @@ void QuaZipNewInfo::setFileNTFSTimes(const QString &fileName)
} }
setFileNTFSmTime(fi.lastModified()); setFileNTFSmTime(fi.lastModified());
setFileNTFSaTime(fi.lastRead()); setFileNTFSaTime(fi.lastRead());
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) setFileNTFScTime(quazip_ctime(fi));
setFileNTFScTime(fi.birthTime());
#else
setFileNTFScTime(fi.created());
#endif
} }
static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position, static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position,
@ -251,16 +248,7 @@ static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position,
extra[timesPos + 2] = static_cast<char>(ntfsTimesLength); extra[timesPos + 2] = static_cast<char>(ntfsTimesLength);
extra[timesPos + 3] = static_cast<char>(ntfsTimesLength >> 8); extra[timesPos + 3] = static_cast<char>(ntfsTimesLength >> 8);
} }
QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); quint64 ticks = quazip_ntfs_ticks(time, fineTicks);
#if (QT_VERSION >= 0x040700)
quint64 ticks = base.msecsTo(time) * 10000 + fineTicks;
#else
QDateTime utc = time.toUTC();
quint64 ticks = (static_cast<qint64>(base.date().daysTo(utc.date()))
* Q_INT64_C(86400000)
+ static_cast<qint64>(base.time().msecsTo(utc.time())))
* Q_INT64_C(10000) + fineTicks;
#endif
extra[timesPos + 4 + position] = static_cast<char>(ticks); extra[timesPos + 4 + position] = static_cast<char>(ticks);
extra[timesPos + 5 + position] = static_cast<char>(ticks >> 8); extra[timesPos + 5 + position] = static_cast<char>(ticks >> 8);
extra[timesPos + 6 + position] = static_cast<char>(ticks >> 16); extra[timesPos + 6 + position] = static_cast<char>(ticks >> 16);

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP. This file is part of QuaZip.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,9 +25,9 @@ Original ZIP package is copyrighted by Gilles Vollant, see
quazip/(un)zip.h files for details, basically it's zlib license. quazip/(un)zip.h files for details, basically it's zlib license.
**/ **/
#include <QDateTime> #include <QtCore/QDateTime>
#include <QFile> #include <QtCore/QFile>
#include <QString> #include <QtCore/QString>
#include "quazip_global.h" #include "quazip_global.h"

View File

@ -10,7 +10,7 @@
Modifications for Zip64 support on both zip and unzip Modifications for Zip64 support on both zip and unzip
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
Modifications for QIODevice support and other QuaZIP fixes Modifications for QIODevice support and other QuaZip fixes
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
For more info read MiniZip_info.txt For more info read MiniZip_info.txt

View File

@ -206,7 +206,7 @@ extern unzFile ZEXPORT unzOpen2_64 OF((voidpf file,
/* /*
* Exported by Sergey A. Tachenov to implement some QuaZIP features. This * Exported by Sergey A. Tachenov to implement some QuaZip features. This
* function MAY change signature in order to implement even more features. * function MAY change signature in order to implement even more features.
* You have been warned! * You have been warned!
* */ * */

View File

@ -9,7 +9,7 @@
For more info read MiniZip_info.txt For more info read MiniZip_info.txt
Modifications for QIODevice support and other QuaZIP fixes Modifications for QIODevice support and other QuaZip fixes
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
Fixing static code analysis issues Fixing static code analysis issues
@ -1742,7 +1742,7 @@ extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_s
if (err==ZIP_OK) if (err==ZIP_OK)
err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader); err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
free(zi->ci.central_header); TRYFREE(zi->ci.central_header);
if (err==ZIP_OK) if (err==ZIP_OK)
{ {

View File

@ -129,7 +129,7 @@ extern zipFile ZEXPORT zipOpen OF((voidpf file, int append));
extern zipFile ZEXPORT zipOpen64 OF((voidpf file, int append)); extern zipFile ZEXPORT zipOpen64 OF((voidpf file, int append));
/* /*
Create a zipfile. Create a zipfile.
the file argument depends on the API used, for QuaZIP it's a QIODevice the file argument depends on the API used, for QuaZip it's a QIODevice
pointer. pointer.
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
will be created at the end of the file. will be created at the end of the file.
@ -157,9 +157,9 @@ extern zipFile ZEXPORT zipOpen2_64 OF((voidpf file,
zlib_filefunc64_def* pzlib_filefunc_def)); zlib_filefunc64_def* pzlib_filefunc_def));
/* /*
* Exported by Sergey A. Tachenov to suit the needs of QuaZIP. * Exported by Sergey A. Tachenov to suit the needs of QuaZip.
* Note that this function MAY change signature in order to * Note that this function MAY change signature in order to
* provide new QuaZIP features. You have been warned! * provide new QuaZip features. You have been warned!
* */ * */
extern zipFile ZEXPORT zipOpen3 (voidpf file, extern zipFile ZEXPORT zipOpen3 (voidpf file,
int append, int append,

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -33,13 +33,14 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "testquazipnewinfo.h" #include "testquazipnewinfo.h"
#include "testquazipfileinfo.h" #include "testquazipfileinfo.h"
#include <quazip/quazip.h> #include <quazip.h>
#include <quazip/quazipfile.h> #include <quazipfile.h>
#include <quazip_qt_compat.h>
#include <QCoreApplication> #include <QtCore/QCoreApplication>
#include <QDir> #include <QtCore/QDir>
#include <QFileInfo> #include <QtCore/QFileInfo>
#include <QTextStream> #include <QtCore/QTextStream>
#include <QtTest/QtTest> #include <QtTest/QtTest>
@ -71,7 +72,7 @@ bool createTestFiles(const QStringList &fileNames, int size, const QString &dir)
} }
if (size == -1) { if (size == -1) {
QTextStream testStream(&testFile); QTextStream testStream(&testFile);
testStream << "This is a test file named " << fileName << endl; testStream << "This is a test file named " << fileName << quazip_endl;
} else { } else {
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
testFile.putChar(static_cast<char>('0' + i % 10)); testFile.putChar(static_cast<char>('0' + i % 10));

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,10 +25,11 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QIODevice> #include <QtCore/QIODevice>
#include <QString> #include <QtCore/QString>
#include <QStringList> #include <QtCore/QStringList>
#include <QTextCodec>
#include <quazip_qt_compat.h>
extern bool createTestFiles(const QStringList &fileNames, extern bool createTestFiles(const QStringList &fileNames,
int size = -1, int size = -1,

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -26,12 +26,14 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "qztest.h" #include "qztest.h"
#include <QDir> #include <QtCore/QDir>
#include <QFileInfo> #include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <quazip_qt_compat.h>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <quazip/JlCompress.h> #include <JlCompress.h>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <windows.h> #include <windows.h>
@ -303,17 +305,29 @@ void TestJlCompress::extractDir_data()
QTest::addColumn<QString>("zipName"); QTest::addColumn<QString>("zipName");
QTest::addColumn<QStringList>("fileNames"); QTest::addColumn<QStringList>("fileNames");
QTest::addColumn<QStringList>("expectedExtracted"); QTest::addColumn<QStringList>("expectedExtracted");
QTest::addColumn<QByteArray>("fileNameCodecName");
QTest::newRow("simple") << "jlextdir.zip" QTest::newRow("simple") << "jlextdir.zip"
<< (QStringList() << "test0.txt" << "testdir1/test1.txt" << (QStringList() << "test0.txt" << "testdir1/test1.txt"
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt") << "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt")
<< (QStringList() << "test0.txt" << "testdir1/test1.txt" << (QStringList() << "test0.txt" << "testdir1/test1.txt"
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt"); << "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt")
<< QByteArray();
QTest::newRow("separate dir") << "sepdir.zip" QTest::newRow("separate dir") << "sepdir.zip"
<< (QStringList() << "laj/" << "laj/lajfile.txt") << (QStringList() << "laj/" << "laj/lajfile.txt")
<< (QStringList() << "laj/" << "laj/lajfile.txt"); << (QStringList() << "laj/" << "laj/lajfile.txt")
<< QByteArray();
QTest::newRow("Zip Slip") << "zipslip.zip" QTest::newRow("Zip Slip") << "zipslip.zip"
<< (QStringList() << "test0.txt" << "../zipslip.txt") << (QStringList() << "test0.txt" << "../zipslip.txt")
<< (QStringList() << "test0.txt"); << (QStringList() << "test0.txt")
<< QByteArray();
QTest::newRow("Cyrillic") << "cyrillic.zip"
<< (QStringList() << QString::fromUtf8("Ще не вмерла Україна"))
<< (QStringList() << QString::fromUtf8("Ще не вмерла Україна"))
<< QByteArray("KOI8-U");
QTest::newRow("Japaneses") << "japanese.zip"
<< (QStringList() << QString::fromUtf8("日本"))
<< (QStringList() << QString::fromUtf8("日本"))
<< QByteArray("UTF-8");
} }
void TestJlCompress::extractDir() void TestJlCompress::extractDir()
@ -321,6 +335,10 @@ void TestJlCompress::extractDir()
QFETCH(QString, zipName); QFETCH(QString, zipName);
QFETCH(QStringList, fileNames); QFETCH(QStringList, fileNames);
QFETCH(QStringList, expectedExtracted); QFETCH(QStringList, expectedExtracted);
QFETCH(QByteArray, fileNameCodecName);
QTextCodec *fileNameCodec = NULL;
if (!fileNameCodecName.isEmpty())
fileNameCodec = QTextCodec::codecForName(fileNameCodecName);
QDir curDir; QDir curDir;
if (!curDir.mkpath("jlext/jldir")) { if (!curDir.mkpath("jlext/jldir")) {
QFAIL("Couldn't mkpath jlext/jldir"); QFAIL("Couldn't mkpath jlext/jldir");
@ -328,12 +346,15 @@ void TestJlCompress::extractDir()
if (!createTestFiles(fileNames)) { if (!createTestFiles(fileNames)) {
QFAIL("Couldn't create test files"); QFAIL("Couldn't create test files");
} }
if (!createTestArchive(zipName, fileNames)) { if (!createTestArchive(zipName, fileNames, fileNameCodec)) {
QFAIL("Couldn't create test archive"); QFAIL("Couldn't create test archive");
} }
QStringList extracted; QStringList extracted;
QCOMPARE((extracted = JlCompress::extractDir(zipName, "jlext/jldir")) if (fileNameCodec == NULL)
.count(), expectedExtracted.count()); extracted = JlCompress::extractDir(zipName, "jlext/jldir");
else // test both overloads here
extracted = JlCompress::extractDir(zipName, fileNameCodec, "jlext/jldir");
QCOMPARE(extracted.count(), expectedExtracted.count());
const QString dir = "jlext/jldir/"; const QString dir = "jlext/jldir/";
foreach (QString fileName, expectedExtracted) { foreach (QString fileName, expectedExtracted) {
QString fullName = dir + fileName; QString fullName = dir + fileName;
@ -352,8 +373,11 @@ void TestJlCompress::extractDir()
// now test the QIODevice* overload // now test the QIODevice* overload
QFile zipFile(zipName); QFile zipFile(zipName);
QVERIFY(zipFile.open(QIODevice::ReadOnly)); QVERIFY(zipFile.open(QIODevice::ReadOnly));
QCOMPARE((extracted = JlCompress::extractDir(&zipFile, "jlext/jldir")) if (fileNameCodec == NULL)
.count(), expectedExtracted.count()); extracted = JlCompress::extractDir(&zipFile, "jlext/jldir");
else // test both overloads here
extracted = JlCompress::extractDir(&zipFile, fileNameCodec, "jlext/jldir");
QCOMPARE(extracted.count(), expectedExtracted.count());
foreach (QString fileName, expectedExtracted) { foreach (QString fileName, expectedExtracted) {
QString fullName = dir + fileName; QString fullName = dir + fileName;
QFileInfo fileInfo(fullName); QFileInfo fileInfo(fullName);
@ -390,3 +414,55 @@ void TestJlCompress::zeroPermissions()
curDir.remove("zero.zip"); curDir.remove("zero.zip");
curDir.remove("zero.txt"); curDir.remove("zero.txt");
} }
#ifdef QUAZIP_SYMLINK_TEST
void TestJlCompress::symlinkHandling()
{
QStringList fileNames { "file.txt" };
if (!createTestFiles(fileNames)) {
QFAIL("Couldn't create test files");
}
QVERIFY(QFile::link("file.txt", "tmp/link.txt"));
fileNames << "link.txt";
QVERIFY(JlCompress::compressDir("symlink.zip", "tmp"));
QDir curDir;
QVERIFY(curDir.mkpath("extsymlink"));
QVERIFY(!JlCompress::extractDir("symlink.zip", "extsymlink").isEmpty());
QFileInfo linkInfo("extsymlink/link.txt");
QVERIFY(quazip_is_symlink(linkInfo));
removeTestFiles(fileNames, "extsymlink");
removeTestFiles(fileNames, "tmp");
curDir.remove("symlink.zip");
}
#endif
#ifdef QUAZIP_SYMLINK_EXTRACTION_ON_WINDOWS_TEST
void TestJlCompress::symlinkExtractionOnWindows()
{
QuaZip zipWithSymlinks("withSymlinks.zip");
QVERIFY(zipWithSymlinks.open(QuaZip::mdCreate));
QuaZipFile file(&zipWithSymlinks);
QVERIFY(file.open(QIODevice::WriteOnly, QuaZipNewInfo("file.txt")));
file.write("contents");
file.close();
QuaZipNewInfo symlinkInfo("symlink.txt");
symlinkInfo.externalAttr |= 0120000 << 16; // symlink attr
QuaZipFile symlink(&zipWithSymlinks);
QVERIFY(symlink.open(QIODevice::WriteOnly, symlinkInfo));
symlink.write("file.txt"); // link target goes into contents
symlink.close();
zipWithSymlinks.close();
QCOMPARE(zipWithSymlinks.getZipError(), ZIP_OK);
// The best we can do here is to test that extraction works at all,
// because it's hard to say what should be the “correct” result when
// trying to extract symbolic links on Windows.
QVERIFY(!JlCompress::extractDir("withSymlinks.zip", "symlinksOnWindows").isEmpty());
QDir curDir;
curDir.remove("withSymlinks.zip");
removeTestFiles(QStringList() << "file.txt" << "symlink.txt", "symlinksOnWindows");
}
#endif

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,15 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QObject> #include <QtCore/QObject>
#ifdef Q_OS_UNIX
#define QUAZIP_SYMLINK_TEST
#endif
#ifdef Q_OS_WIN
#define QUAZIP_SYMLINK_EXTRACTION_ON_WINDOWS_TEST
#endif
class TestJlCompress: public QObject { class TestJlCompress: public QObject {
Q_OBJECT Q_OBJECT
@ -43,6 +51,12 @@ private slots:
void extractDir_data(); void extractDir_data();
void extractDir(); void extractDir();
void zeroPermissions(); void zeroPermissions();
#ifdef QUAZIP_SYMLINK_TEST
void symlinkHandling();
#endif
#ifdef QUAZIP_SYMLINK_EXTRACTION_ON_WINDOWS_TEST
void symlinkExtractionOnWindows();
#endif
}; };
#endif // QUAZIP_TEST_JLCOMPRESS_H #endif // QUAZIP_TEST_JLCOMPRESS_H

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -24,8 +24,8 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "testquachecksum32.h" #include "testquachecksum32.h"
#include <quazip/quaadler32.h> #include <quaadler32.h>
#include <quazip/quacrc32.h> #include <quacrc32.h>
#include <QtTest/QtTest> #include <QtTest/QtTest>

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QObject> #include <QtCore/QObject>
class TestQuaChecksum32: public QObject { class TestQuaChecksum32: public QObject {
Q_OBJECT Q_OBJECT

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -24,8 +24,8 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "testquagzipfile.h" #include "testquagzipfile.h"
#include <zlib.h> #include <zlib.h>
#include <QDir> #include <QtCore/QDir>
#include <quazip/quagzipfile.h> #include <quagzipfile.h>
#include <QtTest/QtTest> #include <QtTest/QtTest>
void TestQuaGzipFile::read() void TestQuaGzipFile::read()

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QObject> #include <QtCore/QObject>
class TestQuaGzipFile: public QObject { class TestQuaGzipFile: public QObject {
Q_OBJECT Q_OBJECT

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -23,9 +23,9 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include "testquaziodevice.h" #include "testquaziodevice.h"
#include <quazip/quaziodevice.h> #include <quaziodevice.h>
#include <QBuffer> #include <QtCore/QBuffer>
#include <QByteArray> #include <QtCore/QByteArray>
#include <QtTest/QtTest> #include <QtTest/QtTest>
void TestQuaZIODevice::read() void TestQuaZIODevice::read()

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QObject> #include <QtCore/QObject>
class TestQuaZIODevice: public QObject { class TestQuaZIODevice: public QObject {
Q_OBJECT Q_OBJECT

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -26,21 +26,21 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "qztest.h" #include "qztest.h"
#include <QDataStream> #include <QtCore/QDataStream>
#include <QDir> #include <QtCore/QDir>
#include <QFileInfo> #include <QtCore/QFileInfo>
#include <QHash> #include <QtCore/QHash>
#ifdef QUAZIP_TEST_QSAVEFILE #ifdef QUAZIP_TEST_QSAVEFILE
#include <QSaveFile> #include <QtCore/QSaveFile>
#endif #endif
#include <QTcpServer> #include <QtNetwork/QTcpServer>
#include <QTcpSocket> #include <QtNetwork/QTcpSocket>
#include <QTextCodec> #include <quazip_qt_compat.h>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <quazip/quazip.h> #include <quazip.h>
#include <quazip/JlCompress.h> #include <JlCompress.h>
void TestQuaZip::getFileList_data() void TestQuaZip::getFileList_data()
{ {
@ -234,6 +234,8 @@ void TestQuaZip::setOsCode()
QuaZipFileInfo64 fi; QuaZipFileInfo64 fi;
QVERIFY(checkZip.getCurrentFileInfo(&fi)); QVERIFY(checkZip.getCurrentFileInfo(&fi));
QCOMPARE(static_cast<uint>(fi.versionCreated) >> 8, osCode); QCOMPARE(static_cast<uint>(fi.versionCreated) >> 8, osCode);
checkZip.close();
QDir().remove(zipName);
} }
void TestQuaZip::setDataDescriptorWritingEnabled() void TestQuaZip::setDataDescriptorWritingEnabled()

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QObject> #include <QtCore/QObject>
#if (QT_VERSION >= 0x050100) #if (QT_VERSION >= 0x050100)
#define QUAZIP_TEST_QSAVEFILE #define QUAZIP_TEST_QSAVEFILE

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,8 +25,8 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "testquazipdir.h" #include "testquazipdir.h"
#include "qztest.h" #include "qztest.h"
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <quazip/quazip.h> #include <quazip.h>
#include <quazip/quazipdir.h> #include <quazipdir.h>
void TestQuaZipDir::entryList_data() void TestQuaZipDir::entryList_data()
{ {

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,7 +25,7 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QObject> #include <QtCore/QObject>
class TestQuaZipDir: public QObject { class TestQuaZipDir: public QObject {
Q_OBJECT Q_OBJECT

View File

@ -1,20 +1,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -26,13 +26,14 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license.
#include "qztest.h" #include "qztest.h"
#include <quazip/JlCompress.h> #include <JlCompress.h>
#include <quazip/quazipfile.h> #include <quazipfile.h>
#include <quazip/quazip.h> #include <quazip.h>
#include <quazip_qt_compat.h>
#include <QFile> #include <QtCore/QFile>
#include <QString> #include <QtCore/QString>
#include <QStringList> #include <QtCore/QStringList>
#include <QtTest/QtTest> #include <QtTest/QtTest>
@ -307,11 +308,11 @@ void TestQuaZipFile::posWrite()
QCOMPARE(zipFile.pos(), (qint64) 1); QCOMPARE(zipFile.pos(), (qint64) 1);
QByteArray buffer(size / 2 - 1, '\0'); QByteArray buffer(size / 2 - 1, '\0');
for (int i = 0; i < buffer.size(); ++i) for (int i = 0; i < buffer.size(); ++i)
buffer[i] = static_cast<char>(qrand()); buffer[i] = static_cast<char>(i);
zipFile.write(buffer); zipFile.write(buffer);
QCOMPARE(zipFile.pos(), qint64(size / 2)); QCOMPARE(zipFile.pos(), qint64(size / 2));
for (int i = 0; i < size - size / 2; ++i) { for (int i = 0; i < size - size / 2; ++i) {
zipFile.putChar(static_cast<char>(qrand())); zipFile.putChar(static_cast<char>(i));
} }
QCOMPARE(zipFile.pos(), qint64(size)); QCOMPARE(zipFile.pos(), qint64(size));
} }
@ -466,9 +467,8 @@ void TestQuaZipFile::setFileAttrs()
QFile::WriteOther | QFile::ReadOther | QFile::ExeOther; QFile::WriteOther | QFile::ReadOther | QFile::ExeOther;
QCOMPARE(info.getPermissions() & usedPermissions, QCOMPARE(info.getPermissions() & usedPermissions,
srcInfo.permissions() & usedPermissions); srcInfo.permissions() & usedPermissions);
// I really hope Qt 6 will use quint64 for time_t! qint64 newTime = quazip_to_time64_t(info.dateTime);
quint64 newTime = info.dateTime.toTime_t(); qint64 oldTime = quazip_to_time64_t(srcInfo.lastModified());
quint64 oldTime = srcInfo.lastModified().toTime_t();
// ZIP uses weird format with 2 second precision // ZIP uses weird format with 2 second precision
QCOMPARE(newTime / 2, oldTime / 2); QCOMPARE(newTime / 2, oldTime / 2);
readFileAttrs.close(); readFileAttrs.close();

View File

@ -4,20 +4,20 @@
/* /*
Copyright (C) 2005-2014 Sergey A. Tachenov Copyright (C) 2005-2014 Sergey A. Tachenov
This file is part of QuaZIP test suite. This file is part of QuaZip test suite.
QuaZIP is free software: you can redistribute it and/or modify QuaZip is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version. (at your option) any later version.
QuaZIP is distributed in the hope that it will be useful, QuaZip is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details. GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
See COPYING file for the full LGPL text. See COPYING file for the full LGPL text.
@ -25,8 +25,8 @@ Original ZIP package is copyrighted by Gilles Vollant and contributors,
see quazip/(un)zip.h files for details. Basically it's the zlib license. see quazip/(un)zip.h files for details. Basically it's the zlib license.
*/ */
#include <QObject> #include <QtCore/QObject>
#include <QStringList> #include <QtCore/QStringList>
class TestQuaZipFile: public QObject { class TestQuaZipFile: public QObject {
Q_OBJECT Q_OBJECT

View File

@ -2,16 +2,23 @@
#include "qztest.h" #include "qztest.h"
#include <QByteArray> #include <QtCore/QByteArray>
#include <QDir> #include <QtCore/QDir>
#include <QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QPair>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include "quazip/quazip.h" #include <quazip.h>
#include "quazip/quazipfile.h" #include <quazipfile.h>
#include "quazip/quazipfileinfo.h" #include <quazipfileinfo.h>
#include "quazip/quazipnewinfo.h" #include <quazipnewinfo.h>
#include <quazip_qt_compat.h>
#if QT_VERSION < 0x050000
Q_DECLARE_METATYPE(QList<qint32>);
Q_DECLARE_METATYPE(QuaExtraFieldHash);
#endif
TestQuaZipFileInfo::TestQuaZipFileInfo(QObject *parent) : TestQuaZipFileInfo::TestQuaZipFileInfo(QObject *parent) :
QObject(parent) QObject(parent)
@ -20,7 +27,10 @@ TestQuaZipFileInfo::TestQuaZipFileInfo(QObject *parent) :
void TestQuaZipFileInfo::getNTFSTime() void TestQuaZipFileInfo::getNTFSTime()
{ {
QString zipName = "newtimes.zip"; QFETCH(QString, zipName);
QFETCH(bool, useMTime);
QFETCH(bool, useATime);
QFETCH(bool, useCTime);
QStringList testFiles; QStringList testFiles;
testFiles << "test.txt"; testFiles << "test.txt";
QDir curDir; QDir curDir;
@ -41,11 +51,7 @@ void TestQuaZipFileInfo::getNTFSTime()
QuaZipFile zipFile(&zip); QuaZipFile zipFile(&zip);
QDateTime lm = fileInfo.lastModified().toUTC(); QDateTime lm = fileInfo.lastModified().toUTC();
QDateTime lr = fileInfo.lastRead().toUTC(); QDateTime lr = fileInfo.lastRead().toUTC();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) QDateTime cr = quazip_ctime(fileInfo).toUTC();
QDateTime cr = fileInfo.birthTime();
#else
QDateTime cr = fileInfo.created();
#endif
mTicks = (static_cast<qint64>(base.date().daysTo(lm.date())) mTicks = (static_cast<qint64>(base.date().daysTo(lm.date()))
* Q_UINT64_C(86400000) * Q_UINT64_C(86400000)
+ static_cast<qint64>(base.time().msecsTo(lm.time()))) + static_cast<qint64>(base.time().msecsTo(lm.time())))
@ -72,11 +78,11 @@ void TestQuaZipFileInfo::getNTFSTime()
for (int i = 12; i < 36; i += 8) { for (int i = 12; i < 36; i += 8) {
quint64 ticks; quint64 ticks;
if (i == 12) { if (i == 12) {
ticks = mTicks; ticks = useMTime ? mTicks : 0;
} else if (i == 20) { } else if (i == 20) {
ticks = aTicks; ticks = useATime ? aTicks : 0;
} else if (i == 28) { } else if (i == 28) {
ticks = cTicks; ticks = useCTime ? cTicks : 0;
} else { } else {
QFAIL("Stupid programming bug here"); QFAIL("Stupid programming bug here");
} }
@ -103,14 +109,232 @@ void TestQuaZipFileInfo::getNTFSTime()
QuaZipFileInfo64 zipFileInfo; QuaZipFileInfo64 zipFileInfo;
QVERIFY(zip.getCurrentFileInfo(&zipFileInfo)); QVERIFY(zip.getCurrentFileInfo(&zipFileInfo));
zip.close(); zip.close();
QCOMPARE(zipFileInfo.getNTFSmTime(), fileInfo.lastModified()); QCOMPARE(zipFileInfo.getNTFSmTime(), useMTime ? fileInfo.lastModified() : QDateTime());
QCOMPARE(zipFileInfo.getNTFSaTime(), fileInfo.lastRead()); QCOMPARE(zipFileInfo.getNTFSaTime(), useATime ? fileInfo.lastRead() : QDateTime());
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) QCOMPARE(zipFileInfo.getNTFScTime(), useCTime ? quazip_ctime(fileInfo) : QDateTime());
QCOMPARE(zipFileInfo.getNTFScTime(), fileInfo.birthTime());
#else
QCOMPARE(zipFileInfo.getNTFScTime(), fileInfo.created());
#endif
} }
removeTestFiles(testFiles); removeTestFiles(testFiles);
curDir.remove(zipName); curDir.remove(zipName);
} }
void TestQuaZipFileInfo::getNTFSTime_data()
{
QTest::addColumn<QString>("zipName");
QTest::addColumn<bool>("useMTime");
QTest::addColumn<bool>("useATime");
QTest::addColumn<bool>("useCTime");
QTest::newRow("no times") << QString::fromUtf8("noTimes") << false << false << false;
QTest::newRow("all times") << QString::fromUtf8("allTimes") << true << true << true;
QTest::newRow("no CTime") << QString::fromUtf8("noCTime") << true << true << false;
}
void TestQuaZipFileInfo::getExtTime_data()
{
QTest::addColumn<QString>("zipName");
QTest::addColumn<quint8>("flags");
QTest::addColumn<quint16>("sizeLocal");
QTest::addColumn< QList<qint32> >("timesLocal");
QTest::addColumn<quint16>("sizeGlobal");
QTest::addColumn< QList<qint32> >("timesGlobal");
QTest::addColumn<QDateTime>("expectedModTime");
QTest::addColumn<QDateTime>("expectedAcTime");
QTest::addColumn<QDateTime>("expectedCrTime");
QTest::newRow("no times") << QString::fromUtf8("noTimes")
<< quint8(0)
<< quint16(1)
<< QList<qint32>()
<< quint16(1)
<< QList<qint32>()
<< QDateTime()
<< QDateTime()
<< QDateTime();
QTest::newRow("all times") << QString::fromUtf8("allTimes")
<< quint8(7)
<< quint16(13)
<< (QList<qint32>() << 1 << 2 << 3)
<< quint16(5)
<< (QList<qint32>() << 1)
<< QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), Qt::UTC)
<< QDateTime(QDate(1970, 1, 1), QTime(0, 0, 2), Qt::UTC)
<< QDateTime(QDate(1970, 1, 1), QTime(0, 0, 3), Qt::UTC);
QTest::newRow("no ac time") << QString::fromUtf8("noAcTime")
<< quint8(5)
<< quint16(9)
<< (QList<qint32>() << 1 << 3)
<< quint16(5)
<< (QList<qint32>() << 1)
<< QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), Qt::UTC)
<< QDateTime()
<< QDateTime(QDate(1970, 1, 1), QTime(0, 0, 3), Qt::UTC);
QTest::newRow("negativeTime") << QString::fromUtf8("negativeTime")
<< quint8(1)
<< quint16(5)
<< (QList<qint32>() << -1)
<< quint16(5)
<< (QList<qint32>() << -1)
<< QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), Qt::UTC)
<< QDateTime()
<< QDateTime();
}
static QByteArray makeExtTimeField(quint16 size, quint8 flags, const QList<qint32> &times)
{
if (size == 0)
return QByteArray();
const quint16 EXT_TIME_MAGIC = 0x5455;
QBuffer buffer;
buffer.open(QBuffer::WriteOnly);
QDataStream localStream(&buffer);
localStream.setByteOrder(QDataStream::LittleEndian);
localStream << EXT_TIME_MAGIC;
localStream << size;
localStream << flags;
Q_FOREACH(qint32 time, times) {
localStream << time;
}
return buffer.buffer();
}
void TestQuaZipFileInfo::getExtTime()
{
QFETCH(QString, zipName);
QFETCH(quint8, flags);
QFETCH(quint16, sizeLocal);
QFETCH(QList<qint32>, timesLocal);
QFETCH(quint16, sizeGlobal);
QFETCH(QList<qint32>, timesGlobal);
QFETCH(QDateTime, expectedModTime);
QFETCH(QDateTime, expectedAcTime);
QFETCH(QDateTime, expectedCrTime);
QStringList fileNames;
QString fileName = QString::fromLatin1("aFile.txt");
fileNames << fileName;
{
createTestFiles(fileNames);
QuaZip testZip("tmp/" + zipName);
testZip.open(QuaZip::mdCreate);
QuaZipFile file(&testZip);
QuaZipNewInfo newInfo(fileName, "tmp/" + fileName);
newInfo.extraLocal = makeExtTimeField(sizeLocal, flags, timesLocal);
newInfo.extraGlobal = makeExtTimeField(sizeGlobal, flags, timesGlobal);
file.open(QIODevice::WriteOnly, newInfo);
file.close();
testZip.close();
}
removeTestFiles(fileNames);
QuaZip zip("tmp/" + zipName);
QVERIFY(zip.open(QuaZip::mdUnzip));
QVERIFY(zip.goToFirstFile());
QuaZipFileInfo64 fileInfo;
QVERIFY(zip.getCurrentFileInfo(&fileInfo));
QuaZipFile zipFile(&zip);
QVERIFY(zipFile.open(QIODevice::ReadOnly));
QDateTime actualGlobalModTime = fileInfo.getExtModTime();
QDateTime actualLocalModTime = zipFile.getExtModTime();
QDateTime actualLocalAcTime = zipFile.getExtAcTime();
QDateTime actualLocalCrTime = zipFile.getExtCrTime();
zipFile.close();
QCOMPARE(actualGlobalModTime, expectedModTime);
QCOMPARE(actualLocalModTime, expectedModTime);
QCOMPARE(actualLocalAcTime, expectedAcTime);
QCOMPARE(actualLocalCrTime, expectedCrTime);
zip.close();
QDir("tmp").remove(zipName);
}
void TestQuaZipFileInfo::getExtTime_issue43()
{
// Test original GitHub issue, just in case.
// (The test above relies on manual ZIP generation, which isn't perfect.)
QuaZip zip(":/test_files/issue43_cant_get_dates.zip");
QVERIFY(zip.open(QuaZip::mdUnzip));
zip.goToFirstFile();
QuaZipFileInfo64 zipFileInfo;
QVERIFY(zip.getCurrentFileInfo(&zipFileInfo));
zip.goToFirstFile();
QuaZipFile zipFile(&zip);
QVERIFY(zipFile.open(QIODevice::ReadOnly));
QDateTime actualGlobalModTime = zipFileInfo.getExtModTime();
QDateTime actualLocalModTime = zipFile.getExtModTime();
QDateTime actualLocalAcTime = zipFile.getExtAcTime();
QDateTime actualLocalCrTime = zipFile.getExtCrTime();
zip.close();
QDateTime extModTime(QDate(2019, 7, 2), QTime(15, 43, 47), Qt::UTC);
QDateTime extAcTime = extModTime;
QDateTime extCrTime = extModTime;
QCOMPARE(actualGlobalModTime, extModTime);
QCOMPARE(actualLocalModTime, extModTime);
QCOMPARE(actualLocalAcTime, extAcTime);
QCOMPARE(actualLocalCrTime, extCrTime);
}
void TestQuaZipFileInfo::parseExtraField_data()
{
QTest::addColumn<QByteArray>("extraField");
QTest::addColumn<QuaExtraFieldHash>("expected");
QTest::newRow("empty")
<< QByteArray()
<< QuaExtraFieldHash();
{
QuaExtraFieldHash oneZeroIdWithNoData;
oneZeroIdWithNoData[0] = QList<QByteArray>() << QByteArray();
QTest::newRow("one zero ID with no data")
<< QByteArray("\x00\x00\x00\x00", 4)
<< oneZeroIdWithNoData;
}
{
QuaExtraFieldHash oneZeroIdWithData;
oneZeroIdWithData[0] = QList<QByteArray>() << QByteArray("DATA", 4);
QTest::newRow("one zero ID with data")
<< QByteArray("\x00\x00\x04\x00" "DATA", 8)
<< oneZeroIdWithData;
}
{
QuaExtraFieldHash oneNonZeroIdWithData;
oneNonZeroIdWithData[1] = QList<QByteArray>() << QByteArray("DATA", 4);
QTest::newRow("one non zero ID with data")
<< QByteArray("\x01\x00\x04\x00" "DATA", 8)
<< oneNonZeroIdWithData;
}
{
QuaExtraFieldHash severalDifferentIDs;
severalDifferentIDs[0] = QList<QByteArray>() << QByteArray("DATA0", 5);
severalDifferentIDs[1] = QList<QByteArray>() << QByteArray("DATA1", 5);
QTest::newRow("two IDs")
<< QByteArray("\x00\x00\x05\x00" "DATA0" "\x01\x00\x05\x00" "DATA1", 18)
<< severalDifferentIDs;
}
{
QuaExtraFieldHash repeatedID;
repeatedID[0] = QList<QByteArray>() << QByteArray("DATA0", 5) << QByteArray("DATA1", 5);
QTest::newRow("repeated ID")
<< QByteArray("\x00\x00\x05\x00" "DATA0" "\x00\x00\x05\x00" "DATA1", 18)
<< repeatedID;
}
{
QuaExtraFieldHash largeID;
largeID[0x0102] = QList<QByteArray>() << QByteArray("DATA", 4);
QTest::newRow("large ID")
<< QByteArray("\x02\x01\x04\x00" "DATA", 8)
<< largeID;
}
{
QuaExtraFieldHash largeData;
largeData[0] = QList<QByteArray>() << QByteArray(65535, 'x');
QTest::newRow("large ID")
<< (QByteArray("\x00\x00\xff\xff", 4) + QByteArray(65535, 'x'))
<< largeData;
}
QTest::newRow("only 1 byte") << QByteArray("\x00", 1) << QuaExtraFieldHash();
QTest::newRow("only 2 bytes") << QByteArray("\x00\x00", 2) << QuaExtraFieldHash();
QTest::newRow("only 3 bytes") << QByteArray("\x00\x00\x00", 3) << QuaExtraFieldHash();
QTest::newRow("truncated data") << QByteArray("\x00\x00\x02\x00\x00", 5) << QuaExtraFieldHash();
}
void TestQuaZipFileInfo::parseExtraField()
{
QFETCH(QByteArray, extraField);
QFETCH(QuaExtraFieldHash, expected);
QuaExtraFieldHash actual = QuaZipFileInfo64::parseExtraField(extraField);
QCOMPARE(actual, expected);
}

View File

@ -1,7 +1,7 @@
#ifndef TESTQUAZIPFILEINFO_H #ifndef TESTQUAZIPFILEINFO_H
#define TESTQUAZIPFILEINFO_H #define TESTQUAZIPFILEINFO_H
#include <QObject> #include <QtCore/QObject>
class TestQuaZipFileInfo : public QObject class TestQuaZipFileInfo : public QObject
{ {
@ -9,7 +9,13 @@ class TestQuaZipFileInfo : public QObject
public: public:
explicit TestQuaZipFileInfo(QObject *parent = 0); explicit TestQuaZipFileInfo(QObject *parent = 0);
private slots: private slots:
void getNTFSTime_data();
void getNTFSTime(); void getNTFSTime();
void getExtTime_data();
void getExtTime();
void getExtTime_issue43();
void parseExtraField_data();
void parseExtraField();
}; };
#endif // TESTQUAZIPFILEINFO_H #endif // TESTQUAZIPFILEINFO_H

View File

@ -2,14 +2,15 @@
#include "qztest.h" #include "qztest.h"
#include <QDir> #include <QtCore/QDir>
#include <QFileInfo> #include <QtCore/QFileInfo>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <quazip/quazip.h> #include <quazip.h>
#include <quazip/quazipfile.h> #include <quazipfile.h>
#include <quazip/quazipnewinfo.h> #include <quazipnewinfo.h>
#include <quazip/quazipfileinfo.h> #include <quazipfileinfo.h>
#include <quazip_qt_compat.h>
TestQuaZipNewInfo::TestQuaZipNewInfo(QObject *parent) : TestQuaZipNewInfo::TestQuaZipNewInfo(QObject *parent) :
QObject(parent) QObject(parent)
@ -39,11 +40,7 @@ void TestQuaZipNewInfo::setFileNTFSTimes()
QFileInfo fileInfo("tmp/test.txt"); QFileInfo fileInfo("tmp/test.txt");
QDateTime lm = fileInfo.lastModified().toUTC(); QDateTime lm = fileInfo.lastModified().toUTC();
QDateTime lr = fileInfo.lastRead().toUTC(); QDateTime lr = fileInfo.lastRead().toUTC();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) QDateTime cr = quazip_ctime(fileInfo).toUTC();
QDateTime cr = fileInfo.birthTime();
#else
QDateTime cr = fileInfo.created();
#endif
mTicks = (static_cast<qint64>(base.date().daysTo(lm.date())) mTicks = (static_cast<qint64>(base.date().daysTo(lm.date()))
* Q_UINT64_C(86400000) * Q_UINT64_C(86400000)
+ static_cast<qint64>(base.time().msecsTo(lm.time()))) + static_cast<qint64>(base.time().msecsTo(lm.time())))

View File

@ -1,7 +1,7 @@
#ifndef TESTQUAZIPNEWINFO_H #ifndef TESTQUAZIPNEWINFO_H
#define TESTQUAZIPNEWINFO_H #define TESTQUAZIPNEWINFO_H
#include <QObject> #include <QtCore/QObject>
class TestQuaZipNewInfo : public QObject class TestQuaZipNewInfo : public QObject
{ {