Merge submodule contents for hecl-gui/master
|
@ -0,0 +1,67 @@
|
|||
#include "ArgumentEditor.hpp"
|
||||
#include "ui_ArgumentEditor.h"
|
||||
//#include "CVarDialog.hpp"
|
||||
#include <QSettings>
|
||||
#include <QInputDialog>
|
||||
#include <QDebug>
|
||||
|
||||
ArgumentEditor::ArgumentEditor(QWidget* parent) : QDialog(parent), m_ui(std::make_unique<Ui::ArgumentEditor>()) {
|
||||
m_ui->setupUi(this);
|
||||
m_model.setStringList(QSettings().value(QStringLiteral("urde_arguments")).toStringList());
|
||||
m_ui->argumentEditor->setModel(&m_model);
|
||||
}
|
||||
|
||||
ArgumentEditor::~ArgumentEditor() = default;
|
||||
|
||||
void ArgumentEditor::on_addButton_clicked() {
|
||||
QInputDialog input(this);
|
||||
int code = input.exec();
|
||||
if (code == DialogCode::Accepted) {
|
||||
QStringList list = m_model.stringList();
|
||||
list << input.textValue();
|
||||
m_model.setStringList(list);
|
||||
}
|
||||
}
|
||||
|
||||
void ArgumentEditor::on_addCvarButton_clicked() {
|
||||
CVarDialog input(this);
|
||||
int code = input.exec();
|
||||
if (code == DialogCode::Accepted) {
|
||||
QStringList list = m_model.stringList();
|
||||
list << input.textValue();
|
||||
m_model.setStringList(list);
|
||||
}
|
||||
}
|
||||
|
||||
void ArgumentEditor::on_editButton_clicked() {
|
||||
QModelIndex index = m_ui->argumentEditor->currentIndex();
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QInputDialog input(this);
|
||||
input.setTextValue(m_model.stringList().value(index.row()));
|
||||
int code = input.exec();
|
||||
if (code == DialogCode::Accepted) {
|
||||
QStringList list = m_model.stringList();
|
||||
list[index.row()] = input.textValue();
|
||||
m_model.setStringList(list);
|
||||
}
|
||||
}
|
||||
|
||||
void ArgumentEditor::on_deleteButton_clicked() {
|
||||
QModelIndex index = m_ui->argumentEditor->currentIndex();
|
||||
if (index.isValid()) {
|
||||
m_model.removeRows(index.row(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
void ArgumentEditor::on_buttonBox_clicked(QAbstractButton* button) {
|
||||
auto* buttonBox = qobject_cast<QDialogButtonBox*>(sender());
|
||||
if (button == buttonBox->button(QDialogButtonBox::Ok)) {
|
||||
QSettings().setValue(QStringLiteral("urde_arguments"), m_model.stringList());
|
||||
accept();
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QDialog>
|
||||
#include <QStringListModel>
|
||||
|
||||
class QAbstractButton;
|
||||
|
||||
namespace Ui {
|
||||
class ArgumentEditor;
|
||||
} // namespace Ui
|
||||
|
||||
class ArgumentEditor : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
std::unique_ptr<Ui::ArgumentEditor> m_ui;
|
||||
QStringListModel m_model;
|
||||
|
||||
public:
|
||||
explicit ArgumentEditor(QWidget* parent = nullptr);
|
||||
~ArgumentEditor() override;
|
||||
|
||||
private slots:
|
||||
void on_addButton_clicked();
|
||||
void on_addCvarButton_clicked();
|
||||
void on_editButton_clicked();
|
||||
void on_deleteButton_clicked();
|
||||
void on_buttonBox_clicked(QAbstractButton*);
|
||||
};
|
|
@ -0,0 +1,75 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ArgumentEditor</class>
|
||||
<widget class="QDialog" name="ArgumentEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>613</width>
|
||||
<height>525</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Argument Editor</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" rowspan="5">
|
||||
<widget class="QListView" name="argumentEditor"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="addButton">
|
||||
<property name="text">
|
||||
<string>&Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="addCvarButton">
|
||||
<property name="text">
|
||||
<string>Add &CVar</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="editButton">
|
||||
<property name="text">
|
||||
<string>&Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QPushButton" name="deleteButton">
|
||||
<property name="text">
|
||||
<string>&Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,173 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
|
||||
if (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
|
||||
set(QT_HOMEBREW_PATH /usr/local/opt/qt)
|
||||
elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
|
||||
set(QT_HOMEBREW_PATH /opt/homebrew/opt/qt)
|
||||
else ()
|
||||
set(QT_HOMEBREW_PATH "")
|
||||
endif ()
|
||||
|
||||
find_package(Qt6Widgets QUIET PATHS ${QT_HOMEBREW_PATH})
|
||||
if (Qt6Widgets_FOUND)
|
||||
find_package(Qt6 COMPONENTS Core5Compat Network Widgets Xml Gui REQUIRED PATHS ${QT_HOMEBREW_PATH})
|
||||
set(QUAZIP_QT_MAJOR_VERSION 6 CACHE STRING "")
|
||||
else ()
|
||||
find_package(Qt5Widgets REQUIRED PATHS ${QT_HOMEBREW_PATH})
|
||||
find_package(Qt5 COMPONENTS Network Widgets Xml Gui REQUIRED PATHS ${QT_HOMEBREW_PATH})
|
||||
set(QUAZIP_QT_MAJOR_VERSION 5 CACHE STRING "")
|
||||
endif ()
|
||||
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
|
||||
set(QUAZIP_INSTALL OFF CACHE BOOL "")
|
||||
add_subdirectory(quazip)
|
||||
|
||||
add_executable(hecl-gui WIN32 MACOSX_BUNDLE
|
||||
#ArgumentEditor.cpp
|
||||
#ArgumentEditor.hpp
|
||||
#ArgumentEditor.ui
|
||||
Common.cpp
|
||||
Common.hpp
|
||||
#CVarDialog.cpp
|
||||
#CVarDialog.hpp
|
||||
#CVarDialog.ui
|
||||
DownloadManager.cpp
|
||||
DownloadManager.hpp
|
||||
ErrorLabel.hpp
|
||||
EscapeSequenceParser.cpp
|
||||
EscapeSequenceParser.hpp
|
||||
ExtractZip.cpp
|
||||
ExtractZip.hpp
|
||||
FileDirDialog.hpp
|
||||
FindBlender.cpp
|
||||
FindBlender.hpp
|
||||
MainWindow.cpp
|
||||
MainWindow.hpp
|
||||
MainWindow.ui
|
||||
LayerDialog.cpp
|
||||
LayerDialog.hpp
|
||||
LayerDialog.ui
|
||||
SysReqTableView.cpp
|
||||
SysReqTableView.hpp
|
||||
|
||||
main.cpp
|
||||
|
||||
${QUAZIP_SRCS}
|
||||
)
|
||||
|
||||
target_compile_definitions(hecl-gui PRIVATE
|
||||
# Disable implicit conversions from ASCII to QString.
|
||||
-DQT_NO_CAST_FROM_ASCII
|
||||
-DQT_NO_CAST_TO_ASCII
|
||||
|
||||
# Disable implicit conversions of QByteArray to const char* or const void*
|
||||
-DQT_NO_CAST_FROM_BYTEARRAY
|
||||
|
||||
# Disable narrowing conversions in signal/slot connect() calls.
|
||||
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
|
||||
|
||||
# Disable unsafe overloads of QProcess' start() function.
|
||||
-DQT_NO_PROCESS_COMBINED_ARGUMENT_START
|
||||
|
||||
# Disable implicit QString->QUrl conversions to enforce use of proper resolving functions.
|
||||
-DQT_NO_URL_CAST_FROM_STRING
|
||||
|
||||
# Allows for more efficient string concatenation, resulting in less temporaries.
|
||||
-DQT_USE_QSTRINGBUILDER
|
||||
)
|
||||
|
||||
if (Qt6Widgets_FOUND)
|
||||
set(Qt_LIBS
|
||||
Qt6::Core
|
||||
Qt6::Core5Compat
|
||||
Qt6::Gui
|
||||
Qt6::Network
|
||||
Qt6::Widgets
|
||||
Qt6::Xml)
|
||||
else ()
|
||||
set(Qt_LIBS
|
||||
Qt5::Core
|
||||
Qt5::Gui
|
||||
Qt5::Network
|
||||
Qt5::Widgets
|
||||
Qt5::Xml)
|
||||
# Check for static linking
|
||||
if (WIN32)
|
||||
get_target_property(HECL_RUNTIME_LIBRARY hecl-gui MSVC_RUNTIME_LIBRARY)
|
||||
if (NOT "${HECL_RUNTIME_LIBRARY}" MATCHES "DLL$")
|
||||
list(APPEND Qt_LIBS Qt5::QWindowsIntegrationPlugin)
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
target_link_libraries(hecl-gui PRIVATE
|
||||
${Qt_LIBS}
|
||||
hecl-light
|
||||
zeus
|
||||
QuaZip::QuaZip)
|
||||
|
||||
target_include_directories(hecl-gui PRIVATE quazip/quazip)
|
||||
target_compile_definitions(hecl-gui PRIVATE QUAZIP_STATIC=1)
|
||||
|
||||
if (APPLE)
|
||||
target_sources(hecl-gui PRIVATE
|
||||
MacOSSystemVersion.hpp
|
||||
MacOSSystemVersion.mm
|
||||
)
|
||||
set_source_files_properties(MacOSSystemVersion.mm
|
||||
PROPERTIES COMPILE_FLAGS -fobjc-arc
|
||||
)
|
||||
find_library(FOUNDATION_LIBRARY Foundation)
|
||||
target_link_libraries(hecl-gui PRIVATE ${FOUNDATION_LIBRARY})
|
||||
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
|
||||
target_link_libraries(hecl-gui PRIVATE
|
||||
dl
|
||||
pthread
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (WIN32)
|
||||
target_sources(hecl-gui PRIVATE
|
||||
platforms/win/hecl-gui.manifest
|
||||
platforms/win/hecl-gui.rc
|
||||
)
|
||||
target_link_libraries(hecl-gui PRIVATE
|
||||
Version)
|
||||
elseif (APPLE)
|
||||
set_target_properties(hecl-gui PROPERTIES
|
||||
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/platforms/mac/Info.plist"
|
||||
)
|
||||
target_sources(hecl-gui PRIVATE platforms/mac/mainicon.icns)
|
||||
set_source_files_properties(platforms/mac/mainicon.icns PROPERTIES
|
||||
MACOSX_PACKAGE_LOCATION Resources
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET hecl-gui POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:urde> $<TARGET_FILE_DIR:hecl-gui>
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:hecl> $<TARGET_FILE_DIR:hecl-gui>
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:visigen> $<TARGET_FILE_DIR:hecl-gui>
|
||||
DEPENDS urde hecl visigen
|
||||
)
|
||||
if (NOT "${SENTRY_DSN}" STREQUAL "")
|
||||
add_custom_command(
|
||||
TARGET hecl-gui POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:crashpad_handler> $<TARGET_FILE_DIR:hecl-gui>
|
||||
DEPENDS crashpad_handler
|
||||
)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
add_subdirectory(platforms/freedesktop)
|
||||
declare_qticon_target()
|
||||
target_sources(hecl-gui PRIVATE mainicon_qt.cpp)
|
||||
|
||||
if (COMMAND add_sanitizers)
|
||||
add_sanitizers(hecl-gui)
|
||||
endif ()
|
||||
|
||||
if (NOT MSVC)
|
||||
target_compile_options(hecl-gui PRIVATE -Wno-misleading-indentation)
|
||||
endif ()
|
|
@ -0,0 +1,78 @@
|
|||
#include "CVarDialog.hpp"
|
||||
#include "ui_CVarDialog.h"
|
||||
#include <utility>
|
||||
|
||||
enum class CVarType {
|
||||
String,
|
||||
Boolean,
|
||||
};
|
||||
|
||||
struct CVarItem {
|
||||
QString m_name;
|
||||
CVarType m_type;
|
||||
QVariant m_defaultValue;
|
||||
|
||||
CVarItem(QString name, CVarType type, QVariant defaultValue)
|
||||
: m_name(std::move(name)), m_type(type), m_defaultValue(std::move(defaultValue)) {}
|
||||
};
|
||||
|
||||
static std::array cvarList{
|
||||
CVarItem{QStringLiteral("tweak.game.FieldOfView"), CVarType::String, 55},
|
||||
CVarItem{QStringLiteral("debugOverlay.playerInfo"), CVarType::Boolean, false},
|
||||
CVarItem{QStringLiteral("debugOverlay.areaInfo"), CVarType::Boolean, false},
|
||||
// TODO expand
|
||||
};
|
||||
|
||||
CVarDialog::CVarDialog(QWidget* parent) : QDialog(parent), m_ui(std::make_unique<Ui::CVarDialog>()) {
|
||||
m_ui->setupUi(this);
|
||||
QStringList list;
|
||||
for (const auto& item : cvarList) {
|
||||
list << item.m_name;
|
||||
}
|
||||
m_model.setStringList(list);
|
||||
m_ui->cvarList->setModel(&m_model);
|
||||
connect(m_ui->cvarList->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
|
||||
SLOT(handleSelectionChanged(QItemSelection)));
|
||||
}
|
||||
|
||||
CVarDialog::~CVarDialog() = default;
|
||||
|
||||
void CVarDialog::on_buttonBox_accepted() {
|
||||
const QModelIndexList& list = m_ui->cvarList->selectionModel()->selectedIndexes();
|
||||
if (list.isEmpty()) {
|
||||
reject();
|
||||
} else {
|
||||
accept();
|
||||
}
|
||||
}
|
||||
|
||||
void CVarDialog::on_buttonBox_rejected() { reject(); }
|
||||
|
||||
void CVarDialog::handleSelectionChanged(const QItemSelection& selection) {
|
||||
const QModelIndexList& list = selection.indexes();
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
const auto item = cvarList[(*list.begin()).row()];
|
||||
m_ui->valueStack->setCurrentIndex(static_cast<int>(item.m_type));
|
||||
if (item.m_type == CVarType::String) {
|
||||
m_ui->stringValueField->setText(item.m_defaultValue.toString());
|
||||
} else if (item.m_type == CVarType::Boolean) {
|
||||
m_ui->booleanValueField->setChecked(item.m_defaultValue.toBool());
|
||||
}
|
||||
}
|
||||
|
||||
QString CVarDialog::textValue() {
|
||||
const QModelIndexList& list = m_ui->cvarList->selectionModel()->selectedIndexes();
|
||||
if (list.isEmpty()) {
|
||||
return QStringLiteral("");
|
||||
}
|
||||
const auto item = cvarList[(*list.begin()).row()];
|
||||
QVariant value;
|
||||
if (item.m_type == CVarType::String) {
|
||||
value = m_ui->stringValueField->text();
|
||||
} else if (item.m_type == CVarType::Boolean) {
|
||||
value = m_ui->booleanValueField->isChecked();
|
||||
}
|
||||
return QStringLiteral("+") + item.m_name + QStringLiteral("=") + value.toString();
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QDialog>
|
||||
#include <QItemSelection>
|
||||
#include <QStringListModel>
|
||||
#include <memory>
|
||||
|
||||
namespace Ui {
|
||||
class CVarDialog;
|
||||
} // namespace Ui
|
||||
|
||||
class CVarDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CVarDialog(QWidget* parent = nullptr);
|
||||
~CVarDialog() override;
|
||||
|
||||
QString textValue();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::CVarDialog> m_ui;
|
||||
QStringListModel m_model;
|
||||
|
||||
private slots:
|
||||
void on_buttonBox_accepted();
|
||||
void on_buttonBox_rejected();
|
||||
void handleSelectionChanged(const QItemSelection& selection);
|
||||
};
|
|
@ -0,0 +1,139 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CVarDialog</class>
|
||||
<widget class="QDialog" name="CVarDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>613</width>
|
||||
<height>525</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Add CVar</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="5" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<spacer name="verticalSpacer2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" rowspan="6">
|
||||
<widget class="QListView" name="cvarList">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QStackedWidget" name="valueStack">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="stringPage">
|
||||
<layout class="QVBoxLayout" name="stringPageLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="stringLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="stringValueField">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="boolPage">
|
||||
<layout class="QVBoxLayout" name="boolPageLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="booleanValueField">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,192 @@
|
|||
#include "Common.hpp"
|
||||
#include <QStringList>
|
||||
#include <csignal>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if __APPLE__
|
||||
const QString CurPlatformString = QStringLiteral("macos");
|
||||
#elif _WIN32
|
||||
const QString CurPlatformString = QStringLiteral("win32");
|
||||
#elif __linux__
|
||||
const QString CurPlatformString = QStringLiteral("linux");
|
||||
#else
|
||||
#error HECL does not know which OS to fetch for
|
||||
#endif
|
||||
|
||||
QString PlatformToString(Platform plat) {
|
||||
switch (plat) {
|
||||
case Platform::MacOS:
|
||||
return QStringLiteral("macos");
|
||||
case Platform::Win32:
|
||||
return QStringLiteral("win32");
|
||||
case Platform::Linux:
|
||||
return QStringLiteral("linux");
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
Architecture CurArchitecture = Architecture::Invalid;
|
||||
QString CurArchitectureString;
|
||||
|
||||
Platform StringToPlatform(const QString& str) {
|
||||
for (int i = 1; i < int(Platform::MAXPlatform); ++i)
|
||||
if (!str.compare(PlatformToString(Platform(i)), Qt::CaseInsensitive))
|
||||
return Platform(i);
|
||||
return Platform::Invalid;
|
||||
}
|
||||
|
||||
QString ArchitectureToString(Architecture arch) {
|
||||
switch (arch) {
|
||||
case Architecture::X86:
|
||||
return QStringLiteral("x86");
|
||||
case Architecture::X86_64:
|
||||
return QStringLiteral("x86_64");
|
||||
case Architecture::ARM:
|
||||
return QStringLiteral("arm");
|
||||
case Architecture::ARM64:
|
||||
return QStringLiteral("arm64");
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
Architecture StringToArchitecture(const QString& str) {
|
||||
for (int i = 1; i < int(Architecture::MAXArchitecture); ++i)
|
||||
if (!str.compare(ArchitectureToString(Architecture(i)), Qt::CaseInsensitive))
|
||||
return Architecture(i);
|
||||
return Architecture::Invalid;
|
||||
}
|
||||
|
||||
QString VectorISAToString(VectorISA visa) {
|
||||
switch (visa) {
|
||||
case VectorISA::X87:
|
||||
return QStringLiteral("x87");
|
||||
case VectorISA::SSE:
|
||||
return QStringLiteral("sse");
|
||||
case VectorISA::SSE2:
|
||||
return QStringLiteral("sse2");
|
||||
case VectorISA::SSE3:
|
||||
return QStringLiteral("sse3");
|
||||
case VectorISA::SSE41:
|
||||
return QStringLiteral("sse41");
|
||||
case VectorISA::AVX:
|
||||
return QStringLiteral("avx");
|
||||
case VectorISA::AVX2:
|
||||
return QStringLiteral("avx2");
|
||||
case VectorISA::AVX512:
|
||||
return QStringLiteral("avx512");
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
VectorISA StringToVectorISA(const QString& str) {
|
||||
for (int i = 1; i < int(VectorISA::MAXVectorISA); ++i)
|
||||
if (!str.compare(VectorISAToString(VectorISA(i)), Qt::CaseInsensitive))
|
||||
return VectorISA(i);
|
||||
return VectorISA::Invalid;
|
||||
}
|
||||
|
||||
URDEVersion::URDEVersion(const QString& filename) {
|
||||
int idx;
|
||||
QString useFilename = filename;
|
||||
if ((idx = filename.lastIndexOf(QLatin1Char{'.'})) > filename.lastIndexOf(QLatin1Char{'-'})) {
|
||||
m_extension = QString(filename).remove(0, idx);
|
||||
useFilename.truncate(idx);
|
||||
}
|
||||
|
||||
const QStringList list = useFilename.split(QLatin1Char{'-'});
|
||||
enum {
|
||||
version,
|
||||
platform,
|
||||
architecture,
|
||||
vectorISA,
|
||||
extra
|
||||
} state = version;
|
||||
for (size_t i = 1; i < list.size(); ++i) {
|
||||
if (state == version) {
|
||||
if (m_version.isEmpty()) {
|
||||
m_version = list[i];
|
||||
continue;
|
||||
}
|
||||
bool ok;
|
||||
int patch = list[i].toInt(&ok);
|
||||
if (ok) {
|
||||
m_version += QLatin1Char('-') + QString::number(patch);
|
||||
continue;
|
||||
}
|
||||
state = platform;
|
||||
}
|
||||
if (state == platform) {
|
||||
if (list[i] == QStringLiteral("dirty")) {
|
||||
m_version += QLatin1Char{'-'} + list[i];
|
||||
continue;
|
||||
}
|
||||
state = architecture;
|
||||
Platform platValue = StringToPlatform(list[i]);
|
||||
if (platValue != Platform::Invalid) {
|
||||
m_platform = platValue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (state == architecture) {
|
||||
state = extra;
|
||||
Architecture archValue = StringToArchitecture(list[i]);
|
||||
if (archValue != Architecture::Invalid) {
|
||||
m_architecture = archValue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// if (state == vectorISA) {
|
||||
// state = extra;
|
||||
// VectorISA isa = StringToVectorISA(list[i]);
|
||||
// if (isa != VectorISA::Invalid) {
|
||||
// m_vectorISA = isa;
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
m_extra += QLatin1Char('-') + list[i];
|
||||
}
|
||||
}
|
||||
|
||||
QString URDEVersion::fileString(bool withExtension) const {
|
||||
if (m_version.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (withExtension && !m_extension.isEmpty()) {
|
||||
return QStringLiteral("urde-%1-%2-%3%4%5")
|
||||
.arg(m_version, PlatformToString(m_platform), ArchitectureToString(m_architecture), m_extra, m_extension);
|
||||
} else {
|
||||
return QStringLiteral("urde-%1-%2-%3%4")
|
||||
.arg(m_version, PlatformToString(m_platform), ArchitectureToString(m_architecture), m_extra);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
static void HUPHandler(int) {}
|
||||
#endif
|
||||
|
||||
void InitializePlatform() {
|
||||
#ifndef _WIN32
|
||||
/* This can happen when terminating hecl - do nothing */
|
||||
signal(SIGHUP, HUPHandler);
|
||||
#endif
|
||||
|
||||
#if ZEUS_ARCH_X86_64
|
||||
const_cast<Architecture&>(CurArchitecture) = Architecture::X86_64;
|
||||
#elif ZEUS_ARCH_X86
|
||||
#if !defined(__APPLE__) && !defined(_WIN32)
|
||||
const_cast<Architecture&>(CurArchitecture) = (sysconf(_SC_WORD_BIT) == 64 ? Architecture::X86_64 : Architecture::X86);
|
||||
#elif _WIN32
|
||||
bool isWOW = false;
|
||||
IsWow64Process(GetCurrentProcess(), &isWOW);
|
||||
const_cast<Architecture&>(CurArchitecture) = (isWOW ? Architecture::X86_64 : Architecture::X86);
|
||||
#endif
|
||||
#endif
|
||||
const_cast<QString&>(CurArchitectureString) = ArchitectureToString(CurArchitecture);
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QMetaType>
|
||||
#include "zeus/Math.hpp"
|
||||
|
||||
enum class Platform { Invalid, MacOS, Win32, Linux, MAXPlatform };
|
||||
QString PlatformToString(Platform plat);
|
||||
Platform StringToPlatform(const QString& str);
|
||||
|
||||
#if __APPLE__
|
||||
constexpr Platform CurPlatform = Platform::MacOS;
|
||||
#elif _WIN32
|
||||
constexpr Platform CurPlatform = Platform::Win32;
|
||||
#elif __linux__
|
||||
constexpr Platform CurPlatform = Platform::Linux;
|
||||
#endif
|
||||
|
||||
extern const QString CurPlatformString;
|
||||
|
||||
enum class Architecture { Invalid, X86, X86_64, ARM, ARM64, MAXArchitecture };
|
||||
QString ArchitectureToString(Architecture arch);
|
||||
Architecture StringToArchitecture(const QString& str);
|
||||
|
||||
extern Architecture CurArchitecture;
|
||||
extern QString CurArchitectureString;
|
||||
|
||||
enum class VectorISA { Invalid, X87, SSE, SSE2, SSE3, SSE41, AVX, AVX2, AVX512, MAXVectorISA };
|
||||
QString VectorISAToString(VectorISA visa);
|
||||
VectorISA StringToVectorISA(const QString& str);
|
||||
|
||||
class URDEVersion {
|
||||
QString m_version{};
|
||||
Platform m_platform = CurPlatform;
|
||||
Architecture m_architecture = CurArchitecture;
|
||||
VectorISA m_vectorISA = VectorISA::Invalid;
|
||||
QString m_extension{};
|
||||
QString m_extra{};
|
||||
|
||||
public:
|
||||
URDEVersion() = default;
|
||||
explicit URDEVersion(const QString& filename);
|
||||
bool isValid() const { return !m_version.isEmpty(); }
|
||||
QString fileString(bool withExtension) const;
|
||||
QString getVersion() const { return m_version; }
|
||||
Platform getPlatform() const { return m_platform; }
|
||||
Architecture getArchitecture() const { return m_architecture; }
|
||||
VectorISA getVectorISA() const { return m_vectorISA; }
|
||||
QString getExtra() const { return m_extra; }
|
||||
};
|
||||
Q_DECLARE_METATYPE(URDEVersion);
|
||||
|
||||
void InitializePlatform();
|
|
@ -0,0 +1,176 @@
|
|||
#include "DownloadManager.hpp"
|
||||
#include "Common.hpp"
|
||||
#include <quazip.h>
|
||||
|
||||
#include <QDesktopServices>
|
||||
|
||||
#define KEY_PINNING 0
|
||||
|
||||
#if KEY_PINNING
|
||||
static const char AxioDLPublicKeyPEM[] =
|
||||
"-----BEGIN PUBLIC KEY-----\n"
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvtshImzoP1a++9P5RK0k\n"
|
||||
"btTOpwie7O7S/wWFZxwwbMezEPhjw2uu86TPqJe3P/1v+6xRKrEf9zFn/sKNygvD\n"
|
||||
"bO64ZkJre4M46IYd0XxwIhiu7PBR+13CD+fqbrbYwPkoG090CP4MtZZN6mt5NAKB\n"
|
||||
"QHoIj0wV5K/jJE9cBQxViwOqrxK05Cl/ivy0gRtpL7Ot6S+QHL3++rb6U2hWydIQ\n"
|
||||
"kS+ucufKCIL77RcDwAc9vwNvzxf9EUU2pmq+EsEtLgRw3fR6BInoltOI8P9X5Wo6\n"
|
||||
"/skeg92xZA++vv0neq5gjjDfa2A1zDgJRysz3Xps/AMlLOe55XCzXse9BpvChT+Z\n"
|
||||
"pwIDAQAB\n"
|
||||
"-----END PUBLIC KEY-----\n";
|
||||
|
||||
static const QSslKey AxioDLPublicKey = QSslKey({AxioDLPublicKeyPEM}, QSsl::Rsa, QSsl::Pem, QSsl::PublicKey);
|
||||
|
||||
static const char AxioDLEdgePublicKeyPEM[] =
|
||||
"-----BEGIN PUBLIC KEY-----\n"
|
||||
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4a8ZLg3LRU0FiK6m8g2pT3qVBTMA\n"
|
||||
"K2Uu5VGl7iamdGpUjynQ4uYWMx+WXf2Qkh7UZZgYvA6UeWHEs3M6ME8T6g==\n"
|
||||
"-----END PUBLIC KEY-----\n";
|
||||
|
||||
static const QSslKey AxioDLEdgePublicKey = QSslKey({AxioDLEdgePublicKeyPEM}, QSsl::Ec, QSsl::Pem, QSsl::PublicKey);
|
||||
#endif
|
||||
|
||||
void DownloadManager::_validateCert(QNetworkReply* reply) {
|
||||
#if KEY_PINNING
|
||||
QSslCertificate peerCert = reply->sslConfiguration().peerCertificate();
|
||||
QSslKey peerKey = peerCert.publicKey();
|
||||
if (peerKey != AxioDLPublicKey && peerKey != AxioDLEdgePublicKey) {
|
||||
const auto cn = peerCert.subjectInfo(QSslCertificate::CommonName);
|
||||
if (cn.empty()) {
|
||||
setError(QNetworkReply::SslHandshakeFailedError, tr("Certificate pinning mismatch"));
|
||||
} else {
|
||||
setError(QNetworkReply::SslHandshakeFailedError, tr("Certificate pinning mismatch \"%1\"").arg(cn.first()));
|
||||
}
|
||||
reply->abort();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static const QString Domain = QStringLiteral("https://releases.axiodl.com/");
|
||||
static const QString Index = QStringLiteral("index.txt");
|
||||
|
||||
void DownloadManager::fetchIndex() {
|
||||
if (m_indexInProgress != nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
resetError();
|
||||
|
||||
const QString track = QSettings().value(QStringLiteral("update_track")).toString();
|
||||
const auto url = QUrl(QStringLiteral("%1%2/%3/%4").arg(Domain, track, CurPlatformString, Index));
|
||||
|
||||
m_indexInProgress = m_netManager.get(QNetworkRequest(url));
|
||||
connect(m_indexInProgress, &QNetworkReply::finished, this, &DownloadManager::indexFinished);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
connect(m_indexInProgress, &QNetworkReply::errorOccurred, this, &DownloadManager::indexError);
|
||||
#else
|
||||
connect(m_indexInProgress, qOverload<QNetworkReply::NetworkError>(&QNetworkReply::error), this,
|
||||
&DownloadManager::indexError);
|
||||
#endif
|
||||
connect(m_indexInProgress, &QNetworkReply::encrypted, this, &DownloadManager::indexValidateCert);
|
||||
}
|
||||
|
||||
void DownloadManager::fetchBinary(const QString& str, const QString& outPath) {
|
||||
if (m_binaryInProgress != nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
resetError();
|
||||
m_outPath = outPath;
|
||||
|
||||
const QString track = QSettings().value(QStringLiteral("update_track")).toString();
|
||||
const auto url = QUrl(QStringLiteral("%1%2/%3/%4").arg(Domain, track, CurPlatformString, str));
|
||||
#if PLATFORM_ZIP_DOWNLOAD
|
||||
m_binaryInProgress = m_netManager.get(QNetworkRequest(url));
|
||||
connect(m_binaryInProgress, &QNetworkReply::finished, this, &DownloadManager::binaryFinished);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
connect(m_binaryInProgress, &QNetworkReply::errorOccurred, this, &DownloadManager::binaryError);
|
||||
#else
|
||||
connect(m_binaryInProgress, qOverload<QNetworkReply::NetworkError>(&QNetworkReply::error), this,
|
||||
&DownloadManager::binaryError);
|
||||
#endif
|
||||
connect(m_binaryInProgress, &QNetworkReply::encrypted, this, &DownloadManager::binaryValidateCert);
|
||||
connect(m_binaryInProgress, &QNetworkReply::downloadProgress, this, &DownloadManager::binaryDownloadProgress);
|
||||
|
||||
if (m_progBar != nullptr) {
|
||||
m_progBar->setEnabled(true);
|
||||
m_progBar->setValue(0);
|
||||
}
|
||||
#else
|
||||
QDesktopServices::openUrl(url);
|
||||
#endif
|
||||
}
|
||||
|
||||
void DownloadManager::indexFinished() {
|
||||
if (m_hasError)
|
||||
return;
|
||||
|
||||
QStringList files;
|
||||
|
||||
while (!m_indexInProgress->atEnd()) {
|
||||
QString line = QString::fromUtf8(m_indexInProgress->readLine()).trimmed();
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
files.push_back(line);
|
||||
}
|
||||
|
||||
if (m_indexCompletionHandler)
|
||||
m_indexCompletionHandler(files);
|
||||
|
||||
m_indexInProgress->deleteLater();
|
||||
m_indexInProgress = nullptr;
|
||||
}
|
||||
|
||||
void DownloadManager::indexError(QNetworkReply::NetworkError error) {
|
||||
setError(error, m_indexInProgress->errorString());
|
||||
m_indexInProgress->deleteLater();
|
||||
m_indexInProgress = nullptr;
|
||||
}
|
||||
|
||||
void DownloadManager::indexValidateCert() { _validateCert(m_indexInProgress); }
|
||||
|
||||
void DownloadManager::binaryFinished() {
|
||||
if (m_hasError)
|
||||
return;
|
||||
|
||||
if (m_progBar)
|
||||
m_progBar->setValue(100);
|
||||
|
||||
QByteArray all = m_binaryInProgress->readAll();
|
||||
QBuffer buff(&all);
|
||||
QuaZip zip(&buff);
|
||||
if (!zip.open(QuaZip::mdUnzip)) {
|
||||
setError(QNetworkReply::UnknownContentError, tr("Unable to open zip archive."));
|
||||
m_binaryInProgress->deleteLater();
|
||||
m_binaryInProgress = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_completionHandler)
|
||||
m_completionHandler(zip);
|
||||
|
||||
m_binaryInProgress->deleteLater();
|
||||
m_binaryInProgress = nullptr;
|
||||
}
|
||||
|
||||
void DownloadManager::binaryError(QNetworkReply::NetworkError error) {
|
||||
setError(error, m_binaryInProgress->errorString());
|
||||
m_binaryInProgress->deleteLater();
|
||||
m_binaryInProgress = nullptr;
|
||||
|
||||
if (m_progBar)
|
||||
m_progBar->setEnabled(false);
|
||||
|
||||
if (m_failedHandler)
|
||||
m_failedHandler();
|
||||
}
|
||||
|
||||
void DownloadManager::binaryValidateCert() { _validateCert(m_binaryInProgress); }
|
||||
|
||||
void DownloadManager::binaryDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||
if (m_progBar) {
|
||||
if (bytesReceived == bytesTotal)
|
||||
m_progBar->setValue(100);
|
||||
else
|
||||
m_progBar->setValue(int(bytesReceived * 100 / bytesTotal));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QtNetwork>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QProgressBar>
|
||||
#include <QLabel>
|
||||
|
||||
//#if _WIN32
|
||||
//#define PLATFORM_ZIP_DOWNLOAD 1
|
||||
//#else
|
||||
#define PLATFORM_ZIP_DOWNLOAD 0
|
||||
//#endif
|
||||
|
||||
class QuaZip;
|
||||
|
||||
class DownloadManager : public QObject {
|
||||
Q_OBJECT
|
||||
QNetworkAccessManager m_netManager;
|
||||
QNetworkReply* m_indexInProgress = nullptr;
|
||||
QNetworkReply* m_binaryInProgress = nullptr;
|
||||
QString m_outPath;
|
||||
bool m_hasError = false;
|
||||
QProgressBar* m_progBar = nullptr;
|
||||
QLabel* m_errorLabel = nullptr;
|
||||
std::function<void(const QStringList& index)> m_indexCompletionHandler;
|
||||
std::function<void(QuaZip& file)> m_completionHandler;
|
||||
std::function<void()> m_failedHandler;
|
||||
|
||||
void resetError() {
|
||||
m_hasError = false;
|
||||
if (m_errorLabel)
|
||||
m_errorLabel->setText(QString());
|
||||
}
|
||||
|
||||
void setError(QNetworkReply::NetworkError error, const QString& errStr) {
|
||||
if (m_hasError && error == QNetworkReply::OperationCanceledError)
|
||||
return;
|
||||
m_hasError = true;
|
||||
if (m_errorLabel)
|
||||
m_errorLabel->setText(errStr);
|
||||
}
|
||||
|
||||
void _validateCert(QNetworkReply* reply);
|
||||
|
||||
public:
|
||||
explicit DownloadManager(QObject* parent = Q_NULLPTR) : QObject(parent), m_netManager(this) {}
|
||||
void connectWidgets(QProgressBar* progBar, QLabel* errorLabel,
|
||||
std::function<void(const QStringList& index)>&& indexCompletionHandler,
|
||||
std::function<void(QuaZip& file)>&& completionHandler, std::function<void()>&& failedHandler) {
|
||||
m_progBar = progBar;
|
||||
m_errorLabel = errorLabel;
|
||||
m_indexCompletionHandler = std::move(indexCompletionHandler);
|
||||
m_completionHandler = std::move(completionHandler);
|
||||
m_failedHandler = std::move(failedHandler);
|
||||
}
|
||||
void fetchIndex();
|
||||
void fetchBinary(const QString& str, const QString& outPath);
|
||||
bool hasError() const { return m_hasError; }
|
||||
|
||||
public slots:
|
||||
void indexFinished();
|
||||
void indexError(QNetworkReply::NetworkError error);
|
||||
void indexValidateCert();
|
||||
|
||||
void binaryFinished();
|
||||
void binaryError(QNetworkReply::NetworkError error);
|
||||
void binaryValidateCert();
|
||||
void binaryDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
};
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
class ErrorLabel : public QLabel {
|
||||
public:
|
||||
ErrorLabel(QWidget* parent = Q_NULLPTR) : QLabel(parent) {}
|
||||
void setText(const QString& str, bool success = false) {
|
||||
QPalette pal = QLabel::palette();
|
||||
if (success)
|
||||
pal.setColor(QPalette::WindowText, QColor(0, 255, 0));
|
||||
else
|
||||
pal.setColor(QPalette::WindowText, QColor(255, 47, 0));
|
||||
QLabel::setPalette(pal);
|
||||
QLabel::setText(str);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,561 @@
|
|||
#include "EscapeSequenceParser.hpp"
|
||||
#include <QFontDatabase>
|
||||
|
||||
/* TODO: more complete Vt102 emulation */
|
||||
// based on information: http://en.m.wikipedia.org/wiki/ANSI_escape_code
|
||||
// http://misc.flogisoft.com/bash/tip_colors_and_formatting
|
||||
// http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
||||
void ParseEscapeSequence(int attribute, QListIterator<QString>& i, QTextCharFormat& textCharFormat,
|
||||
const QTextCharFormat& defaultTextCharFormat) {
|
||||
switch (attribute) {
|
||||
case 0: { // Normal/Default (reset all attributes)
|
||||
textCharFormat = defaultTextCharFormat;
|
||||
break;
|
||||
}
|
||||
case 1: { // Bold/Bright (bold or increased intensity)
|
||||
textCharFormat.setFontWeight(QFont::Bold);
|
||||
break;
|
||||
}
|
||||
case 2: { // Dim/Faint (decreased intensity)
|
||||
textCharFormat.setFontWeight(QFont::Light);
|
||||
break;
|
||||
}
|
||||
case 3: { // Italicized (italic on)
|
||||
textCharFormat.setFontItalic(true);
|
||||
break;
|
||||
}
|
||||
case 4: { // Underscore (single underlined)
|
||||
textCharFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
||||
textCharFormat.setFontUnderline(true);
|
||||
break;
|
||||
}
|
||||
case 5: { // Blink (slow, appears as Bold)
|
||||
textCharFormat.setFontWeight(QFont::Bold);
|
||||
break;
|
||||
}
|
||||
case 6: { // Blink (rapid, appears as very Bold)
|
||||
textCharFormat.setFontWeight(QFont::Black);
|
||||
break;
|
||||
}
|
||||
case 7: { // Reverse/Inverse (swap foreground and background)
|
||||
QBrush foregroundBrush = textCharFormat.foreground();
|
||||
textCharFormat.setForeground(textCharFormat.background());
|
||||
textCharFormat.setBackground(foregroundBrush);
|
||||
break;
|
||||
}
|
||||
case 8: { // Concealed/Hidden/Invisible (usefull for passwords)
|
||||
textCharFormat.setForeground(textCharFormat.background());
|
||||
break;
|
||||
}
|
||||
case 9: { // Crossed-out characters
|
||||
textCharFormat.setFontStrikeOut(true);
|
||||
break;
|
||||
}
|
||||
case 10: { // Primary (default) font
|
||||
textCharFormat.setFont(defaultTextCharFormat.font());
|
||||
break;
|
||||
}
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 19: {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QString fontFamily = textCharFormat.fontFamily();
|
||||
QStringList fontStyles = QFontDatabase::styles(fontFamily);
|
||||
int fontStyleIndex = attribute - 11;
|
||||
if (fontStyleIndex < fontStyles.length()) {
|
||||
textCharFormat.setFont(
|
||||
QFontDatabase::font(fontFamily, fontStyles.at(fontStyleIndex), textCharFormat.font().pointSize()));
|
||||
}
|
||||
#else
|
||||
QFontDatabase fontDatabase;
|
||||
QString fontFamily = textCharFormat.fontFamily();
|
||||
QStringList fontStyles = fontDatabase.styles(fontFamily);
|
||||
int fontStyleIndex = attribute - 11;
|
||||
if (fontStyleIndex < fontStyles.length()) {
|
||||
textCharFormat.setFont(
|
||||
fontDatabase.font(fontFamily, fontStyles.at(fontStyleIndex), textCharFormat.font().pointSize()));
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case 20: { // Fraktur (unsupported)
|
||||
break;
|
||||
}
|
||||
case 21: { // Set Bold off
|
||||
textCharFormat.setFontWeight(QFont::Normal);
|
||||
break;
|
||||
}
|
||||
case 22: { // Set Dim off
|
||||
textCharFormat.setFontWeight(QFont::Normal);
|
||||
break;
|
||||
}
|
||||
case 23: { // Unset italic and unset fraktur
|
||||
textCharFormat.setFontItalic(false);
|
||||
break;
|
||||
}
|
||||
case 24: { // Unset underlining
|
||||
textCharFormat.setUnderlineStyle(QTextCharFormat::NoUnderline);
|
||||
textCharFormat.setFontUnderline(false);
|
||||
break;
|
||||
}
|
||||
case 25: { // Unset Blink/Bold
|
||||
textCharFormat.setFontWeight(QFont::Normal);
|
||||
break;
|
||||
}
|
||||
case 26: { // Reserved
|
||||
break;
|
||||
}
|
||||
case 27: { // Positive (non-inverted)
|
||||
QBrush backgroundBrush = textCharFormat.background();
|
||||
textCharFormat.setBackground(textCharFormat.foreground());
|
||||
textCharFormat.setForeground(backgroundBrush);
|
||||
break;
|
||||
}
|
||||
case 28: {
|
||||
textCharFormat.setForeground(defaultTextCharFormat.foreground());
|
||||
textCharFormat.setBackground(defaultTextCharFormat.background());
|
||||
break;
|
||||
}
|
||||
case 29: {
|
||||
textCharFormat.setUnderlineStyle(QTextCharFormat::NoUnderline);
|
||||
textCharFormat.setFontUnderline(false);
|
||||
break;
|
||||
}
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
case 33:
|
||||
case 34:
|
||||
case 35:
|
||||
case 36:
|
||||
case 37: {
|
||||
int colorIndex = attribute - 30;
|
||||
QColor color;
|
||||
if (QFont::Normal < textCharFormat.fontWeight()) {
|
||||
switch (colorIndex) {
|
||||
case 0: {
|
||||
color = Qt::darkGray;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
color = Qt::red;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
color = Qt::green;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
color = Qt::yellow;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
color = Qt::blue;
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
color = Qt::magenta;
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
color = Qt::cyan;
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
color = Qt::white;
|
||||
break;
|
||||
}
|
||||
default: { Q_ASSERT(false); }
|
||||
}
|
||||
} else {
|
||||
/* Normally dark colors, but forced to light colors for visibility */
|
||||
switch (colorIndex) {
|
||||
case 0: {
|
||||
color = Qt::darkGray;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
color = Qt::red;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
color = Qt::green;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
color = Qt::yellow;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
color = Qt::blue;
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
color = Qt::magenta;
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
color = Qt::cyan;
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
color = Qt::white;
|
||||
break;
|
||||
}
|
||||
default: { Q_ASSERT(false); }
|
||||
}
|
||||
}
|
||||
textCharFormat.setForeground(color);
|
||||
break;
|
||||
}
|
||||
case 38: {
|
||||
if (i.hasNext()) {
|
||||
bool ok = false;
|
||||
int selector = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
QColor color;
|
||||
switch (selector) {
|
||||
case 2: {
|
||||
if (!i.hasNext()) {
|
||||
break;
|
||||
}
|
||||
int red = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
if (!i.hasNext()) {
|
||||
break;
|
||||
}
|
||||
int green = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
if (!i.hasNext()) {
|
||||
break;
|
||||
}
|
||||
int blue = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
color.setRgb(red, green, blue);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
if (!i.hasNext()) {
|
||||
break;
|
||||
}
|
||||
int index = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
if (index >= 0 && index <= 0x07) { // 0x00-0x07: standard colors (as in ESC [ 30..37 m)
|
||||
return ParseEscapeSequence(index - 0x00 + 30, i, textCharFormat, defaultTextCharFormat);
|
||||
} else if (index >= 0x08 && index <= 0x0F) { // 0x08-0x0F: high intensity colors (as in ESC [ 90..97 m)
|
||||
return ParseEscapeSequence(index - 0x08 + 90, i, textCharFormat, defaultTextCharFormat);
|
||||
} else if (index >= 0x10 && index <= 0xE7) { // 0x10-0xE7: 6*6*6=216 colors: 16 + 36*r + 6*g + b (0≤r,g,b≤5)
|
||||
index -= 0x10;
|
||||
int red = index % 6;
|
||||
index /= 6;
|
||||
int green = index % 6;
|
||||
index /= 6;
|
||||
int blue = index % 6;
|
||||
index /= 6;
|
||||
Q_ASSERT(index == 0);
|
||||
color.setRgb(red, green, blue);
|
||||
break;
|
||||
} else if (index >= 0xE8 && index <= 0xFF) { // 0xE8-0xFF: grayscale from black to white in 24 steps
|
||||
qreal intensity = qreal(index - 0xE8) / (0xFF - 0xE8);
|
||||
color.setRgbF(intensity, intensity, intensity);
|
||||
break;
|
||||
}
|
||||
textCharFormat.setForeground(color);
|
||||
break;
|
||||
}
|
||||
default: { break; }
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 39: {
|
||||
textCharFormat.setForeground(defaultTextCharFormat.foreground());
|
||||
break;
|
||||
}
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
case 44:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47: {
|
||||
int colorIndex = attribute - 40;
|
||||
QColor color;
|
||||
switch (colorIndex) {
|
||||
case 0: {
|
||||
color = Qt::darkGray;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
color = Qt::red;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
color = Qt::green;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
color = Qt::yellow;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
color = Qt::blue;
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
color = Qt::magenta;
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
color = Qt::cyan;
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
color = Qt::white;
|
||||
break;
|
||||
}
|
||||
default: { Q_ASSERT(false); }
|
||||
}
|
||||
textCharFormat.setBackground(color);
|
||||
break;
|
||||
}
|
||||
case 48: {
|
||||
if (i.hasNext()) {
|
||||
bool ok = false;
|
||||
int selector = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
QColor color;
|
||||
switch (selector) {
|
||||
case 2: {
|
||||
if (!i.hasNext()) {
|
||||
break;
|
||||
}
|
||||
int red = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
if (!i.hasNext()) {
|
||||
break;
|
||||
}
|
||||
int green = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
if (!i.hasNext()) {
|
||||
break;
|
||||
}
|
||||
int blue = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
color.setRgb(red, green, blue);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
if (!i.hasNext()) {
|
||||
break;
|
||||
}
|
||||
int index = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
if (index >= 0x00 && index <= 0x07) { // 0x00-0x07: standard colors (as in ESC [ 40..47 m)
|
||||
return ParseEscapeSequence(index - 0x00 + 40, i, textCharFormat, defaultTextCharFormat);
|
||||
} else if (index >= 0x08 && index <= 0x0F) { // 0x08-0x0F: high intensity colors (as in ESC [ 100..107 m)
|
||||
return ParseEscapeSequence(index - 0x08 + 100, i, textCharFormat, defaultTextCharFormat);
|
||||
} else if (index >= 0x10 && index <= 0xE7) { // 0x10-0xE7: 6*6*6=216 colors: 16 + 36*r + 6*g + b (0≤r,g,b≤5)
|
||||
index -= 0x10;
|
||||
int red = index % 6;
|
||||
index /= 6;
|
||||
int green = index % 6;
|
||||
index /= 6;
|
||||
int blue = index % 6;
|
||||
index /= 6;
|
||||
Q_ASSERT(index == 0);
|
||||
color.setRgb(red, green, blue);
|
||||
break;
|
||||
} else if (index >= 0xE8 && index <= 0xFF) { // 0xE8-0xFF: grayscale from black to white in 24 steps
|
||||
qreal intensity = qreal(index - 0xE8) / (0xFF - 0xE8);
|
||||
color.setRgbF(intensity, intensity, intensity);
|
||||
}
|
||||
}
|
||||
textCharFormat.setBackground(color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 49: {
|
||||
textCharFormat.setBackground(defaultTextCharFormat.background());
|
||||
break;
|
||||
}
|
||||
case 90:
|
||||
case 91:
|
||||
case 92:
|
||||
case 93:
|
||||
case 94:
|
||||
case 95:
|
||||
case 96:
|
||||
case 97: {
|
||||
int colorIndex = attribute - 90;
|
||||
QColor color;
|
||||
switch (colorIndex) {
|
||||
case 0: {
|
||||
color = Qt::darkGray;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
color = Qt::red;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
color = Qt::green;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
color = Qt::yellow;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
color = Qt::blue;
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
color = Qt::magenta;
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
color = Qt::cyan;
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
color = Qt::white;
|
||||
break;
|
||||
}
|
||||
default: { Q_ASSERT(false); }
|
||||
}
|
||||
// color.setRedF(color.redF() * 0.8);
|
||||
// color.setGreenF(color.greenF() * 0.8);
|
||||
// color.setBlueF(color.blueF() * 0.8);
|
||||
textCharFormat.setForeground(color);
|
||||
break;
|
||||
}
|
||||
case 100:
|
||||
case 101:
|
||||
case 102:
|
||||
case 103:
|
||||
case 104:
|
||||
case 105:
|
||||
case 106:
|
||||
case 107: {
|
||||
int colorIndex = attribute - 100;
|
||||
QColor color;
|
||||
switch (colorIndex) {
|
||||
case 0: {
|
||||
color = Qt::darkGray;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
color = Qt::red;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
color = Qt::green;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
color = Qt::yellow;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
color = Qt::blue;
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
color = Qt::magenta;
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
color = Qt::cyan;
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
color = Qt::white;
|
||||
break;
|
||||
}
|
||||
default: { Q_ASSERT(false); }
|
||||
}
|
||||
// color.setRedF(color.redF() * 0.8);
|
||||
// color.setGreenF(color.greenF() * 0.8);
|
||||
// color.setBlueF(color.blueF() * 0.8);
|
||||
textCharFormat.setBackground(color);
|
||||
break;
|
||||
}
|
||||
default: { break; }
|
||||
}
|
||||
}
|
||||
|
||||
void ReturnInsert(QTextCursor& cur, const QString& text) {
|
||||
const auto DoLine = [&](const QString& line) {
|
||||
const auto DoReturn = [&](const QString& ret) {
|
||||
if (!ret.isEmpty()) {
|
||||
cur.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, ret.size());
|
||||
cur.insertText(ret);
|
||||
}
|
||||
};
|
||||
const QStringList list = line.split(QLatin1Char{'\r'});
|
||||
DoReturn(list.front());
|
||||
if (list.size() > 1) {
|
||||
for (auto it = list.begin() + 1; it != list.end(); ++it) {
|
||||
cur.movePosition(QTextCursor::StartOfBlock);
|
||||
DoReturn(*it);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if _WIN32
|
||||
const QStringList lineSplit = text.split(QStringLiteral("\r\n"));
|
||||
#else
|
||||
const QStringList lineSplit = text.split(QLatin1Char{'\n'});
|
||||
#endif
|
||||
DoLine(lineSplit.front());
|
||||
if (lineSplit.size() > 1) {
|
||||
for (auto it = lineSplit.begin() + 1; it != lineSplit.end(); ++it) {
|
||||
cur.movePosition(QTextCursor::EndOfLine);
|
||||
cur.insertBlock();
|
||||
DoLine(*it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReturnInsert(QTextCursor& cur, const QString& text, const QTextCharFormat& format) {
|
||||
const auto DoLine = [&](const QString& line) {
|
||||
const auto DoReturn = [&](const QString& ret) {
|
||||
if (!ret.isEmpty()) {
|
||||
cur.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, ret.size());
|
||||
cur.insertText(ret, format);
|
||||
}
|
||||
};
|
||||
const QStringList list = line.split(QLatin1Char{'\r'});
|
||||
DoReturn(list.front());
|
||||
if (list.size() > 1) {
|
||||
for (auto it = list.begin() + 1; it != list.end(); ++it) {
|
||||
cur.movePosition(QTextCursor::StartOfBlock);
|
||||
DoReturn(*it);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#if _WIN32
|
||||
const QStringList lineSplit = text.split(QStringLiteral("\r\n"));
|
||||
#else
|
||||
const QStringList lineSplit = text.split(QLatin1Char{'\n'});
|
||||
#endif
|
||||
DoLine(lineSplit.front());
|
||||
if (lineSplit.size() > 1) {
|
||||
for (auto it = lineSplit.begin() + 1; it != lineSplit.end(); ++it) {
|
||||
cur.movePosition(QTextCursor::EndOfLine);
|
||||
cur.insertBlock();
|
||||
DoLine(*it);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <QTextCharFormat>
|
||||
#include <QTextCursor>
|
||||
|
||||
void ParseEscapeSequence(int attribute, QListIterator<QString>& i, QTextCharFormat& textCharFormat,
|
||||
const QTextCharFormat& defaultTextCharFormat);
|
||||
|
||||
void ReturnInsert(QTextCursor& cur, const QString& text);
|
||||
|
||||
void ReturnInsert(QTextCursor& cur, const QString& text, const QTextCharFormat& format);
|
|
@ -0,0 +1,141 @@
|
|||
#include "ExtractZip.hpp"
|
||||
#include <QDir>
|
||||
#include <quazip.h>
|
||||
#include <quazipfile.h>
|
||||
|
||||
/**
|
||||
* Modified JICompress utilities to operate on in-memory zip.
|
||||
* Only contains directory extraction functionality.
|
||||
*/
|
||||
|
||||
static bool copyData(QIODevice& inFile, QIODevice& outFile) {
|
||||
while (!inFile.atEnd()) {
|
||||
char buf[4096];
|
||||
qint64 readLen = inFile.read(buf, 4096);
|
||||
if (readLen <= 0)
|
||||
return false;
|
||||
if (outFile.write(buf, readLen) != readLen)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList ExtractZip::getFileList(QuaZip& zip) {
|
||||
// Estraggo i nomi dei file
|
||||
QStringList lst;
|
||||
QuaZipFileInfo64 info;
|
||||
for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) {
|
||||
if (!zip.getCurrentFileInfo(&info))
|
||||
return {};
|
||||
lst << info.name;
|
||||
// info.name.toLocal8Bit().constData()
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
/**OK
|
||||
* Estrae il file fileName, contenuto nell'oggetto zip, con il nome fileDest.
|
||||
* Se la funzione fallisce restituisce false e cancella il file che si e tentato di estrarre.
|
||||
*
|
||||
* La funzione fallisce se:
|
||||
* * zip==NULL;
|
||||
* * l'oggetto zip e stato aperto in una modalita non compatibile con l'estrazione di file;
|
||||
* * non e possibile aprire il file all'interno dell'oggetto zip;
|
||||
* * non e possibile creare il file estratto;
|
||||
* * si e rilevato un errore nella copia dei dati (1);
|
||||
* * non e stato possibile chiudere il file all'interno dell'oggetto zip (1);
|
||||
*
|
||||
* (1): prima di uscire dalla funzione cancella il file estratto.
|
||||
*/
|
||||
bool ExtractZip::extractFile(QuaZip& zip, QString fileName, QString fileDest) {
|
||||
// zip: oggetto dove aggiungere il file
|
||||
// filename: nome del file reale
|
||||
// fileincompress: nome del file all'interno del file compresso
|
||||
|
||||
// Controllo l'apertura dello zip
|
||||
if (zip.getMode() != QuaZip::mdUnzip)
|
||||
return false;
|
||||
|
||||
// Apro il file compresso
|
||||
if (!fileName.isEmpty())
|
||||
zip.setCurrentFile(fileName);
|
||||
QuaZipFile inFile(&zip);
|
||||
if (!inFile.open(QIODevice::ReadOnly) || inFile.getZipError() != UNZ_OK)
|
||||
return false;
|
||||
|
||||
// Controllo esistenza cartella file risultato
|
||||
QDir curDir;
|
||||
if (fileDest.endsWith(QLatin1Char{'/'})) {
|
||||
if (!curDir.mkpath(fileDest)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!curDir.mkpath(QFileInfo(fileDest).absolutePath())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QuaZipFileInfo64 info;
|
||||
if (!zip.getCurrentFileInfo(&info))
|
||||
return false;
|
||||
|
||||
QFile::Permissions srcPerm = info.getPermissions();
|
||||
if (fileDest.endsWith(QLatin1Char{'/'}) && QFileInfo(fileDest).isDir()) {
|
||||
if (srcPerm != 0) {
|
||||
QFile(fileDest).setPermissions(srcPerm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Apro il file risultato
|
||||
QFile outFile;
|
||||
outFile.setFileName(fileDest);
|
||||
if (!outFile.open(QIODevice::WriteOnly))
|
||||
return false;
|
||||
|
||||
// Copio i dati
|
||||
if (!copyData(inFile, outFile) || inFile.getZipError() != UNZ_OK) {
|
||||
outFile.close();
|
||||
return false;
|
||||
}
|
||||
outFile.close();
|
||||
|
||||
// Chiudo i file
|
||||
inFile.close();
|
||||
if (inFile.getZipError() != UNZ_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (srcPerm != 0) {
|
||||
outFile.setPermissions(srcPerm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**OK
|
||||
* Estrae il file fileCompressed nella cartella dir.
|
||||
* Se dir = "" allora il file viene estratto nella cartella corrente.
|
||||
* Se la funzione fallisce cancella i file che si e tentato di estrarre.
|
||||
* Restituisce i nomi assoluti dei file estratti.
|
||||
*
|
||||
* La funzione fallisce se:
|
||||
* * non si riesce ad aprire l'oggetto zip;
|
||||
* * la compressione di un file fallisce;
|
||||
* * non si riesce a chiudere l'oggetto zip;
|
||||
*/
|
||||
bool ExtractZip::extractDir(QuaZip& zip, QString dir) {
|
||||
const QDir directory(dir);
|
||||
if (!zip.goToFirstFile()) {
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
const QString name = zip.getCurrentFileName();
|
||||
const QString absFilePath = directory.absoluteFilePath(name);
|
||||
if (!extractFile(zip, {}, absFilePath)) {
|
||||
return false;
|
||||
}
|
||||
} while (zip.goToNextFile());
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <QStringList>
|
||||
class QuaZip;
|
||||
class QString;
|
||||
|
||||
class ExtractZip {
|
||||
public:
|
||||
static QStringList getFileList(QuaZip& zip);
|
||||
static bool extractFile(QuaZip& zip, QString fileName, QString fileDest);
|
||||
static bool extractDir(QuaZip& zip, QString dir);
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
class FileDirDialog : public QFileDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileDirDialog(QWidget* parent = nullptr) : QFileDialog(parent) { setFileMode(QFileDialog::Directory); }
|
||||
};
|
|
@ -0,0 +1,140 @@
|
|||
#include "FindBlender.hpp"
|
||||
#include "hecl/SteamFinder.hpp"
|
||||
#include "hecl/hecl.hpp"
|
||||
|
||||
namespace hecl::blender {
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define DEFAULT_BLENDER_BIN "/Applications/Blender.app/Contents/MacOS/blender"
|
||||
#elif __linux__
|
||||
#define DEFAULT_BLENDER_BIN "/usr/bin/blender"
|
||||
#else
|
||||
#define DEFAULT_BLENDER_BIN "blender"
|
||||
#endif
|
||||
|
||||
static const std::regex regBlenderVersion(R"(Blender (\d+)\.(\d+)(?:\.(\d+))?)",
|
||||
std::regex::ECMAScript | std::regex::optimize);
|
||||
|
||||
static bool RegFileExists(const hecl::SystemChar* path) {
|
||||
if (!path)
|
||||
return false;
|
||||
hecl::Sstat theStat;
|
||||
return !hecl::Stat(path, &theStat) && S_ISREG(theStat.st_mode);
|
||||
}
|
||||
|
||||
hecl::SystemString FindBlender(int& major, int& minor) {
|
||||
major = 0;
|
||||
minor = 0;
|
||||
|
||||
/* User-specified blender path */
|
||||
#if _WIN32
|
||||
wchar_t BLENDER_BIN_BUF[2048];
|
||||
const wchar_t* blenderBin = _wgetenv(L"BLENDER_BIN");
|
||||
#else
|
||||
const char* blenderBin = getenv("BLENDER_BIN");
|
||||
#endif
|
||||
|
||||
/* Steam blender */
|
||||
hecl::SystemString steamBlender;
|
||||
|
||||
/* Child process of blender */
|
||||
#if _WIN32
|
||||
if (!blenderBin || !RegFileExists(blenderBin)) {
|
||||
/* Environment not set; try steam */
|
||||
steamBlender = hecl::FindCommonSteamApp(_SYS_STR("Blender"));
|
||||
if (steamBlender.size()) {
|
||||
steamBlender += _SYS_STR("\\blender.exe");
|
||||
blenderBin = steamBlender.c_str();
|
||||
}
|
||||
|
||||
if (!RegFileExists(blenderBin)) {
|
||||
/* No steam; try default */
|
||||
wchar_t progFiles[256];
|
||||
if (GetEnvironmentVariableW(L"ProgramFiles", progFiles, 256)) {
|
||||
for (size_t major = MaxBlenderMajorSearch; major >= MinBlenderMajorSearch; --major) {
|
||||
bool found = false;
|
||||
for (size_t minor = MaxBlenderMinorSearch; minor > MinBlenderMinorSearch; --minor) {
|
||||
_snwprintf(BLENDER_BIN_BUF, 2048, L"%s\\Blender Foundation\\Blender %i.%i\\blender.exe", progFiles, major,
|
||||
minor);
|
||||
if (RegFileExists(BLENDER_BIN_BUF)) {
|
||||
blenderBin = BLENDER_BIN_BUF;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
if (!RegFileExists(blenderBin)) {
|
||||
/* Try steam */
|
||||
steamBlender = hecl::FindCommonSteamApp(_SYS_STR("Blender"));
|
||||
if (steamBlender.size()) {
|
||||
#ifdef __APPLE__
|
||||
steamBlender += "/blender.app/Contents/MacOS/blender";
|
||||
#else
|
||||
steamBlender += "/blender";
|
||||
#endif
|
||||
blenderBin = steamBlender.c_str();
|
||||
if (!RegFileExists(blenderBin)) {
|
||||
blenderBin = DEFAULT_BLENDER_BIN;
|
||||
if (!RegFileExists(blenderBin)) {
|
||||
blenderBin = nullptr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
blenderBin = DEFAULT_BLENDER_BIN;
|
||||
if (!RegFileExists(blenderBin)) {
|
||||
blenderBin = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!blenderBin)
|
||||
return {};
|
||||
|
||||
#if _WIN32
|
||||
DWORD handle = 0;
|
||||
DWORD infoSize = GetFileVersionInfoSizeW(blenderBin, &handle);
|
||||
|
||||
if (infoSize != NULL) {
|
||||
auto* infoData = new char[infoSize];
|
||||
if (GetFileVersionInfoW(blenderBin, handle, infoSize, infoData)) {
|
||||
UINT size = 0;
|
||||
LPVOID lpBuffer = nullptr;
|
||||
if (VerQueryValueW(infoData, L"\\", &lpBuffer, &size) && size != 0u) {
|
||||
auto* verInfo = static_cast<VS_FIXEDFILEINFO*>(lpBuffer);
|
||||
if (verInfo->dwSignature == 0xfeef04bd) {
|
||||
major = static_cast<int>((verInfo->dwFileVersionMS >> 16) & 0xffff);
|
||||
minor = static_cast<int>((verInfo->dwFileVersionMS >> 0 & 0xffff) * 10 +
|
||||
(verInfo->dwFileVersionLS >> 16 & 0xffff));
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] infoData;
|
||||
}
|
||||
#else
|
||||
hecl::SystemString command = hecl::SystemString(_SYS_STR("\"")) + blenderBin + _SYS_STR("\" --version");
|
||||
FILE* fp = popen(command.c_str(), "r");
|
||||
char versionBuf[256];
|
||||
size_t rdSize = fread(versionBuf, 1, 255, fp);
|
||||
versionBuf[rdSize] = '\0';
|
||||
pclose(fp);
|
||||
|
||||
std::cmatch match;
|
||||
if (std::regex_search(versionBuf, match, regBlenderVersion)) {
|
||||
major = atoi(match[1].str().c_str());
|
||||
minor = atoi(match[2].str().c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
return blenderBin;
|
||||
}
|
||||
|
||||
} // namespace hecl::blender
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "hecl/hecl.hpp"
|
||||
|
||||
namespace hecl::blender {
|
||||
constexpr uint32_t MinBlenderMajorSearch = 2;
|
||||
constexpr uint32_t MaxBlenderMajorSearch = 2;
|
||||
constexpr uint32_t MinBlenderMinorSearch = 83;
|
||||
constexpr uint32_t MaxBlenderMinorSearch = 92;
|
||||
|
||||
hecl::SystemString FindBlender(int& major, int& minor);
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#include "LayerDialog.hpp"
|
||||
#include <QCheckBox>
|
||||
#include "ui_LayerDialog.h"
|
||||
|
||||
LayerDialog::LayerDialog(QWidget* parent) : QDialog(parent), m_ui(std::make_unique<Ui::LayerDialog>()) {
|
||||
m_ui->setupUi(this);
|
||||
}
|
||||
|
||||
LayerDialog::~LayerDialog() = default;
|
||||
|
||||
void LayerDialog::createLayerCheckboxes(QList<Layer> layers) {
|
||||
bool firstLayer = true;
|
||||
for (const auto& layer : layers) {
|
||||
QCheckBox* chkBox = new QCheckBox(layer.name);
|
||||
chkBox->setChecked(layer.active);
|
||||
if (firstLayer) {
|
||||
chkBox->setEnabled(false);
|
||||
firstLayer = false;
|
||||
}
|
||||
m_ui->checkboxLayout->addWidget(chkBox);
|
||||
}
|
||||
}
|
||||
QString LayerDialog::getLayerBits() const {
|
||||
QString layerBits;
|
||||
bool firstLayer = true;
|
||||
for (const auto& item : findChildren<QCheckBox*>()) {
|
||||
if (firstLayer) {
|
||||
layerBits += QLatin1String("1");
|
||||
firstLayer = false;
|
||||
} else {
|
||||
layerBits += item->isChecked() ? QStringLiteral("1") : QStringLiteral("0");
|
||||
}
|
||||
}
|
||||
return layerBits;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef LAYERDIALOG_HPP
|
||||
#define LAYERDIALOG_HPP
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
|
||||
namespace Ui {
|
||||
class LayerDialog;
|
||||
} // namespace Ui
|
||||
|
||||
struct Layer {
|
||||
QString name;
|
||||
bool active;
|
||||
};
|
||||
class LayerDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
std::unique_ptr<Ui::LayerDialog> m_ui;
|
||||
|
||||
public:
|
||||
explicit LayerDialog(QWidget* parent = nullptr);
|
||||
~LayerDialog() override;
|
||||
|
||||
void createLayerCheckboxes(QList<Layer> layers);
|
||||
QString getLayerBits() const;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LayerDialog</class>
|
||||
<widget class="QDialog" name="LayerDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>209</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Select Active Layers</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="checkboxLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>LayerDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>LayerDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void GetMacOSSystemVersion(int& major, int& minor, int& patch);
|
|
@ -0,0 +1,172 @@
|
|||
#include "MacOSSystemVersion.hpp"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
#error ARC Required
|
||||
#endif
|
||||
|
||||
void GetMacOSSystemVersion(int& major, int& minor, int& patch)
|
||||
{
|
||||
major = 0;
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
|
||||
id pInfo = [NSProcessInfo processInfo];
|
||||
if ([pInfo respondsToSelector:@selector(operatingSystemVersion)])
|
||||
{
|
||||
NSOperatingSystemVersion version = [pInfo operatingSystemVersion];
|
||||
major = version.majorVersion;
|
||||
minor = version.minorVersion;
|
||||
patch = version.patchVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
major = 10;
|
||||
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_9_2)
|
||||
{
|
||||
minor = 9;
|
||||
patch = 2;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_9_1)
|
||||
{
|
||||
minor = 9;
|
||||
patch = 1;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_9)
|
||||
{
|
||||
minor = 9;
|
||||
patch = 0;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8_4)
|
||||
{
|
||||
minor = 8;
|
||||
patch = 4;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8_3)
|
||||
{
|
||||
minor = 8;
|
||||
patch = 3;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8_2)
|
||||
{
|
||||
minor = 8;
|
||||
patch = 2;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8_1)
|
||||
{
|
||||
minor = 8;
|
||||
patch = 1;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_8)
|
||||
{
|
||||
minor = 8;
|
||||
patch = 0;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_5)
|
||||
{
|
||||
minor = 7;
|
||||
patch = 5;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_4)
|
||||
{
|
||||
minor = 7;
|
||||
patch = 4;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_3)
|
||||
{
|
||||
minor = 7;
|
||||
patch = 3;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_2)
|
||||
{
|
||||
minor = 7;
|
||||
patch = 2;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7_1)
|
||||
{
|
||||
minor = 7;
|
||||
patch = 1;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_7)
|
||||
{
|
||||
minor = 7;
|
||||
patch = 0;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_8)
|
||||
{
|
||||
minor = 6;
|
||||
patch = 8;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_7)
|
||||
{
|
||||
minor = 6;
|
||||
patch = 7;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_6)
|
||||
{
|
||||
minor = 6;
|
||||
patch = 6;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_5)
|
||||
{
|
||||
minor = 6;
|
||||
patch = 5;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_4)
|
||||
{
|
||||
minor = 6;
|
||||
patch = 4;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_3)
|
||||
{
|
||||
minor = 6;
|
||||
patch = 3;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_2)
|
||||
{
|
||||
minor = 6;
|
||||
patch = 2;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6_1)
|
||||
{
|
||||
minor = 6;
|
||||
patch = 1;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_6)
|
||||
{
|
||||
minor = 6;
|
||||
patch = 0;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_5)
|
||||
{
|
||||
minor = 5;
|
||||
patch = 0;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_4)
|
||||
{
|
||||
minor = 4;
|
||||
patch = 0;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_3)
|
||||
{
|
||||
minor = 3;
|
||||
patch = 0;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_2)
|
||||
{
|
||||
minor = 2;
|
||||
patch = 0;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_1)
|
||||
{
|
||||
minor = 1;
|
||||
patch = 0;
|
||||
}
|
||||
else if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber10_0)
|
||||
{
|
||||
minor = 0;
|
||||
patch = 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,784 @@
|
|||
#include "MainWindow.hpp"
|
||||
#include "ui_MainWindow.h"
|
||||
#include "LayerDialog.hpp"
|
||||
|
||||
#include <QFontDatabase>
|
||||
#include <QMessageBox>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QTreeView>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
#include <QtCore5Compat>
|
||||
#endif
|
||||
#include "EscapeSequenceParser.hpp"
|
||||
#include "FileDirDialog.hpp"
|
||||
#include "ExtractZip.hpp"
|
||||
|
||||
#if _WIN32
|
||||
#include <Windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <TlHelp32.h>
|
||||
|
||||
static void KillProcessTree(QProcess& proc) {
|
||||
quint64 pid = proc.processId();
|
||||
if (pid == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
PROCESSENTRY32 pe = {};
|
||||
pe.dwSize = sizeof(PROCESSENTRY32);
|
||||
|
||||
HANDLE hSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
|
||||
if (::Process32First(hSnap, &pe) == TRUE) {
|
||||
BOOL bContinue = TRUE;
|
||||
|
||||
// kill child processes
|
||||
while (bContinue != FALSE) {
|
||||
// only kill child processes
|
||||
if (pe.th32ParentProcessID == pid) {
|
||||
HANDLE hChildProc = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID);
|
||||
|
||||
if (hChildProc) {
|
||||
::TerminateProcess(hChildProc, 1);
|
||||
::CloseHandle(hChildProc);
|
||||
}
|
||||
}
|
||||
|
||||
bContinue = ::Process32Next(hSnap, &pe);
|
||||
}
|
||||
}
|
||||
|
||||
proc.close();
|
||||
proc.terminate();
|
||||
}
|
||||
#else
|
||||
static void KillProcessTree(QProcess& proc) {
|
||||
proc.close();
|
||||
proc.terminate();
|
||||
}
|
||||
#endif
|
||||
|
||||
const QStringList MainWindow::skUpdateTracks = {QStringLiteral("stable"), QStringLiteral("dev"), QStringLiteral("continuous")};
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: QMainWindow(parent)
|
||||
, m_ui(std::make_unique<Ui::MainWindow>())
|
||||
, m_fileMgr(_SYS_STR("urde"))
|
||||
, m_cvarManager(m_fileMgr)
|
||||
, m_cvarCommons(m_cvarManager)
|
||||
, m_heclProc(this)
|
||||
, m_dlManager(this) {
|
||||
if (m_settings.value(QStringLiteral("urde_arguments")).isNull()) {
|
||||
m_settings.setValue(QStringLiteral("urde_arguments"), QStringList{QStringLiteral("--no-shader-warmup")});
|
||||
}
|
||||
if (m_settings.value(QStringLiteral("update_track")).isNull()) {
|
||||
m_settings.setValue(QStringLiteral("update_track"), QStringLiteral("dev"));
|
||||
}
|
||||
|
||||
m_ui->setupUi(this);
|
||||
m_ui->heclTabs->setCurrentIndex(0);
|
||||
|
||||
m_ui->aboutIcon->setPixmap(QApplication::windowIcon().pixmap(256, 256));
|
||||
|
||||
QFont mFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
||||
mFont.setPointSize(m_ui->currentBinaryLabel->font().pointSize());
|
||||
m_ui->currentBinaryLabel->setFont(mFont);
|
||||
m_ui->recommendedBinaryLabel->setFont(mFont);
|
||||
mFont.setPointSize(10);
|
||||
m_ui->processOutput->setFont(mFont);
|
||||
m_cursor = QTextCursor(m_ui->processOutput->document());
|
||||
connect(m_ui->saveLogButton, &QPushButton::pressed, this, [this] {
|
||||
QString defaultFileName = QStringLiteral("urde-") + QDateTime::currentDateTime().toString(Qt::DateFormat::ISODate) +
|
||||
QStringLiteral(".log");
|
||||
defaultFileName.replace(QLatin1Char(':'), QLatin1Char('-'));
|
||||
const QString fileName =
|
||||
QFileDialog::getSaveFileName(this, tr("Save Log"), defaultFileName, QStringLiteral("*.log"));
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
QFile file = QFile(fileName);
|
||||
if (file.open(QFile::OpenModeFlag::WriteOnly | QFile::OpenModeFlag::Truncate | QFile::OpenModeFlag::Text)) {
|
||||
QTextStream stream(&file);
|
||||
stream << m_ui->processOutput->toPlainText();
|
||||
stream.flush();
|
||||
file.close();
|
||||
} else {
|
||||
QMessageBox::critical(this, tr("Save Log"), tr("Failed to open log file"));
|
||||
}
|
||||
});
|
||||
|
||||
qDebug() << "Stored track " << m_settings.value(QStringLiteral("update_track"));
|
||||
const int index = skUpdateTracks.indexOf(m_settings.value(QStringLiteral("update_track")).toString());
|
||||
m_ui->devTrackWarning->setVisible(index == 1);
|
||||
m_ui->continuousTrackWarning->setVisible(index == 2);
|
||||
m_ui->updateTrackComboBox->setCurrentIndex(index);
|
||||
connect(m_ui->updateTrackComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||
&MainWindow::onUpdateTrackChanged);
|
||||
|
||||
m_dlManager.connectWidgets(m_ui->downloadProgressBar, m_ui->downloadErrorLabel,
|
||||
std::bind(&MainWindow::onIndexDownloaded, this, std::placeholders::_1),
|
||||
std::bind(&MainWindow::onBinaryDownloaded, this, std::placeholders::_1),
|
||||
std::bind(&MainWindow::onBinaryFailed, this));
|
||||
#if !PLATFORM_ZIP_DOWNLOAD
|
||||
m_ui->downloadProgressBar->hide();
|
||||
#endif
|
||||
|
||||
initOptions();
|
||||
initSlots();
|
||||
|
||||
m_dlManager.fetchIndex();
|
||||
|
||||
setPath(m_settings.value(QStringLiteral("working_dir")).toString());
|
||||
resize(1024, 768);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() { KillProcessTree(m_heclProc); }
|
||||
|
||||
void MainWindow::onExtract() {
|
||||
if (m_path.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString imgPath =
|
||||
QFileDialog::getOpenFileName(this, tr("Extract Image"), m_path, tr("Images (*.iso *.wbfs *.gcm)"));
|
||||
if (imgPath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_ui->processOutput->clear();
|
||||
KillProcessTree(m_heclProc);
|
||||
m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
|
||||
m_heclProc.setWorkingDirectory(m_path);
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
env.insert(QStringLiteral("TERM"), QStringLiteral("xterm-color"));
|
||||
env.insert(QStringLiteral("ConEmuANSI"), QStringLiteral("ON"));
|
||||
m_heclProc.setProcessEnvironment(env);
|
||||
disconnect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), nullptr, nullptr);
|
||||
connect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &MainWindow::onExtractFinished);
|
||||
|
||||
const QStringList heclProcArguments{
|
||||
QStringLiteral("extract"), QStringLiteral("-y"), QStringLiteral("-g"), QStringLiteral("-o"), m_path, imgPath};
|
||||
m_heclProc.start(m_heclPath, heclProcArguments, QIODevice::ReadOnly | QIODevice::Unbuffered);
|
||||
|
||||
m_ui->heclTabs->setCurrentIndex(0);
|
||||
|
||||
disableOperations();
|
||||
m_ui->extractBtn->setText(tr("&Cancel"));
|
||||
m_ui->extractBtn->setEnabled(true);
|
||||
disconnect(m_ui->extractBtn, &QPushButton::clicked, nullptr, nullptr);
|
||||
connect(m_ui->extractBtn, &QPushButton::clicked, this, &MainWindow::doHECLTerminate);
|
||||
}
|
||||
|
||||
void MainWindow::onExtractFinished(int returnCode, QProcess::ExitStatus) {
|
||||
m_cursor.movePosition(QTextCursor::End);
|
||||
m_cursor.insertBlock();
|
||||
disconnect(m_ui->extractBtn, &QPushButton::clicked, nullptr, nullptr);
|
||||
connect(m_ui->extractBtn, &QPushButton::clicked, this, &MainWindow::onExtract);
|
||||
checkDownloadedBinary();
|
||||
}
|
||||
|
||||
void MainWindow::onPackage() {
|
||||
if (m_path.isEmpty())
|
||||
return;
|
||||
m_ui->processOutput->clear();
|
||||
KillProcessTree(m_heclProc);
|
||||
m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
|
||||
m_heclProc.setWorkingDirectory(m_path);
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
env.insert(QStringLiteral("TERM"), QStringLiteral("xterm-color"));
|
||||
env.insert(QStringLiteral("ConEmuANSI"), QStringLiteral("ON"));
|
||||
m_heclProc.setProcessEnvironment(env);
|
||||
disconnect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), nullptr, nullptr);
|
||||
connect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &MainWindow::onPackageFinished);
|
||||
|
||||
const QStringList heclProcArguments{QStringLiteral("package"), QStringLiteral("MP1"), QStringLiteral("-y"),
|
||||
QStringLiteral("-g")};
|
||||
m_heclProc.start(m_heclPath, heclProcArguments, QIODevice::ReadOnly | QIODevice::Unbuffered);
|
||||
|
||||
m_ui->heclTabs->setCurrentIndex(0);
|
||||
|
||||
disableOperations();
|
||||
m_ui->packageBtn->setText(tr("&Cancel"));
|
||||
m_ui->packageBtn->setEnabled(true);
|
||||
disconnect(m_ui->packageBtn, &QPushButton::clicked, nullptr, nullptr);
|
||||
connect(m_ui->packageBtn, &QPushButton::clicked, this, &MainWindow::doHECLTerminate);
|
||||
|
||||
QSize size = QWidget::size();
|
||||
if (size.width() < 1100)
|
||||
size.setWidth(1100);
|
||||
resize(size);
|
||||
}
|
||||
|
||||
void MainWindow::onPackageFinished(int returnCode, QProcess::ExitStatus) {
|
||||
m_cursor.movePosition(QTextCursor::End);
|
||||
m_cursor.insertBlock();
|
||||
disconnect(m_ui->packageBtn, &QPushButton::clicked, nullptr, nullptr);
|
||||
connect(m_ui->packageBtn, &QPushButton::clicked, this, &MainWindow::onPackage);
|
||||
checkDownloadedBinary();
|
||||
}
|
||||
|
||||
void MainWindow::onLaunch() {
|
||||
if (m_path.isEmpty())
|
||||
return;
|
||||
m_ui->processOutput->clear();
|
||||
KillProcessTree(m_heclProc);
|
||||
m_heclProc.setProcessChannelMode(QProcess::ProcessChannelMode::MergedChannels);
|
||||
m_heclProc.setWorkingDirectory(m_path);
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
env.insert(QStringLiteral("TERM"), QStringLiteral("xterm-color"));
|
||||
env.insert(QStringLiteral("ConEmuANSI"), QStringLiteral("ON"));
|
||||
m_heclProc.setProcessEnvironment(env);
|
||||
disconnect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), nullptr, nullptr);
|
||||
connect(&m_heclProc, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &MainWindow::onLaunchFinished);
|
||||
|
||||
const auto heclProcArguments = QStringList{m_path + QStringLiteral("/out/MP1")}
|
||||
<< m_warpSettings << QStringLiteral("-l")
|
||||
<< m_settings.value(QStringLiteral("urde_arguments"))
|
||||
.toStringList()
|
||||
.join(QLatin1Char{' '})
|
||||
.split(QLatin1Char{' '});
|
||||
m_heclProc.start(m_urdePath, heclProcArguments, QIODevice::ReadOnly | QIODevice::Unbuffered);
|
||||
|
||||
m_ui->heclTabs->setCurrentIndex(0);
|
||||
|
||||
disableOperations();
|
||||
}
|
||||
|
||||
void MainWindow::onLaunchFinished(int returnCode, QProcess::ExitStatus) {
|
||||
m_cursor.movePosition(QTextCursor::End);
|
||||
m_cursor.insertBlock();
|
||||
checkDownloadedBinary();
|
||||
}
|
||||
|
||||
void MainWindow::doHECLTerminate() { KillProcessTree(m_heclProc); }
|
||||
|
||||
void MainWindow::onReturnPressed() {
|
||||
if (sender() == m_ui->pathEdit)
|
||||
setPath(m_ui->pathEdit->text());
|
||||
}
|
||||
|
||||
void MainWindow::onIndexDownloaded(const QStringList& index) {
|
||||
int bestVersion = 0;
|
||||
m_ui->binaryComboBox->clear();
|
||||
for (const QString& str : index) {
|
||||
URDEVersion version(str);
|
||||
m_ui->binaryComboBox->addItem(version.fileString(false), QVariant::fromValue(version));
|
||||
}
|
||||
m_ui->binaryComboBox->setCurrentIndex(bestVersion);
|
||||
m_recommendedVersion = m_ui->binaryComboBox->itemData(bestVersion).value<URDEVersion>();
|
||||
m_ui->recommendedBinaryLabel->setText(m_recommendedVersion.fileString(false));
|
||||
m_ui->binaryComboBox->setEnabled(true);
|
||||
|
||||
if (!m_path.isEmpty()) {
|
||||
checkDownloadedBinary();
|
||||
m_ui->downloadButton->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onDownloadPressed() {
|
||||
QString filename = m_ui->binaryComboBox->currentData().value<URDEVersion>().fileString(true);
|
||||
#if PLATFORM_ZIP_DOWNLOAD
|
||||
disableOperations();
|
||||
m_ui->downloadButton->setEnabled(false);
|
||||
#endif
|
||||
m_dlManager.fetchBinary(filename, m_path + QLatin1Char{'/'} + filename);
|
||||
}
|
||||
|
||||
void MainWindow::onBinaryDownloaded(QuaZip& file) {
|
||||
const bool err = !ExtractZip::extractDir(file, m_path);
|
||||
|
||||
if (err) {
|
||||
m_ui->downloadErrorLabel->setText(tr("Error extracting zip"));
|
||||
} else {
|
||||
m_ui->downloadErrorLabel->setText(tr("Download successful"), true);
|
||||
}
|
||||
|
||||
m_ui->downloadButton->setEnabled(true);
|
||||
checkDownloadedBinary();
|
||||
|
||||
if (!err && m_ui->extractBtn->isEnabled()) {
|
||||
m_ui->downloadErrorLabel->setText(tr("Download successful - Press 'Extract' to continue."), true);
|
||||
}
|
||||
if (!err && !m_ui->sysReqTable->isBlenderVersionOk()) {
|
||||
m_ui->downloadErrorLabel->setText(
|
||||
tr("Blender 2.90 or greater must be installed. Please download via Steam or blender.org."));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onBinaryFailed() {
|
||||
m_ui->downloadButton->setEnabled(true);
|
||||
checkDownloadedBinary();
|
||||
}
|
||||
|
||||
void MainWindow::disableOperations() {
|
||||
m_ui->extractBtn->setEnabled(false);
|
||||
m_ui->packageBtn->setEnabled(false);
|
||||
m_ui->launchBtn->setEnabled(false);
|
||||
m_ui->pathEdit->setEnabled(false);
|
||||
m_ui->browseBtn->setEnabled(false);
|
||||
m_ui->downloadButton->setEnabled(false);
|
||||
m_ui->warpBtn->setEnabled(false);
|
||||
}
|
||||
|
||||
void MainWindow::enableOperations() {
|
||||
disableOperations();
|
||||
m_ui->pathEdit->setEnabled(true);
|
||||
m_ui->browseBtn->setEnabled(true);
|
||||
|
||||
if (hecl::com_enableCheats->toBoolean()) {
|
||||
m_ui->warpBtn->show();
|
||||
} else {
|
||||
m_ui->warpBtn->hide();
|
||||
}
|
||||
|
||||
if (m_path.isEmpty())
|
||||
return;
|
||||
|
||||
m_ui->downloadButton->setEnabled(true);
|
||||
|
||||
if (m_heclPath.isEmpty())
|
||||
return;
|
||||
|
||||
m_ui->extractBtn->setText(tr("&Extract"));
|
||||
m_ui->packageBtn->setText(tr("&Package"));
|
||||
m_ui->launchBtn->setText(tr("&Launch"));
|
||||
|
||||
m_ui->extractBtn->setEnabled(true);
|
||||
if (QFile::exists(m_path + QStringLiteral("/out/files/MP1/version.yaml"))) {
|
||||
m_ui->packageBtn->setEnabled(true);
|
||||
if (isPackageComplete()) {
|
||||
m_ui->launchBtn->setEnabled(true);
|
||||
if (hecl::com_enableCheats->toBoolean()) {
|
||||
m_ui->warpBtn->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_ui->sysReqTable->isBlenderVersionOk()) {
|
||||
insertContinueNote(tr("Blender 2.90 or greater must be installed. Please download via Steam or blender.org."));
|
||||
} else if (m_ui->launchBtn->isEnabled()) {
|
||||
insertContinueNote(tr("Package complete - Press 'Launch' to start URDE."));
|
||||
} else if (m_ui->packageBtn->isEnabled()) {
|
||||
insertContinueNote(tr("Extract complete - Press 'Package' to continue."));
|
||||
} else if (m_ui->extractBtn->isEnabled()) {
|
||||
insertContinueNote(tr("Press 'Extract' to begin."));
|
||||
}
|
||||
}
|
||||
|
||||
bool MainWindow::isPackageComplete() const {
|
||||
return QFile::exists(m_path + QStringLiteral("/out/files/MP1/AudioGrp.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/GGuiSys.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid1.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid2.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid3.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid4.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/metroid5.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid6.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid7.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/Metroid8.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/MidiData.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/MiscData.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/NoARAM.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/SamGunFx.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/SamusGun.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/SlideShow.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/TestAnim.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/Tweaks.upak")) &&
|
||||
QFile::exists(m_path + QStringLiteral("/out/files/MP1/URDE.upak"));
|
||||
}
|
||||
|
||||
static bool GetDLPackage(const QString& path, QString& dlPackage) {
|
||||
QProcess proc;
|
||||
proc.start(path, {QStringLiteral("--dlpackage")}, QIODevice::ReadOnly);
|
||||
if (proc.waitForStarted()) {
|
||||
proc.waitForFinished();
|
||||
if (proc.exitCode() == 100)
|
||||
dlPackage = QString::fromUtf8(proc.readLine()).trimmed();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MainWindow::checkDownloadedBinary() {
|
||||
m_urdePath = QString();
|
||||
m_heclPath = QString();
|
||||
|
||||
if (m_path.isEmpty()) {
|
||||
m_ui->heclTabs->setCurrentIndex(2);
|
||||
m_ui->downloadErrorLabel->setText(tr("Set working directory to continue."), true);
|
||||
enableOperations();
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString dir = QApplication::instance()->applicationDirPath();
|
||||
#if _WIN32
|
||||
QString urdePath = dir + QStringLiteral("/urde.exe");
|
||||
QString heclPath = dir + QStringLiteral("/hecl.exe");
|
||||
QString visigenPath = dir + QStringLiteral("/visigen.exe");
|
||||
if (!QFileInfo::exists(urdePath) || !QFileInfo::exists(heclPath) || !QFileInfo::exists(visigenPath)) {
|
||||
urdePath = m_path + QStringLiteral("/urde.exe");
|
||||
heclPath = m_path + QStringLiteral("/hecl.exe");
|
||||
visigenPath = m_path + QStringLiteral("/visigen.exe");
|
||||
}
|
||||
#else
|
||||
QString urdePath = dir + QStringLiteral("/urde");
|
||||
QString heclPath = dir + QStringLiteral("/hecl");
|
||||
QString visigenPath = dir + QStringLiteral("/visigen");
|
||||
#endif
|
||||
urdePath = QFileInfo(urdePath).absoluteFilePath();
|
||||
heclPath = QFileInfo(heclPath).absoluteFilePath();
|
||||
visigenPath = QFileInfo(visigenPath).absoluteFilePath();
|
||||
|
||||
QString urdeDlPackage, heclDlPackage, visigenDlPackage;
|
||||
if (GetDLPackage(urdePath, urdeDlPackage) && GetDLPackage(heclPath, heclDlPackage) &&
|
||||
GetDLPackage(visigenPath, visigenDlPackage)) {
|
||||
if (!urdeDlPackage.isEmpty() && urdeDlPackage == heclDlPackage && urdeDlPackage == visigenDlPackage) {
|
||||
URDEVersion v(urdeDlPackage);
|
||||
m_ui->currentBinaryLabel->setText(v.fileString(false));
|
||||
} else {
|
||||
m_ui->currentBinaryLabel->setText(tr("unknown -- re-download recommended"));
|
||||
}
|
||||
|
||||
m_urdePath = urdePath;
|
||||
m_heclPath = heclPath;
|
||||
m_ui->downloadErrorLabel->setText({}, true);
|
||||
enableOperations();
|
||||
return true;
|
||||
}
|
||||
|
||||
m_ui->currentBinaryLabel->setText(tr("none"));
|
||||
m_ui->heclTabs->setCurrentIndex(2);
|
||||
m_ui->downloadErrorLabel->setText(tr("Press 'Download' to fetch latest URDE binary."), true);
|
||||
enableOperations();
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainWindow::setPath(const QString& path) {
|
||||
const QFileInfo finfo(path);
|
||||
|
||||
QString usePath;
|
||||
if (!path.isEmpty()) {
|
||||
usePath = finfo.absoluteFilePath();
|
||||
}
|
||||
|
||||
if (!usePath.isEmpty() && !finfo.exists()) {
|
||||
if (QMessageBox::question(this, tr("Make Directory"), tr("%1 does not exist. Create it now?").arg(usePath)) ==
|
||||
QMessageBox::Yes) {
|
||||
QDir().mkpath(usePath);
|
||||
} else {
|
||||
usePath = QString();
|
||||
}
|
||||
}
|
||||
|
||||
if (!usePath.isEmpty() && !finfo.isDir()) {
|
||||
QMessageBox::warning(this, tr("Directory Error"), tr("%1 is not a directory").arg(usePath), QMessageBox::Ok,
|
||||
QMessageBox::NoButton);
|
||||
usePath = QString();
|
||||
}
|
||||
|
||||
m_path = usePath;
|
||||
m_settings.setValue(QStringLiteral("working_dir"), m_path);
|
||||
|
||||
if (!m_path.isEmpty()) {
|
||||
m_ui->pathEdit->setText(m_path);
|
||||
m_ui->downloadButton->setToolTip(QString());
|
||||
m_ui->downloadButton->setEnabled(m_ui->binaryComboBox->isEnabled());
|
||||
} else {
|
||||
m_ui->downloadButton->setToolTip(tr("Working directory must be set"));
|
||||
m_ui->downloadButton->setEnabled(false);
|
||||
m_ui->currentBinaryLabel->setText(tr("none"));
|
||||
}
|
||||
|
||||
m_ui->sysReqTable->updateFreeDiskSpace(m_path);
|
||||
checkDownloadedBinary();
|
||||
}
|
||||
|
||||
void MainWindow::initSlots() {
|
||||
connect(&m_heclProc, &QProcess::readyRead, [this]() {
|
||||
const QByteArray bytes = m_heclProc.readAll();
|
||||
setTextTermFormatting(QString::fromUtf8(bytes));
|
||||
});
|
||||
|
||||
connect(m_ui->extractBtn, &QPushButton::clicked, this, &MainWindow::onExtract);
|
||||
connect(m_ui->packageBtn, &QPushButton::clicked, this, &MainWindow::onPackage);
|
||||
connect(m_ui->launchBtn, &QPushButton::clicked, this, &MainWindow::onLaunch);
|
||||
|
||||
connect(m_ui->browseBtn, &QPushButton::clicked, [this]() {
|
||||
FileDirDialog dialog(this);
|
||||
dialog.setDirectory(m_path);
|
||||
dialog.setWindowTitle(tr("Select Working Directory"));
|
||||
int res = dialog.exec();
|
||||
if (res == QFileDialog::Rejected)
|
||||
return;
|
||||
|
||||
if (dialog.selectedFiles().size() <= 0)
|
||||
return;
|
||||
|
||||
setPath(dialog.selectedFiles().at(0));
|
||||
});
|
||||
connect(m_ui->pathEdit, &QLineEdit::editingFinished, [this]() { setPath(m_ui->pathEdit->text()); });
|
||||
|
||||
connect(m_ui->downloadButton, &QPushButton::clicked, this, &MainWindow::onDownloadPressed);
|
||||
}
|
||||
|
||||
void MainWindow::setTextTermFormatting(const QString& text) {
|
||||
m_inContinueNote = false;
|
||||
|
||||
m_cursor.beginEditBlock();
|
||||
// TODO: Migrate QRegExp to QRegularExpression
|
||||
QRegExp const escapeSequenceExpression(QStringLiteral(R"(\x1B\[([\d;\?FA]+)([mlh]?))"));
|
||||
QTextCharFormat defaultTextCharFormat = m_cursor.charFormat();
|
||||
int offset = escapeSequenceExpression.indexIn(text);
|
||||
ReturnInsert(m_cursor, text.mid(0, offset));
|
||||
QTextCharFormat textCharFormat = defaultTextCharFormat;
|
||||
while (offset >= 0) {
|
||||
int previousOffset = offset + escapeSequenceExpression.matchedLength();
|
||||
QStringList captures = escapeSequenceExpression.capturedTexts();
|
||||
if (captures.size() >= 3 && captures[2] == QStringLiteral("m")) {
|
||||
QStringList capturedTexts = captures[1].split(QLatin1Char{';'});
|
||||
QListIterator<QString> i(capturedTexts);
|
||||
while (i.hasNext()) {
|
||||
bool ok = false;
|
||||
int attribute = i.next().toInt(&ok);
|
||||
Q_ASSERT(ok);
|
||||
ParseEscapeSequence(attribute, i, textCharFormat, defaultTextCharFormat);
|
||||
}
|
||||
} else if (captures.size() >= 2 &&
|
||||
(captures[1].endsWith(QLatin1Char{'F'}) || captures[1].endsWith(QLatin1Char{'A'}))) {
|
||||
int lineCount = captures[1].chopped(1).toInt();
|
||||
if (!lineCount)
|
||||
lineCount = 1;
|
||||
for (int i = 0; i < lineCount; ++i) {
|
||||
m_cursor.movePosition(QTextCursor::PreviousBlock);
|
||||
m_cursor.select(QTextCursor::BlockUnderCursor);
|
||||
m_cursor.removeSelectedText();
|
||||
m_cursor.insertBlock();
|
||||
}
|
||||
}
|
||||
offset = escapeSequenceExpression.indexIn(text, previousOffset);
|
||||
if (offset < 0) {
|
||||
ReturnInsert(m_cursor, text.mid(previousOffset), textCharFormat);
|
||||
} else {
|
||||
ReturnInsert(m_cursor, text.mid(previousOffset, offset - previousOffset), textCharFormat);
|
||||
}
|
||||
}
|
||||
m_cursor.setCharFormat(defaultTextCharFormat);
|
||||
m_cursor.endEditBlock();
|
||||
m_ui->processOutput->ensureCursorVisible();
|
||||
}
|
||||
|
||||
void MainWindow::insertContinueNote(const QString& text) {
|
||||
if (m_inContinueNote)
|
||||
return;
|
||||
m_inContinueNote = true;
|
||||
|
||||
m_cursor.movePosition(QTextCursor::End);
|
||||
QTextCharFormat textCharFormat = m_cursor.charFormat();
|
||||
textCharFormat.setForeground(QColor(0, 255, 0));
|
||||
m_cursor.insertText(text, textCharFormat);
|
||||
m_cursor.insertBlock();
|
||||
m_ui->processOutput->ensureCursorVisible();
|
||||
}
|
||||
|
||||
void MainWindow::onUpdateTrackChanged(int index) {
|
||||
qDebug() << "Track changed from " << m_settings.value(QStringLiteral("update_track")) << " to "
|
||||
<< skUpdateTracks[index];
|
||||
m_settings.setValue(QStringLiteral("update_track"), skUpdateTracks[index]);
|
||||
m_dlManager.fetchIndex();
|
||||
m_ui->devTrackWarning->setVisible(index == 1);
|
||||
m_ui->continuousTrackWarning->setVisible(index == 2);
|
||||
}
|
||||
|
||||
void MainWindow::initOptions() {
|
||||
initGraphicsApiOption(m_ui->metalOption, CurPlatform != Platform::MacOS, DEFAULT_GRAPHICS_API == "Metal"sv);
|
||||
initGraphicsApiOption(m_ui->vulkanOption, CurPlatform == Platform::MacOS, DEFAULT_GRAPHICS_API == "Vulkan"sv);
|
||||
initGraphicsApiOption(m_ui->d3d11Option, CurPlatform != Platform::Win32, DEFAULT_GRAPHICS_API == "D3D11"sv);
|
||||
initNumberComboOption(m_ui->anistropicFilteringBox, m_cvarCommons.m_texAnisotropy);
|
||||
initNumberComboOption(m_ui->antialiasingBox, m_cvarCommons.m_drawSamples);
|
||||
initCheckboxOption(m_ui->fullscreen, m_cvarCommons.m_fullscreen);
|
||||
initCheckboxOption(m_ui->deepColor, m_cvarCommons.m_deepColor);
|
||||
|
||||
m_ui->developerModeBox->setToolTip(QString::fromUtf8(hecl::com_developer->rawHelp().data()));
|
||||
m_ui->developerModeBox->setChecked(hecl::com_developer->toBoolean());
|
||||
m_ui->developerOptionsGroup->setVisible(hecl::com_developer->toBoolean());
|
||||
connect(m_ui->developerModeBox, &QCheckBox::stateChanged, this, [this](int state) {
|
||||
bool isChecked = state == Qt::Checked;
|
||||
if (hecl::com_enableCheats->toBoolean() && !isChecked) {
|
||||
m_ui->enableCheatsBox->setChecked(false);
|
||||
// m_ui->tweaksOptionsGroup->setVisible(false);
|
||||
m_ui->warpBtn->setVisible(false);
|
||||
}
|
||||
m_ui->developerOptionsGroup->setVisible(isChecked);
|
||||
hecl::CVarManager::instance()->setDeveloperMode(isChecked, true);
|
||||
m_cvarManager.serialize();
|
||||
});
|
||||
|
||||
m_ui->enableCheatsBox->setToolTip(QString::fromUtf8(hecl::com_enableCheats->rawHelp().data()));
|
||||
m_ui->enableCheatsBox->setChecked(hecl::com_enableCheats->toBoolean());
|
||||
m_ui->tweaksOptionsGroup->setVisible(false); // hecl::com_enableCheats->toBoolean()
|
||||
m_ui->warpBtn->setVisible(hecl::com_enableCheats->toBoolean());
|
||||
connect(m_ui->enableCheatsBox, &QCheckBox::stateChanged, this, [this](int state) {
|
||||
bool isChecked = state == Qt::Checked;
|
||||
if (!hecl::com_developer->toBoolean() && isChecked) {
|
||||
m_ui->developerModeBox->setChecked(true);
|
||||
m_ui->developerOptionsGroup->setVisible(true);
|
||||
}
|
||||
// m_ui->tweaksOptionsGroup->setVisible(isChecked);
|
||||
m_ui->warpBtn->setVisible(isChecked);
|
||||
hecl::CVarManager::instance()->setCheatsEnabled(isChecked, true);
|
||||
m_cvarManager.serialize();
|
||||
});
|
||||
|
||||
initCheckboxOption(m_ui->developerModeBox, hecl::com_developer);
|
||||
initCheckboxOption(m_ui->enableCheatsBox, hecl::com_enableCheats);
|
||||
initCheckboxOption(m_ui->variableDtBox, m_cvarCommons.m_variableDt);
|
||||
initCheckboxOption(m_ui->areaInfoOverlayBox, m_cvarCommons.m_debugOverlayAreaInfo);
|
||||
initCheckboxOption(m_ui->playerInfoOverlayBox, m_cvarCommons.m_debugOverlayPlayerInfo);
|
||||
initCheckboxOption(m_ui->worldInfoOverlayBox, m_cvarCommons.m_debugOverlayWorldInfo);
|
||||
initCheckboxOption(m_ui->frameCounterBox, m_cvarCommons.m_debugOverlayShowFrameCounter);
|
||||
initCheckboxOption(m_ui->inGameTimeBox, m_cvarCommons.m_debugOverlayShowInGameTime);
|
||||
initCheckboxOption(m_ui->resourceStatsOverlayBox, m_cvarCommons.m_debugOverlayShowResourceStats);
|
||||
initCheckboxOption(m_ui->drawLighting, m_cvarCommons.m_debugToolDrawLighting);
|
||||
initCheckboxOption(m_ui->drawAiPaths, m_cvarCommons.m_debugToolDrawAiPath);
|
||||
initCheckboxOption(m_ui->drawCollisionActors, m_cvarCommons.m_debugToolDrawCollisionActors);
|
||||
initCheckboxOption(m_ui->drawMazePath, m_cvarCommons.m_debugToolDrawMazePath);
|
||||
initCheckboxOption(m_ui->drawPlatformCollision, m_cvarCommons.m_debugToolDrawPlatformCollision);
|
||||
initCheckboxOption(m_ui->logScriptingBox,
|
||||
// TODO centralize
|
||||
hecl::CVarManager::instance()->findOrMakeCVar(
|
||||
"stateManager.logScripting"sv, "Prints object communication to the console", false,
|
||||
hecl::CVar::EFlags::ReadOnly | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Game));
|
||||
initCheckboxOption(m_ui->skipSplashScreensBox,
|
||||
// TODO centralize
|
||||
hecl::CVarManager::instance()->findOrMakeCVar(
|
||||
"tweak.game.SplashScreensDisabled"sv, "Skip splash screens on game startup", false,
|
||||
hecl::CVar::EFlags::ReadOnly | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Game));
|
||||
|
||||
m_launchOptionsModel.setStringList(QSettings().value(QStringLiteral("urde_arguments")).toStringList());
|
||||
m_ui->launchOptionsList->setModel(&m_launchOptionsModel);
|
||||
|
||||
connect(m_ui->launchOptionAddButton, &QPushButton::clicked, this, [this] {
|
||||
int row = m_launchOptionsModel.rowCount();
|
||||
if (m_launchOptionsModel.insertRow(row)) {
|
||||
QModelIndex index = m_launchOptionsModel.index(row);
|
||||
m_ui->launchOptionsList->selectionModel()->select(index, QItemSelectionModel::SelectionFlag::ClearAndSelect);
|
||||
m_ui->launchOptionsList->edit(index);
|
||||
}
|
||||
});
|
||||
connect(m_ui->launchOptionDeleteButton, &QPushButton::clicked, this, [this] {
|
||||
QItemSelectionModel* selection = m_ui->launchOptionsList->selectionModel();
|
||||
if (selection == nullptr) {
|
||||
return;
|
||||
}
|
||||
QModelIndexList list = selection->selectedRows();
|
||||
for (QModelIndex index : list) {
|
||||
m_launchOptionsModel.removeRow(index.row());
|
||||
}
|
||||
});
|
||||
connect(&m_launchOptionsModel, &QStringListModel::dataChanged, this,
|
||||
[this]() { QSettings().setValue(QStringLiteral("urde_arguments"), m_launchOptionsModel.stringList()); });
|
||||
connect(&m_launchOptionsModel, &QStringListModel::rowsRemoved, this,
|
||||
[this]() { QSettings().setValue(QStringLiteral("urde_arguments"), m_launchOptionsModel.stringList()); });
|
||||
connect(m_ui->warpBtn, &QPushButton::clicked, this, [this] {
|
||||
QFileInfo areaPath(
|
||||
QFileDialog::getOpenFileName(this, tr("Select area to warp to..."), m_path, QStringLiteral("*.blend")));
|
||||
if (!areaPath.exists() || areaPath.suffix() != QStringLiteral("blend") ||
|
||||
!areaPath.fileName().contains(QStringLiteral("!area_"))) {
|
||||
m_warpSettings.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
auto ret =
|
||||
QMessageBox::question(this, tr("Select enabled layers?"), tr("Do you want to only enable certain layers?"));
|
||||
|
||||
QString layerBits;
|
||||
if (ret == QMessageBox::StandardButton::Yes) {
|
||||
QList<Layer> layers;
|
||||
QDirIterator iter(areaPath.absolutePath(), QDir::Filter::Dirs);
|
||||
while (iter.hasNext()) {
|
||||
QFileInfo f(iter.next());
|
||||
if (f.isDir()) {
|
||||
QDir dir(f.absoluteFilePath());
|
||||
if (dir.exists(QStringLiteral("!objects.yaml"))) {
|
||||
bool active = dir.exists(QStringLiteral("!defaultactive"));
|
||||
layers.push_back({f.baseName(), active});
|
||||
}
|
||||
}
|
||||
}
|
||||
std::sort(layers.begin(), layers.end(), [&](const auto& a, const auto& b) { return a.name < b.name; });
|
||||
|
||||
LayerDialog layer(this);
|
||||
layer.createLayerCheckboxes(layers);
|
||||
auto code = layer.exec();
|
||||
if (code == QDialog::DialogCode::Accepted) {
|
||||
layerBits = layer.getLayerBits();
|
||||
}
|
||||
}
|
||||
QString directoryPath = areaPath.path();
|
||||
#if _WIN32
|
||||
directoryPath.replace(QLatin1Char('/'), QDir::separator());
|
||||
#else
|
||||
directoryPath.replace(QLatin1Char('\\'), QDir::separator());
|
||||
#endif
|
||||
auto list = directoryPath.split(QDir::separator());
|
||||
std::string areaDirectory = list.last().toLower().toStdString();
|
||||
list.pop_back();
|
||||
list.pop_back();
|
||||
std::string worldDir = list.last().toLower().toStdString();
|
||||
quint32 worldIndex;
|
||||
std::sscanf(worldDir.c_str(), "metroid%i", &worldIndex);
|
||||
quint32 areaIndex;
|
||||
char areaName[2048];
|
||||
std::sscanf(areaDirectory.c_str(), "%2i%[^\n]", &areaIndex, areaName);
|
||||
if (layerBits.isEmpty()) {
|
||||
m_warpSettings = QStringLiteral("--warp %1 %2").arg(worldIndex).arg(areaIndex).split(QLatin1Char(' '));
|
||||
} else {
|
||||
m_warpSettings =
|
||||
QStringLiteral("--warp %1 %2 %3").arg(worldIndex).arg(areaIndex).arg(layerBits).split(QLatin1Char(' '));
|
||||
}
|
||||
onLaunch();
|
||||
m_warpSettings.clear();
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::initNumberComboOption(QComboBox* action, hecl::CVar* cvar) {
|
||||
QString itemString;
|
||||
for (int i = 0; !(itemString = action->itemText(i)).isEmpty(); ++i) {
|
||||
if (itemString.toInt() == cvar->toSigned()) {
|
||||
action->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
action->setToolTip(QString::fromUtf8(cvar->rawHelp().data()));
|
||||
connect(action, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
||||
[this, action, cvar](const int i) {
|
||||
cvar->fromInteger(action->itemText(i).toInt());
|
||||
m_cvarManager.serialize();
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::initCheckboxOption(QCheckBox* action, hecl::CVar* cvar) {
|
||||
action->setToolTip(QString::fromUtf8(cvar->rawHelp().data()));
|
||||
action->setChecked(cvar->toBoolean());
|
||||
connect(action, &QCheckBox::stateChanged, this, [this, cvar](int state) {
|
||||
cvar->fromBoolean(state == Qt::Checked);
|
||||
m_cvarManager.serialize();
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::initGraphicsApiOption(QRadioButton* action, bool hidden, bool isDefault) {
|
||||
if (hidden) {
|
||||
action->hide();
|
||||
return;
|
||||
}
|
||||
const std::string& currApi = m_cvarCommons.getGraphicsApi();
|
||||
action->setChecked(action->text().compare(QString::fromUtf8(currApi.data()), Qt::CaseInsensitive) == 0 ||
|
||||
(isDefault && currApi.empty()));
|
||||
connect(action, &QRadioButton::toggled, this, [this, action](bool checked) {
|
||||
if (checked) {
|
||||
m_cvarCommons.setGraphicsApi(action->text().toStdString());
|
||||
m_cvarCommons.serialize();
|
||||
}
|
||||
});
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QProcess>
|
||||
#include <QTextCursor>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QRadioButton>
|
||||
|
||||
#include "Common.hpp"
|
||||
#include "DownloadManager.hpp"
|
||||
|
||||
#include <hecl/CVarCommons.hpp>
|
||||
#include <hecl/Runtime.hpp>
|
||||
|
||||
class QPushButton;
|
||||
class QTextCharFormat;
|
||||
class QTextEdit;
|
||||
class QuaZip;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
} // namespace Ui
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
static const QStringList skUpdateTracks;
|
||||
Q_OBJECT
|
||||
std::unique_ptr<Ui::MainWindow> m_ui;
|
||||
hecl::Runtime::FileStoreManager m_fileMgr;
|
||||
hecl::CVarManager m_cvarManager;
|
||||
hecl::CVarCommons m_cvarCommons;
|
||||
QTextCursor m_cursor;
|
||||
QString m_path;
|
||||
QString m_urdePath;
|
||||
QString m_heclPath;
|
||||
QProcess m_heclProc;
|
||||
DownloadManager m_dlManager;
|
||||
QStringList m_warpSettings;
|
||||
QSettings m_settings;
|
||||
URDEVersion m_recommendedVersion;
|
||||
bool m_inContinueNote = false;
|
||||
QStringListModel m_launchOptionsModel;
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget* parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
void setTextTermFormatting(const QString& text);
|
||||
void insertContinueNote(const QString& text);
|
||||
|
||||
private slots:
|
||||
void onExtract();
|
||||
void onExtractFinished(int exitCode, QProcess::ExitStatus);
|
||||
void onPackage();
|
||||
void onPackageFinished(int exitCode, QProcess::ExitStatus);
|
||||
void onLaunch();
|
||||
void onLaunchFinished(int exitCode, QProcess::ExitStatus);
|
||||
void doHECLTerminate();
|
||||
void onReturnPressed();
|
||||
void onDownloadPressed();
|
||||
// void onUpdateURDEPressed();
|
||||
void onUpdateTrackChanged(int index);
|
||||
|
||||
private:
|
||||
bool checkDownloadedBinary();
|
||||
void setPath(const QString& path);
|
||||
void initSlots();
|
||||
void onIndexDownloaded(const QStringList& index);
|
||||
void onBinaryDownloaded(QuaZip& file);
|
||||
void onBinaryFailed();
|
||||
void disableOperations();
|
||||
void enableOperations();
|
||||
bool isPackageComplete() const;
|
||||
void initOptions();
|
||||
void initGraphicsApiOption(QRadioButton* action, bool hidden, bool isDefault);
|
||||
void initNumberComboOption(QComboBox* action, hecl::CVar* cvar);
|
||||
void initCheckboxOption(QCheckBox* action, hecl::CVar* cvar);
|
||||
};
|
|
@ -0,0 +1,250 @@
|
|||
#include "SysReqTableView.hpp"
|
||||
#include <QPropertyAnimation>
|
||||
#include <QSequentialAnimationGroup>
|
||||
#include <QHeaderView>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDomDocument>
|
||||
#include <QProcess>
|
||||
#include <QStorageInfo>
|
||||
#include "FindBlender.hpp"
|
||||
#include <QDebug>
|
||||
|
||||
#if _WIN32
|
||||
#include <Windows.h>
|
||||
#include <VersionHelpers.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if __APPLE__
|
||||
#include "MacOSSystemVersion.hpp"
|
||||
#elif _WIN32
|
||||
static QString GetWindowsVersionString() {
|
||||
if (IsWindows10OrGreater())
|
||||
return QObject::tr("Windows 10");
|
||||
else if (IsWindows8Point1OrGreater())
|
||||
return QObject::tr("Windows 8.1");
|
||||
else if (IsWindows8OrGreater())
|
||||
return QObject::tr("Windows 8");
|
||||
else if (IsWindows7SP1OrGreater())
|
||||
return QObject::tr("Windows 7 SP1");
|
||||
else if (IsWindows7OrGreater())
|
||||
return QObject::tr("Windows 7");
|
||||
else if (IsWindowsVistaOrGreater())
|
||||
return QObject::tr("Windows Vista");
|
||||
else if (IsWindowsXPOrGreater())
|
||||
return QObject::tr("Windows XP");
|
||||
else
|
||||
return QObject::tr("Windows Old And Won't Work");
|
||||
}
|
||||
#endif
|
||||
|
||||
SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent) {
|
||||
#if _WIN32
|
||||
ULONGLONG memSize;
|
||||
GetPhysicallyInstalledSystemMemory(&memSize);
|
||||
m_memorySize = memSize * 1024;
|
||||
#else
|
||||
m_memorySize = uint64_t(sysconf(_SC_PHYS_PAGES)) * sysconf(_SC_PAGESIZE);
|
||||
#endif
|
||||
m_memorySizeStr = tr("%1 GiB").arg(m_memorySize / 1024.f / 1024.f / 1024.f);
|
||||
#ifdef __APPLE__
|
||||
GetMacOSSystemVersion(m_macosMajor, m_macosMinor, m_macosPatch);
|
||||
if (m_macosPatch == 0) {
|
||||
m_osVersion = tr("macOS %1.%2").arg(m_macosMajor, m_macosMinor);
|
||||
} else {
|
||||
m_osVersion = tr("macOS %1.%2.%3")
|
||||
.arg(QString::number(m_macosMajor), QString::number(m_macosMinor), QString::number(m_macosPatch));
|
||||
}
|
||||
#elif _WIN32
|
||||
m_win7SP1OrGreater = IsWindows7SP1OrGreater();
|
||||
m_osVersion = GetWindowsVersionString();
|
||||
#elif __linux__
|
||||
m_osVersion = tr("Linux");
|
||||
#endif
|
||||
hecl::blender::FindBlender(m_blendMajor, m_blendMinor);
|
||||
if (m_blendMajor != 0) {
|
||||
m_blendVersionStr = tr("Blender %1.%2").arg(QString::number(m_blendMajor), QString::number(m_blendMinor));
|
||||
} else {
|
||||
m_blendVersionStr = tr("Not Found");
|
||||
}
|
||||
}
|
||||
|
||||
void SysReqTableModel::updateFreeDiskSpace(const QString& path) {
|
||||
if (path.isEmpty()) {
|
||||
m_freeDiskSpace = 0;
|
||||
m_freeDiskSpaceStr = tr("<Set Working Directory>");
|
||||
} else {
|
||||
m_freeDiskSpace = QStorageInfo(path).bytesFree();
|
||||
m_freeDiskSpaceStr = tr("%1 GB").arg(m_freeDiskSpace / 1000.f / 1000.f / 1000.f, 1, 'f', 1);
|
||||
}
|
||||
emit dataChanged(index(1, 0), index(1, 0));
|
||||
}
|
||||
|
||||
int SysReqTableModel::rowCount(const QModelIndex& parent) const { return 4; }
|
||||
|
||||
int SysReqTableModel::columnCount(const QModelIndex& parent) const { return 2; }
|
||||
|
||||
QVariant SysReqTableModel::data(const QModelIndex& index, int role) const {
|
||||
if (role != Qt::DisplayRole && role != Qt::UserRole) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (role == Qt::UserRole) {
|
||||
switch (index.row()) {
|
||||
case 0:
|
||||
return m_memorySize >= 0xC0000000;
|
||||
case 1:
|
||||
return m_freeDiskSpace >= qint64(5) * 1000 * 1000 * 1000;
|
||||
case 2:
|
||||
#ifdef __APPLE__
|
||||
return m_macosMajor > 10 || m_macosMinor >= 11;
|
||||
#elif defined(_WIN32)
|
||||
return m_win7SP1OrGreater;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
case 3:
|
||||
return isBlenderVersionOk();
|
||||
}
|
||||
} else {
|
||||
if (index.column() == 0) {
|
||||
/* Recommended */
|
||||
switch (index.row()) {
|
||||
case 0:
|
||||
return tr("3 GiB");
|
||||
case 1:
|
||||
return tr("5 GB (MP1)");
|
||||
case 2:
|
||||
#ifdef __APPLE__
|
||||
return tr("macOS 10.11");
|
||||
#elif defined(_WIN32)
|
||||
return tr("Windows 7 SP1");
|
||||
#elif defined(__linux__)
|
||||
return tr("Linux");
|
||||
#else
|
||||
return {};
|
||||
#endif
|
||||
case 3:
|
||||
return QStringLiteral("Blender %1.%2+")
|
||||
.arg(hecl::blender::MinBlenderMajorSearch)
|
||||
.arg(hecl::blender::MinBlenderMinorSearch);
|
||||
}
|
||||
} else if (index.column() == 1) {
|
||||
/* Your System */
|
||||
switch (index.row()) {
|
||||
case 0:
|
||||
return m_memorySizeStr;
|
||||
case 1:
|
||||
return m_freeDiskSpaceStr;
|
||||
case 2:
|
||||
return m_osVersion;
|
||||
case 3:
|
||||
return m_blendVersionStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
QVariant SysReqTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if (role != Qt::DisplayRole) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (orientation == Qt::Horizontal) {
|
||||
switch (section) {
|
||||
case 0:
|
||||
default:
|
||||
return tr("Recommended");
|
||||
case 1:
|
||||
return tr("Your System");
|
||||
}
|
||||
} else {
|
||||
switch (section) {
|
||||
default:
|
||||
case 0:
|
||||
return tr("Memory");
|
||||
case 1:
|
||||
return tr("Disk Space");
|
||||
case 2:
|
||||
return tr("OS");
|
||||
case 3:
|
||||
return tr("Blender");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SysReqTableModel::isBlenderVersionOk() const {
|
||||
return (m_blendMajor >= hecl::blender::MinBlenderMajorSearch &&
|
||||
m_blendMajor <= hecl::blender::MaxBlenderMajorSearch) &&
|
||||
(m_blendMinor >= hecl::blender::MinBlenderMinorSearch && m_blendMinor <= hecl::blender::MaxBlenderMinorSearch);
|
||||
}
|
||||
|
||||
void SysReqTableView::paintEvent(QPaintEvent* e) {
|
||||
int tableWidth = columnWidth(0) + columnWidth(1);
|
||||
int tableX = verticalHeader()->width() + columnViewportPosition(0);
|
||||
int tableY = horizontalHeader()->height();
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
QWidget* w = std::get<0>(m_backgroundWidgets[i]);
|
||||
|
||||
QPalette pal = palette();
|
||||
if (m_model.data(m_model.index(i, 0), Qt::UserRole).toBool())
|
||||
pal.setColor(QPalette::Window, QColor::fromRgbF(0.f, 1.f, 0.f, 0.2f));
|
||||
else
|
||||
pal.setColor(QPalette::Window, QColor::fromRgbF(1.f, 0.f, 0.f, 0.2f));
|
||||
w->setPalette(pal);
|
||||
|
||||
QSequentialAnimationGroup* animation = std::get<1>(m_backgroundWidgets[i]);
|
||||
QPropertyAnimation* pAnimation = static_cast<QPropertyAnimation*>(animation->animationAt(1));
|
||||
bool& running = std::get<2>(m_backgroundWidgets[i]);
|
||||
if (!running) {
|
||||
w->setGeometry(QRect(tableX, tableY + rowViewportPosition(i), 0, rowHeight(i)));
|
||||
pAnimation->setStartValue(QRect(tableX, tableY + rowViewportPosition(i), 0, rowHeight(i)));
|
||||
pAnimation->setEndValue(QRect(tableX, tableY + rowViewportPosition(i), tableWidth, rowHeight(i)));
|
||||
animation->start();
|
||||
running = true;
|
||||
}
|
||||
if (animation->state() == QAbstractAnimation::State::Running)
|
||||
pAnimation->setEndValue(QRect(tableX, tableY + rowViewportPosition(i), tableWidth, rowHeight(i)));
|
||||
else
|
||||
w->setGeometry(QRect(tableX, tableY + rowViewportPosition(i), tableWidth, rowHeight(i)));
|
||||
}
|
||||
QTableView::paintEvent(e);
|
||||
}
|
||||
|
||||
SysReqTableView::SysReqTableView(QWidget* parent) : QTableView(parent) {
|
||||
setModel(&m_model);
|
||||
|
||||
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
setSelectionMode(QAbstractItemView::SelectionMode::NoSelection);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
QWidget* w = new QWidget(this);
|
||||
std::get<0>(m_backgroundWidgets[i]) = w;
|
||||
|
||||
QPalette pal = palette();
|
||||
if (m_model.data(m_model.index(i, 0), Qt::UserRole).toBool())
|
||||
pal.setColor(QPalette::Window, QColor::fromRgbF(0.f, 1.f, 0.f, 0.2f));
|
||||
else
|
||||
pal.setColor(QPalette::Window, QColor::fromRgbF(1.f, 0.f, 0.f, 0.2f));
|
||||
|
||||
w->setAutoFillBackground(true);
|
||||
w->setPalette(pal);
|
||||
w->lower();
|
||||
w->show();
|
||||
|
||||
QPropertyAnimation* animation = new QPropertyAnimation(w, "geometry", this);
|
||||
animation->setDuration(2000);
|
||||
animation->setEasingCurve(QEasingCurve::Type::InOutCubic);
|
||||
|
||||
QSequentialAnimationGroup* seq = new QSequentialAnimationGroup(this);
|
||||
std::get<1>(m_backgroundWidgets[i]) = seq;
|
||||
seq->addPause(i * 100);
|
||||
seq->addAnimation(animation);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include <QTableView>
|
||||
|
||||
class QSequentialAnimationGroup;
|
||||
|
||||
class SysReqTableModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
uint64_t m_memorySize = 0;
|
||||
QString m_memorySizeStr;
|
||||
qint64 m_freeDiskSpace = 0;
|
||||
QString m_freeDiskSpaceStr = tr("<Set Working Directory>");
|
||||
#if __APPLE__
|
||||
int m_macosMajor = 0;
|
||||
int m_macosMinor = 0;
|
||||
int m_macosPatch = 0;
|
||||
#elif _WIN32
|
||||
bool m_win7SP1OrGreater = false;
|
||||
#endif
|
||||
QString m_osVersion;
|
||||
int m_blendMajor = 0;
|
||||
int m_blendMinor = 0;
|
||||
QString m_blendVersionStr;
|
||||
|
||||
public:
|
||||
SysReqTableModel(QObject* parent = Q_NULLPTR);
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
bool isBlenderVersionOk() const;
|
||||
void updateFreeDiskSpace(const QString& path);
|
||||
};
|
||||
|
||||
class SysReqTableView : public QTableView {
|
||||
Q_OBJECT
|
||||
SysReqTableModel m_model;
|
||||
std::tuple<QWidget*, QSequentialAnimationGroup*, bool> m_backgroundWidgets[6] = {};
|
||||
|
||||
public:
|
||||
SysReqTableView(QWidget* parent = Q_NULLPTR);
|
||||
void paintEvent(QPaintEvent* e) override;
|
||||
const SysReqTableModel& getModel() const { return m_model; }
|
||||
bool isBlenderVersionOk() const { return m_model.isBlenderVersionOk(); }
|
||||
void updateFreeDiskSpace(const QString& path) { m_model.updateFreeDiskSpace(path); }
|
||||
};
|
|
@ -0,0 +1,73 @@
|
|||
#include <QtGlobal>
|
||||
#if defined(_WIN32) && !defined(_DLL)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
// Static linking on Windows
|
||||
#include <QtPlugin>
|
||||
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStyleFactory>
|
||||
#include "MainWindow.hpp"
|
||||
#include "Common.hpp"
|
||||
|
||||
extern "C" const uint8_t MAINICON_QT[];
|
||||
|
||||
static QIcon MakeAppIcon() {
|
||||
QIcon ret;
|
||||
|
||||
const uint8_t* ptr = MAINICON_QT;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
uint32_t size = *reinterpret_cast<const uint32_t*>(ptr);
|
||||
ptr += 4;
|
||||
|
||||
QPixmap pm;
|
||||
pm.loadFromData(ptr, size);
|
||||
ret.addPixmap(pm);
|
||||
ptr += size;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
InitializePlatform();
|
||||
|
||||
QApplication::setOrganizationName(QStringLiteral("AxioDL"));
|
||||
QApplication::setApplicationName(QStringLiteral("HECL"));
|
||||
|
||||
#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_UseHighDpiPixmaps);
|
||||
#endif
|
||||
QApplication::setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
|
||||
QApplication a(argc, argv);
|
||||
QApplication::setWindowIcon(MakeAppIcon());
|
||||
|
||||
QPalette darkPalette;
|
||||
darkPalette.setColor(QPalette::Window, QColor(53, 53, 53));
|
||||
darkPalette.setColor(QPalette::WindowText, Qt::white);
|
||||
darkPalette.setColor(QPalette::Base, QColor(42, 42, 42));
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Base, QColor(25, 25, 25, 53));
|
||||
darkPalette.setColor(QPalette::AlternateBase, QColor(53, 53, 53));
|
||||
darkPalette.setColor(QPalette::ToolTipBase, QColor(42, 42, 42));
|
||||
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
|
||||
darkPalette.setColor(QPalette::Text, Qt::white);
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(255, 255, 255, 120));
|
||||
darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Button, QColor(53, 53, 53, 53));
|
||||
darkPalette.setColor(QPalette::ButtonText, Qt::white);
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(255, 255, 255, 120));
|
||||
darkPalette.setColor(QPalette::BrightText, Qt::red);
|
||||
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
|
||||
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(42, 130, 218, 53));
|
||||
darkPalette.setColor(QPalette::HighlightedText, Qt::white);
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(255, 255, 255, 120));
|
||||
QApplication::setPalette(darkPalette);
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return QApplication::exec();
|
||||
}
|
After Width: | Height: | Size: 1.1 MiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 281 KiB |
After Width: | Height: | Size: 6.9 KiB |
|
@ -0,0 +1,18 @@
|
|||
add_executable(mkqticon mkqticon.c)
|
||||
target_link_libraries(mkqticon ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})
|
||||
target_include_directories(mkqticon PRIVATE ${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
|
||||
|
||||
macro(declare_qticon_target)
|
||||
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/hecl-gui/platforms/freedesktop/mainicon_qt.bin
|
||||
COMMAND $<TARGET_FILE:mkqticon>
|
||||
ARGS ${CMAKE_BINARY_DIR}/hecl-gui/platforms/freedesktop/mainicon_qt.bin
|
||||
DEPENDS
|
||||
${CMAKE_SOURCE_DIR}/hecl-gui/platforms/freedesktop/128x128/apps/hecl.png
|
||||
${CMAKE_SOURCE_DIR}/hecl-gui/platforms/freedesktop/64x64/apps/hecl.png
|
||||
${CMAKE_SOURCE_DIR}/hecl-gui/platforms/freedesktop/48x48/apps/hecl.png
|
||||
${CMAKE_SOURCE_DIR}/hecl-gui/platforms/freedesktop/32x32/apps/hecl.png
|
||||
${CMAKE_SOURCE_DIR}/hecl-gui/platforms/freedesktop/16x16/apps/hecl.png
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/hecl-gui/platforms/freedesktop
|
||||
COMMENT "Generating mainicon_qt.bin")
|
||||
bintoc(mainicon_qt.cpp ${CMAKE_BINARY_DIR}/hecl-gui/platforms/freedesktop/mainicon_qt.bin MAINICON_QT)
|
||||
endmacro()
|
|
@ -0,0 +1,9 @@
|
|||
[Desktop Entry]
|
||||
Name=HECL
|
||||
GenericName=Game Data Prep Tool
|
||||
Comment=Prepare Game Data for URDE
|
||||
Exec=hecl-gui
|
||||
Icon=hecl
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=Graphics;3DGraphics;
|
|
@ -0,0 +1,71 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static const int DIMS[] =
|
||||
{
|
||||
16,
|
||||
32,
|
||||
48,
|
||||
64,
|
||||
128,
|
||||
256,
|
||||
0
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Usage: makeqticon <out.bin>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
FILE* ofp = fopen(argv[1], "wb");
|
||||
if (!ofp)
|
||||
{
|
||||
fprintf(stderr, "'%s' is not able to be opened for writing as a regular file\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char command[2048];
|
||||
|
||||
for (const int* d = DIMS ; *d != 0 ; ++d)
|
||||
{
|
||||
printf("Rendering main icon @%dx%d\n", *d, *d);
|
||||
fflush(stdout);
|
||||
|
||||
snprintf(command, 2048, "%dx%d/apps/hecl.png", *d, *d);
|
||||
FILE* fp = fopen(command, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
fprintf(stderr, "unable to open '%s' for reading\n", command);
|
||||
fclose(ofp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
uint32_t size = (uint32_t)ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
fwrite(&size, 1, 4, ofp);
|
||||
|
||||
uint8_t buf[1024];
|
||||
while (size > 0)
|
||||
{
|
||||
long thisSize = size;
|
||||
if (thisSize > 1024)
|
||||
thisSize = 1024;
|
||||
|
||||
fread(buf, 1, (size_t)thisSize, fp);
|
||||
fwrite(buf, 1, (size_t)thisSize, ofp);
|
||||
size -= thisSize;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
fclose(ofp);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>hecl-gui</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>@URDE_WC_DESCRIBE@</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>@URDE_WC_DESCRIBE@</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>2015-@CURRENT_YEAR@ AxioDL Team</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>mainicon.icns</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.axiodl.URDE</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>URDE</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>@URDE_WC_DESCRIBE@</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||
<description>HECL-GUI</description>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- Windows 10 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
<!-- Windows 8.1 -->
|
||||
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
|
||||
<!-- Windows Vista -->
|
||||
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
|
||||
<!-- Windows 7 -->
|
||||
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
|
||||
<!-- Windows 8 -->
|
||||
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
|
||||
</application>
|
||||
</compatibility>
|
||||
<asmv3:application>
|
||||
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
|
||||
<dpiAware>true/PM</dpiAware>
|
||||
</asmv3:windowsSettings>
|
||||
</asmv3:application>
|
||||
</assembly>
|
|
@ -0,0 +1,33 @@
|
|||
#include "winver.h"
|
||||
#define IDI_ICON1 101
|
||||
|
||||
IDI_ICON1 ICON DISCARDABLE "mainicon.ico"
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,0
|
||||
PRODUCTVERSION 1,0,0,0
|
||||
FILEFLAGS 0x0L
|
||||
FILEFLAGSMASK 0x3fL
|
||||
FILEOS 0x00040004L
|
||||
FILETYPE 0x1L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "000004b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Antidote / Jackoalan"
|
||||
VALUE "FileDescription", "HECL"
|
||||
VALUE "FileVersion", "BETA"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2015-2018 Antidote / Jackoalan"
|
||||
VALUE "InternalName", "hecl"
|
||||
VALUE "OriginalFilename", "hecl.exe"
|
||||
VALUE "ProductName", "HECL"
|
||||
VALUE "ProductVersion", "BETA"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0, 1200
|
||||
END
|
||||
END
|
After Width: | Height: | Size: 352 KiB |
|
@ -0,0 +1,6 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
indent_size = 4
|
|
@ -0,0 +1,75 @@
|
|||
# require 3.15 for GNUInstallDirs
|
||||
cmake_minimum_required(VERSION 3.15...3.18)
|
||||
|
||||
project(QuaZip VERSION 1.1)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
set(QUAZIP_LIB_VERSION ${QuaZip_VERSION})
|
||||
set(QUAZIP_LIB_SOVERSION 1.0.0)
|
||||
|
||||
option(BUILD_SHARED_LIBS "" ON)
|
||||
option(QUAZIP_INSTALL "" 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()
|
||||
|
||||
enable_testing()
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_DEBUG_POSTFIX d)
|
||||
|
||||
set(QUAZIP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_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_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()
|
||||
elseif(QUAZIP_QT_MAJOR_VERSION EQUAL 5)
|
||||
find_package(Qt5 REQUIRED COMPONENTS Core
|
||||
OPTIONAL_COMPONENTS Network Test)
|
||||
set(QUAZIP_LIB_LIBRARIES Qt5::Core)
|
||||
set(QUAZIP_TEST_QT_LIBRARIES Qt5::Core Qt5::Network Qt5::Test)
|
||||
set(QUAZIP_PKGCONFIG_REQUIRES Qt5Core)
|
||||
if (Qt5Network_FOUND AND Qt5Test_FOUND)
|
||||
set(QUAZIP_ENABLE_TESTS ON)
|
||||
endif()
|
||||
elseif(QUAZIP_QT_MAJOR_VERSION EQUAL 4)
|
||||
find_package(Qt4 4.5.0 REQUIRED COMPONENTS QtCore
|
||||
OPTIONAL_COMPONENTS QtNetwork QtTest)
|
||||
set(QUAZIP_LIB_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()
|
||||
|
||||
find_package(Qt${QUAZIP_QT_MAJOR_VERSION} QUIET OPTIONAL_COMPONENTS Zlib)
|
||||
if (Qt${QUAZIP_QT_MAJOR_VERSION}Zlib_FOUND)
|
||||
set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} Qt${QUAZIP_QT_MAJOR_VERSION}::Zlib)
|
||||
else()
|
||||
find_package(ZLIB REQUIRED)
|
||||
set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} ZLIB::ZLIB)
|
||||
endif()
|
||||
|
||||
add_subdirectory(quazip)
|
||||
|
||||
if(QUAZIP_ENABLE_TESTS)
|
||||
add_subdirectory(qztest EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
Fixed a bug? Implemented a new feature? Want to have it included in QuaZip?
|
||||
Here's what you need to do.
|
||||
|
||||
0. If you don't have a GitHub account, create one. It's ridiculously easy.
|
||||
|
||||
1. First, open an [issue](https://github.com/stachenov/quazip/issues).
|
||||
Even if you have already fixed it. It helps to track things because
|
||||
instead of a commit saying “fixed this and that” you have a reference
|
||||
to a full issue description.
|
||||
|
||||
2. Next, figure out the right branch to work on. *Usually* it's `master`,
|
||||
but sometimes it's something different. For example, there was time
|
||||
when new features went to `pre1.0`, and `master` was for 0.x bugfixes only.
|
||||
|
||||
3. Next, send a PR (pull request). There are numerous articles how to do it,
|
||||
but it's not exactly intuitive, just like anything with Git, so do
|
||||
some research before attempting to create a PR.
|
||||
|
||||
**Contribution guidelines**
|
||||
|
||||
To avoid spending time on something that may never be accepted, here are
|
||||
some guidelines.
|
||||
|
||||
1. Changes should be backwards-compatible. Don't just change method names
|
||||
and their signatures randomly. Don't just remove deprecated features—some
|
||||
of them are there to keep compatibility with old Qt versions. Even Qt 4 is
|
||||
still supported! Unless you're working on some sort of `pre2.0` branch
|
||||
or something like that, you should keep ABI compatibility as well! Meaning,
|
||||
no adding virtual functions, no changing parameter types, even if it's
|
||||
a source-compatible change, and a lot of other things, really.
|
||||
|
||||
2. If your change targets some new version of Qt, it's a very good idea
|
||||
to keep various `#ifs` in `quazip_qt_compat.h`, which exists for this very
|
||||
purpose. Don't just throw them into the code. Don't just replace deprecated
|
||||
things with their newer alternatives—it would break support of the old
|
||||
Qt versions.
|
||||
|
||||
3. If your changes aren't limited to a small fix or a convenience method,
|
||||
discussing them in the issue you just opened (if you didn't, do!) could
|
||||
help to achieve some agreement on what exactly is a good idea in your case.
|
||||
|
||||
4. Whether you're fixing a bug or adding a new feature, it's an awesome idea
|
||||
to add a new test in the `qztest` subproject. This way you make sure the
|
||||
bug stays fixed and the feature keeps working. This is *not* a mandatory
|
||||
requirement, however, because adding tests to a project you're not familiar
|
||||
with can be challenging, and it should not stop you from sending a PR.
|
||||
|
||||
5. It would be nice if you also update NEWS.txt with whatever changes
|
||||
you propose. Just add another line on top.
|
||||
|
||||
6. QuaZip doesn't really have any policies on PR commits. Just use common sense.
|
||||
Generally, it's better to keep separate things separate. If you made 2 changes,
|
||||
and there are 6 commits for one change and 4 for another, that's OK.
|
||||
Don't squash commits just to squash them. If your branch gets outdated before PR
|
||||
is accepted, merge or rebase—it doesn't really mater, as long as there are no
|
||||
conflicts.
|
|
@ -0,0 +1,491 @@
|
|||
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.
|
||||
|
||||
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
|
||||
|
||||
The copyright holders give you permission to link this library with
|
||||
independent modules to produce an executable, regardless of the license
|
||||
terms of these independent modules, and to copy and distribute the
|
||||
resulting executable under terms of your choice, provided that you also
|
||||
meet, for each linked independent module, the terms and conditions of
|
||||
the license of that module. An independent module is a module which is
|
||||
not derived from or based on this library. If you modify this library,
|
||||
you must extend this exception to your version of the library.
|
||||
|
||||
The text of the GNU Lesser General Public License V2.1 follows.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
|
@ -0,0 +1,205 @@
|
|||
QuaZip changes
|
||||
|
||||
* Current
|
||||
* Add CMake option to disable installation (Sebastian Rettenberger)
|
||||
* Use Qt's internal zlib instead of an external one if available
|
||||
|
||||
* 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
|
||||
* CMake regression fix
|
||||
|
||||
* 2019-05-23 0.8
|
||||
* Support for UTF-8 in file names and comments (Denis Zavorotnyy)
|
||||
* get/setOsCode(), get/setDefaultOsCode()
|
||||
* Fixed Z_STREAM_END handling in QuaZioDevice
|
||||
|
||||
* 2018-06-13 0.7.6
|
||||
* Fixed the Zip Slip vulnerability in JlCompress
|
||||
* Renamed crypt.h to minizip_crypt.h to avoid conflicts
|
||||
|
||||
* 2018-05-20 0.7.5
|
||||
* Fixed target_link_libraries call in CMakeLists
|
||||
* Worked around a Qt 4.6 bug (QTBUG-15421) screwing up hidden
|
||||
files handling in JlCompress::compressDir()
|
||||
* Removed Q_FOREACH uses to avoid conflicts (SF patch #32)
|
||||
|
||||
* 2017-02-05 0.7.4
|
||||
* Static analysis patch from Intel Deutschland GmbH
|
||||
* Replaced UNUSED with QUAZIP_UNUSED to avoid name clashes
|
||||
* Minor bug fixes
|
||||
|
||||
* 2017-02-05 0.7.3
|
||||
* Symlink handling
|
||||
* Static linking exception for LGPL
|
||||
* Minor bug fixes
|
||||
|
||||
* 2016-03-29 0.7.2
|
||||
* New JlCompress methods (QIODevice*-based API by Lukasz Kwiecinski)
|
||||
* Implemented QuaZioDevice::atEnd() and bytesAvailable()--these might
|
||||
break ABI, but pretty unlikely.
|
||||
|
||||
* 2015-01-07 0.7.1
|
||||
* Fixed licensing issues (bug #45).
|
||||
* Added the convenience method QuaZipFileInfo::isEncrypted().
|
||||
|
||||
* 2014-07-24 0.7
|
||||
* It is now possible to write ZIP files to sequential devices
|
||||
like sockets (only in mdCreate mode, so no self-extract, sorry).
|
||||
* A few zip64 fixes.
|
||||
* Several bug fixes and portability improvements.
|
||||
|
||||
* 2014-02-09 0.6.2
|
||||
* QuaZipNewInfo / QuaZipFileInfo64 now provide API to access/set
|
||||
NTFS time stamps - useful even on non-NTFS systems if you
|
||||
need more precise dates and times than default ones.
|
||||
* QuaZipNewInfo may now be initialized from QuaZipFileInfo64.
|
||||
* No more crashes when using QSaveFile as QIODevice for ZIP.
|
||||
* The new QuaZip::setAutoClose() method allows to leave the
|
||||
QIODevice open when you close the QuaZip instance.
|
||||
* qztest now depends on quazip, no longer breaking the build.
|
||||
|
||||
* 2014-01-26 0.6.1
|
||||
* Improved zip64 support.
|
||||
* A LOT more tests thanks to g++ --coverage / lcov.
|
||||
* JlCompress extraction methods now create files with default
|
||||
permissions if they are zero in the original archive.
|
||||
* Some QuaZipDir fixes (thanks to the new tests).
|
||||
|
||||
* 2014-01-22 0.6
|
||||
* Minizip updated to 1.1 (with all the necessary modifications
|
||||
re-done), and that means that...
|
||||
* the long-awaited zip64 support is now available!
|
||||
* A few rather minor fixes.
|
||||
|
||||
* 2014-01-19 0.5.2
|
||||
* Some minor bug fixes.
|
||||
* API to access file permissions subfield of the external
|
||||
attributes.
|
||||
* MS VS 2012 Express support.
|
||||
* API to set the default codec used to encode/decode file names
|
||||
(mainly for use by various wrappers such as JlCompress, when
|
||||
you don't have direct access to the underlying QuaZip instance).
|
||||
|
||||
* 2013-03-02 0.5.1
|
||||
* Lots of QuaZipDir fixes, thanks to all bug reporters.
|
||||
* Full Qt Creator support.
|
||||
* MS VS 2010 Express support.
|
||||
* Qt5 support (didn't need any source code changes anyway).
|
||||
* Lots of minor bug fixes.
|
||||
|
||||
* 2012-09-07 0.5
|
||||
* Added run_moc.bat files for building under Windows in case Qt
|
||||
integration is not available (e. g. VS 2008 Express).
|
||||
* Added the QuaZipDir class to simplify ZIP navigation in terms
|
||||
of directories.
|
||||
* Added the QuaGzipFile class for working with GZIP archives. It
|
||||
was added as a bonus since it has nothing to do with the main
|
||||
purpose of the library. It probably won't get any major
|
||||
improvements, although minor bug fixes are possible.
|
||||
* Added the QuaZIODevice class for working with zlib
|
||||
compression. It has nothing to do with the ZIP format, and
|
||||
therefore the same notice as for the QuaGzipFile applies.
|
||||
* The global comment is no longer erased when adding files to
|
||||
an archive.
|
||||
* Many bug fixes.
|
||||
|
||||
* 2012-01-14 0.4.4
|
||||
* Fixed isSequential() test that was causing open() failures on
|
||||
Unix.
|
||||
* Fixed sub-directory compressing in JlCompress.
|
||||
* Added MS VS 2008 solution, compatible with the binary Qt
|
||||
distribution (tested on MS VS 2008 Express, had to run MOC
|
||||
manually due to the lack of plugin in Express).
|
||||
* Fixed extracting directories in JlCompress.
|
||||
* Fixed JlCompress.h includes in the test suite, which used
|
||||
lowercase names thus breaking on case-sensitive systems.
|
||||
* Implemented missing QuaZipFile::getZip() that was only
|
||||
declared.
|
||||
* Fixed reopening closed files.
|
||||
* Fixed possible memory leak in case of open error.
|
||||
|
||||
* 2011-09-09 0.4.3
|
||||
* New test suite using QTestLib.
|
||||
* Fixed bytesAvailable(), pos() and atEnd().
|
||||
* Added ZIP v1.0 support and disabling data descriptor for
|
||||
compatibility with some older software.
|
||||
* Fixed DLL export/import issues for some symbols.
|
||||
* Added QUAZIP_STATIC macro for compiling as a static library or
|
||||
directly including the source.
|
||||
* Added getFileNameList() and getFileInfoList() convenience
|
||||
functions.
|
||||
* Added some buffering to JlCompress to improve performance.
|
||||
|
||||
* 2011-08-10 0.4.2
|
||||
* Cmake patch (thanks to Bernhard Rosenkraenzer).
|
||||
* Symbian patch (thanks to Hamish Willee).
|
||||
* Documented the multiple files limitation of QuaZipFile.
|
||||
* Fixed relative paths handling in JlCompress.
|
||||
* Fixed linking to MinGW zlib.
|
||||
|
||||
* 2011-05-26 0.4.1
|
||||
* License statement updated to avoid confusion. GPL license
|
||||
removed for the very same reason.
|
||||
* Parts of original package are now clearly marked as modified,
|
||||
just as their license requires.
|
||||
|
||||
* 2011-05-23 0.4
|
||||
* QuaZip and QuaZipFile classes now use the Pimpl idiom. This
|
||||
means that future releases will probably be binary compatible
|
||||
with this one, but it also means that this one is binary
|
||||
incompatible with the old ones.
|
||||
* IO API has been rewritten using QIODevice instead of standard
|
||||
C library. Among other things it means that QuaZip now supports
|
||||
files up to 4 GB in size instead of 2 GB.
|
||||
* Added QuaZip methods allowing access to ZIP files represented
|
||||
by any seekable QIODevice implementation (QBuffer is a good
|
||||
example).
|
||||
|
||||
* 2010-07-23 0.3
|
||||
* Fixed getComment() for global comments.
|
||||
* Added some useful classes for calculating checksums (thanks to
|
||||
Adam Walczak).
|
||||
* Added some utility classes for working with whole directories
|
||||
(thanks to Roberto Pompermaier). It would be nice if someone
|
||||
documents these in English, though.
|
||||
* Probably fixed some problems with passwords (thanks to Vasiliy
|
||||
Sorokin). I didn't test it, though.
|
||||
|
||||
* 2008-09-17 0.2.3
|
||||
* Fixed license notices in sources.
|
||||
|
||||
* SVN
|
||||
* Fixed a small bug in QuaZipFile::atEnd().
|
||||
|
||||
* 2007-01-16 0.2.2
|
||||
* Added LGPL as alternative license.
|
||||
* Added FAQ documentation page.
|
||||
|
||||
* 2006-03-21 0.2.1
|
||||
* Fixed setCommentCodec() bug.
|
||||
* Fixed bug that set month 1-12 instead of 0-11, as specified in
|
||||
zip.h.
|
||||
* Added workaround for Qt's bug that caused wrong timestamps.
|
||||
* Few documentation fixes and cosmetic changes.
|
||||
|
||||
* 2005-07-08 0.2
|
||||
* Write support.
|
||||
* Extended QuaZipFile API, including size(), *pos() functions.
|
||||
* Support for comments encoding/decoding.
|
||||
|
||||
* 2005-07-01 0.1
|
||||
* Initial version.
|
|
@ -0,0 +1,93 @@
|
|||
**QuaZip 0.x -> 1.x migration guide**
|
||||
|
||||
This guide contains important information mostly for package
|
||||
maintainers, although it can also be useful for developers
|
||||
as well.
|
||||
|
||||
**TL;DR**
|
||||
|
||||
QuaZip 1.0 is supposed to be installed in parallel with 0.x,
|
||||
**not** replace 0.x. Package maintainers should keep it in mind.
|
||||
The developers should switch to 1.0 in their new releases if
|
||||
they use CMake and/or want new features (although there are only few).
|
||||
|
||||
**What happened in 1.0**
|
||||
|
||||
QuaZip 1.0 introduced some important changes:
|
||||
|
||||
- modern CMake support was introduced;
|
||||
- include paths and binary names were changed;
|
||||
- qmake support was ditched completely.
|
||||
|
||||
This change was intended, thoroughly discussed and planned.
|
||||
The reasons for this change were:
|
||||
|
||||
- CMake support was a mess because at that time I didn't understand
|
||||
it at all, and was just blindly accepted all CMake-related PRs and
|
||||
patches, which lead to numerous inconsistencies between qmake and CMake
|
||||
builds;
|
||||
- maintaining both qmake and CMake support in a consistent manner
|
||||
would be next to impossible, as CMake installs some metadata
|
||||
that is very useful, and there is no easy way to generate
|
||||
it with qmake;
|
||||
- old CMake style is a mess in itself, while modern CMake, even if
|
||||
not at all easy to learn, at least leads to consistent, clean
|
||||
and easy to use (for the users of the library) configuration
|
||||
files.
|
||||
|
||||
It was thus impossible to make 1.0 a drop-in replacement for 0.x.
|
||||
Specifically, since 0.x has this qmake/CMake inconsistency
|
||||
(that even changed between versions in an unreasonable manner),
|
||||
it wouldn't be possible to make 1.0 both consistent and 0.x-compatible.
|
||||
Consistency was chosen over compatibility.
|
||||
|
||||
To avoid possible conflicts with 0.x, however, it was decided to make
|
||||
1.0 co-installable with 0.x, by using different include paths and binary
|
||||
names. Binary names had to be changed anyway because they were inconsistent
|
||||
for qmake and CMake, and made no sense at all.
|
||||
|
||||
**The differences**
|
||||
|
||||
QuaZip 0.x uses this “scheme”:
|
||||
|
||||
- the includes went either to `include/quazip` or `include/quazip5`
|
||||
depending both on qmake/CMake and Qt4/Qt5 usage (only the CMake+Qt5
|
||||
combination would yield `quazip5`);
|
||||
- the binary base name was either `quazip` or `quazip5`, again,
|
||||
depending on qmake/CMake *and* Qt4/Qt5 choice;
|
||||
- the CMake config files were installed only when building with CMake;
|
||||
- the CMake package name was `QuaZip` (for Qt4) or `QuaZip5` (for Qt5);
|
||||
- the CMake target name was the same as the binary name.
|
||||
|
||||
QuaZip 1.x uses this scheme:
|
||||
|
||||
- the includes go to `include/QuaZip-QtX-Y/quazip`, where `include` is
|
||||
the installation prefix include path (`/usr/include` or something),
|
||||
`X` is the major version of Qt, and `Y` is the full version of QuaZip,
|
||||
e. g. `include/QuaZip-Qt5-1.0/quazip`;
|
||||
- the binary base name is `quazipZ-qtX`, where `Z` is the major version of
|
||||
QuaZip, e. g. `libquazip1-qt5.so.1.0.0`;
|
||||
- the CMake package name is `QuaZip-QtX`, e. g. `QuaZip-Qt5`;
|
||||
- the CMake target name is `QuaZip::QuaZip`.
|
||||
|
||||
This can't possibly conflict with any crazy 0.x setup, no matter
|
||||
qmake or CMake. CMake users get the easy modern CMake way
|
||||
(`find_package(QuaZip-Qt5)`, `target_link_libraries(... QuaZip::QuaZip)`)
|
||||
of using QuaZip, and includes can be either in the `#include <quazipfile.h>`
|
||||
or in the `#include <quazip/quazipfile.h>` style (which some qmake users
|
||||
used), as both `include/QuaZip-QtX-Y` and `include/QuaZip-QtX-Y/quazip`
|
||||
include paths are added by default. This ensures source
|
||||
compatibility between 0.x and 1.x without any annoying search-and-replace.
|
||||
|
||||
**The intended use**
|
||||
|
||||
QuaZip 1.0 should be installed along with 0.x. Whatever applications
|
||||
were built with 0.x should continue to happily use 0.x. When application
|
||||
developers decide so, they should switch to QuaZip 1.0 in their new
|
||||
releases (and preferably switch to CMake as well).
|
||||
|
||||
Package maintainers should *not* consider 1.0 an upgrade from 0.x,
|
||||
but rather an independent package, pretty much the same way as Qt4 and Qt5
|
||||
are separate packages. The same goes for future major
|
||||
versions such as 2.0, whenever they are released. Or at least that's
|
||||
the current plan.
|
|
@ -0,0 +1,22 @@
|
|||
QuaZip is the C++ wrapper for Gilles Vollant's ZIP/UNZIP package
|
||||
(AKA Minizip) using Trolltech's Qt library.
|
||||
|
||||
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.
|
||||
|
||||
See [the documentation](https://stachenov.github.io/quazip/) for details.
|
||||
|
||||
Want to report a bug or ask for a feature? Open an [issue](https://github.com/stachenov/quazip/issues).
|
||||
|
||||
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 (C) 2005-2020 Sergey A. Tachenov and contributors
|
||||
|
||||
Distributed under LGPL, full details in the COPYING file.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant, see
|
||||
quazip/(un)zip.h files for details, but basically it's the zlib license.
|
|
@ -0,0 +1,99 @@
|
|||
project(QuaZip_Library VERSION ${QUAZIP_LIB_VERSION})
|
||||
|
||||
include(GNUInstallDirs) # configurable CMAKE_INSTALL_*DIR
|
||||
|
||||
set(QUAZIP_HEADERS
|
||||
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
|
||||
)
|
||||
|
||||
set(QUAZIP_SOURCES
|
||||
${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
|
||||
)
|
||||
|
||||
set(QUAZIP_INCLUDE_PATH ${QUAZIP_DIR_NAME}/quazip)
|
||||
set(QUAZIP_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake)
|
||||
set(QUAZIP_PKGCONFIG_NAME quazip${QuaZip_VERSION_MAJOR}-qt${QUAZIP_QT_MAJOR_VERSION})
|
||||
|
||||
add_library(${QUAZIP_LIB_TARGET_NAME} ${QUAZIP_SOURCES})
|
||||
add_library(QuaZip::QuaZip ALIAS ${QUAZIP_LIB_TARGET_NAME})
|
||||
|
||||
set_target_properties(${QUAZIP_LIB_TARGET_NAME} PROPERTIES
|
||||
VERSION ${QUAZIP_LIB_VERSION}
|
||||
SOVERSION ${QUAZIP_LIB_SOVERSION}
|
||||
OUTPUT_NAME ${QUAZIP_LIB_FILE_NAME}
|
||||
PUBLIC_HEADER "${QUAZIP_HEADERS}"
|
||||
)
|
||||
target_include_directories(${QUAZIP_LIB_TARGET_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${QUAZIP_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QUAZIP_DIR_NAME}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${QUAZIP_INCLUDE_PATH}>
|
||||
)
|
||||
target_link_libraries(${QUAZIP_LIB_TARGET_NAME} ${QUAZIP_LIB_LIBRARIES})
|
||||
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()
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
if(QUAZIP_INSTALL)
|
||||
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)
|
||||
endif()
|
|
@ -0,0 +1,478 @@
|
|||
/*
|
||||
Copyright (C) 2010 Roberto Pompermaier
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "JlCompress.h"
|
||||
|
||||
static bool copyData(QIODevice &inFile, QIODevice &outFile)
|
||||
{
|
||||
while (!inFile.atEnd()) {
|
||||
char buf[4096];
|
||||
qint64 readLen = inFile.read(buf, 4096);
|
||||
if (readLen <= 0)
|
||||
return false;
|
||||
if (outFile.write(buf, readLen) != readLen)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JlCompress::compressFile(QuaZip* zip, QString fileName, QString fileDest) {
|
||||
// zip: oggetto dove aggiungere il file
|
||||
// fileName: nome del file reale
|
||||
// fileDest: nome del file all'interno del file compresso
|
||||
|
||||
// Controllo l'apertura dello zip
|
||||
if (!zip) return false;
|
||||
if (zip->getMode()!=QuaZip::mdCreate &&
|
||||
zip->getMode()!=QuaZip::mdAppend &&
|
||||
zip->getMode()!=QuaZip::mdAdd) return false;
|
||||
|
||||
// Apro il file risulato
|
||||
QuaZipFile outFile(zip);
|
||||
if(!outFile.open(QIODevice::WriteOnly, QuaZipNewInfo(fileDest, fileName))) return false;
|
||||
|
||||
QFileInfo input(fileName);
|
||||
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;
|
||||
if (!copyData(inFile, outFile) || outFile.getZipError()!=UNZ_OK)
|
||||
return false;
|
||||
inFile.close();
|
||||
}
|
||||
|
||||
// Chiudo i file
|
||||
outFile.close();
|
||||
if (outFile.getZipError()!=UNZ_OK) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JlCompress::compressSubDir(QuaZip* zip, QString dir, QString origDir, bool recursive, QDir::Filters filters) {
|
||||
// zip: oggetto dove aggiungere il file
|
||||
// dir: cartella reale corrente
|
||||
// origDir: cartella reale originale
|
||||
// (path(dir)-path(origDir)) = path interno all'oggetto zip
|
||||
|
||||
// Controllo l'apertura dello zip
|
||||
if (!zip) return false;
|
||||
if (zip->getMode()!=QuaZip::mdCreate &&
|
||||
zip->getMode()!=QuaZip::mdAppend &&
|
||||
zip->getMode()!=QuaZip::mdAdd) return false;
|
||||
|
||||
// Controllo la cartella
|
||||
QDir directory(dir);
|
||||
if (!directory.exists()) return false;
|
||||
|
||||
QDir origDirectory(origDir);
|
||||
if (dir != origDir) {
|
||||
QuaZipFile dirZipFile(zip);
|
||||
if (!dirZipFile.open(QIODevice::WriteOnly,
|
||||
QuaZipNewInfo(origDirectory.relativeFilePath(dir) + QLatin1String("/"), dir), nullptr, 0, 0)) {
|
||||
return false;
|
||||
}
|
||||
dirZipFile.close();
|
||||
}
|
||||
|
||||
|
||||
// Se comprimo anche le sotto cartelle
|
||||
if (recursive) {
|
||||
// Per ogni sotto cartella
|
||||
QFileInfoList files = directory.entryInfoList(QDir::AllDirs|QDir::NoDotAndDotDot|filters);
|
||||
for (int index = 0; index < files.size(); ++index ) {
|
||||
const QFileInfo & file( files.at( index ) );
|
||||
if (!file.isDir()) // needed for Qt < 4.7 because it doesn't understand AllDirs
|
||||
continue;
|
||||
// Comprimo la sotto cartella
|
||||
if(!compressSubDir(zip,file.absoluteFilePath(),origDir,recursive,filters)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Per ogni file nella cartella
|
||||
QFileInfoList files = directory.entryInfoList(QDir::Files|filters);
|
||||
for (int index = 0; index < files.size(); ++index ) {
|
||||
const QFileInfo & file( files.at( index ) );
|
||||
// Se non e un file o e il file compresso che sto creando
|
||||
if(!file.isFile()||file.absoluteFilePath()==zip->getZipName()) continue;
|
||||
|
||||
// Creo il nome relativo da usare all'interno del file compresso
|
||||
QString filename = origDirectory.relativeFilePath(file.absoluteFilePath());
|
||||
|
||||
// Comprimo il file
|
||||
if (!compressFile(zip,file.absoluteFilePath(),filename)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JlCompress::extractFile(QuaZip* zip, QString fileName, QString fileDest) {
|
||||
// zip: oggetto dove aggiungere il file
|
||||
// filename: nome del file reale
|
||||
// fileincompress: nome del file all'interno del file compresso
|
||||
|
||||
// Controllo l'apertura dello zip
|
||||
if (!zip) return false;
|
||||
if (zip->getMode()!=QuaZip::mdUnzip) return false;
|
||||
|
||||
// Apro il file compresso
|
||||
if (!fileName.isEmpty())
|
||||
zip->setCurrentFile(fileName);
|
||||
QuaZipFile inFile(zip);
|
||||
if(!inFile.open(QIODevice::ReadOnly) || inFile.getZipError()!=UNZ_OK) return false;
|
||||
|
||||
// Controllo esistenza cartella file risultato
|
||||
QDir curDir;
|
||||
if (fileDest.endsWith(QLatin1String("/"))) {
|
||||
if (!curDir.mkpath(fileDest)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!curDir.mkpath(QFileInfo(fileDest).absolutePath())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QuaZipFileInfo64 info;
|
||||
if (!zip->getCurrentFileInfo(&info))
|
||||
return false;
|
||||
|
||||
QFile::Permissions srcPerm = info.getPermissions();
|
||||
if (fileDest.endsWith(QLatin1String("/")) && QFileInfo(fileDest).isDir()) {
|
||||
if (srcPerm != 0) {
|
||||
QFile(fileDest).setPermissions(srcPerm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (info.isSymbolicLink()) {
|
||||
QString target = QFile::decodeName(inFile.readAll());
|
||||
if (!QFile::link(target, fileDest))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Apro il file risultato
|
||||
QFile outFile;
|
||||
outFile.setFileName(fileDest);
|
||||
if(!outFile.open(QIODevice::WriteOnly)) return false;
|
||||
|
||||
// Copio i dati
|
||||
if (!copyData(inFile, outFile) || inFile.getZipError()!=UNZ_OK) {
|
||||
outFile.close();
|
||||
removeFile(QStringList(fileDest));
|
||||
return false;
|
||||
}
|
||||
outFile.close();
|
||||
|
||||
// Chiudo i file
|
||||
inFile.close();
|
||||
if (inFile.getZipError()!=UNZ_OK) {
|
||||
removeFile(QStringList(fileDest));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (srcPerm != 0) {
|
||||
outFile.setPermissions(srcPerm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JlCompress::removeFile(QStringList listFile) {
|
||||
bool ret = true;
|
||||
// Per ogni file
|
||||
for (int i=0; i<listFile.count(); i++) {
|
||||
// Lo elimino
|
||||
ret = ret && QFile::remove(listFile.at(i));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool JlCompress::compressFile(QString fileCompressed, QString file) {
|
||||
// Creo lo zip
|
||||
QuaZip zip(fileCompressed);
|
||||
QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
|
||||
if(!zip.open(QuaZip::mdCreate)) {
|
||||
QFile::remove(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Aggiungo il file
|
||||
if (!compressFile(&zip,file,QFileInfo(file).fileName())) {
|
||||
QFile::remove(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Chiudo il file zip
|
||||
zip.close();
|
||||
if(zip.getZipError()!=0) {
|
||||
QFile::remove(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JlCompress::compressFiles(QString fileCompressed, QStringList files) {
|
||||
// Creo lo zip
|
||||
QuaZip zip(fileCompressed);
|
||||
QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
|
||||
if(!zip.open(QuaZip::mdCreate)) {
|
||||
QFile::remove(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprimo i file
|
||||
QFileInfo info;
|
||||
for (int index = 0; index < files.size(); ++index ) {
|
||||
const QString & file( files.at( index ) );
|
||||
info.setFile(file);
|
||||
if (!info.exists() || !compressFile(&zip,file,info.fileName())) {
|
||||
QFile::remove(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Chiudo il file zip
|
||||
zip.close();
|
||||
if(zip.getZipError()!=0) {
|
||||
QFile::remove(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JlCompress::compressDir(QString fileCompressed, QString dir, bool recursive) {
|
||||
return compressDir(fileCompressed, dir, recursive, QDir::Filters());
|
||||
}
|
||||
|
||||
bool JlCompress::compressDir(QString fileCompressed, QString dir,
|
||||
bool recursive, QDir::Filters filters)
|
||||
{
|
||||
// Creo lo zip
|
||||
QuaZip zip(fileCompressed);
|
||||
QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
|
||||
if(!zip.open(QuaZip::mdCreate)) {
|
||||
QFile::remove(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Aggiungo i file e le sotto cartelle
|
||||
if (!compressSubDir(&zip,dir,dir,recursive, filters)) {
|
||||
QFile::remove(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Chiudo il file zip
|
||||
zip.close();
|
||||
if(zip.getZipError()!=0) {
|
||||
QFile::remove(fileCompressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString JlCompress::extractFile(QString fileCompressed, QString fileName, QString fileDest) {
|
||||
// Apro lo zip
|
||||
QuaZip zip(fileCompressed);
|
||||
return extractFile(zip, fileName, fileDest);
|
||||
}
|
||||
|
||||
QString JlCompress::extractFile(QuaZip &zip, QString fileName, QString fileDest)
|
||||
{
|
||||
if(!zip.open(QuaZip::mdUnzip)) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
// Estraggo il file
|
||||
if (fileDest.isEmpty())
|
||||
fileDest = fileName;
|
||||
if (!extractFile(&zip,fileName,fileDest)) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
// Chiudo il file zip
|
||||
zip.close();
|
||||
if(zip.getZipError()!=0) {
|
||||
removeFile(QStringList(fileDest));
|
||||
return QString();
|
||||
}
|
||||
return QFileInfo(fileDest).absoluteFilePath();
|
||||
}
|
||||
|
||||
QStringList JlCompress::extractFiles(QString fileCompressed, QStringList files, QString dir) {
|
||||
// Creo lo zip
|
||||
QuaZip zip(fileCompressed);
|
||||
return extractFiles(zip, files, dir);
|
||||
}
|
||||
|
||||
QStringList JlCompress::extractFiles(QuaZip &zip, const QStringList &files, const QString &dir)
|
||||
{
|
||||
if(!zip.open(QuaZip::mdUnzip)) {
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
// Estraggo i file
|
||||
QStringList extracted;
|
||||
for (int i=0; i<files.count(); i++) {
|
||||
QString absPath = QDir(dir).absoluteFilePath(files.at(i));
|
||||
if (!extractFile(&zip, files.at(i), absPath)) {
|
||||
removeFile(extracted);
|
||||
return QStringList();
|
||||
}
|
||||
extracted.append(absPath);
|
||||
}
|
||||
|
||||
// Chiudo il file zip
|
||||
zip.close();
|
||||
if(zip.getZipError()!=0) {
|
||||
removeFile(extracted);
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
|
||||
QStringList JlCompress::extractDir(QString fileCompressed, QTextCodec* fileNameCodec, QString dir) {
|
||||
// Apro lo zip
|
||||
QuaZip zip(fileCompressed);
|
||||
if (fileNameCodec)
|
||||
zip.setFileNameCodec(fileNameCodec);
|
||||
return extractDir(zip, dir);
|
||||
}
|
||||
|
||||
QStringList JlCompress::extractDir(QString fileCompressed, QString dir) {
|
||||
return extractDir(fileCompressed, nullptr, dir);
|
||||
}
|
||||
|
||||
QStringList JlCompress::extractDir(QuaZip &zip, const QString &dir)
|
||||
{
|
||||
if(!zip.open(QuaZip::mdUnzip)) {
|
||||
return QStringList();
|
||||
}
|
||||
QString cleanDir = QDir::cleanPath(dir);
|
||||
QDir directory(cleanDir);
|
||||
QString absCleanDir = directory.absolutePath();
|
||||
QStringList extracted;
|
||||
if (!zip.goToFirstFile()) {
|
||||
return QStringList();
|
||||
}
|
||||
do {
|
||||
QString name = zip.getCurrentFileName();
|
||||
QString absFilePath = directory.absoluteFilePath(name);
|
||||
QString absCleanPath = QDir::cleanPath(absFilePath);
|
||||
if (!absCleanPath.startsWith(absCleanDir + QLatin1String("/")))
|
||||
continue;
|
||||
if (!extractFile(&zip, QLatin1String(""), absFilePath)) {
|
||||
removeFile(extracted);
|
||||
return QStringList();
|
||||
}
|
||||
extracted.append(absFilePath);
|
||||
} while (zip.goToNextFile());
|
||||
|
||||
// Chiudo il file zip
|
||||
zip.close();
|
||||
if(zip.getZipError()!=0) {
|
||||
removeFile(extracted);
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
|
||||
QStringList JlCompress::getFileList(QString fileCompressed) {
|
||||
// Apro lo zip
|
||||
QuaZip* zip = new QuaZip(QFileInfo(fileCompressed).absoluteFilePath());
|
||||
return getFileList(zip);
|
||||
}
|
||||
|
||||
QStringList JlCompress::getFileList(QuaZip *zip)
|
||||
{
|
||||
if(!zip->open(QuaZip::mdUnzip)) {
|
||||
delete zip;
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
// Estraggo i nomi dei file
|
||||
QStringList lst;
|
||||
QuaZipFileInfo64 info;
|
||||
for(bool more=zip->goToFirstFile(); more; more=zip->goToNextFile()) {
|
||||
if(!zip->getCurrentFileInfo(&info)) {
|
||||
delete zip;
|
||||
return QStringList();
|
||||
}
|
||||
lst << info.name;
|
||||
//info.name.toLocal8Bit().constData()
|
||||
}
|
||||
|
||||
// Chiudo il file zip
|
||||
zip->close();
|
||||
if(zip->getZipError()!=0) {
|
||||
delete zip;
|
||||
return QStringList();
|
||||
}
|
||||
delete zip;
|
||||
return lst;
|
||||
}
|
||||
|
||||
QStringList JlCompress::extractDir(QIODevice* ioDevice, QTextCodec* fileNameCodec, QString dir)
|
||||
{
|
||||
QuaZip zip(ioDevice);
|
||||
if (fileNameCodec)
|
||||
zip.setFileNameCodec(fileNameCodec);
|
||||
return extractDir(zip, dir);
|
||||
}
|
||||
|
||||
QStringList JlCompress::extractDir(QIODevice *ioDevice, QString dir)
|
||||
{
|
||||
return extractDir(ioDevice, nullptr, dir);
|
||||
}
|
||||
|
||||
QStringList JlCompress::getFileList(QIODevice *ioDevice)
|
||||
{
|
||||
QuaZip *zip = new QuaZip(ioDevice);
|
||||
return getFileList(zip);
|
||||
}
|
||||
|
||||
QString JlCompress::extractFile(QIODevice *ioDevice, QString fileName, QString fileDest)
|
||||
{
|
||||
QuaZip zip(ioDevice);
|
||||
return extractFile(zip, fileName, fileDest);
|
||||
}
|
||||
|
||||
QStringList JlCompress::extractFiles(QIODevice *ioDevice, QStringList files, QString dir)
|
||||
{
|
||||
QuaZip zip(ioDevice);
|
||||
return extractFiles(zip, files, dir);
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
#ifndef JLCOMPRESSFOLDER_H_
|
||||
#define JLCOMPRESSFOLDER_H_
|
||||
|
||||
/*
|
||||
Copyright (C) 2010 Roberto Pompermaier
|
||||
Copyright (C) 2005-2016 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "quazip.h"
|
||||
#include "quazipfile.h"
|
||||
#include "quazipfileinfo.h"
|
||||
#include "quazip_qt_compat.h"
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QFile>
|
||||
|
||||
/// Utility class for typical operations.
|
||||
/**
|
||||
This class contains a number of useful static functions to perform
|
||||
simple operations, such as mass ZIP packing or extraction.
|
||||
*/
|
||||
class QUAZIP_EXPORT JlCompress {
|
||||
private:
|
||||
static QStringList extractDir(QuaZip &zip, const QString &dir);
|
||||
static QStringList getFileList(QuaZip *zip);
|
||||
static QString extractFile(QuaZip &zip, QString fileName, QString fileDest);
|
||||
static QStringList extractFiles(QuaZip &zip, const QStringList &files, const QString &dir);
|
||||
/// Compress a single file.
|
||||
/**
|
||||
\param zip Opened zip to compress the file to.
|
||||
\param fileName The full path to the source file.
|
||||
\param fileDest The full name of the file inside the archive.
|
||||
\return true if success, false otherwise.
|
||||
*/
|
||||
static bool compressFile(QuaZip* zip, QString fileName, QString fileDest);
|
||||
/// Compress a subdirectory.
|
||||
/**
|
||||
\param parentZip Opened zip containing the parent directory.
|
||||
\param dir The full path to the directory to pack.
|
||||
\param parentDir The full path to the directory corresponding to
|
||||
the root of the ZIP.
|
||||
\param recursive Whether to pack sub-directories as well or only
|
||||
files.
|
||||
\return true if success, false otherwise.
|
||||
*/
|
||||
static bool compressSubDir(QuaZip* parentZip, QString dir, QString parentDir, bool recursive,
|
||||
QDir::Filters filters);
|
||||
/// Extract a single file.
|
||||
/**
|
||||
\param zip The opened zip archive to extract from.
|
||||
\param fileName The full name of the file to extract.
|
||||
\param fileDest The full path to the destination file.
|
||||
\return true if success, false otherwise.
|
||||
*/
|
||||
static bool extractFile(QuaZip* zip, QString fileName, QString fileDest);
|
||||
/// Remove some files.
|
||||
/**
|
||||
\param listFile The list of files to remove.
|
||||
\return true if success, false otherwise.
|
||||
*/
|
||||
static bool removeFile(QStringList listFile);
|
||||
|
||||
public:
|
||||
/// Compress a single file.
|
||||
/**
|
||||
\param fileCompressed The name of the archive.
|
||||
\param file The file to compress.
|
||||
\return true if success, false otherwise.
|
||||
*/
|
||||
static bool compressFile(QString fileCompressed, QString file);
|
||||
/// Compress a list of files.
|
||||
/**
|
||||
\param fileCompressed The name of the archive.
|
||||
\param files The file list to compress.
|
||||
\return true if success, false otherwise.
|
||||
*/
|
||||
static bool compressFiles(QString fileCompressed, QStringList files);
|
||||
/// Compress a whole directory.
|
||||
/**
|
||||
Does not compress hidden files. See compressDir(QString, QString, bool, QDir::Filters).
|
||||
|
||||
\param fileCompressed The name of the archive.
|
||||
\param dir The directory to compress.
|
||||
\param recursive Whether to pack the subdirectories as well, or
|
||||
just regular files.
|
||||
\return true if success, false otherwise.
|
||||
*/
|
||||
static bool compressDir(QString fileCompressed, QString dir = QString(), bool recursive = true);
|
||||
/**
|
||||
* @brief Compress a whole directory.
|
||||
*
|
||||
* Unless filters are specified explicitly, packs
|
||||
* only regular non-hidden files (and subdirs, if @c recursive is true).
|
||||
* If filters are specified, they are OR-combined with
|
||||
* <tt>%QDir::AllDirs|%QDir::NoDotAndDotDot</tt> when searching for dirs
|
||||
* and with <tt>QDir::Files</tt> when searching for files.
|
||||
*
|
||||
* @param fileCompressed path to the resulting archive
|
||||
* @param dir path to the directory being compressed
|
||||
* @param recursive if true, then the subdirectories are packed as well
|
||||
* @param filters what to pack, filters are applied both when searching
|
||||
* for subdirs (if packing recursively) and when looking for files to pack
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
static bool compressDir(QString fileCompressed, QString dir,
|
||||
bool recursive, QDir::Filters filters);
|
||||
|
||||
public:
|
||||
/// Extract a single file.
|
||||
/**
|
||||
\param fileCompressed The name of the archive.
|
||||
\param fileName The file to extract.
|
||||
\param fileDest The destination file, assumed to be identical to
|
||||
\a file if left empty.
|
||||
\return The list of the full paths of the files extracted, empty on failure.
|
||||
*/
|
||||
static QString extractFile(QString fileCompressed, QString fileName, QString fileDest = QString());
|
||||
/// Extract a list of files.
|
||||
/**
|
||||
\param fileCompressed The name of the archive.
|
||||
\param files The file list to extract.
|
||||
\param dir The directory to put the files to, the current
|
||||
directory if left empty.
|
||||
\return The list of the full paths of the files extracted, empty on failure.
|
||||
*/
|
||||
static QStringList extractFiles(QString fileCompressed, QStringList files, QString dir = QString());
|
||||
/// Extract a whole archive.
|
||||
/**
|
||||
\param fileCompressed The name of the archive.
|
||||
\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, 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.
|
||||
/**
|
||||
\return The list of the files in the archive, or, more precisely, the
|
||||
list of the entries, including both files and directories if they
|
||||
are present separately.
|
||||
*/
|
||||
static QStringList getFileList(QString fileCompressed);
|
||||
/// Extract a single file.
|
||||
/**
|
||||
\param ioDevice pointer to device with compressed data.
|
||||
\param fileName The file to extract.
|
||||
\param fileDest The destination file, assumed to be identical to
|
||||
\a file if left empty.
|
||||
\return The list of the full paths of the files extracted, empty on failure.
|
||||
*/
|
||||
static QString extractFile(QIODevice *ioDevice, QString fileName, QString fileDest = QString());
|
||||
/// Extract a list of files.
|
||||
/**
|
||||
\param ioDevice pointer to device with compressed data.
|
||||
\param files The file list to extract.
|
||||
\param dir The directory to put the files to, the current
|
||||
directory if left empty.
|
||||
\return The list of the full paths of the files extracted, empty on failure.
|
||||
*/
|
||||
static QStringList extractFiles(QIODevice *ioDevice, QStringList files, QString dir = QString());
|
||||
/// Extract a whole archive.
|
||||
/**
|
||||
\param ioDevice pointer to device with compressed data.
|
||||
\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, 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.
|
||||
/**
|
||||
\return The list of the files in the archive, or, more precisely, the
|
||||
list of the entries, including both files and directories if they
|
||||
are present separately.
|
||||
*/
|
||||
static QStringList getFileList(QIODevice *ioDevice);
|
||||
};
|
||||
|
||||
#endif /* JLCOMPRESSFOLDER_H_ */
|
|
@ -0,0 +1,20 @@
|
|||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
find_dependency(ZLIB REQUIRED)
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@QUAZIP_EXPORT_SET@.cmake")
|
||||
|
||||
if(@QUAZIP_QT_MAJOR_VERSION@ EQUAL 6)
|
||||
find_dependency(Qt6 REQUIRED COMPONENTS Core Core5Compat)
|
||||
elseif(@QUAZIP_QT_MAJOR_VERSION@ EQUAL 5)
|
||||
find_dependency(Qt5 REQUIRED COMPONENTS Core)
|
||||
elseif(@QUAZIP_QT_MAJOR_VERSION@ EQUAL 4)
|
||||
find_dependency(Qt4 4.5.0 REQUIRED COMPONENTS QtCore)
|
||||
else()
|
||||
message(FATAL_ERROR "Qt version QUAZIP_QT_MAJOR_VERSION=@QUAZIP_QT_MAJOR_VERSION@ is unsupported")
|
||||
endif()
|
||||
set_target_properties(QuaZip::QuaZip PROPERTIES IMPORTED_GLOBAL TRUE)
|
||||
|
||||
check_required_components(@QUAZIP_PACKAGE_NAME@)
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
\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-zip64 "Q. Can QuaZip handle files larger than 4GB? What about zip64 standard?"
|
||||
|
||||
\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-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
|
||||
through QIODevice API?</b>
|
||||
|
||||
A. Usually not. For example, if you are passing file name to some
|
||||
database driver (like SQLite), Qt usually just passes this name down
|
||||
to the 3rd-party library, which is usually does not know anything
|
||||
about QIODevice and therefore there is no way to pass QuaZipFile as
|
||||
a normal file. However, if we are talking about some place where you
|
||||
pass file name, and then internally use QFile to open it, then it is
|
||||
a good idea to make an overloaded method, which accepts a QIODevice
|
||||
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
|
||||
possible if you have control over the sources of the particular class.
|
||||
|
||||
\anchor faq-zip64 <b>Q. Can %QuaZip handle files larger than 4GB? What
|
||||
about zip64 standard?</b>
|
||||
|
||||
A. Starting with version 0.6, %QuaZip uses Minizip 1.1 with zip64
|
||||
support which should handle large files perfectly. The zip64 support
|
||||
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.
|
||||
|
||||
\anchor faq-seekable <b>Q. Can %QuaZip write archives to a sequential QIODevice like QTcpSocket?</b>
|
||||
|
||||
A. Writing is possible since %QuaZip v0.7. It's only possible in
|
||||
mdCreate mode, no mdAppend support. Reading is not supported either.
|
||||
|
||||
\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,
|
||||
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
|
||||
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.
|
||||
|
||||
\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.
|
||||
|
||||
*/
|
|
@ -0,0 +1,201 @@
|
|||
/**
|
||||
\mainpage %QuaZip - %Qt/C++ wrapper for Minizip
|
||||
|
||||
\section overview Overview
|
||||
|
||||
<a href="http://www.winimage.com/zLibDll/minizip.html">Minizip, or
|
||||
Gilles Vollant's ZIP/UNZIP package</a> is a simple C library
|
||||
for creating, appending and reading ZIP archives.
|
||||
|
||||
<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
|
||||
create rich GUIs, perform networking activities, accessing databases
|
||||
and much much more. If Java is “write once, run everywhere”, %Qt
|
||||
is “write once, compile everywhere” which is not that bad either.
|
||||
|
||||
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
|
||||
interface which isn't exactly compatible with %Qt. Namely, in %Qt
|
||||
there is an abstract class called QIODevice, which
|
||||
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
|
||||
serialize XML to a QIODevice, for example. Therefore, wouldn't it
|
||||
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
|
||||
%QuaZip comes into the picture.
|
||||
|
||||
Technically speaking, %QuaZip is a simple C++ wrapper around Minizip.
|
||||
Or you could call it an implementation of the Adapter pattern. With
|
||||
%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
|
||||
like TCP sockets, although some limitations apply in this case.
|
||||
|
||||
\section download Download QuaZip
|
||||
|
||||
The latest downloads are available from the
|
||||
<a href="https://github.com/stachenov/quazip/releases">GitHub page</a>.
|
||||
Downloads are in source format. The documentation you're reading
|
||||
right now can be build with the “doxygen” tool if you have one
|
||||
installed. Just run it from the project directory and it will
|
||||
create the “doc” directory for you. If you don't have Doxygen
|
||||
installed, you can still read offline docs in the “quazip/doc”
|
||||
subdir and in the header files. Don't confuse those dirs:
|
||||
|
||||
- “doc” in the project's root is where Doxygen \em output is.
|
||||
- “quazip/doc” is where Doxygen \em input is, the part of it that
|
||||
doesn't belong to any particular header files.
|
||||
|
||||
Older downloads are available from
|
||||
<a href="http://sourceforge.net/projects/quazip/">%QuaZip project's page at SourceForge.net</a>.
|
||||
|
||||
\section platforms Platforms supported
|
||||
|
||||
%QuaZip 1.1 was tested on:
|
||||
- %Qt 5.15.0 MinGW 8.1 x32
|
||||
- %Qt 5.12.9 MinGW 7.3 x32
|
||||
- %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.8.7 or later.
|
||||
In theory, even versions as old as %Qt 4.6.2 might work as well, but
|
||||
aren't guaranteed to.
|
||||
|
||||
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.
|
||||
|
||||
\section Dependencies
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
%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
|
||||
using some UNIX dialect, but the build process should be very similar
|
||||
on MinGW x32 too. On other platforms it's essentially the
|
||||
same process, maybe with some CMake adjustments not specific to
|
||||
%QuaZip itself.
|
||||
|
||||
To build the library, run:
|
||||
\verbatim
|
||||
$ cd /wherever/quazip/source/is/quazip-x.y.z
|
||||
$ cmake -S . -B wherever/you/want/your/build/to/be -D QUAZIP_QT_MAJOR_VERSION=4, 5 or 6
|
||||
$ cmake --build wherever/you/want/your/build/to/be
|
||||
\endverbatim
|
||||
|
||||
\c QUAZIP_QT_MAJOR_VERSION is just one number, and it defaults to 5, so if building with %Qt 5, it is optional.
|
||||
|
||||
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
|
||||
$ cmake --build wherever/you/want/your/build/to/be --target install -D CMAKE_INSTALL_PREFIX=/wherever/you/want/to/install
|
||||
\endverbatim
|
||||
|
||||
%QuaZip installs as CMake package QuaZip-QtX, where X is the major
|
||||
version of %Qt. For example, QuaZip-Qt5. Different major versions of
|
||||
%QuaZip have different binary names (libquazip1-qt5, for example),
|
||||
which allows to install them in parallel.
|
||||
|
||||
To reconfigure (for another %Qt version or release/debug, or anything else), just nuke the whole build directory
|
||||
and repeat everything.
|
||||
|
||||
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
|
||||
with version 1.0, thanks to the Pimpl idiom. That is, the next binary
|
||||
incompatible version will be 2.x in the worst case.
|
||||
|
||||
\section test Testing
|
||||
|
||||
To test, run:
|
||||
\verbatim
|
||||
$ cmake --build wherever/you/want/your/build/to/be --target check
|
||||
\endverbatim
|
||||
|
||||
Note that tests are not included in the \c all target, so if you want
|
||||
to build and test with %Qt Creator, add another build step and select
|
||||
the \c qztest target. Then set up run configuration to launch
|
||||
the qztest binary.
|
||||
|
||||
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
|
||||
SHLIB_PATH to get “qztest” to actually run and to use the version of %QuaZip you've just built,
|
||||
especially if you already have some version of %QuaZip installed somewhere.
|
||||
|
||||
If everything went fine, the test suite should report a lot of PASS
|
||||
messages and the “All tests executed successfully” message.
|
||||
If something goes wrong, it will provide details and a
|
||||
warning that some tests failed.
|
||||
|
||||
\section using Using
|
||||
|
||||
See the \ref usage "Usage Page".
|
||||
|
||||
\section contacts Authors and contacts
|
||||
|
||||
This wrapper has been written by Sergei Tachenov.
|
||||
This is my first open source project, and it's pretty old, but it
|
||||
works and many people are happily using it, including myself.
|
||||
|
||||
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,
|
||||
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.
|
||||
I may be busy, I may be tired of working on %QuaZip, I may be even
|
||||
dead already (you never know...).
|
||||
|
||||
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
|
||||
awesome site, where you can report bugs or register yourself an
|
||||
account, fork %QuaZip (don't hesitate to do so), create a new branch,
|
||||
make some changes and issue a
|
||||
<a href="https://help.github.com/articles/about-pull-requests/">pull
|
||||
request</a>, which is GitHub's way of offering patches. See CONTRIBUTING.md
|
||||
file for details.
|
||||
|
||||
Do not use e-mail to report bugs, please. Reporting bugs and problems
|
||||
with GitHub has that advantage that
|
||||
it is visible to public, and I can always search for open tickets
|
||||
that were created long ago. It is highly unlikely that I will search
|
||||
my mail for that kind of stuff, so if a bug reported by mail isn't
|
||||
fixed immediately, it will likely be forgotten forever.
|
||||
|
||||
Old bugs may still be available at
|
||||
<a href="https://sourceforge.net/projects/quazip/">SourceForge</a>
|
||||
for reference.
|
||||
|
||||
Copyright (C) 2005-2020 Sergei Tachenov and contributors
|
||||
*/
|
|
@ -0,0 +1,182 @@
|
|||
/** \page usage Usage
|
||||
|
||||
This page provides general information on %QuaZip usage. See classes
|
||||
QuaZip and QuaZipFile for the detailed documentation on what can
|
||||
%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
|
||||
good idea too. After all, %QuaZip is just a wrapper with a few
|
||||
convenience extensions and reimplementations.
|
||||
|
||||
\section CMake
|
||||
|
||||
To get started, as it is usual with modern CMake, you just need
|
||||
something like this in your CMakeLists.txt:
|
||||
|
||||
\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
|
||||
|
||||
“%QuaZip” means the whole library or the \c QuaZip class, depending
|
||||
on the context.
|
||||
|
||||
“ZIP/UNZIP API” or “Minizip” means the original API of the Gilles
|
||||
Vollant's ZIP/UNZIP package. It was slightly modified to better
|
||||
integrate with Qt. These modifications are not source or binary
|
||||
compatible with the official Minizip release, which means you can't
|
||||
just drop the newer Minizip version into %QuaZip sources and make it
|
||||
work.
|
||||
|
||||
“ZIP”, “ZIP archive” or “ZIP file” means any ZIP archive. Typically
|
||||
this is a plain file with “.zip” (or “.ZIP”) file name suffix, but it
|
||||
can also be any seekable QIODevice (say, QBuffer, but not
|
||||
QTcpSocket).
|
||||
|
||||
“A file inside archive”, “a file inside ZIP” or something like that
|
||||
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
|
||||
|
||||
In general, the process looks like this:
|
||||
|
||||
-# Open or create an archive with a QuaZip instance.
|
||||
-# Open or create a file in the archive with a QuaZipFile instance.
|
||||
-# Perform reading or writing.
|
||||
-# Close the QuaZipFile instance.
|
||||
-# Repeat steps 2–4 for other files if needed.
|
||||
-# Close the QuaZip instance.
|
||||
|
||||
See the “qztest” subdirectory for examples. TestQuaZipFile::zipUnzip()
|
||||
is a good place to start.
|
||||
|
||||
\section error-handling Error handling
|
||||
|
||||
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,
|
||||
but it would cause unnecessary code bloating without any benefit. So,
|
||||
%QuaZip only checks for situations that ZIP/UNZIP API can not check
|
||||
for. For example, ZIP/UNZIP API has no “ZIP open mode” concept
|
||||
because read and write modes are completely separated. On the other
|
||||
hand, to avoid creating classes like “QuaZipReader”, “QuaZipWriter”
|
||||
or something like that, %QuaZip introduces “ZIP open mode” concept
|
||||
instead, thus making it possible to use one class (QuaZip) for both
|
||||
reading and writing. But this leads to additional open mode checks
|
||||
which are not done in ZIP/UNZIP package.
|
||||
|
||||
Therefore, error checking is two-level (%QuaZip's level and ZIP/UNZIP
|
||||
API level), which sometimes can be confusing, so here are some
|
||||
advices on how the error checking should be properly done:
|
||||
|
||||
- Both QuaZip and QuaZipFile have getZipError() function, which return
|
||||
error code of the last ZIP/UNZIP API call. Most function calls
|
||||
reset error code to UNZ_OK on success and set error code on
|
||||
failure. Some functions do not reset error code. Most of them are
|
||||
\c const and do not access ZIP archive in any way. Some, on the
|
||||
other hand, \em do access ZIP archive, but do not reset or set
|
||||
error code. For example, QuaZipFile::pos() function. Such functions
|
||||
are explicitly marked in the documentation.
|
||||
- Most functions have their own way to report errors, by returning a
|
||||
null string, negative value or \c false. If such a function returns
|
||||
error value, call getZipError() to get more information about
|
||||
error. See “zip.h” and “unzip.h” of the ZIP/UNZIP package for error
|
||||
codes.
|
||||
- If the function returns error-stating value (like \c false), but
|
||||
getZipError() returns UNZ_OK, it means that you did something
|
||||
obviously wrong. For example, tried to write in the archive open
|
||||
for reading or not open at all. You better just not do that!
|
||||
Most functions also issue a warning using qWarning() function in
|
||||
such cases. See documentation for a specific function for details
|
||||
on when it should not be called.
|
||||
|
||||
I know that this is somewhat messy, but I could not find a better way
|
||||
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.
|
||||
*/
|
|
@ -0,0 +1,207 @@
|
|||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
|
||||
Modified by Sergey A. Tachenov to allow QIODevice API usage.
|
||||
|
||||
For more info read MiniZip_info.txt
|
||||
|
||||
Changes
|
||||
|
||||
Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this)
|
||||
Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
|
||||
More if/def section may be needed to support other platforms
|
||||
Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
|
||||
(but you should use iowin32.c for windows instead)
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _ZLIBIOAPI64_H
|
||||
#define _ZLIBIOAPI64_H
|
||||
|
||||
#if (!defined(_WIN32)) && (!defined(WIN32))
|
||||
|
||||
// Linux needs this to support file operation on files larger then 4+GB
|
||||
// But might need better if/def to select just the platforms that needs them.
|
||||
|
||||
#ifndef __USE_FILE_OFFSET64
|
||||
#define __USE_FILE_OFFSET64
|
||||
#endif
|
||||
#ifndef __USE_LARGEFILE64
|
||||
#define __USE_LARGEFILE64
|
||||
#endif
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
#define _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
#ifndef _FILE_OFFSET_BIT
|
||||
#define _FILE_OFFSET_BIT 64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#if defined(USE_FILE32API)
|
||||
#define fopen64 fopen
|
||||
#define ftello64 ftell
|
||||
#define fseeko64 fseek
|
||||
#else
|
||||
#ifdef _MSC_VER
|
||||
#define fopen64 fopen
|
||||
#if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
|
||||
#define ftello64 _ftelli64
|
||||
#define fseeko64 _fseeki64
|
||||
#else // old MSC
|
||||
#define ftello64 ftell
|
||||
#define fseeko64 fseek
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef ZPOS64_T
|
||||
#ifdef _WIN32
|
||||
#define ZPOS64_T fpos_t
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#define ZPOS64_T uint64_t
|
||||
#endif
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifdef HAVE_MINIZIP64_CONF_H
|
||||
#include "mz64conf.h"
|
||||
#endif
|
||||
|
||||
/* a type choosen by DEFINE */
|
||||
#ifdef HAVE_64BIT_INT_CUSTOM
|
||||
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
|
||||
#else
|
||||
#ifdef HAS_STDINT_H
|
||||
#include "stdint.h"
|
||||
typedef uint64_t ZPOS64_T;
|
||||
#else
|
||||
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef unsigned __int64 ZPOS64_T;
|
||||
#else
|
||||
typedef unsigned long long int ZPOS64_T;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef OF
|
||||
#define OF _Z_OF
|
||||
#endif
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
#if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
#define ZCALLBACK CALLBACK
|
||||
#else
|
||||
#define ZCALLBACK
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, voidpf file, int mode));
|
||||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
||||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
||||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
|
||||
|
||||
typedef uLong (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
|
||||
|
||||
|
||||
/* here is the "old" 32 bits structure structure */
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell_file_func ztell_file;
|
||||
seek_file_func zseek_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
|
||||
typedef int (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
||||
typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, voidpf file, int mode));
|
||||
|
||||
typedef struct zlib_filefunc64_def_s
|
||||
{
|
||||
open64_file_func zopen64_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell64_file_func ztell64_file;
|
||||
seek64_file_func zseek64_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
close_file_func zfakeclose_file; // for no-auto-close flag
|
||||
} zlib_filefunc64_def;
|
||||
|
||||
void fill_qiodevice64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
void fill_qiodevice_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
/* now internal definition, only for zip.c and unzip.h */
|
||||
typedef struct zlib_filefunc64_32_def_s
|
||||
{
|
||||
zlib_filefunc64_def zfile_func64;
|
||||
open_file_func zopen32_file;
|
||||
tell_file_func ztell32_file;
|
||||
seek_file_func zseek32_file;
|
||||
} zlib_filefunc64_32_def;
|
||||
|
||||
|
||||
#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
||||
#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
||||
//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
|
||||
//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
|
||||
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
|
||||
#define ZFAKECLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zfakeclose_file)) ((filefunc).zfile_func64.opaque,filestream))
|
||||
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
|
||||
|
||||
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode));
|
||||
int call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
|
||||
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
|
||||
|
||||
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
|
||||
|
||||
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
|
||||
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
|
||||
#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,135 @@
|
|||
/* crypt.h -- base code for crypt/uncrypt ZIPfile
|
||||
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
This code is a modified version of crypting code in Infozip distribution
|
||||
|
||||
The encryption/decryption parts of this source code (as opposed to the
|
||||
non-echoing password parts) were originally written in Europe. The
|
||||
whole source package can be freely distributed, including from the USA.
|
||||
(Prior to January 2000, re-export from the US was a violation of US law.)
|
||||
|
||||
This encryption code is a direct transcription of the algorithm from
|
||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||
version without encryption capabilities).
|
||||
|
||||
If you don't need crypting in your application, just define symbols
|
||||
NOCRYPT and NOUNCRYPT.
|
||||
|
||||
This code support the "Traditional PKWARE Encryption".
|
||||
|
||||
The new AES encryption added on Zip format by Winzip (see the page
|
||||
http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
|
||||
Encryption is not supported.
|
||||
*/
|
||||
|
||||
#include "quazip_global.h"
|
||||
|
||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
/***********************************************************************
|
||||
* Return the next byte in the pseudo-random sequence
|
||||
*/
|
||||
static int decrypt_byte(unsigned long* pkeys, const z_crc_t FAR * pcrc_32_tab QUAZIP_UNUSED)
|
||||
{
|
||||
//(void) pcrc_32_tab; /* avoid "unused parameter" warning */
|
||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||
* unpredictable manner on 16-bit systems; not a problem
|
||||
* with any known compiler so far, though */
|
||||
|
||||
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
|
||||
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Update the encryption keys with the next byte of plain text
|
||||
*/
|
||||
static int update_keys(unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab,int c)
|
||||
{
|
||||
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
|
||||
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
||||
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
||||
{
|
||||
register int keyshift = (int)((*(pkeys+1)) >> 24);
|
||||
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* Initialize the encryption keys and the random header according to
|
||||
* the given password.
|
||||
*/
|
||||
static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab)
|
||||
{
|
||||
*(pkeys+0) = 305419896L;
|
||||
*(pkeys+1) = 591751049L;
|
||||
*(pkeys+2) = 878082192L;
|
||||
while (*passwd != '\0') {
|
||||
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
|
||||
passwd++;
|
||||
}
|
||||
}
|
||||
|
||||
#define zdecode(pkeys,pcrc_32_tab,c) \
|
||||
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
|
||||
|
||||
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
||||
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
||||
|
||||
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
|
||||
|
||||
#define RAND_HEAD_LEN 12
|
||||
/* "last resort" source for second part of crypt seed pattern */
|
||||
# ifndef ZCR_SEED2
|
||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||
# endif
|
||||
|
||||
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
|
||||
const char *passwd; /* password string */
|
||||
unsigned char *buf; /* where to write header */
|
||||
int bufSize;
|
||||
unsigned long* pkeys;
|
||||
const z_crc_t FAR * pcrc_32_tab;
|
||||
unsigned long crcForCrypting;
|
||||
{
|
||||
int n; /* index in random header */
|
||||
int t; /* temporary */
|
||||
int c; /* random byte */
|
||||
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
|
||||
static unsigned calls = 0; /* ensure different random header each time */
|
||||
|
||||
if (bufSize<RAND_HEAD_LEN)
|
||||
return 0;
|
||||
|
||||
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
|
||||
* output of rand() to get less predictability, since rand() is
|
||||
* often poorly implemented.
|
||||
*/
|
||||
if (++calls == 1)
|
||||
{
|
||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||
}
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
c = (rand() >> 7) & 0xff;
|
||||
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
|
||||
}
|
||||
/* Encrypt random header (last two bytes is high word of crc) */
|
||||
init_keys(passwd, pkeys, pcrc_32_tab);
|
||||
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
||||
{
|
||||
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
|
||||
}
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
|
||||
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
|
||||
return n;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,348 @@
|
|||
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
||||
files using zlib + zip or unzip API
|
||||
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
Modified by Sergey A. Tachenov to integrate with Qt.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "ioapi.h"
|
||||
#include "quazip_global.h"
|
||||
#include <QtCore/QIODevice>
|
||||
#include "quazip_qt_compat.h"
|
||||
|
||||
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
|
||||
|
||||
#ifndef SEEK_CUR
|
||||
#define SEEK_CUR 1
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_END
|
||||
#define SEEK_END 2
|
||||
#endif
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0
|
||||
#endif
|
||||
|
||||
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zopen64_file != nullptr)
|
||||
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,file,mode);
|
||||
else
|
||||
{
|
||||
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,file,mode);
|
||||
}
|
||||
}
|
||||
|
||||
int call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zseek64_file != nullptr)
|
||||
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
|
||||
else
|
||||
{
|
||||
uLong offsetTruncated = (uLong)offset;
|
||||
if (offsetTruncated != offset)
|
||||
return -1;
|
||||
else
|
||||
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
|
||||
}
|
||||
}
|
||||
|
||||
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zseek64_file != nullptr)
|
||||
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
|
||||
else
|
||||
{
|
||||
uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
|
||||
if ((tell_uLong) == ((uLong)-1))
|
||||
return (ZPOS64_T)-1;
|
||||
else
|
||||
return tell_uLong;
|
||||
}
|
||||
}
|
||||
|
||||
/// @cond internal
|
||||
struct QIODevice_descriptor {
|
||||
// Position only used for writing to sequential devices.
|
||||
qint64 pos;
|
||||
inline QIODevice_descriptor():
|
||||
pos(0)
|
||||
{}
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
voidpf ZCALLBACK qiodevice_open_file_func (
|
||||
voidpf opaque,
|
||||
voidpf file,
|
||||
int mode)
|
||||
{
|
||||
QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(file);
|
||||
QIODevice::OpenMode desiredMode;
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
||||
desiredMode = QIODevice::ReadOnly;
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
desiredMode = QIODevice::ReadWrite;
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
desiredMode = QIODevice::WriteOnly;
|
||||
if (iodevice->isOpen()) {
|
||||
if ((iodevice->openMode() & desiredMode) == desiredMode) {
|
||||
if (desiredMode != QIODevice::WriteOnly
|
||||
&& iodevice->isSequential()) {
|
||||
// We can use sequential devices only for writing.
|
||||
delete d;
|
||||
return nullptr;
|
||||
} else {
|
||||
if ((desiredMode & QIODevice::WriteOnly) != 0) {
|
||||
// open for writing, need to seek existing device
|
||||
if (!iodevice->isSequential()) {
|
||||
iodevice->seek(0);
|
||||
} else {
|
||||
d->pos = iodevice->pos();
|
||||
}
|
||||
}
|
||||
}
|
||||
return iodevice;
|
||||
} else {
|
||||
delete d;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
iodevice->open(desiredMode);
|
||||
if (iodevice->isOpen()) {
|
||||
if (desiredMode != QIODevice::WriteOnly && iodevice->isSequential()) {
|
||||
// We can use sequential devices only for writing.
|
||||
iodevice->close();
|
||||
delete d;
|
||||
return nullptr;
|
||||
} else {
|
||||
return iodevice;
|
||||
}
|
||||
} else {
|
||||
delete d;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK qiodevice_read_file_func (
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
void* buf,
|
||||
uLong size)
|
||||
{
|
||||
QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
|
||||
qint64 ret64 = iodevice->read((char*)buf,size);
|
||||
uLong ret;
|
||||
ret = (uLong) ret64;
|
||||
if (ret64 != -1) {
|
||||
d->pos += ret64;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uLong ZCALLBACK qiodevice_write_file_func (
|
||||
voidpf opaque,
|
||||
voidpf stream,
|
||||
const void* buf,
|
||||
uLong size)
|
||||
{
|
||||
QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
|
||||
uLong ret;
|
||||
qint64 ret64 = iodevice->write((char*)buf,size);
|
||||
if (ret64 != -1) {
|
||||
d->pos += ret64;
|
||||
}
|
||||
ret = (uLong) ret64;
|
||||
return ret;
|
||||
}
|
||||
|
||||
uLong ZCALLBACK qiodevice_tell_file_func (
|
||||
voidpf opaque,
|
||||
voidpf stream)
|
||||
{
|
||||
QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
|
||||
uLong ret;
|
||||
qint64 ret64;
|
||||
if (iodevice->isSequential()) {
|
||||
ret64 = d->pos;
|
||||
} else {
|
||||
ret64 = iodevice->pos();
|
||||
}
|
||||
ret = static_cast<uLong>(ret64);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ZPOS64_T ZCALLBACK qiodevice64_tell_file_func (
|
||||
voidpf opaque,
|
||||
voidpf stream)
|
||||
{
|
||||
QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
|
||||
qint64 ret;
|
||||
if (iodevice->isSequential()) {
|
||||
ret = d->pos;
|
||||
} else {
|
||||
ret = iodevice->pos();
|
||||
}
|
||||
return static_cast<ZPOS64_T>(ret);
|
||||
}
|
||||
|
||||
int ZCALLBACK qiodevice_seek_file_func (
|
||||
voidpf /*opaque UNUSED*/,
|
||||
voidpf stream,
|
||||
uLong offset,
|
||||
int origin)
|
||||
{
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
|
||||
if (iodevice->isSequential()) {
|
||||
if (origin == ZLIB_FILEFUNC_SEEK_END
|
||||
&& offset == 0) {
|
||||
// sequential devices are always at end (needed in mdAppend)
|
||||
return 0;
|
||||
} else {
|
||||
qWarning("qiodevice_seek_file_func() called for sequential device");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
uLong qiodevice_seek_result=0;
|
||||
int ret;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
qiodevice_seek_result = ((QIODevice*)stream)->pos() + offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
qiodevice_seek_result = ((QIODevice*)stream)->size() - offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
qiodevice_seek_result = offset;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
ret = !iodevice->seek(qiodevice_seek_result);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK qiodevice64_seek_file_func (
|
||||
voidpf /*opaque UNUSED*/,
|
||||
voidpf stream,
|
||||
ZPOS64_T offset,
|
||||
int origin)
|
||||
{
|
||||
QIODevice *iodevice = reinterpret_cast<QIODevice*>(stream);
|
||||
if (iodevice->isSequential()) {
|
||||
if (origin == ZLIB_FILEFUNC_SEEK_END
|
||||
&& offset == 0) {
|
||||
// sequential devices are always at end (needed in mdAppend)
|
||||
return 0;
|
||||
} else {
|
||||
qWarning("qiodevice_seek_file_func() called for sequential device");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
qint64 qiodevice_seek_result=0;
|
||||
int ret;
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR :
|
||||
qiodevice_seek_result = ((QIODevice*)stream)->pos() + offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END :
|
||||
qiodevice_seek_result = ((QIODevice*)stream)->size() - offset;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET :
|
||||
qiodevice_seek_result = offset;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
ret = !iodevice->seek(qiodevice_seek_result);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ZCALLBACK qiodevice_close_file_func (
|
||||
voidpf opaque,
|
||||
voidpf stream)
|
||||
{
|
||||
QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
|
||||
delete d;
|
||||
QIODevice *device = reinterpret_cast<QIODevice*>(stream);
|
||||
return quazip_close(device) ? 0 : -1;
|
||||
}
|
||||
|
||||
int ZCALLBACK qiodevice_fakeclose_file_func (
|
||||
voidpf opaque,
|
||||
voidpf /*stream*/)
|
||||
{
|
||||
QIODevice_descriptor *d = reinterpret_cast<QIODevice_descriptor*>(opaque);
|
||||
delete d;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ZCALLBACK qiodevice_error_file_func (
|
||||
voidpf /*opaque UNUSED*/,
|
||||
voidpf /*stream UNUSED*/)
|
||||
{
|
||||
// can't check for error due to the QIODevice API limitation
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fill_qiodevice_filefunc (
|
||||
zlib_filefunc_def* pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = qiodevice_open_file_func;
|
||||
pzlib_filefunc_def->zread_file = qiodevice_read_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = qiodevice_write_file_func;
|
||||
pzlib_filefunc_def->ztell_file = qiodevice_tell_file_func;
|
||||
pzlib_filefunc_def->zseek_file = qiodevice_seek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = qiodevice_close_file_func;
|
||||
pzlib_filefunc_def->zerror_file = qiodevice_error_file_func;
|
||||
pzlib_filefunc_def->opaque = new QIODevice_descriptor;
|
||||
}
|
||||
|
||||
void fill_qiodevice64_filefunc (
|
||||
zlib_filefunc64_def* pzlib_filefunc_def)
|
||||
{
|
||||
// Open functions are the same for Qt.
|
||||
pzlib_filefunc_def->zopen64_file = qiodevice_open_file_func;
|
||||
pzlib_filefunc_def->zread_file = qiodevice_read_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = qiodevice_write_file_func;
|
||||
pzlib_filefunc_def->ztell64_file = qiodevice64_tell_file_func;
|
||||
pzlib_filefunc_def->zseek64_file = qiodevice64_seek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = qiodevice_close_file_func;
|
||||
pzlib_filefunc_def->zerror_file = qiodevice_error_file_func;
|
||||
pzlib_filefunc_def->opaque = new QIODevice_descriptor;
|
||||
pzlib_filefunc_def->zfakeclose_file = qiodevice_fakeclose_file_func;
|
||||
}
|
||||
|
||||
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 = nullptr;
|
||||
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.zread_file = p_filefunc32->zread_file;
|
||||
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
|
||||
p_filefunc64_32->zfile_func64.ztell64_file = nullptr;
|
||||
p_filefunc64_32->zfile_func64.zseek64_file = nullptr;
|
||||
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.opaque = p_filefunc32->opaque;
|
||||
p_filefunc64_32->zfile_func64.zfakeclose_file = nullptr;
|
||||
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
|
||||
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Copyright (C) 2010 Adam Walczak
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "quaadler32.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
QuaAdler32::QuaAdler32()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
quint32 QuaAdler32::calculate(const QByteArray &data)
|
||||
{
|
||||
return adler32( adler32(0L, Z_NULL, 0), (const Bytef*)data.data(), data.size() );
|
||||
}
|
||||
|
||||
void QuaAdler32::reset()
|
||||
{
|
||||
checksum = adler32(0L, Z_NULL, 0);
|
||||
}
|
||||
|
||||
void QuaAdler32::update(const QByteArray &buf)
|
||||
{
|
||||
checksum = adler32( checksum, (const Bytef*)buf.data(), buf.size() );
|
||||
}
|
||||
|
||||
quint32 QuaAdler32::value()
|
||||
{
|
||||
return checksum;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
#ifndef QUAADLER32_H
|
||||
#define QUAADLER32_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2010 Adam Walczak
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QByteArray>
|
||||
|
||||
#include "quachecksum32.h"
|
||||
|
||||
/// Adler32 checksum
|
||||
/** \class QuaAdler32 quaadler32.h <quazip/quaadler32.h>
|
||||
* This class wrappers the adler32 function with the QuaChecksum32 interface.
|
||||
* See QuaChecksum32 for more info.
|
||||
*/
|
||||
class QUAZIP_EXPORT QuaAdler32 : public QuaChecksum32
|
||||
{
|
||||
|
||||
public:
|
||||
QuaAdler32();
|
||||
|
||||
quint32 calculate(const QByteArray &data);
|
||||
|
||||
void reset();
|
||||
void update(const QByteArray &buf);
|
||||
quint32 value();
|
||||
|
||||
private:
|
||||
quint32 checksum;
|
||||
};
|
||||
|
||||
#endif //QUAADLER32_H
|
|
@ -0,0 +1,5 @@
|
|||
#include "quachecksum32.h"
|
||||
|
||||
QuaChecksum32::~QuaChecksum32()
|
||||
{
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
#ifndef QUACHECKSUM32_H
|
||||
#define QUACHECKSUM32_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QByteArray>
|
||||
#include "quazip_global.h"
|
||||
|
||||
/// Checksum interface.
|
||||
/** \class QuaChecksum32 quachecksum32.h <quazip/quachecksum32.h>
|
||||
* This is an interface for 32 bit checksums.
|
||||
* Classes implementing this interface can calcunate a certin
|
||||
* checksum in a single step:
|
||||
* \code
|
||||
* QChecksum32 *crc32 = new QuaCrc32();
|
||||
* rasoult = crc32->calculate(data);
|
||||
* \endcode
|
||||
* or by streaming the data:
|
||||
* \code
|
||||
* QChecksum32 *crc32 = new QuaCrc32();
|
||||
* while(!fileA.atEnd())
|
||||
* crc32->update(fileA.read(bufSize));
|
||||
* resoultA = crc32->value();
|
||||
* crc32->reset();
|
||||
* while(!fileB.atEnd())
|
||||
* crc32->update(fileB.read(bufSize));
|
||||
* resoultB = crc32->value();
|
||||
* \endcode
|
||||
*/
|
||||
class QUAZIP_EXPORT QuaChecksum32
|
||||
{
|
||||
|
||||
public:
|
||||
virtual ~QuaChecksum32();
|
||||
///Calculates the checksum for data.
|
||||
/** \a data source data
|
||||
* \return data checksum
|
||||
*
|
||||
* This function has no efect on the value returned by value().
|
||||
*/
|
||||
virtual quint32 calculate(const QByteArray &data) = 0;
|
||||
|
||||
///Resets the calculation on a checksun for a stream.
|
||||
virtual void reset() = 0;
|
||||
|
||||
///Updates the calculated checksum for the stream
|
||||
/** \a buf next portion of data from the stream
|
||||
*/
|
||||
virtual void update(const QByteArray &buf) = 0;
|
||||
|
||||
///Value of the checksum calculated for the stream passed throw update().
|
||||
/** \return checksum
|
||||
*/
|
||||
virtual quint32 value() = 0;
|
||||
};
|
||||
|
||||
#endif //QUACHECKSUM32_H
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "quacrc32.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
QuaCrc32::QuaCrc32()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
quint32 QuaCrc32::calculate(const QByteArray &data)
|
||||
{
|
||||
return crc32( crc32(0L, Z_NULL, 0), (const Bytef*)data.data(), data.size() );
|
||||
}
|
||||
|
||||
void QuaCrc32::reset()
|
||||
{
|
||||
checksum = crc32(0L, Z_NULL, 0);
|
||||
}
|
||||
|
||||
void QuaCrc32::update(const QByteArray &buf)
|
||||
{
|
||||
checksum = crc32( checksum, (const Bytef*)buf.data(), buf.size() );
|
||||
}
|
||||
|
||||
quint32 QuaCrc32::value()
|
||||
{
|
||||
return checksum;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef QUACRC32_H
|
||||
#define QUACRC32_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "quachecksum32.h"
|
||||
|
||||
///CRC32 checksum
|
||||
/** \class QuaCrc32 quacrc32.h <quazip/quacrc32.h>
|
||||
* This class wrappers the crc32 function with the QuaChecksum32 interface.
|
||||
* See QuaChecksum32 for more info.
|
||||
*/
|
||||
class QUAZIP_EXPORT QuaCrc32 : public QuaChecksum32 {
|
||||
|
||||
public:
|
||||
QuaCrc32();
|
||||
|
||||
quint32 calculate(const QByteArray &data);
|
||||
|
||||
void reset();
|
||||
void update(const QByteArray &buf);
|
||||
quint32 value();
|
||||
|
||||
private:
|
||||
quint32 checksum;
|
||||
};
|
||||
|
||||
#endif //QUACRC32_H
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QFile>
|
||||
|
||||
#include "quagzipfile.h"
|
||||
|
||||
/// \cond internal
|
||||
class QuaGzipFilePrivate {
|
||||
friend class QuaGzipFile;
|
||||
QString fileName;
|
||||
gzFile gzd;
|
||||
inline QuaGzipFilePrivate(): gzd(nullptr) {}
|
||||
inline QuaGzipFilePrivate(const QString &fileName):
|
||||
fileName(fileName), gzd(nullptr) {}
|
||||
template<typename FileId> bool open(FileId id,
|
||||
QIODevice::OpenMode mode, QString &error);
|
||||
gzFile open(int fd, const char *modeString);
|
||||
gzFile open(const QString &name, const char *modeString);
|
||||
};
|
||||
|
||||
gzFile QuaGzipFilePrivate::open(const QString &name, const char *modeString)
|
||||
{
|
||||
return gzopen(QFile::encodeName(name).constData(), modeString);
|
||||
}
|
||||
|
||||
gzFile QuaGzipFilePrivate::open(int fd, const char *modeString)
|
||||
{
|
||||
return gzdopen(fd, modeString);
|
||||
}
|
||||
|
||||
template<typename FileId>
|
||||
bool QuaGzipFilePrivate::open(FileId id, QIODevice::OpenMode mode,
|
||||
QString &error)
|
||||
{
|
||||
char modeString[2];
|
||||
modeString[0] = modeString[1] = '\0';
|
||||
if ((mode & QIODevice::Append) != 0) {
|
||||
error = QuaGzipFile::tr("QIODevice::Append is not "
|
||||
"supported for GZIP");
|
||||
return false;
|
||||
}
|
||||
if ((mode & QIODevice::ReadOnly) != 0
|
||||
&& (mode & QIODevice::WriteOnly) != 0) {
|
||||
error = QuaGzipFile::tr("Opening gzip for both reading"
|
||||
" and writing is not supported");
|
||||
return false;
|
||||
} else if ((mode & QIODevice::ReadOnly) != 0) {
|
||||
modeString[0] = 'r';
|
||||
} else if ((mode & QIODevice::WriteOnly) != 0) {
|
||||
modeString[0] = 'w';
|
||||
} else {
|
||||
error = QuaGzipFile::tr("You can open a gzip either for reading"
|
||||
" or for writing. Which is it?");
|
||||
return false;
|
||||
}
|
||||
gzd = open(id, modeString);
|
||||
if (gzd == nullptr) {
|
||||
error = QuaGzipFile::tr("Could not gzopen() file");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// \endcond
|
||||
|
||||
QuaGzipFile::QuaGzipFile():
|
||||
d(new QuaGzipFilePrivate())
|
||||
{
|
||||
}
|
||||
|
||||
QuaGzipFile::QuaGzipFile(QObject *parent):
|
||||
QIODevice(parent),
|
||||
d(new QuaGzipFilePrivate())
|
||||
{
|
||||
}
|
||||
|
||||
QuaGzipFile::QuaGzipFile(const QString &fileName, QObject *parent):
|
||||
QIODevice(parent),
|
||||
d(new QuaGzipFilePrivate(fileName))
|
||||
{
|
||||
}
|
||||
|
||||
QuaGzipFile::~QuaGzipFile()
|
||||
{
|
||||
if (isOpen()) {
|
||||
close();
|
||||
}
|
||||
delete d;
|
||||
}
|
||||
|
||||
void QuaGzipFile::setFileName(const QString& fileName)
|
||||
{
|
||||
d->fileName = fileName;
|
||||
}
|
||||
|
||||
QString QuaGzipFile::getFileName() const
|
||||
{
|
||||
return d->fileName;
|
||||
}
|
||||
|
||||
bool QuaGzipFile::isSequential() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QuaGzipFile::open(QIODevice::OpenMode mode)
|
||||
{
|
||||
QString error;
|
||||
if (!d->open(d->fileName, mode, error)) {
|
||||
setErrorString(error);
|
||||
return false;
|
||||
}
|
||||
return QIODevice::open(mode);
|
||||
}
|
||||
|
||||
bool QuaGzipFile::open(int fd, QIODevice::OpenMode mode)
|
||||
{
|
||||
QString error;
|
||||
if (!d->open(fd, mode, error)) {
|
||||
setErrorString(error);
|
||||
return false;
|
||||
}
|
||||
return QIODevice::open(mode);
|
||||
}
|
||||
|
||||
bool QuaGzipFile::flush()
|
||||
{
|
||||
return gzflush(d->gzd, Z_SYNC_FLUSH) == Z_OK;
|
||||
}
|
||||
|
||||
void QuaGzipFile::close()
|
||||
{
|
||||
QIODevice::close();
|
||||
gzclose(d->gzd);
|
||||
}
|
||||
|
||||
qint64 QuaGzipFile::readData(char *data, qint64 maxSize)
|
||||
{
|
||||
return gzread(d->gzd, (voidp)data, (unsigned)maxSize);
|
||||
}
|
||||
|
||||
qint64 QuaGzipFile::writeData(const char *data, qint64 maxSize)
|
||||
{
|
||||
if (maxSize == 0)
|
||||
return 0;
|
||||
int written = gzwrite(d->gzd, (voidp)data, (unsigned)maxSize);
|
||||
if (written == 0)
|
||||
return -1;
|
||||
else
|
||||
return written;
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
#ifndef QUAZIP_QUAGZIPFILE_H
|
||||
#define QUAZIP_QUAGZIPFILE_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include "quazip_global.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
class QuaGzipFilePrivate;
|
||||
|
||||
/// GZIP file
|
||||
/**
|
||||
This class is a wrapper around GZIP file access functions in zlib. Unlike QuaZip classes, it doesn't allow reading from a GZIP file opened as QIODevice, for example, if your GZIP file is in QBuffer. It only provides QIODevice access to a GZIP file contents, but the GZIP file itself must be identified by its name on disk or by descriptor id.
|
||||
*/
|
||||
class QUAZIP_EXPORT QuaGzipFile: public QIODevice {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/// Empty constructor.
|
||||
/**
|
||||
Must call setFileName() before trying to open.
|
||||
*/
|
||||
QuaGzipFile();
|
||||
/// Empty constructor with a parent.
|
||||
/**
|
||||
Must call setFileName() before trying to open.
|
||||
\param parent The parent object, as per QObject logic.
|
||||
*/
|
||||
QuaGzipFile(QObject *parent);
|
||||
/// Constructor.
|
||||
/**
|
||||
\param fileName The name of the GZIP file.
|
||||
\param parent The parent object, as per QObject logic.
|
||||
*/
|
||||
QuaGzipFile(const QString &fileName, QObject *parent = nullptr);
|
||||
/// Destructor.
|
||||
virtual ~QuaGzipFile();
|
||||
/// Sets the name of the GZIP file to be opened.
|
||||
void setFileName(const QString& fileName);
|
||||
/// Returns the name of the GZIP file.
|
||||
QString getFileName() const;
|
||||
/// Returns true.
|
||||
/**
|
||||
Strictly speaking, zlib supports seeking for GZIP files, but it is
|
||||
poorly implemented, because there is no way to implement it
|
||||
properly. For reading, seeking backwards is very slow, and for
|
||||
writing, it is downright impossible. Therefore, QuaGzipFile does not
|
||||
support seeking at all.
|
||||
*/
|
||||
virtual bool isSequential() const;
|
||||
/// Opens the file.
|
||||
/**
|
||||
\param mode Can be either QIODevice::Write or QIODevice::Read.
|
||||
ReadWrite and Append aren't supported.
|
||||
*/
|
||||
virtual bool open(QIODevice::OpenMode mode);
|
||||
/// Opens the file.
|
||||
/**
|
||||
\overload
|
||||
\param fd The file descriptor to read/write the GZIP file from/to.
|
||||
\param mode Can be either QIODevice::Write or QIODevice::Read.
|
||||
ReadWrite and Append aren't supported.
|
||||
*/
|
||||
virtual bool open(int fd, QIODevice::OpenMode mode);
|
||||
/// Flushes data to file.
|
||||
/**
|
||||
The data is written using Z_SYNC_FLUSH mode. Doesn't make any sense
|
||||
when reading.
|
||||
*/
|
||||
virtual bool flush();
|
||||
/// Closes the file.
|
||||
virtual void close();
|
||||
protected:
|
||||
/// Implementation of QIODevice::readData().
|
||||
virtual qint64 readData(char *data, qint64 maxSize);
|
||||
/// Implementation of QIODevice::writeData().
|
||||
virtual qint64 writeData(const char *data, qint64 maxSize);
|
||||
private:
|
||||
// not implemented by design to disable copy
|
||||
QuaGzipFile(const QuaGzipFile &that);
|
||||
QuaGzipFile& operator=(const QuaGzipFile &that);
|
||||
QuaGzipFilePrivate *d;
|
||||
};
|
||||
|
||||
#endif // QUAZIP_QUAGZIPFILE_H
|
|
@ -0,0 +1,349 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "quaziodevice.h"
|
||||
|
||||
#define QUAZIO_INBUFSIZE 4096
|
||||
#define QUAZIO_OUTBUFSIZE 4096
|
||||
|
||||
/// \cond internal
|
||||
class QuaZIODevicePrivate {
|
||||
friend class QuaZIODevice;
|
||||
QuaZIODevicePrivate(QIODevice *io, QuaZIODevice *q);
|
||||
~QuaZIODevicePrivate();
|
||||
QIODevice *io;
|
||||
QuaZIODevice *q;
|
||||
z_stream zins;
|
||||
z_stream zouts;
|
||||
char *inBuf;
|
||||
int inBufPos;
|
||||
int inBufSize;
|
||||
char *outBuf;
|
||||
int outBufPos;
|
||||
int outBufSize;
|
||||
bool zBufError;
|
||||
bool atEnd;
|
||||
bool flush(int sync);
|
||||
int doFlush(QString &error);
|
||||
};
|
||||
|
||||
QuaZIODevicePrivate::QuaZIODevicePrivate(QIODevice *io, QuaZIODevice *q):
|
||||
io(io),
|
||||
q(q),
|
||||
inBuf(nullptr),
|
||||
inBufPos(0),
|
||||
inBufSize(0),
|
||||
outBuf(nullptr),
|
||||
outBufPos(0),
|
||||
outBufSize(0),
|
||||
zBufError(false),
|
||||
atEnd(false)
|
||||
{
|
||||
zins.zalloc = (alloc_func) nullptr;
|
||||
zins.zfree = (free_func) nullptr;
|
||||
zins.opaque = nullptr;
|
||||
zouts.zalloc = (alloc_func) nullptr;
|
||||
zouts.zfree = (free_func) nullptr;
|
||||
zouts.opaque = nullptr;
|
||||
inBuf = new char[QUAZIO_INBUFSIZE];
|
||||
outBuf = new char[QUAZIO_OUTBUFSIZE];
|
||||
#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT
|
||||
debug.setFileName("debug.out");
|
||||
debug.open(QIODevice::WriteOnly);
|
||||
#endif
|
||||
#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT
|
||||
indebug.setFileName("debug.in");
|
||||
indebug.open(QIODevice::WriteOnly);
|
||||
#endif
|
||||
}
|
||||
|
||||
QuaZIODevicePrivate::~QuaZIODevicePrivate()
|
||||
{
|
||||
#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT
|
||||
debug.close();
|
||||
#endif
|
||||
#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT
|
||||
indebug.close();
|
||||
#endif
|
||||
if (inBuf != nullptr)
|
||||
delete[] inBuf;
|
||||
if (outBuf != nullptr)
|
||||
delete[] outBuf;
|
||||
}
|
||||
|
||||
bool QuaZIODevicePrivate::flush(int sync)
|
||||
{
|
||||
QString error;
|
||||
if (doFlush(error) < 0) {
|
||||
q->setErrorString(error);
|
||||
return false;
|
||||
}
|
||||
// can't flush buffer, some data is still waiting
|
||||
if (outBufPos < outBufSize)
|
||||
return true;
|
||||
Bytef c = 0;
|
||||
zouts.next_in = &c; // fake input buffer
|
||||
zouts.avail_in = 0; // of zero size
|
||||
do {
|
||||
zouts.next_out = (Bytef *) outBuf;
|
||||
zouts.avail_out = QUAZIO_OUTBUFSIZE;
|
||||
int result = deflate(&zouts, sync);
|
||||
switch (result) {
|
||||
case Z_OK:
|
||||
case Z_STREAM_END:
|
||||
outBufSize = (char *) zouts.next_out - outBuf;
|
||||
if (doFlush(error) < 0) {
|
||||
q->setErrorString(error);
|
||||
return false;
|
||||
}
|
||||
if (outBufPos < outBufSize)
|
||||
return true;
|
||||
break;
|
||||
case Z_BUF_ERROR: // nothing to write?
|
||||
return true;
|
||||
default:
|
||||
q->setErrorString(QString::fromLocal8Bit(zouts.msg));
|
||||
return false;
|
||||
}
|
||||
} while (zouts.avail_out == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
int QuaZIODevicePrivate::doFlush(QString &error)
|
||||
{
|
||||
int flushed = 0;
|
||||
while (outBufPos < outBufSize) {
|
||||
int more = io->write(outBuf + outBufPos, outBufSize - outBufPos);
|
||||
if (more == -1) {
|
||||
error = io->errorString();
|
||||
return -1;
|
||||
}
|
||||
if (more == 0)
|
||||
break;
|
||||
outBufPos += more;
|
||||
flushed += more;
|
||||
}
|
||||
if (outBufPos == outBufSize) {
|
||||
outBufPos = outBufSize = 0;
|
||||
}
|
||||
return flushed;
|
||||
}
|
||||
|
||||
/// \endcond
|
||||
|
||||
// #define QUAZIP_ZIODEVICE_DEBUG_OUTPUT
|
||||
// #define QUAZIP_ZIODEVICE_DEBUG_INPUT
|
||||
#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT
|
||||
#include <QtCore/QFile>
|
||||
static QFile debug;
|
||||
#endif
|
||||
#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT
|
||||
#include <QtCore/QFile>
|
||||
static QFile indebug;
|
||||
#endif
|
||||
|
||||
QuaZIODevice::QuaZIODevice(QIODevice *io, QObject *parent):
|
||||
QIODevice(parent),
|
||||
d(new QuaZIODevicePrivate(io, this))
|
||||
{
|
||||
connect(io, SIGNAL(readyRead()), SIGNAL(readyRead()));
|
||||
}
|
||||
|
||||
QuaZIODevice::~QuaZIODevice()
|
||||
{
|
||||
if (isOpen())
|
||||
close();
|
||||
delete d;
|
||||
}
|
||||
|
||||
QIODevice *QuaZIODevice::getIoDevice() const
|
||||
{
|
||||
return d->io;
|
||||
}
|
||||
|
||||
bool QuaZIODevice::open(QIODevice::OpenMode mode)
|
||||
{
|
||||
if ((mode & QIODevice::Append) != 0) {
|
||||
setErrorString(tr("QIODevice::Append is not supported for"
|
||||
" QuaZIODevice"));
|
||||
return false;
|
||||
}
|
||||
if ((mode & QIODevice::ReadWrite) == QIODevice::ReadWrite) {
|
||||
setErrorString(tr("QIODevice::ReadWrite is not supported for"
|
||||
" QuaZIODevice"));
|
||||
return false;
|
||||
}
|
||||
if ((mode & QIODevice::ReadOnly) != 0) {
|
||||
if (inflateInit(&d->zins) != Z_OK) {
|
||||
setErrorString(QString::fromLocal8Bit(d->zins.msg));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((mode & QIODevice::WriteOnly) != 0) {
|
||||
if (deflateInit(&d->zouts, Z_DEFAULT_COMPRESSION) != Z_OK) {
|
||||
setErrorString(QString::fromLocal8Bit(d->zouts.msg));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return QIODevice::open(mode);
|
||||
}
|
||||
|
||||
void QuaZIODevice::close()
|
||||
{
|
||||
if ((openMode() & QIODevice::ReadOnly) != 0) {
|
||||
if (inflateEnd(&d->zins) != Z_OK) {
|
||||
setErrorString(QString::fromLocal8Bit(d->zins.msg));
|
||||
}
|
||||
}
|
||||
if ((openMode() & QIODevice::WriteOnly) != 0) {
|
||||
d->flush(Z_FINISH);
|
||||
if (deflateEnd(&d->zouts) != Z_OK) {
|
||||
setErrorString(QString::fromLocal8Bit(d->zouts.msg));
|
||||
}
|
||||
}
|
||||
QIODevice::close();
|
||||
}
|
||||
|
||||
qint64 QuaZIODevice::readData(char *data, qint64 maxSize)
|
||||
{
|
||||
int read = 0;
|
||||
while (read < maxSize) {
|
||||
if (d->inBufPos == d->inBufSize) {
|
||||
d->inBufPos = 0;
|
||||
d->inBufSize = d->io->read(d->inBuf, QUAZIO_INBUFSIZE);
|
||||
if (d->inBufSize == -1) {
|
||||
d->inBufSize = 0;
|
||||
setErrorString(d->io->errorString());
|
||||
return -1;
|
||||
}
|
||||
if (d->inBufSize == 0)
|
||||
break;
|
||||
}
|
||||
while (read < maxSize && d->inBufPos < d->inBufSize) {
|
||||
d->zins.next_in = (Bytef *) (d->inBuf + d->inBufPos);
|
||||
d->zins.avail_in = d->inBufSize - d->inBufPos;
|
||||
d->zins.next_out = (Bytef *) (data + read);
|
||||
d->zins.avail_out = (uInt) (maxSize - read); // hope it's less than 2GB
|
||||
int more = 0;
|
||||
switch (inflate(&d->zins, Z_SYNC_FLUSH)) {
|
||||
case Z_OK:
|
||||
read = (char *) d->zins.next_out - data;
|
||||
d->inBufPos = (char *) d->zins.next_in - d->inBuf;
|
||||
break;
|
||||
case Z_STREAM_END:
|
||||
read = (char *) d->zins.next_out - data;
|
||||
d->inBufPos = (char *) d->zins.next_in - d->inBuf;
|
||||
d->atEnd = true;
|
||||
return read;
|
||||
case Z_BUF_ERROR: // this should never happen, but just in case
|
||||
if (!d->zBufError) {
|
||||
qWarning("Z_BUF_ERROR detected with %d/%d in/out, weird",
|
||||
d->zins.avail_in, d->zins.avail_out);
|
||||
d->zBufError = true;
|
||||
}
|
||||
memmove(d->inBuf, d->inBuf + d->inBufPos, d->inBufSize - d->inBufPos);
|
||||
d->inBufSize -= d->inBufPos;
|
||||
d->inBufPos = 0;
|
||||
more = d->io->read(d->inBuf + d->inBufSize, QUAZIO_INBUFSIZE - d->inBufSize);
|
||||
if (more == -1) {
|
||||
setErrorString(d->io->errorString());
|
||||
return -1;
|
||||
}
|
||||
if (more == 0)
|
||||
return read;
|
||||
d->inBufSize += more;
|
||||
break;
|
||||
default:
|
||||
setErrorString(QString::fromLocal8Bit(d->zins.msg));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT
|
||||
indebug.write(data, read);
|
||||
#endif
|
||||
return read;
|
||||
}
|
||||
|
||||
qint64 QuaZIODevice::writeData(const char *data, qint64 maxSize)
|
||||
{
|
||||
int written = 0;
|
||||
QString error;
|
||||
if (d->doFlush(error) == -1) {
|
||||
setErrorString(error);
|
||||
return -1;
|
||||
}
|
||||
while (written < maxSize) {
|
||||
// there is some data waiting in the output buffer
|
||||
if (d->outBufPos < d->outBufSize)
|
||||
return written;
|
||||
d->zouts.next_in = (Bytef *) (data + written);
|
||||
d->zouts.avail_in = (uInt) (maxSize - written); // hope it's less than 2GB
|
||||
d->zouts.next_out = (Bytef *) d->outBuf;
|
||||
d->zouts.avail_out = QUAZIO_OUTBUFSIZE;
|
||||
switch (deflate(&d->zouts, Z_NO_FLUSH)) {
|
||||
case Z_OK:
|
||||
written = (char *) d->zouts.next_in - data;
|
||||
d->outBufSize = (char *) d->zouts.next_out - d->outBuf;
|
||||
break;
|
||||
default:
|
||||
setErrorString(QString::fromLocal8Bit(d->zouts.msg));
|
||||
return -1;
|
||||
}
|
||||
if (d->doFlush(error) == -1) {
|
||||
setErrorString(error);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT
|
||||
debug.write(data, written);
|
||||
#endif
|
||||
return written;
|
||||
}
|
||||
|
||||
bool QuaZIODevice::flush()
|
||||
{
|
||||
return d->flush(Z_SYNC_FLUSH);
|
||||
}
|
||||
|
||||
bool QuaZIODevice::isSequential() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QuaZIODevice::atEnd() const
|
||||
{
|
||||
// Here we MUST check QIODevice::bytesAvailable() because WE
|
||||
// might have reached the end, but QIODevice didn't--
|
||||
// it could have simply pre-buffered all remaining data.
|
||||
return (openMode() == NotOpen) || (QIODevice::bytesAvailable() == 0 && d->atEnd);
|
||||
}
|
||||
|
||||
qint64 QuaZIODevice::bytesAvailable() const
|
||||
{
|
||||
// If we haven't recevied Z_STREAM_END, it means that
|
||||
// we have at least one more input byte available.
|
||||
// Plus whatever QIODevice has buffered.
|
||||
return (d->atEnd ? 0 : 1) + QIODevice::bytesAvailable();
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
#ifndef QUAZIP_QUAZIODEVICE_H
|
||||
#define QUAZIP_QUAZIODEVICE_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include "quazip_global.h"
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
class QuaZIODevicePrivate;
|
||||
|
||||
/// A class to compress/decompress QIODevice.
|
||||
/**
|
||||
This class can be used to compress any data written to QIODevice or
|
||||
decompress it back. Compressing data sent over a QTcpSocket is a good
|
||||
example.
|
||||
*/
|
||||
class QUAZIP_EXPORT QuaZIODevice: public QIODevice {
|
||||
friend class QuaZIODevicePrivate;
|
||||
Q_OBJECT
|
||||
public:
|
||||
/// Constructor.
|
||||
/**
|
||||
\param io The QIODevice to read/write.
|
||||
\param parent The parent object, as per QObject logic.
|
||||
*/
|
||||
QuaZIODevice(QIODevice *io, QObject *parent = nullptr);
|
||||
/// Destructor.
|
||||
~QuaZIODevice();
|
||||
/// Flushes data waiting to be written.
|
||||
/**
|
||||
Unfortunately, as QIODevice doesn't support flush() by itself, the
|
||||
only thing this method does is write the compressed data into the
|
||||
device using Z_SYNC_FLUSH mode. If you need the compressed data to
|
||||
actually be flushed from the buffer of the underlying QIODevice, you
|
||||
need to call its flush() method as well, providing it supports it
|
||||
(like QTcpSocket does). Example:
|
||||
\code
|
||||
QuaZIODevice dev(&sock);
|
||||
dev.open(QIODevice::Write);
|
||||
dev.write(yourDataGoesHere);
|
||||
dev.flush();
|
||||
sock->flush(); // this actually sends data to network
|
||||
\endcode
|
||||
|
||||
This may change in the future versions of %QuaZip by implementing an
|
||||
ugly hack: trying to cast the QIODevice using qobject_cast to known
|
||||
flush()-supporting subclasses, and calling flush if the resulting
|
||||
pointer is not zero.
|
||||
*/
|
||||
virtual bool flush();
|
||||
/// Opens the device.
|
||||
/**
|
||||
\param mode Neither QIODevice::ReadWrite nor QIODevice::Append are
|
||||
not supported.
|
||||
*/
|
||||
virtual bool open(QIODevice::OpenMode mode);
|
||||
/// Closes this device, but not the underlying one.
|
||||
/**
|
||||
The underlying QIODevice is not closed in case you want to write
|
||||
something else to it.
|
||||
*/
|
||||
virtual void close();
|
||||
/// Returns the underlying device.
|
||||
QIODevice *getIoDevice() const;
|
||||
/// Returns true.
|
||||
virtual bool isSequential() const;
|
||||
/// Returns true iff the end of the compressed stream is reached.
|
||||
virtual bool atEnd() const;
|
||||
/// Returns the number of the bytes buffered.
|
||||
virtual qint64 bytesAvailable() const;
|
||||
protected:
|
||||
/// Implementation of QIODevice::readData().
|
||||
virtual qint64 readData(char *data, qint64 maxSize);
|
||||
/// Implementation of QIODevice::writeData().
|
||||
virtual qint64 writeData(const char *data, qint64 maxSize);
|
||||
private:
|
||||
QuaZIODevicePrivate *d;
|
||||
};
|
||||
#endif // QUAZIP_QUAZIODEVICE_H
|
|
@ -0,0 +1,846 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant, see
|
||||
quazip/(un)zip.h files for details, basically it's zlib license.
|
||||
**/
|
||||
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFlags>
|
||||
#include <QtCore/QHash>
|
||||
|
||||
#include "quazip.h"
|
||||
|
||||
#define QUAZIP_OS_UNIX 3u
|
||||
|
||||
/// All the internal stuff for the QuaZip class.
|
||||
/**
|
||||
\internal
|
||||
|
||||
This class keeps all the private stuff for the QuaZip class so it can
|
||||
be changed without breaking binary compatibility, according to the
|
||||
Pimpl idiom.
|
||||
*/
|
||||
class QuaZipPrivate {
|
||||
friend class QuaZip;
|
||||
private:
|
||||
Q_DISABLE_COPY(QuaZipPrivate)
|
||||
/// The pointer to the corresponding QuaZip instance.
|
||||
QuaZip *q;
|
||||
/// The codec for file names (used when UTF-8 is not enabled).
|
||||
QTextCodec *fileNameCodec;
|
||||
/// The codec for comments (used when UTF-8 is not enabled).
|
||||
QTextCodec *commentCodec;
|
||||
/// The archive file name.
|
||||
QString zipName;
|
||||
/// The device to access the archive.
|
||||
QIODevice *ioDevice;
|
||||
/// The global comment.
|
||||
QString comment;
|
||||
/// The open mode.
|
||||
QuaZip::Mode mode;
|
||||
union {
|
||||
/// The internal handle for UNZIP modes.
|
||||
unzFile unzFile_f;
|
||||
/// The internal handle for ZIP modes.
|
||||
zipFile zipFile_f;
|
||||
};
|
||||
/// Whether a current file is set.
|
||||
bool hasCurrentFile_f;
|
||||
/// The last error.
|
||||
int zipError;
|
||||
/// Whether \ref QuaZip::setDataDescriptorWritingEnabled() "the data descriptor writing mode" is enabled.
|
||||
bool dataDescriptorWritingEnabled;
|
||||
/// The zip64 mode.
|
||||
bool zip64;
|
||||
/// The auto-close flag.
|
||||
bool autoClose;
|
||||
/// The UTF-8 flag.
|
||||
bool utf8;
|
||||
/// The OS code.
|
||||
uint osCode;
|
||||
inline QTextCodec *getDefaultFileNameCodec()
|
||||
{
|
||||
if (defaultFileNameCodec == nullptr) {
|
||||
return QTextCodec::codecForLocale();
|
||||
} else {
|
||||
return defaultFileNameCodec;
|
||||
}
|
||||
}
|
||||
/// The constructor for the corresponding QuaZip constructor.
|
||||
inline QuaZipPrivate(QuaZip *q):
|
||||
q(q),
|
||||
fileNameCodec(getDefaultFileNameCodec()),
|
||||
commentCodec(QTextCodec::codecForLocale()),
|
||||
ioDevice(nullptr),
|
||||
mode(QuaZip::mdNotOpen),
|
||||
hasCurrentFile_f(false),
|
||||
zipError(UNZ_OK),
|
||||
dataDescriptorWritingEnabled(true),
|
||||
zip64(false),
|
||||
autoClose(true),
|
||||
utf8(false),
|
||||
osCode(defaultOsCode)
|
||||
{
|
||||
unzFile_f = nullptr;
|
||||
zipFile_f = nullptr;
|
||||
lastMappedDirectoryEntry.num_of_file = 0;
|
||||
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
|
||||
}
|
||||
/// The constructor for the corresponding QuaZip constructor.
|
||||
inline QuaZipPrivate(QuaZip *q, const QString &zipName):
|
||||
q(q),
|
||||
fileNameCodec(getDefaultFileNameCodec()),
|
||||
commentCodec(QTextCodec::codecForLocale()),
|
||||
zipName(zipName),
|
||||
ioDevice(nullptr),
|
||||
mode(QuaZip::mdNotOpen),
|
||||
hasCurrentFile_f(false),
|
||||
zipError(UNZ_OK),
|
||||
dataDescriptorWritingEnabled(true),
|
||||
zip64(false),
|
||||
autoClose(true),
|
||||
utf8(false),
|
||||
osCode(defaultOsCode)
|
||||
{
|
||||
unzFile_f = nullptr;
|
||||
zipFile_f = nullptr;
|
||||
lastMappedDirectoryEntry.num_of_file = 0;
|
||||
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
|
||||
}
|
||||
/// The constructor for the corresponding QuaZip constructor.
|
||||
inline QuaZipPrivate(QuaZip *q, QIODevice *ioDevice):
|
||||
q(q),
|
||||
fileNameCodec(getDefaultFileNameCodec()),
|
||||
commentCodec(QTextCodec::codecForLocale()),
|
||||
ioDevice(ioDevice),
|
||||
mode(QuaZip::mdNotOpen),
|
||||
hasCurrentFile_f(false),
|
||||
zipError(UNZ_OK),
|
||||
dataDescriptorWritingEnabled(true),
|
||||
zip64(false),
|
||||
autoClose(true),
|
||||
utf8(false),
|
||||
osCode(defaultOsCode)
|
||||
{
|
||||
unzFile_f = nullptr;
|
||||
zipFile_f = nullptr;
|
||||
lastMappedDirectoryEntry.num_of_file = 0;
|
||||
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
|
||||
}
|
||||
/// Returns either a list of file names or a list of QuaZipFileInfo.
|
||||
template<typename TFileInfo>
|
||||
bool getFileInfoList(QList<TFileInfo> *result) const;
|
||||
|
||||
/// Stores map of filenames and file locations for unzipping
|
||||
inline void clearDirectoryMap();
|
||||
inline void addCurrentFileToDirectoryMap(const QString &fileName);
|
||||
bool goToFirstUnmappedFile();
|
||||
QHash<QString, unz64_file_pos> directoryCaseSensitive;
|
||||
QHash<QString, unz64_file_pos> directoryCaseInsensitive;
|
||||
unz64_file_pos lastMappedDirectoryEntry;
|
||||
static QTextCodec *defaultFileNameCodec;
|
||||
static uint defaultOsCode;
|
||||
};
|
||||
|
||||
QTextCodec *QuaZipPrivate::defaultFileNameCodec = nullptr;
|
||||
uint QuaZipPrivate::defaultOsCode = QUAZIP_OS_UNIX;
|
||||
|
||||
void QuaZipPrivate::clearDirectoryMap()
|
||||
{
|
||||
directoryCaseInsensitive.clear();
|
||||
directoryCaseSensitive.clear();
|
||||
lastMappedDirectoryEntry.num_of_file = 0;
|
||||
lastMappedDirectoryEntry.pos_in_zip_directory = 0;
|
||||
}
|
||||
|
||||
void QuaZipPrivate::addCurrentFileToDirectoryMap(const QString &fileName)
|
||||
{
|
||||
if (!hasCurrentFile_f || fileName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// Adds current file to filename map as fileName
|
||||
unz64_file_pos fileDirectoryPos;
|
||||
unzGetFilePos64(unzFile_f, &fileDirectoryPos);
|
||||
directoryCaseSensitive.insert(fileName, fileDirectoryPos);
|
||||
// Only add lowercase to directory map if not already there
|
||||
// ensures only map the first one seen
|
||||
QString lower = fileName.toLower();
|
||||
if (!directoryCaseInsensitive.contains(lower))
|
||||
directoryCaseInsensitive.insert(lower, fileDirectoryPos);
|
||||
// Mark last one
|
||||
if (fileDirectoryPos.pos_in_zip_directory > lastMappedDirectoryEntry.pos_in_zip_directory)
|
||||
lastMappedDirectoryEntry = fileDirectoryPos;
|
||||
}
|
||||
|
||||
bool QuaZipPrivate::goToFirstUnmappedFile()
|
||||
{
|
||||
zipError = UNZ_OK;
|
||||
if (mode != QuaZip::mdUnzip) {
|
||||
qWarning("QuaZipPrivate::goToNextUnmappedFile(): ZIP is not open in mdUnzip mode");
|
||||
return false;
|
||||
}
|
||||
// If not mapped anything, go to beginning
|
||||
if (lastMappedDirectoryEntry.pos_in_zip_directory == 0) {
|
||||
unzGoToFirstFile(unzFile_f);
|
||||
} else {
|
||||
// Goto the last one mapped, plus one
|
||||
unzGoToFilePos64(unzFile_f, &lastMappedDirectoryEntry);
|
||||
unzGoToNextFile(unzFile_f);
|
||||
}
|
||||
hasCurrentFile_f=zipError==UNZ_OK;
|
||||
if(zipError==UNZ_END_OF_LIST_OF_FILE)
|
||||
zipError=UNZ_OK;
|
||||
return hasCurrentFile_f;
|
||||
}
|
||||
|
||||
QuaZip::QuaZip():
|
||||
p(new QuaZipPrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
QuaZip::QuaZip(const QString& zipName):
|
||||
p(new QuaZipPrivate(this, zipName))
|
||||
{
|
||||
}
|
||||
|
||||
QuaZip::QuaZip(QIODevice *ioDevice):
|
||||
p(new QuaZipPrivate(this, ioDevice))
|
||||
{
|
||||
}
|
||||
|
||||
QuaZip::~QuaZip()
|
||||
{
|
||||
if(isOpen())
|
||||
close();
|
||||
delete p;
|
||||
}
|
||||
|
||||
bool QuaZip::open(Mode mode, zlib_filefunc_def* ioApi)
|
||||
{
|
||||
p->zipError=UNZ_OK;
|
||||
if(isOpen()) {
|
||||
qWarning("QuaZip::open(): ZIP already opened");
|
||||
return false;
|
||||
}
|
||||
QIODevice *ioDevice = p->ioDevice;
|
||||
if (ioDevice == nullptr) {
|
||||
if (p->zipName.isEmpty()) {
|
||||
qWarning("QuaZip::open(): set either ZIP file name or IO device first");
|
||||
return false;
|
||||
} else {
|
||||
ioDevice = new QFile(p->zipName);
|
||||
}
|
||||
}
|
||||
unsigned flags = 0;
|
||||
switch(mode) {
|
||||
case mdUnzip:
|
||||
if (ioApi == nullptr) {
|
||||
if (p->autoClose)
|
||||
flags |= UNZ_AUTO_CLOSE;
|
||||
p->unzFile_f=unzOpenInternal(ioDevice, nullptr, 1, flags);
|
||||
} else {
|
||||
// QuaZip pre-zip64 compatibility mode
|
||||
p->unzFile_f=unzOpen2(ioDevice, ioApi);
|
||||
if (p->unzFile_f != nullptr) {
|
||||
if (p->autoClose) {
|
||||
unzSetFlags(p->unzFile_f, UNZ_AUTO_CLOSE);
|
||||
} else {
|
||||
unzClearFlags(p->unzFile_f, UNZ_AUTO_CLOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(p->unzFile_f!=nullptr) {
|
||||
if (ioDevice->isSequential()) {
|
||||
unzClose(p->unzFile_f);
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
qWarning("QuaZip::open(): "
|
||||
"only mdCreate can be used with "
|
||||
"sequential devices");
|
||||
return false;
|
||||
}
|
||||
p->mode=mode;
|
||||
p->ioDevice = ioDevice;
|
||||
return true;
|
||||
} else {
|
||||
p->zipError=UNZ_OPENERROR;
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
return false;
|
||||
}
|
||||
case mdCreate:
|
||||
case mdAppend:
|
||||
case mdAdd:
|
||||
if (ioApi == nullptr) {
|
||||
if (p->autoClose)
|
||||
flags |= ZIP_AUTO_CLOSE;
|
||||
if (p->dataDescriptorWritingEnabled)
|
||||
flags |= ZIP_WRITE_DATA_DESCRIPTOR;
|
||||
if (p->utf8)
|
||||
flags |= ZIP_ENCODING_UTF8;
|
||||
p->zipFile_f=zipOpen3(ioDevice,
|
||||
mode==mdCreate?APPEND_STATUS_CREATE:
|
||||
mode==mdAppend?APPEND_STATUS_CREATEAFTER:
|
||||
APPEND_STATUS_ADDINZIP,
|
||||
nullptr, nullptr, flags);
|
||||
} else {
|
||||
// QuaZip pre-zip64 compatibility mode
|
||||
p->zipFile_f=zipOpen2(ioDevice,
|
||||
mode==mdCreate?APPEND_STATUS_CREATE:
|
||||
mode==mdAppend?APPEND_STATUS_CREATEAFTER:
|
||||
APPEND_STATUS_ADDINZIP,
|
||||
nullptr,
|
||||
ioApi);
|
||||
if (p->zipFile_f != nullptr) {
|
||||
zipSetFlags(p->zipFile_f, flags);
|
||||
}
|
||||
}
|
||||
if(p->zipFile_f!=nullptr) {
|
||||
if (ioDevice->isSequential()) {
|
||||
if (mode != mdCreate) {
|
||||
zipClose(p->zipFile_f, nullptr);
|
||||
qWarning("QuaZip::open(): "
|
||||
"only mdCreate can be used with "
|
||||
"sequential devices");
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
return false;
|
||||
}
|
||||
zipSetFlags(p->zipFile_f, ZIP_SEQUENTIAL);
|
||||
}
|
||||
p->mode=mode;
|
||||
p->ioDevice = ioDevice;
|
||||
return true;
|
||||
} else {
|
||||
p->zipError=UNZ_OPENERROR;
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
qWarning("QuaZip::open(): unknown mode: %d", (int)mode);
|
||||
if (!p->zipName.isEmpty())
|
||||
delete ioDevice;
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void QuaZip::close()
|
||||
{
|
||||
p->zipError=UNZ_OK;
|
||||
switch(p->mode) {
|
||||
case mdNotOpen:
|
||||
qWarning("QuaZip::close(): ZIP is not open");
|
||||
return;
|
||||
case mdUnzip:
|
||||
p->zipError=unzClose(p->unzFile_f);
|
||||
break;
|
||||
case mdCreate:
|
||||
case mdAppend:
|
||||
case mdAdd:
|
||||
p->zipError=zipClose(p->zipFile_f, p->comment.isNull() ? nullptr : isUtf8Enabled()
|
||||
? p->comment.toUtf8().constData()
|
||||
: p->commentCodec->fromUnicode(p->comment).constData());
|
||||
break;
|
||||
default:
|
||||
qWarning("QuaZip::close(): unknown mode: %d", (int)p->mode);
|
||||
return;
|
||||
}
|
||||
// opened by name, need to delete the internal IO device
|
||||
if (!p->zipName.isEmpty()) {
|
||||
delete p->ioDevice;
|
||||
p->ioDevice = nullptr;
|
||||
}
|
||||
p->clearDirectoryMap();
|
||||
if(p->zipError==UNZ_OK)
|
||||
p->mode=mdNotOpen;
|
||||
}
|
||||
|
||||
void QuaZip::setZipName(const QString& zipName)
|
||||
{
|
||||
if(isOpen()) {
|
||||
qWarning("QuaZip::setZipName(): ZIP is already open!");
|
||||
return;
|
||||
}
|
||||
p->zipName=zipName;
|
||||
p->ioDevice = nullptr;
|
||||
}
|
||||
|
||||
void QuaZip::setIoDevice(QIODevice *ioDevice)
|
||||
{
|
||||
if(isOpen()) {
|
||||
qWarning("QuaZip::setIoDevice(): ZIP is already open!");
|
||||
return;
|
||||
}
|
||||
p->ioDevice = ioDevice;
|
||||
p->zipName = QString();
|
||||
}
|
||||
|
||||
int QuaZip::getEntriesCount()const
|
||||
{
|
||||
QuaZip *fakeThis=(QuaZip*)this; // non-const
|
||||
fakeThis->p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::getEntriesCount(): ZIP is not open in mdUnzip mode");
|
||||
return -1;
|
||||
}
|
||||
unz_global_info64 globalInfo;
|
||||
if((fakeThis->p->zipError=unzGetGlobalInfo64(p->unzFile_f, &globalInfo))!=UNZ_OK)
|
||||
return p->zipError;
|
||||
return (int)globalInfo.number_entry;
|
||||
}
|
||||
|
||||
QString QuaZip::getComment()const
|
||||
{
|
||||
QuaZip *fakeThis=(QuaZip*)this; // non-const
|
||||
fakeThis->p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::getComment(): ZIP is not open in mdUnzip mode");
|
||||
return QString();
|
||||
}
|
||||
unz_global_info64 globalInfo;
|
||||
QByteArray comment;
|
||||
if((fakeThis->p->zipError=unzGetGlobalInfo64(p->unzFile_f, &globalInfo))!=UNZ_OK)
|
||||
return QString();
|
||||
comment.resize(globalInfo.size_comment);
|
||||
if((fakeThis->p->zipError=unzGetGlobalComment(p->unzFile_f, comment.data(), comment.size())) < 0)
|
||||
return QString();
|
||||
fakeThis->p->zipError = UNZ_OK;
|
||||
unsigned flags = 0;
|
||||
return (unzGetFileFlags(p->unzFile_f, &flags) == UNZ_OK) && (flags & UNZ_ENCODING_UTF8)
|
||||
? QString::fromUtf8(comment) : p->commentCodec->toUnicode(comment);
|
||||
}
|
||||
|
||||
bool QuaZip::setCurrentFile(const QString& fileName, CaseSensitivity cs)
|
||||
{
|
||||
p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::setCurrentFile(): ZIP is not open in mdUnzip mode");
|
||||
return false;
|
||||
}
|
||||
if(fileName.isEmpty()) {
|
||||
p->hasCurrentFile_f=false;
|
||||
return true;
|
||||
}
|
||||
// Unicode-aware reimplementation of the unzLocateFile function
|
||||
if(p->unzFile_f==nullptr) {
|
||||
p->zipError=UNZ_PARAMERROR;
|
||||
return false;
|
||||
}
|
||||
if(fileName.length()>MAX_FILE_NAME_LENGTH) {
|
||||
p->zipError=UNZ_PARAMERROR;
|
||||
return false;
|
||||
}
|
||||
// Find the file by name
|
||||
bool sens = convertCaseSensitivity(cs) == Qt::CaseSensitive;
|
||||
QString lower, current;
|
||||
if(!sens) lower=fileName.toLower();
|
||||
p->hasCurrentFile_f=false;
|
||||
|
||||
// Check the appropriate Map
|
||||
unz64_file_pos fileDirPos;
|
||||
fileDirPos.pos_in_zip_directory = 0;
|
||||
if (sens) {
|
||||
if (p->directoryCaseSensitive.contains(fileName))
|
||||
fileDirPos = p->directoryCaseSensitive.value(fileName);
|
||||
} else {
|
||||
if (p->directoryCaseInsensitive.contains(lower))
|
||||
fileDirPos = p->directoryCaseInsensitive.value(lower);
|
||||
}
|
||||
|
||||
if (fileDirPos.pos_in_zip_directory != 0) {
|
||||
p->zipError = unzGoToFilePos64(p->unzFile_f, &fileDirPos);
|
||||
p->hasCurrentFile_f = p->zipError == UNZ_OK;
|
||||
}
|
||||
|
||||
if (p->hasCurrentFile_f)
|
||||
return p->hasCurrentFile_f;
|
||||
|
||||
// Not mapped yet, start from where we have got to so far
|
||||
for(bool more=p->goToFirstUnmappedFile(); more; more=goToNextFile()) {
|
||||
current=getCurrentFileName();
|
||||
if(current.isEmpty()) return false;
|
||||
if(sens) {
|
||||
if(current==fileName) break;
|
||||
} else {
|
||||
if(current.toLower()==lower) break;
|
||||
}
|
||||
}
|
||||
return p->hasCurrentFile_f;
|
||||
}
|
||||
|
||||
bool QuaZip::goToFirstFile()
|
||||
{
|
||||
p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
|
||||
return false;
|
||||
}
|
||||
p->zipError=unzGoToFirstFile(p->unzFile_f);
|
||||
p->hasCurrentFile_f=p->zipError==UNZ_OK;
|
||||
return p->hasCurrentFile_f;
|
||||
}
|
||||
|
||||
bool QuaZip::goToNextFile()
|
||||
{
|
||||
p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::goToFirstFile(): ZIP is not open in mdUnzip mode");
|
||||
return false;
|
||||
}
|
||||
p->zipError=unzGoToNextFile(p->unzFile_f);
|
||||
p->hasCurrentFile_f=p->zipError==UNZ_OK;
|
||||
if(p->zipError==UNZ_END_OF_LIST_OF_FILE)
|
||||
p->zipError=UNZ_OK;
|
||||
return p->hasCurrentFile_f;
|
||||
}
|
||||
|
||||
bool QuaZip::getCurrentFileInfo(QuaZipFileInfo *info)const
|
||||
{
|
||||
QuaZipFileInfo64 info64;
|
||||
if (info == nullptr) { // Very unlikely because of the overloads
|
||||
return false;
|
||||
}
|
||||
if (getCurrentFileInfo(&info64)) {
|
||||
info64.toQuaZipFileInfo(*info);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool QuaZip::getCurrentFileInfo(QuaZipFileInfo64 *info)const
|
||||
{
|
||||
QuaZip *fakeThis=(QuaZip*)this; // non-const
|
||||
fakeThis->p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::getCurrentFileInfo(): ZIP is not open in mdUnzip mode");
|
||||
return false;
|
||||
}
|
||||
unz_file_info64 info_z;
|
||||
QByteArray fileName;
|
||||
QByteArray extra;
|
||||
QByteArray comment;
|
||||
if(info==nullptr) return false;
|
||||
if(!isOpen()||!hasCurrentFile()) return false;
|
||||
if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &info_z, nullptr, 0, nullptr, 0, nullptr, 0))!=UNZ_OK)
|
||||
return false;
|
||||
fileName.resize(info_z.size_filename);
|
||||
extra.resize(info_z.size_file_extra);
|
||||
comment.resize(info_z.size_file_comment);
|
||||
if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, nullptr,
|
||||
fileName.data(), fileName.size(),
|
||||
extra.data(), extra.size(),
|
||||
comment.data(), comment.size()))!=UNZ_OK)
|
||||
return false;
|
||||
info->versionCreated=info_z.version;
|
||||
info->versionNeeded=info_z.version_needed;
|
||||
info->flags=info_z.flag;
|
||||
info->method=info_z.compression_method;
|
||||
info->crc=info_z.crc;
|
||||
info->compressedSize=info_z.compressed_size;
|
||||
info->uncompressedSize=info_z.uncompressed_size;
|
||||
info->diskNumberStart=info_z.disk_num_start;
|
||||
info->internalAttr=info_z.internal_fa;
|
||||
info->externalAttr=info_z.external_fa;
|
||||
info->name=(info->flags & UNZ_ENCODING_UTF8) ? QString::fromUtf8(fileName) : p->fileNameCodec->toUnicode(fileName);
|
||||
info->comment=(info->flags & UNZ_ENCODING_UTF8) ? QString::fromUtf8(comment) : p->commentCodec->toUnicode(comment);
|
||||
info->extra=extra;
|
||||
info->dateTime=QDateTime(
|
||||
QDate(info_z.tmu_date.tm_year, info_z.tmu_date.tm_mon+1, info_z.tmu_date.tm_mday),
|
||||
QTime(info_z.tmu_date.tm_hour, info_z.tmu_date.tm_min, info_z.tmu_date.tm_sec));
|
||||
// Add to directory map
|
||||
p->addCurrentFileToDirectoryMap(info->name);
|
||||
return true;
|
||||
}
|
||||
|
||||
QString QuaZip::getCurrentFileName()const
|
||||
{
|
||||
QuaZip *fakeThis=(QuaZip*)this; // non-const
|
||||
fakeThis->p->zipError=UNZ_OK;
|
||||
if(p->mode!=mdUnzip) {
|
||||
qWarning("QuaZip::getCurrentFileName(): ZIP is not open in mdUnzip mode");
|
||||
return QString();
|
||||
}
|
||||
if(!isOpen()||!hasCurrentFile()) return QString();
|
||||
QByteArray fileName(MAX_FILE_NAME_LENGTH, 0);
|
||||
unz_file_info64 file_info;
|
||||
if((fakeThis->p->zipError=unzGetCurrentFileInfo64(p->unzFile_f, &file_info, fileName.data(), fileName.size(),
|
||||
nullptr, 0, nullptr, 0))!=UNZ_OK)
|
||||
return QString();
|
||||
fileName.resize(file_info.size_filename);
|
||||
QString result = (file_info.flag & UNZ_ENCODING_UTF8)
|
||||
? QString::fromUtf8(fileName) : p->fileNameCodec->toUnicode(fileName);
|
||||
if (result.isEmpty())
|
||||
return result;
|
||||
// Add to directory map
|
||||
p->addCurrentFileToDirectoryMap(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void QuaZip::setFileNameCodec(QTextCodec *fileNameCodec)
|
||||
{
|
||||
p->fileNameCodec=fileNameCodec;
|
||||
}
|
||||
|
||||
void QuaZip::setFileNameCodec(const char *fileNameCodecName)
|
||||
{
|
||||
p->fileNameCodec=QTextCodec::codecForName(fileNameCodecName);
|
||||
}
|
||||
|
||||
void QuaZip::setOsCode(uint osCode)
|
||||
{
|
||||
p->osCode = osCode;
|
||||
}
|
||||
|
||||
uint QuaZip::getOsCode() const
|
||||
{
|
||||
return p->osCode;
|
||||
}
|
||||
|
||||
QTextCodec *QuaZip::getFileNameCodec()const
|
||||
{
|
||||
return p->fileNameCodec;
|
||||
}
|
||||
|
||||
void QuaZip::setCommentCodec(QTextCodec *commentCodec)
|
||||
{
|
||||
p->commentCodec=commentCodec;
|
||||
}
|
||||
|
||||
void QuaZip::setCommentCodec(const char *commentCodecName)
|
||||
{
|
||||
p->commentCodec=QTextCodec::codecForName(commentCodecName);
|
||||
}
|
||||
|
||||
QTextCodec *QuaZip::getCommentCodec()const
|
||||
{
|
||||
return p->commentCodec;
|
||||
}
|
||||
|
||||
QString QuaZip::getZipName() const
|
||||
{
|
||||
return p->zipName;
|
||||
}
|
||||
|
||||
QIODevice *QuaZip::getIoDevice() const
|
||||
{
|
||||
if (!p->zipName.isEmpty()) // opened by name, using an internal QIODevice
|
||||
return nullptr;
|
||||
return p->ioDevice;
|
||||
}
|
||||
|
||||
QuaZip::Mode QuaZip::getMode()const
|
||||
{
|
||||
return p->mode;
|
||||
}
|
||||
|
||||
bool QuaZip::isOpen()const
|
||||
{
|
||||
return p->mode!=mdNotOpen;
|
||||
}
|
||||
|
||||
int QuaZip::getZipError() const
|
||||
{
|
||||
return p->zipError;
|
||||
}
|
||||
|
||||
void QuaZip::setComment(const QString& comment)
|
||||
{
|
||||
p->comment=comment;
|
||||
}
|
||||
|
||||
bool QuaZip::hasCurrentFile()const
|
||||
{
|
||||
return p->hasCurrentFile_f;
|
||||
}
|
||||
|
||||
unzFile QuaZip::getUnzFile()
|
||||
{
|
||||
return p->unzFile_f;
|
||||
}
|
||||
|
||||
zipFile QuaZip::getZipFile()
|
||||
{
|
||||
return p->zipFile_f;
|
||||
}
|
||||
|
||||
void QuaZip::setDataDescriptorWritingEnabled(bool enabled)
|
||||
{
|
||||
p->dataDescriptorWritingEnabled = enabled;
|
||||
}
|
||||
|
||||
bool QuaZip::isDataDescriptorWritingEnabled() const
|
||||
{
|
||||
return p->dataDescriptorWritingEnabled;
|
||||
}
|
||||
|
||||
template<typename TFileInfo>
|
||||
TFileInfo QuaZip_getFileInfo(QuaZip *zip, bool *ok);
|
||||
|
||||
template<>
|
||||
QuaZipFileInfo QuaZip_getFileInfo(QuaZip *zip, bool *ok)
|
||||
{
|
||||
QuaZipFileInfo info;
|
||||
*ok = zip->getCurrentFileInfo(&info);
|
||||
return info;
|
||||
}
|
||||
|
||||
template<>
|
||||
QuaZipFileInfo64 QuaZip_getFileInfo(QuaZip *zip, bool *ok)
|
||||
{
|
||||
QuaZipFileInfo64 info;
|
||||
*ok = zip->getCurrentFileInfo(&info);
|
||||
return info;
|
||||
}
|
||||
|
||||
template<>
|
||||
QString QuaZip_getFileInfo(QuaZip *zip, bool *ok)
|
||||
{
|
||||
QString name = zip->getCurrentFileName();
|
||||
*ok = !name.isEmpty();
|
||||
return name;
|
||||
}
|
||||
|
||||
template<typename TFileInfo>
|
||||
bool QuaZipPrivate::getFileInfoList(QList<TFileInfo> *result) const
|
||||
{
|
||||
QuaZipPrivate *fakeThis=const_cast<QuaZipPrivate*>(this);
|
||||
fakeThis->zipError=UNZ_OK;
|
||||
if (mode!=QuaZip::mdUnzip) {
|
||||
qWarning("QuaZip::getFileNameList/getFileInfoList(): "
|
||||
"ZIP is not open in mdUnzip mode");
|
||||
return false;
|
||||
}
|
||||
QString currentFile;
|
||||
if (q->hasCurrentFile()) {
|
||||
currentFile = q->getCurrentFileName();
|
||||
}
|
||||
if (q->goToFirstFile()) {
|
||||
do {
|
||||
bool ok;
|
||||
result->append(QuaZip_getFileInfo<TFileInfo>(q, &ok));
|
||||
if (!ok)
|
||||
return false;
|
||||
} while (q->goToNextFile());
|
||||
}
|
||||
if (zipError != UNZ_OK)
|
||||
return false;
|
||||
if (currentFile.isEmpty()) {
|
||||
if (!q->goToFirstFile())
|
||||
return false;
|
||||
} else {
|
||||
if (!q->setCurrentFile(currentFile))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList QuaZip::getFileNameList() const
|
||||
{
|
||||
QStringList list;
|
||||
if (p->getFileInfoList(&list))
|
||||
return list;
|
||||
else
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QList<QuaZipFileInfo> QuaZip::getFileInfoList() const
|
||||
{
|
||||
QList<QuaZipFileInfo> list;
|
||||
if (p->getFileInfoList(&list))
|
||||
return list;
|
||||
else
|
||||
return QList<QuaZipFileInfo>();
|
||||
}
|
||||
|
||||
QList<QuaZipFileInfo64> QuaZip::getFileInfoList64() const
|
||||
{
|
||||
QList<QuaZipFileInfo64> list;
|
||||
if (p->getFileInfoList(&list))
|
||||
return list;
|
||||
else
|
||||
return QList<QuaZipFileInfo64>();
|
||||
}
|
||||
|
||||
Qt::CaseSensitivity QuaZip::convertCaseSensitivity(QuaZip::CaseSensitivity cs)
|
||||
{
|
||||
if (cs == csDefault) {
|
||||
#ifdef Q_OS_WIN
|
||||
return Qt::CaseInsensitive;
|
||||
#else
|
||||
return Qt::CaseSensitive;
|
||||
#endif
|
||||
} else {
|
||||
return cs == csSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
|
||||
}
|
||||
}
|
||||
|
||||
void QuaZip::setDefaultFileNameCodec(QTextCodec *codec)
|
||||
{
|
||||
QuaZipPrivate::defaultFileNameCodec = codec;
|
||||
}
|
||||
|
||||
void QuaZip::setDefaultFileNameCodec(const char *codecName)
|
||||
{
|
||||
setDefaultFileNameCodec(QTextCodec::codecForName(codecName));
|
||||
}
|
||||
|
||||
void QuaZip::setDefaultOsCode(uint osCode)
|
||||
{
|
||||
QuaZipPrivate::defaultOsCode = osCode;
|
||||
}
|
||||
|
||||
uint QuaZip::getDefaultOsCode()
|
||||
{
|
||||
return QuaZipPrivate::defaultOsCode;
|
||||
}
|
||||
|
||||
void QuaZip::setZip64Enabled(bool zip64)
|
||||
{
|
||||
p->zip64 = zip64;
|
||||
}
|
||||
|
||||
bool QuaZip::isZip64Enabled() const
|
||||
{
|
||||
return p->zip64;
|
||||
}
|
||||
|
||||
void QuaZip::setUtf8Enabled(bool utf8)
|
||||
{
|
||||
p->utf8 = utf8;
|
||||
}
|
||||
|
||||
bool QuaZip::isUtf8Enabled() const
|
||||
{
|
||||
return p->utf8;
|
||||
}
|
||||
|
||||
bool QuaZip::isAutoClose() const
|
||||
{
|
||||
return p->autoClose;
|
||||
}
|
||||
|
||||
void QuaZip::setAutoClose(bool autoClose) const
|
||||
{
|
||||
p->autoClose = autoClose;
|
||||
}
|
|
@ -0,0 +1,611 @@
|
|||
#ifndef QUA_ZIP_H
|
||||
#define QUA_ZIP_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant, see
|
||||
quazip/(un)zip.h files for details, basically it's zlib license.
|
||||
**/
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include "quazip_qt_compat.h"
|
||||
|
||||
#include "zip.h"
|
||||
#include "unzip.h"
|
||||
|
||||
#include "quazip_global.h"
|
||||
#include "quazipfileinfo.h"
|
||||
|
||||
// just in case it will be defined in the later versions of the ZIP/UNZIP
|
||||
#ifndef UNZ_OPENERROR
|
||||
// define additional error code
|
||||
#define UNZ_OPENERROR -1000
|
||||
#endif
|
||||
|
||||
class QuaZipPrivate;
|
||||
|
||||
/// ZIP archive.
|
||||
/** \class QuaZip quazip.h <quazip/quazip.h>
|
||||
* This class implements basic interface to the ZIP archive. It can be
|
||||
* used to read table contents of the ZIP archive and retreiving
|
||||
* information about the files inside it.
|
||||
*
|
||||
* You can also use this class to open files inside archive by passing
|
||||
* pointer to the instance of this class to the constructor of the
|
||||
* QuaZipFile class. But see QuaZipFile::QuaZipFile(QuaZip*, QObject*)
|
||||
* for the possible pitfalls.
|
||||
*
|
||||
* This class is indended to provide interface to the ZIP subpackage of
|
||||
* the ZIP/UNZIP package as well as to the UNZIP subpackage. But
|
||||
* currently it supports only UNZIP.
|
||||
*
|
||||
* The use of this class is simple - just create instance using
|
||||
* constructor, then set ZIP archive file name using setFile() function
|
||||
* (if you did not passed the name to the constructor), then open() and
|
||||
* then use different functions to work with it! Well, if you are
|
||||
* paranoid, you may also wish to call close before destructing the
|
||||
* instance, to check for errors on close.
|
||||
*
|
||||
* You may also use getUnzFile() and getZipFile() functions to get the
|
||||
* ZIP archive handle and use it with ZIP/UNZIP package API directly.
|
||||
*
|
||||
* This class supports localized file names inside ZIP archive, but you
|
||||
* have to set up proper codec with setCodec() function. By default,
|
||||
* locale codec will be used, which is probably ok for UNIX systems, but
|
||||
* will almost certainly fail with ZIP archives created in Windows. This
|
||||
* is because Windows ZIP programs have strange habit of using DOS
|
||||
* encoding for file names in ZIP archives. For example, ZIP archive
|
||||
* with cyrillic names created in Windows will have file names in \c
|
||||
* IBM866 encoding instead of \c WINDOWS-1251. I think that calling one
|
||||
* function is not much trouble, but for true platform independency it
|
||||
* would be nice to have some mechanism for file name encoding auto
|
||||
* detection using locale information. Does anyone know a good way to do
|
||||
* it?
|
||||
**/
|
||||
class QUAZIP_EXPORT QuaZip {
|
||||
friend class QuaZipPrivate;
|
||||
public:
|
||||
/// Useful constants.
|
||||
enum Constants {
|
||||
MAX_FILE_NAME_LENGTH=256 /**< Maximum file name length. Taken from
|
||||
\c UNZ_MAXFILENAMEINZIP constant in
|
||||
unzip.c. */
|
||||
};
|
||||
/// Open mode of the ZIP file.
|
||||
enum Mode {
|
||||
mdNotOpen, ///< ZIP file is not open. This is the initial mode.
|
||||
mdUnzip, ///< ZIP file is open for reading files inside it.
|
||||
mdCreate, ///< ZIP file was created with open() call.
|
||||
mdAppend, /**< ZIP file was opened in append mode. This refers to
|
||||
* \c APPEND_STATUS_CREATEAFTER mode in ZIP/UNZIP package
|
||||
* and means that zip is appended to some existing file
|
||||
* what is useful when that file contains
|
||||
* self-extractor code. This is obviously \em not what
|
||||
* you whant to use to add files to the existing ZIP
|
||||
* archive.
|
||||
**/
|
||||
mdAdd ///< ZIP file was opened for adding files in the archive.
|
||||
};
|
||||
/// Case sensitivity for the file names.
|
||||
/** This is what you specify when accessing files in the archive.
|
||||
* Works perfectly fine with any characters thanks to Qt's great
|
||||
* unicode support. This is different from ZIP/UNZIP API, where
|
||||
* only US-ASCII characters was supported.
|
||||
**/
|
||||
enum CaseSensitivity {
|
||||
csDefault=0, ///< Default for platform. Case sensitive for UNIX, not for Windows.
|
||||
csSensitive=1, ///< Case sensitive.
|
||||
csInsensitive=2 ///< Case insensitive.
|
||||
};
|
||||
/// Returns the actual case sensitivity for the specified QuaZip one.
|
||||
/**
|
||||
\param cs The value to convert.
|
||||
\returns If CaseSensitivity::csDefault, then returns the default
|
||||
file name case sensitivity for the platform. Otherwise, just
|
||||
returns the appropriate value from the Qt::CaseSensitivity enum.
|
||||
*/
|
||||
static Qt::CaseSensitivity convertCaseSensitivity(
|
||||
CaseSensitivity cs);
|
||||
private:
|
||||
QuaZipPrivate *p;
|
||||
// not (and will not be) implemented
|
||||
QuaZip(const QuaZip& that);
|
||||
// not (and will not be) implemented
|
||||
QuaZip& operator=(const QuaZip& that);
|
||||
public:
|
||||
/// Constructs QuaZip object.
|
||||
/** Call setName() before opening constructed object. */
|
||||
QuaZip();
|
||||
/// Constructs QuaZip object associated with ZIP file \a zipName.
|
||||
QuaZip(const QString& zipName);
|
||||
/// Constructs QuaZip object associated with ZIP file represented by \a ioDevice.
|
||||
/** The IO device must be seekable, otherwise an error will occur when opening. */
|
||||
QuaZip(QIODevice *ioDevice);
|
||||
/// Destroys QuaZip object.
|
||||
/** Calls close() if necessary. */
|
||||
~QuaZip();
|
||||
/// Opens ZIP file.
|
||||
/**
|
||||
* Argument \a mode specifies open mode of the ZIP archive. See Mode
|
||||
* for details. Note that there is zipOpen2() function in the
|
||||
* ZIP/UNZIP API which accepts \a globalcomment argument, but it
|
||||
* does not use it anywhere, so this open() function does not have this
|
||||
* argument. See setComment() if you need to set global comment.
|
||||
*
|
||||
* If the ZIP file is accessed via explicitly set QIODevice, then
|
||||
* this device is opened in the necessary mode. If the device was
|
||||
* already opened by some other means, then QuaZip checks if the
|
||||
* open mode is compatible to the mode needed for the requested operation.
|
||||
* If necessary, seeking is performed to position the device properly.
|
||||
*
|
||||
* \return \c true if successful, \c false otherwise.
|
||||
*
|
||||
* \note ZIP/UNZIP API open calls do not return error code - they
|
||||
* just return \c null indicating an error. But to make things
|
||||
* easier, quazip.h header defines additional error code \c
|
||||
* UNZ_ERROROPEN and getZipError() will return it if the open call
|
||||
* of the ZIP/UNZIP API returns \c null.
|
||||
*
|
||||
* Argument \a ioApi specifies IO function set for ZIP/UNZIP
|
||||
* package to use. See unzip.h, zip.h and ioapi.h for details. Note
|
||||
* that IO API for QuaZip is different from the original package.
|
||||
* The file path argument was changed to be of type \c voidpf, and
|
||||
* QuaZip passes a QIODevice pointer there. This QIODevice is either
|
||||
* set explicitly via setIoDevice() or the QuaZip(QIODevice*)
|
||||
* constructor, or it is created internally when opening the archive
|
||||
* by its file name. The default API (qioapi.cpp) just delegates
|
||||
* everything to the QIODevice API. Not only this allows to use a
|
||||
* 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).
|
||||
*
|
||||
* \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
|
||||
* provide a 32-bit API only.
|
||||
*
|
||||
* \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
|
||||
* doesn't support the 'fake close' operation, causing slight memory leaks
|
||||
* and other possible troubles (like closing the output device in case
|
||||
* when an error occurs during opening).
|
||||
*
|
||||
* In short: just forget about the \a ioApi argument and you'll be
|
||||
* fine.
|
||||
**/
|
||||
bool open(Mode mode, zlib_filefunc_def *ioApi =nullptr);
|
||||
/// Closes ZIP file.
|
||||
/** Call getZipError() to determine if the close was successful.
|
||||
*
|
||||
* If the file was opened by name, then the underlying QIODevice is closed
|
||||
* and deleted.
|
||||
*
|
||||
* If the underlying QIODevice was set explicitly using setIoDevice() or
|
||||
* the appropriate constructor, then it is closed if the auto-close flag
|
||||
* is set (which it is by default). Call setAutoClose() to clear the
|
||||
* auto-close flag if this behavior is undesirable.
|
||||
*
|
||||
* Since Qt 5.1, the QSaveFile was introduced. It breaks the QIODevice API
|
||||
* 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
|
||||
* of poor design that illustrates why you should never ever break
|
||||
* an is-a relationship between the base class and a subclass. QuaZip
|
||||
* works around this bug by checking if the QIODevice is an instance
|
||||
* of QSaveFile, using qobject_cast<>, and if it is, calls
|
||||
* QSaveFile::commit() instead of close(). It is a really ugly hack,
|
||||
* but at least it makes your programs work instead of crashing. Note that
|
||||
* if the auto-close flag is cleared, then this is a non-issue, and
|
||||
* commit() isn't called.
|
||||
*/
|
||||
void close();
|
||||
/// Sets the codec used to encode/decode file names inside archive.
|
||||
/** This is necessary to access files in the ZIP archive created
|
||||
* under Windows with non-latin characters in file names. For
|
||||
* example, file names with cyrillic letters will be in \c IBM866
|
||||
* encoding.
|
||||
**/
|
||||
void setFileNameCodec(QTextCodec *fileNameCodec);
|
||||
/// Sets the codec used to encode/decode file names inside archive.
|
||||
/** \overload
|
||||
* Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName));
|
||||
**/
|
||||
void setFileNameCodec(const char *fileNameCodecName);
|
||||
/// Sets the OS code (highest 8 bits of the “version made by” field) for new files.
|
||||
/** There is currently no way to specify this for each file individually,
|
||||
except by calling this function before opening each file. If this function is not called,
|
||||
then the default OS code will be used. The default code is set by calling
|
||||
setDefaultOsCode(). The default value at the moment of QuaZip creation will be used. */
|
||||
void setOsCode(uint osCode);
|
||||
/// Returns the OS code for new files.
|
||||
uint getOsCode() const;
|
||||
/// Returns the codec used to encode/decode comments inside archive.
|
||||
QTextCodec* getFileNameCodec() const;
|
||||
/// Sets the codec used to encode/decode comments inside archive.
|
||||
/** This codec defaults to locale codec, which is probably ok.
|
||||
**/
|
||||
void setCommentCodec(QTextCodec *commentCodec);
|
||||
/// Sets the codec used to encode/decode comments inside archive.
|
||||
/** \overload
|
||||
* Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName));
|
||||
**/
|
||||
void setCommentCodec(const char *commentCodecName);
|
||||
/// Returns the codec used to encode/decode comments inside archive.
|
||||
QTextCodec* getCommentCodec() const;
|
||||
/// Returns the name of the ZIP file.
|
||||
/** Returns null string if no ZIP file name has been set, for
|
||||
* example when the QuaZip instance is set up to use a QIODevice
|
||||
* instead.
|
||||
* \sa setZipName(), setIoDevice(), getIoDevice()
|
||||
**/
|
||||
QString getZipName() const;
|
||||
/// Sets the name of the ZIP file.
|
||||
/** Does nothing if the ZIP file is open.
|
||||
*
|
||||
* Does not reset error code returned by getZipError().
|
||||
* \sa setIoDevice(), getIoDevice(), getZipName()
|
||||
**/
|
||||
void setZipName(const QString& zipName);
|
||||
/// Returns the device representing this ZIP file.
|
||||
/** Returns null string if no device has been set explicitly, for
|
||||
* example when opening a ZIP file by name.
|
||||
* \sa setIoDevice(), getZipName(), setZipName()
|
||||
**/
|
||||
QIODevice *getIoDevice() const;
|
||||
/// Sets the device representing the ZIP file.
|
||||
/** Does nothing if the ZIP file is open.
|
||||
*
|
||||
* Does not reset error code returned by getZipError().
|
||||
* \sa getIoDevice(), getZipName(), setZipName()
|
||||
**/
|
||||
void setIoDevice(QIODevice *ioDevice);
|
||||
/// Returns the mode in which ZIP file was opened.
|
||||
Mode getMode() const;
|
||||
/// Returns \c true if ZIP file is open, \c false otherwise.
|
||||
bool isOpen() const;
|
||||
/// Returns the error code of the last operation.
|
||||
/** Returns \c UNZ_OK if the last operation was successful.
|
||||
*
|
||||
* Error code resets to \c UNZ_OK every time you call any function
|
||||
* that accesses something inside ZIP archive, even if it is \c
|
||||
* const (like getEntriesCount()). open() and close() calls reset
|
||||
* error code too. See documentation for the specific functions for
|
||||
* details on error detection.
|
||||
**/
|
||||
int getZipError() const;
|
||||
/// Returns number of the entries in the ZIP central directory.
|
||||
/** Returns negative error code in the case of error. The same error
|
||||
* code will be returned by subsequent getZipError() call.
|
||||
**/
|
||||
int getEntriesCount() const;
|
||||
/// Returns global comment in the ZIP file.
|
||||
QString getComment() const;
|
||||
/// Sets the global comment in the ZIP file.
|
||||
/** The comment will be written to the archive on close operation.
|
||||
* QuaZip makes a distinction between a null QByteArray() comment
|
||||
* and an empty "" comment in the QuaZip::mdAdd mode.
|
||||
* A null comment is the default and it means "don't change
|
||||
* the comment". An empty comment removes the original comment.
|
||||
*
|
||||
* \sa open()
|
||||
**/
|
||||
void setComment(const QString& comment);
|
||||
/// Sets the current file to the first file in the archive.
|
||||
/** Returns \c true on success, \c false otherwise. Call
|
||||
* getZipError() to get the error code.
|
||||
**/
|
||||
bool goToFirstFile();
|
||||
/// Sets the current file to the next file in the archive.
|
||||
/** Returns \c true on success, \c false otherwise. Call
|
||||
* getZipError() to determine if there was an error.
|
||||
*
|
||||
* Should be used only in QuaZip::mdUnzip mode.
|
||||
*
|
||||
* \note If the end of file was reached, getZipError() will return
|
||||
* \c UNZ_OK instead of \c UNZ_END_OF_LIST_OF_FILE. This is to make
|
||||
* things like this easier:
|
||||
* \code
|
||||
* for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
|
||||
* // do something
|
||||
* }
|
||||
* if(zip.getZipError()==UNZ_OK) {
|
||||
* // ok, there was no error
|
||||
* }
|
||||
* \endcode
|
||||
**/
|
||||
bool goToNextFile();
|
||||
/// Sets current file by its name.
|
||||
/** Returns \c true if successful, \c false otherwise. Argument \a
|
||||
* cs specifies case sensitivity of the file name. Call
|
||||
* getZipError() in the case of a failure to get error code.
|
||||
*
|
||||
* This is not a wrapper to unzLocateFile() function. That is
|
||||
* because I had to implement locale-specific case-insensitive
|
||||
* comparison.
|
||||
*
|
||||
* Here are the differences from the original implementation:
|
||||
*
|
||||
* - If the file was not found, error code is \c UNZ_OK, not \c
|
||||
* UNZ_END_OF_LIST_OF_FILE (see also goToNextFile()).
|
||||
* - If this function fails, it unsets the current file rather than
|
||||
* resetting it back to what it was before the call.
|
||||
*
|
||||
* If \a fileName is null string then this function unsets the
|
||||
* current file and return \c true. Note that you should close the
|
||||
* file first if it is open! See
|
||||
* QuaZipFile::QuaZipFile(QuaZip*,QObject*) for the details.
|
||||
*
|
||||
* Should be used only in QuaZip::mdUnzip mode.
|
||||
*
|
||||
* \sa setFileNameCodec(), CaseSensitivity
|
||||
**/
|
||||
bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault);
|
||||
/// Returns \c true if the current file has been set.
|
||||
bool hasCurrentFile() const;
|
||||
/// Retrieves information about the current file.
|
||||
/** Fills the structure pointed by \a info. Returns \c true on
|
||||
* success, \c false otherwise. In the latter case structure pointed
|
||||
* by \a info remains untouched. If there was an error,
|
||||
* getZipError() returns error code.
|
||||
*
|
||||
* Should be used only in QuaZip::mdUnzip mode.
|
||||
*
|
||||
* Does nothing and returns \c false in any of the following cases.
|
||||
* - ZIP is not open;
|
||||
* - ZIP does not have current file.
|
||||
*
|
||||
* In both cases getZipError() returns \c UNZ_OK since there
|
||||
* is no ZIP/UNZIP API call.
|
||||
*
|
||||
* This overload doesn't support zip64, but will work OK on zip64 archives
|
||||
* except that if one of the sizes (compressed or uncompressed) is greater
|
||||
* than 0xFFFFFFFFu, it will be set to exactly 0xFFFFFFFFu.
|
||||
*
|
||||
* \sa getCurrentFileInfo(QuaZipFileInfo64* info)const
|
||||
* \sa QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo&)const
|
||||
**/
|
||||
bool getCurrentFileInfo(QuaZipFileInfo* info)const;
|
||||
/// Retrieves information about the current file.
|
||||
/** \overload
|
||||
*
|
||||
* This function supports zip64. If the archive doesn't use zip64, it is
|
||||
* completely equivalent to getCurrentFileInfo(QuaZipFileInfo* info)
|
||||
* except for the argument type.
|
||||
*
|
||||
* \sa
|
||||
**/
|
||||
bool getCurrentFileInfo(QuaZipFileInfo64* info)const;
|
||||
/// Returns the current file name.
|
||||
/** Equivalent to calling getCurrentFileInfo() and then getting \c
|
||||
* name field of the QuaZipFileInfo structure, but faster and more
|
||||
* convenient.
|
||||
*
|
||||
* Should be used only in QuaZip::mdUnzip mode.
|
||||
**/
|
||||
QString getCurrentFileName()const;
|
||||
/// Returns \c unzFile handle.
|
||||
/** You can use this handle to directly call UNZIP part of the
|
||||
* ZIP/UNZIP package functions (see unzip.h).
|
||||
*
|
||||
* \warning When using the handle returned by this function, please
|
||||
* keep in mind that QuaZip class is unable to detect any changes
|
||||
* you make in the ZIP file state (e. g. changing current file, or
|
||||
* closing the handle). So please do not do anything with this
|
||||
* handle that is possible to do with the functions of this class.
|
||||
* Or at least return the handle in the original state before
|
||||
* calling some another function of this class (including implicit
|
||||
* destructor calls and calls from the QuaZipFile objects that refer
|
||||
* to this QuaZip instance!). So if you have changed the current
|
||||
* file in the ZIP archive - then change it back or you may
|
||||
* experience some strange behavior or even crashes.
|
||||
**/
|
||||
unzFile getUnzFile();
|
||||
/// Returns \c zipFile handle.
|
||||
/** You can use this handle to directly call ZIP part of the
|
||||
* ZIP/UNZIP package functions (see zip.h). Warnings about the
|
||||
* getUnzFile() function also apply to this function.
|
||||
**/
|
||||
zipFile getZipFile();
|
||||
/// Changes the data descriptor writing mode.
|
||||
/**
|
||||
According to the ZIP format specification, a file inside archive
|
||||
may have a data descriptor immediately following the file
|
||||
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 writes the data descriptor unless both method and level were
|
||||
set to 0, in which case it operates in 1.0-compatible mode and
|
||||
never writes data descriptors.
|
||||
|
||||
By setting this flag to false, it is possible to disable data
|
||||
descriptor writing, thus increasing compatibility with archive
|
||||
readers that don't understand this feature of the ZIP file format.
|
||||
|
||||
Setting this flag affects all the QuaZipFile instances that are
|
||||
opened after this flag is set.
|
||||
|
||||
The data descriptor writing mode is enabled by default.
|
||||
|
||||
Note that if the ZIP archive is written into a QIODevice for which
|
||||
QIODevice::isSequential() returns \c true, then the data descriptor
|
||||
is mandatory and will be written even if this flag is set to false.
|
||||
|
||||
\param enabled If \c true, enable local descriptor writing,
|
||||
disable it otherwise.
|
||||
|
||||
\sa QuaZipFile::isDataDescriptorWritingEnabled()
|
||||
*/
|
||||
void setDataDescriptorWritingEnabled(bool enabled);
|
||||
/// Returns the data descriptor default writing mode.
|
||||
/**
|
||||
\sa setDataDescriptorWritingEnabled()
|
||||
*/
|
||||
bool isDataDescriptorWritingEnabled() const;
|
||||
/// Returns a list of files inside the archive.
|
||||
/**
|
||||
\return A list of file names or an empty list if there
|
||||
was an error or if the archive is empty (call getZipError() to
|
||||
figure out which).
|
||||
\sa getFileInfoList()
|
||||
*/
|
||||
QStringList getFileNameList() const;
|
||||
/// Returns information list about all files inside the archive.
|
||||
/**
|
||||
\return A list of QuaZipFileInfo objects or an empty list if there
|
||||
was an error or if the archive is empty (call getZipError() to
|
||||
figure out which).
|
||||
|
||||
This function doesn't support zip64, but will still work with zip64
|
||||
archives, converting results using QuaZipFileInfo64::toQuaZipFileInfo().
|
||||
If all file sizes are below 4 GB, it will work just fine.
|
||||
|
||||
\sa getFileNameList()
|
||||
\sa getFileInfoList64()
|
||||
*/
|
||||
QList<QuaZipFileInfo> getFileInfoList() const;
|
||||
/// Returns information list about all files inside the archive.
|
||||
/**
|
||||
\overload
|
||||
|
||||
This function supports zip64.
|
||||
|
||||
\sa getFileNameList()
|
||||
\sa getFileInfoList()
|
||||
*/
|
||||
QList<QuaZipFileInfo64> getFileInfoList64() const;
|
||||
/// Enables the zip64 mode.
|
||||
/**
|
||||
* @param zip64 If \c true, the zip64 mode is enabled, disabled otherwise.
|
||||
*
|
||||
* Once this is enabled, all new files (until the mode is disabled again)
|
||||
* will be created in the zip64 mode, thus enabling the ability to write
|
||||
* files larger than 4 GB. By default, the zip64 mode is off due to
|
||||
* compatibility reasons.
|
||||
*
|
||||
* Note that this does not affect the ability to read zip64 archives in any
|
||||
* way.
|
||||
*
|
||||
* \sa isZip64Enabled()
|
||||
*/
|
||||
void setZip64Enabled(bool zip64);
|
||||
/// Returns whether the zip64 mode is enabled.
|
||||
/**
|
||||
* @return \c true if and only if the zip64 mode is enabled.
|
||||
*
|
||||
* \sa setZip64Enabled()
|
||||
*/
|
||||
bool isZip64Enabled() const;
|
||||
/// Enables the use of UTF-8 encoding for file names and comments text.
|
||||
/**
|
||||
* @param utf8 If \c true, the UTF-8 mode is enabled, disabled otherwise.
|
||||
*
|
||||
* Once this is enabled, the names of all new files and comments text (until
|
||||
* the mode is disabled again) will be encoded in UTF-8 encoding, and the
|
||||
* version to extract will be set to 6.3 (63) in ZIP header. By default,
|
||||
* the UTF-8 mode is off due to compatibility reasons.
|
||||
*
|
||||
* Note that when extracting ZIP archives, the UTF-8 mode is determined from
|
||||
* ZIP file header, not from this flag.
|
||||
*
|
||||
* \sa isUtf8Enabled()
|
||||
*/
|
||||
void setUtf8Enabled(bool utf8);
|
||||
/// Returns whether the UTF-8 encoding mode is enabled.
|
||||
/**
|
||||
* @return \c true if and only if the UTF-8 mode is enabled.
|
||||
*
|
||||
* \sa setUtf8Enabled()
|
||||
*/
|
||||
bool isUtf8Enabled() const;
|
||||
/// Returns the auto-close flag.
|
||||
/**
|
||||
@sa setAutoClose()
|
||||
*/
|
||||
bool isAutoClose() const;
|
||||
/// Sets or unsets the auto-close flag.
|
||||
/**
|
||||
By default, QuaZip opens the underlying QIODevice when open() is called,
|
||||
and closes it when close() is called. In some cases, when the device
|
||||
is set explicitly using setIoDevice(), it may be desirable to
|
||||
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.
|
||||
|
||||
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
|
||||
during the open() call if an error is encountered after the device
|
||||
is opened.
|
||||
|
||||
If the device was not set explicitly, but rather the setZipName() or
|
||||
the appropriate constructor was used to set the ZIP file name instead,
|
||||
then the auto-close flag has no effect, and the internal device
|
||||
is closed nevertheless because there is no other way to close it.
|
||||
|
||||
@sa isAutoClose()
|
||||
@sa setIoDevice()
|
||||
*/
|
||||
void setAutoClose(bool autoClose) const;
|
||||
/// Sets the default file name codec to use.
|
||||
/**
|
||||
* The default codec is used by the constructors, so calling this function
|
||||
* won't affect the QuaZip instances already created at that moment.
|
||||
*
|
||||
* The codec specified here can be overriden by calling setFileNameCodec().
|
||||
* If neither function is called, QTextCodec::codecForLocale() will be used
|
||||
* to decode or encode file names. Use this function with caution if
|
||||
* the application uses other libraries that depend on QuaZip. Those
|
||||
* libraries can either call this function by themselves, thus overriding
|
||||
* your setting or can rely on the default encoding, thus failing
|
||||
* mysteriously if you change it. For these reasons, it isn't recommended
|
||||
* to use this function if you are developing a library, not an application.
|
||||
* Instead, ask your library users to call it in case they need specific
|
||||
* encoding.
|
||||
*
|
||||
* In most cases, using setFileNameCodec() instead is the right choice.
|
||||
* 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
|
||||
* 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.
|
||||
* This applies to the JlCompress class as well, as it was contributed and
|
||||
* doesn't support explicit encoding parameters.
|
||||
*
|
||||
* In short: use setFileNameCodec() when you can, resort to
|
||||
* setDefaultFileNameCodec() when you don't have access to the QuaZip
|
||||
* instance.
|
||||
*
|
||||
* @param codec The codec to use by default. If null, resets to default.
|
||||
*/
|
||||
static void setDefaultFileNameCodec(QTextCodec *codec);
|
||||
/**
|
||||
* @overload
|
||||
* Equivalent to calling
|
||||
* setDefaultFileNameCodec(QTextCodec::codecForName(codecName)).
|
||||
*/
|
||||
static void setDefaultFileNameCodec(const char *codecName);
|
||||
/// Sets default OS code.
|
||||
/**
|
||||
* @sa setOsCode()
|
||||
*/
|
||||
static void setDefaultOsCode(uint osCode);
|
||||
/// Returns default OS code.
|
||||
/**
|
||||
* @sa getOsCode()
|
||||
*/
|
||||
static uint getDefaultOsCode();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${prefix}/lib@LIB_SUFFIX@
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: QuaZip-Qt@QUAZIP_QT_MAJOR_VERSION@
|
||||
Description: Minizip wrapper library for Qt @QUAZIP_QT_MAJOR_VERSION@.x
|
||||
Version: @QUAZIP_LIB_VERSION@
|
||||
Libs: -l@QUAZIP_LIB_FILE_NAME@ -lz
|
||||
Cflags: -I${includedir}/@QUAZIP_DIR_NAME@ -I${includedir}/@QUAZIP_INCLUDE_PATH@
|
||||
Requires: @QUAZIP_PKGCONFIG_REQUIRES@
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef QUAZIP_GLOBAL_H
|
||||
#define QUAZIP_GLOBAL_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
/**
|
||||
This is automatically defined when building a static library, but when
|
||||
including QuaZip sources directly into a project, QUAZIP_STATIC should
|
||||
be defined explicitly to avoid possible troubles with unnecessary
|
||||
importing/exporting.
|
||||
*/
|
||||
#ifdef QUAZIP_STATIC
|
||||
#define QUAZIP_EXPORT
|
||||
#else
|
||||
/**
|
||||
* When building a DLL with MSVC, QUAZIP_BUILD must be defined.
|
||||
* qglobal.h takes care of defining Q_DECL_* correctly for msvc/gcc.
|
||||
*/
|
||||
#if defined(QUAZIP_BUILD)
|
||||
#define QUAZIP_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
#define QUAZIP_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
#endif // QUAZIP_STATIC
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define QUAZIP_UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
#define QUAZIP_UNUSED
|
||||
#endif
|
||||
|
||||
#define QUAZIP_EXTRA_NTFS_MAGIC 0x000Au
|
||||
#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
|
|
@ -0,0 +1,145 @@
|
|||
#ifndef QUAZIP_QT_COMPAT_H
|
||||
#define QUAZIP_QT_COMPAT_H
|
||||
|
||||
/*
|
||||
* For some reason, Qt 5.14 and 5.15 introduced a whole mess of seemingly random
|
||||
* moves and deprecations. To avoid populating code with #ifs,
|
||||
* we handle this stuff here, as well as some other compatibility issues.
|
||||
*
|
||||
* Some includes are repeated just in case we want to split this file later.
|
||||
*/
|
||||
|
||||
#include <QtCore/Qt>
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
// Legacy encodings are still everywhere, but the Qt team decided we
|
||||
// don't need them anymore and moved them out of Core in Qt 6.
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
# include <QtCore5Compat/QTextCodec>
|
||||
#else
|
||||
# include <QtCore/QTextCodec>
|
||||
#endif
|
||||
|
||||
// QSaveFile terribly breaks the is-a idiom (Liskov substitution principle):
|
||||
// QSaveFile is-a QIODevice, but it makes close() private and aborts
|
||||
// if you call it through the base class. Hence this ugly hack:
|
||||
#if (QT_VERSION >= 0x050100)
|
||||
#include <QtCore/QSaveFile>
|
||||
inline bool quazip_close(QIODevice *device) {
|
||||
QSaveFile *file = qobject_cast<QSaveFile*>(device);
|
||||
if (file != nullptr) {
|
||||
// We have to call the ugly commit() instead:
|
||||
return file->commit();
|
||||
} else {
|
||||
device->close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#else
|
||||
inline bool quazip_close(QIODevice *device) {
|
||||
device->close();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// this is yet another stupid move and deprecation
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
using Qt::SkipEmptyParts;
|
||||
#else
|
||||
#include <QtCore/QString>
|
||||
const auto SkipEmptyParts = QString::SplitBehavior::SkipEmptyParts;
|
||||
#endif
|
||||
|
||||
// and yet another... (why didn't they just make qSort delegate to std::sort?)
|
||||
#include <QtCore/QList>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
||||
#include <algorithm>
|
||||
template<typename T, typename C>
|
||||
inline void quazip_sort(T begin, T end, C comparator) {
|
||||
std::sort(begin, end, comparator);
|
||||
}
|
||||
#else
|
||||
#include <QtCore/QtAlgorithms>
|
||||
template<typename T, typename C>
|
||||
inline void quazip_sort(T begin, T end, C comparator) {
|
||||
qSort(begin, end, comparator);
|
||||
}
|
||||
#endif
|
||||
|
||||
// this is a stupid rename...
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QFileInfo>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
inline QDateTime quazip_ctime(const QFileInfo &fi) {
|
||||
return fi.birthTime();
|
||||
}
|
||||
#else
|
||||
inline QDateTime quazip_ctime(const QFileInfo &fi) {
|
||||
return fi.created();
|
||||
}
|
||||
#endif
|
||||
|
||||
// this is just a slightly better alternative
|
||||
#include <QtCore/QFileInfo>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
inline bool quazip_is_symlink(const QFileInfo &fi) {
|
||||
return fi.isSymbolicLink();
|
||||
}
|
||||
#else
|
||||
inline bool quazip_is_symlink(const QFileInfo &fi) {
|
||||
// also detects *.lnk on Windows, but better than nothing
|
||||
return fi.isSymLink();
|
||||
}
|
||||
#endif
|
||||
|
||||
// I'm not even sure what this one is, but nevertheless
|
||||
#include <QtCore/QFileInfo>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
||||
inline QString quazip_symlink_target(const QFileInfo &fi) {
|
||||
return fi.symLinkTarget();
|
||||
}
|
||||
#else
|
||||
inline QString quazip_symlink_target(const QFileInfo &fi) {
|
||||
return fi.readLink(); // What's the difference? I've no idea.
|
||||
}
|
||||
#endif
|
||||
|
||||
// this is not a deprecation but an improvement, for a change
|
||||
#include <QtCore/QDateTime>
|
||||
#if (QT_VERSION >= 0x040700)
|
||||
inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) {
|
||||
QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
return base.msecsTo(time) * 10000 + fineTicks;
|
||||
}
|
||||
#else
|
||||
inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) {
|
||||
QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
QDateTime utc = time.toUTC();
|
||||
return (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
|
||||
|
||||
// yet another improvement...
|
||||
#include <QtCore/QDateTime>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) // Yay! Finally a way to get time as qint64!
|
||||
inline qint64 quazip_to_time64_t(const QDateTime &time) {
|
||||
return time.toSecsSinceEpoch();
|
||||
}
|
||||
#else
|
||||
inline qint64 quazip_to_time64_t(const QDateTime &time) {
|
||||
return static_cast<qint64>(time.toTime_t()); // 32 bits only, but better than nothing
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <QtCore/QTextStream>
|
||||
// and another stupid move
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
const auto quazip_endl = Qt::endl;
|
||||
#else
|
||||
const auto quazip_endl = endl;
|
||||
#endif
|
||||
|
||||
#endif // QUAZIP_QT_COMPAT_H
|
|
@ -0,0 +1,568 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "quazipdir.h"
|
||||
#include "quazip_qt_compat.h"
|
||||
|
||||
#include <QtCore/QSet>
|
||||
#include <QtCore/QSharedData>
|
||||
|
||||
/// \cond internal
|
||||
class QuaZipDirPrivate: public QSharedData {
|
||||
friend class QuaZipDir;
|
||||
private:
|
||||
QuaZipDirPrivate(QuaZip *zip, const QString &dir = QString()):
|
||||
zip(zip), dir(dir), caseSensitivity(QuaZip::csDefault),
|
||||
filter(QDir::NoFilter), sorting(QDir::NoSort) {}
|
||||
QuaZip *zip;
|
||||
QString dir;
|
||||
QuaZip::CaseSensitivity caseSensitivity;
|
||||
QDir::Filters filter;
|
||||
QStringList nameFilters;
|
||||
QDir::SortFlags sorting;
|
||||
template<typename TFileInfoList>
|
||||
bool entryInfoList(QStringList nameFilters, QDir::Filters filter,
|
||||
QDir::SortFlags sort, TFileInfoList &result) const;
|
||||
inline QString simplePath() const {return QDir::cleanPath(dir);}
|
||||
};
|
||||
/// \endcond
|
||||
|
||||
QuaZipDir::QuaZipDir(const QuaZipDir &that):
|
||||
d(that.d)
|
||||
{
|
||||
}
|
||||
|
||||
QuaZipDir::QuaZipDir(QuaZip *zip, const QString &dir):
|
||||
d(new QuaZipDirPrivate(zip, dir))
|
||||
{
|
||||
if (d->dir.startsWith(QLatin1String("/")))
|
||||
d->dir = d->dir.mid(1);
|
||||
}
|
||||
|
||||
QuaZipDir::~QuaZipDir()
|
||||
{
|
||||
}
|
||||
|
||||
bool QuaZipDir::operator==(const QuaZipDir &that)
|
||||
{
|
||||
return d->zip == that.d->zip && d->dir == that.d->dir;
|
||||
}
|
||||
|
||||
QuaZipDir& QuaZipDir::operator=(const QuaZipDir &that)
|
||||
{
|
||||
this->d = that.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
QString QuaZipDir::operator[](int pos) const
|
||||
{
|
||||
return entryList().at(pos);
|
||||
}
|
||||
|
||||
QuaZip::CaseSensitivity QuaZipDir::caseSensitivity() const
|
||||
{
|
||||
return d->caseSensitivity;
|
||||
}
|
||||
|
||||
bool QuaZipDir::cd(const QString &directoryName)
|
||||
{
|
||||
if (directoryName == QLatin1String("/")) {
|
||||
d->dir = QLatin1String("");
|
||||
return true;
|
||||
}
|
||||
QString dirName = directoryName;
|
||||
if (dirName.endsWith(QLatin1String("/")))
|
||||
dirName.chop(1);
|
||||
if (dirName.contains(QLatin1String("/"))) {
|
||||
QuaZipDir dir(*this);
|
||||
if (dirName.startsWith(QLatin1String("/"))) {
|
||||
#ifdef QUAZIP_QUAZIPDIR_DEBUG
|
||||
qDebug("QuaZipDir::cd(%s): going to /",
|
||||
dirName.toUtf8().constData());
|
||||
#endif
|
||||
if (!dir.cd(QLatin1String("/")))
|
||||
return false;
|
||||
}
|
||||
QStringList path = dirName.split(QLatin1String("/"), SkipEmptyParts);
|
||||
for (QStringList::const_iterator i = path.constBegin();
|
||||
i != path.constEnd();
|
||||
++i) {
|
||||
const QString &step = *i;
|
||||
#ifdef QUAZIP_QUAZIPDIR_DEBUG
|
||||
qDebug("QuaZipDir::cd(%s): going to %s",
|
||||
dirName.toUtf8().constData(),
|
||||
step.toUtf8().constData());
|
||||
#endif
|
||||
if (!dir.cd(step))
|
||||
return false;
|
||||
}
|
||||
d->dir = dir.path();
|
||||
return true;
|
||||
} else { // no '/'
|
||||
if (dirName == QLatin1String(".")) {
|
||||
return true;
|
||||
} else if (dirName == QLatin1String("..")) {
|
||||
if (isRoot()) {
|
||||
return false;
|
||||
} else {
|
||||
int slashPos = d->dir.lastIndexOf(QLatin1String("/"));
|
||||
if (slashPos == -1) {
|
||||
d->dir = QLatin1String("");
|
||||
} else {
|
||||
d->dir = d->dir.left(slashPos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else { // a simple subdirectory
|
||||
if (exists(dirName)) {
|
||||
if (isRoot())
|
||||
d->dir = dirName;
|
||||
else
|
||||
d->dir += QLatin1String("/") + dirName;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool QuaZipDir::cdUp()
|
||||
{
|
||||
return cd(QLatin1String(".."));
|
||||
}
|
||||
|
||||
uint QuaZipDir::count() const
|
||||
{
|
||||
return entryList().count();
|
||||
}
|
||||
|
||||
QString QuaZipDir::dirName() const
|
||||
{
|
||||
return QDir(d->dir).dirName();
|
||||
}
|
||||
|
||||
QuaZipFileInfo64 QuaZipDir_getFileInfo(QuaZip *zip, bool *ok,
|
||||
const QString &relativeName,
|
||||
bool isReal)
|
||||
{
|
||||
QuaZipFileInfo64 info;
|
||||
if (isReal) {
|
||||
*ok = zip->getCurrentFileInfo(&info);
|
||||
} else {
|
||||
*ok = true;
|
||||
info.compressedSize = 0;
|
||||
info.crc = 0;
|
||||
info.diskNumberStart = 0;
|
||||
info.externalAttr = 0;
|
||||
info.flags = 0;
|
||||
info.internalAttr = 0;
|
||||
info.method = 0;
|
||||
info.uncompressedSize = 0;
|
||||
info.versionCreated = info.versionNeeded = 0;
|
||||
}
|
||||
info.name = relativeName;
|
||||
return info;
|
||||
}
|
||||
|
||||
static void QuaZipDir_convertInfoList(const QList<QuaZipFileInfo64> &from,
|
||||
QList<QuaZipFileInfo64> &to)
|
||||
{
|
||||
to = from;
|
||||
}
|
||||
|
||||
static void QuaZipDir_convertInfoList(const QList<QuaZipFileInfo64> &from,
|
||||
QStringList &to)
|
||||
{
|
||||
to.clear();
|
||||
for (QList<QuaZipFileInfo64>::const_iterator i = from.constBegin();
|
||||
i != from.constEnd();
|
||||
++i) {
|
||||
to.append(i->name);
|
||||
}
|
||||
}
|
||||
|
||||
static void QuaZipDir_convertInfoList(const QList<QuaZipFileInfo64> &from,
|
||||
QList<QuaZipFileInfo> &to)
|
||||
{
|
||||
to.clear();
|
||||
for (QList<QuaZipFileInfo64>::const_iterator i = from.constBegin();
|
||||
i != from.constEnd();
|
||||
++i) {
|
||||
QuaZipFileInfo info32;
|
||||
i->toQuaZipFileInfo(info32);
|
||||
to.append(info32);
|
||||
}
|
||||
}
|
||||
|
||||
/// \cond internal
|
||||
/**
|
||||
An utility class to restore the current file.
|
||||
*/
|
||||
class QuaZipDirRestoreCurrent {
|
||||
public:
|
||||
inline QuaZipDirRestoreCurrent(QuaZip *zip):
|
||||
zip(zip), currentFile(zip->getCurrentFileName()) {}
|
||||
inline ~QuaZipDirRestoreCurrent()
|
||||
{
|
||||
zip->setCurrentFile(currentFile);
|
||||
}
|
||||
private:
|
||||
QuaZip *zip;
|
||||
QString currentFile;
|
||||
};
|
||||
/// \endcond
|
||||
|
||||
/// \cond internal
|
||||
class QuaZipDirComparator
|
||||
{
|
||||
private:
|
||||
QDir::SortFlags sort;
|
||||
static QString getExtension(const QString &name);
|
||||
int compareStrings(const QString &string1, const QString &string2);
|
||||
public:
|
||||
inline QuaZipDirComparator(QDir::SortFlags sort): sort(sort) {}
|
||||
bool operator()(const QuaZipFileInfo64 &info1, const QuaZipFileInfo64 &info2);
|
||||
};
|
||||
|
||||
QString QuaZipDirComparator::getExtension(const QString &name)
|
||||
{
|
||||
if (name.endsWith(QLatin1String(".")) || name.indexOf(QLatin1String("."), 1) == -1) {
|
||||
return QLatin1String("");
|
||||
} else {
|
||||
return name.mid(name.lastIndexOf(QLatin1String(".")) + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int QuaZipDirComparator::compareStrings(const QString &string1,
|
||||
const QString &string2)
|
||||
{
|
||||
if (sort & QDir::LocaleAware) {
|
||||
if (sort & QDir::IgnoreCase) {
|
||||
return string1.toLower().localeAwareCompare(string2.toLower());
|
||||
} else {
|
||||
return string1.localeAwareCompare(string2);
|
||||
}
|
||||
} else {
|
||||
return string1.compare(string2, (sort & QDir::IgnoreCase)
|
||||
? Qt::CaseInsensitive : Qt::CaseSensitive);
|
||||
}
|
||||
}
|
||||
|
||||
bool QuaZipDirComparator::operator()(const QuaZipFileInfo64 &info1,
|
||||
const QuaZipFileInfo64 &info2)
|
||||
{
|
||||
QDir::SortFlags order = sort
|
||||
& (QDir::Name | QDir::Time | QDir::Size | QDir::Type);
|
||||
if ((sort & QDir::DirsFirst) == QDir::DirsFirst
|
||||
|| (sort & QDir::DirsLast) == QDir::DirsLast) {
|
||||
if (info1.name.endsWith(QLatin1String("/")) && !info2.name.endsWith(QLatin1String("/")))
|
||||
return (sort & QDir::DirsFirst) == QDir::DirsFirst;
|
||||
else if (!info1.name.endsWith(QLatin1String("/")) && info2.name.endsWith(QLatin1String("/")))
|
||||
return (sort & QDir::DirsLast) == QDir::DirsLast;
|
||||
}
|
||||
bool result;
|
||||
int extDiff;
|
||||
switch (order) {
|
||||
case QDir::Name:
|
||||
result = compareStrings(info1.name, info2.name) < 0;
|
||||
break;
|
||||
case QDir::Type:
|
||||
extDiff = compareStrings(getExtension(info1.name),
|
||||
getExtension(info2.name));
|
||||
if (extDiff == 0) {
|
||||
result = compareStrings(info1.name, info2.name) < 0;
|
||||
} else {
|
||||
result = extDiff < 0;
|
||||
}
|
||||
break;
|
||||
case QDir::Size:
|
||||
if (info1.uncompressedSize == info2.uncompressedSize) {
|
||||
result = compareStrings(info1.name, info2.name) < 0;
|
||||
} else {
|
||||
result = info1.uncompressedSize < info2.uncompressedSize;
|
||||
}
|
||||
break;
|
||||
case QDir::Time:
|
||||
if (info1.dateTime == info2.dateTime) {
|
||||
result = compareStrings(info1.name, info2.name) < 0;
|
||||
} else {
|
||||
result = info1.dateTime < info2.dateTime;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
qWarning("QuaZipDirComparator(): Invalid sort mode 0x%2X",
|
||||
static_cast<unsigned>(sort));
|
||||
return false;
|
||||
}
|
||||
return (sort & QDir::Reversed) ? !result : result;
|
||||
}
|
||||
|
||||
template<typename TFileInfoList>
|
||||
bool QuaZipDirPrivate::entryInfoList(QStringList nameFilters,
|
||||
QDir::Filters filter, QDir::SortFlags sort, TFileInfoList &result) const
|
||||
{
|
||||
QString basePath = simplePath();
|
||||
if (!basePath.isEmpty())
|
||||
basePath += QLatin1String("/");
|
||||
int baseLength = basePath.length();
|
||||
result.clear();
|
||||
QuaZipDirRestoreCurrent saveCurrent(zip);
|
||||
if (!zip->goToFirstFile()) {
|
||||
return zip->getZipError() == UNZ_OK;
|
||||
}
|
||||
QDir::Filters fltr = filter;
|
||||
if (fltr == QDir::NoFilter)
|
||||
fltr = this->filter;
|
||||
if (fltr == QDir::NoFilter)
|
||||
fltr = QDir::AllEntries;
|
||||
QStringList nmfltr = nameFilters;
|
||||
if (nmfltr.isEmpty())
|
||||
nmfltr = this->nameFilters;
|
||||
QSet<QString> dirsFound;
|
||||
QList<QuaZipFileInfo64> list;
|
||||
do {
|
||||
QString name = zip->getCurrentFileName();
|
||||
if (!name.startsWith(basePath))
|
||||
continue;
|
||||
QString relativeName = name.mid(baseLength);
|
||||
if (relativeName.isEmpty())
|
||||
continue;
|
||||
bool isDir = false;
|
||||
bool isReal = true;
|
||||
if (relativeName.contains(QLatin1String("/"))) {
|
||||
int indexOfSlash = relativeName.indexOf(QLatin1String("/"));
|
||||
// something like "subdir/"
|
||||
isReal = indexOfSlash == relativeName.length() - 1;
|
||||
relativeName = relativeName.left(indexOfSlash + 1);
|
||||
if (dirsFound.contains(relativeName))
|
||||
continue;
|
||||
isDir = true;
|
||||
}
|
||||
dirsFound.insert(relativeName);
|
||||
if ((fltr & QDir::Dirs) == 0 && isDir)
|
||||
continue;
|
||||
if ((fltr & QDir::Files) == 0 && !isDir)
|
||||
continue;
|
||||
if (!nmfltr.isEmpty() && !QDir::match(nmfltr, relativeName))
|
||||
continue;
|
||||
bool ok;
|
||||
QuaZipFileInfo64 info = QuaZipDir_getFileInfo(zip, &ok, relativeName,
|
||||
isReal);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
list.append(info);
|
||||
} while (zip->goToNextFile());
|
||||
QDir::SortFlags srt = sort;
|
||||
if (srt == QDir::NoSort)
|
||||
srt = sorting;
|
||||
#ifdef QUAZIP_QUAZIPDIR_DEBUG
|
||||
qDebug("QuaZipDirPrivate::entryInfoList(): before sort:");
|
||||
foreach (QuaZipFileInfo64 info, list) {
|
||||
qDebug("%s\t%s", info.name.toUtf8().constData(),
|
||||
info.dateTime.toString(Qt::ISODate).toUtf8().constData());
|
||||
}
|
||||
#endif
|
||||
if (srt != QDir::NoSort && (srt & QDir::Unsorted) != QDir::Unsorted) {
|
||||
if (QuaZip::convertCaseSensitivity(caseSensitivity)
|
||||
== Qt::CaseInsensitive)
|
||||
srt |= QDir::IgnoreCase;
|
||||
QuaZipDirComparator lessThan(srt);
|
||||
quazip_sort(list.begin(), list.end(), lessThan);
|
||||
}
|
||||
QuaZipDir_convertInfoList(list, result);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// \endcond
|
||||
|
||||
QList<QuaZipFileInfo> QuaZipDir::entryInfoList(const QStringList &nameFilters,
|
||||
QDir::Filters filters, QDir::SortFlags sort) const
|
||||
{
|
||||
QList<QuaZipFileInfo> result;
|
||||
if (d->entryInfoList(nameFilters, filters, sort, result))
|
||||
return result;
|
||||
else
|
||||
return QList<QuaZipFileInfo>();
|
||||
}
|
||||
|
||||
QList<QuaZipFileInfo> QuaZipDir::entryInfoList(QDir::Filters filters,
|
||||
QDir::SortFlags sort) const
|
||||
{
|
||||
return entryInfoList(QStringList(), filters, sort);
|
||||
}
|
||||
|
||||
QList<QuaZipFileInfo64> QuaZipDir::entryInfoList64(const QStringList &nameFilters,
|
||||
QDir::Filters filters, QDir::SortFlags sort) const
|
||||
{
|
||||
QList<QuaZipFileInfo64> result;
|
||||
if (d->entryInfoList(nameFilters, filters, sort, result))
|
||||
return result;
|
||||
else
|
||||
return QList<QuaZipFileInfo64>();
|
||||
}
|
||||
|
||||
QList<QuaZipFileInfo64> QuaZipDir::entryInfoList64(QDir::Filters filters,
|
||||
QDir::SortFlags sort) const
|
||||
{
|
||||
return entryInfoList64(QStringList(), filters, sort);
|
||||
}
|
||||
|
||||
QStringList QuaZipDir::entryList(const QStringList &nameFilters,
|
||||
QDir::Filters filters, QDir::SortFlags sort) const
|
||||
{
|
||||
QStringList result;
|
||||
if (d->entryInfoList(nameFilters, filters, sort, result))
|
||||
return result;
|
||||
else
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QStringList QuaZipDir::entryList(QDir::Filters filters,
|
||||
QDir::SortFlags sort) const
|
||||
{
|
||||
return entryList(QStringList(), filters, sort);
|
||||
}
|
||||
|
||||
bool QuaZipDir::exists(const QString &filePath) const
|
||||
{
|
||||
if (filePath == QLatin1String("/") || filePath.isEmpty())
|
||||
return true;
|
||||
QString fileName = filePath;
|
||||
if (fileName.endsWith(QLatin1String("/")))
|
||||
fileName.chop(1);
|
||||
if (fileName.contains(QLatin1String("/"))) {
|
||||
QFileInfo fileInfo(fileName);
|
||||
#ifdef QUAZIP_QUAZIPDIR_DEBUG
|
||||
qDebug("QuaZipDir::exists(): fileName=%s, fileInfo.fileName()=%s, "
|
||||
"fileInfo.path()=%s", fileName.toUtf8().constData(),
|
||||
fileInfo.fileName().toUtf8().constData(),
|
||||
fileInfo.path().toUtf8().constData());
|
||||
#endif
|
||||
QuaZipDir dir(*this);
|
||||
return dir.cd(fileInfo.path()) && dir.exists(fileInfo.fileName());
|
||||
} else {
|
||||
if (fileName == QLatin1String("..")) {
|
||||
return !isRoot();
|
||||
} else if (fileName == QLatin1String(".")) {
|
||||
return true;
|
||||
} else {
|
||||
QStringList entries = entryList(QDir::AllEntries, QDir::NoSort);
|
||||
#ifdef QUAZIP_QUAZIPDIR_DEBUG
|
||||
qDebug("QuaZipDir::exists(): looking for %s",
|
||||
fileName.toUtf8().constData());
|
||||
for (QStringList::const_iterator i = entries.constBegin();
|
||||
i != entries.constEnd();
|
||||
++i) {
|
||||
qDebug("QuaZipDir::exists(): entry: %s",
|
||||
i->toUtf8().constData());
|
||||
}
|
||||
#endif
|
||||
Qt::CaseSensitivity cs = QuaZip::convertCaseSensitivity(
|
||||
d->caseSensitivity);
|
||||
if (filePath.endsWith(QLatin1String("/"))) {
|
||||
return entries.contains(filePath, cs);
|
||||
} else {
|
||||
return entries.contains(fileName, cs)
|
||||
|| entries.contains(fileName + QLatin1String("/"), cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool QuaZipDir::exists() const
|
||||
{
|
||||
return QuaZipDir(d->zip).exists(d->dir);
|
||||
}
|
||||
|
||||
QString QuaZipDir::filePath(const QString &fileName) const
|
||||
{
|
||||
return QDir(d->dir).filePath(fileName);
|
||||
}
|
||||
|
||||
QDir::Filters QuaZipDir::filter()
|
||||
{
|
||||
return d->filter;
|
||||
}
|
||||
|
||||
bool QuaZipDir::isRoot() const
|
||||
{
|
||||
return d->simplePath().isEmpty();
|
||||
}
|
||||
|
||||
QStringList QuaZipDir::nameFilters() const
|
||||
{
|
||||
return d->nameFilters;
|
||||
}
|
||||
|
||||
QString QuaZipDir::path() const
|
||||
{
|
||||
return d->dir;
|
||||
}
|
||||
|
||||
QString QuaZipDir::relativeFilePath(const QString &fileName) const
|
||||
{
|
||||
return QDir(QLatin1String("/") + d->dir).relativeFilePath(fileName);
|
||||
}
|
||||
|
||||
void QuaZipDir::setCaseSensitivity(QuaZip::CaseSensitivity caseSensitivity)
|
||||
{
|
||||
d->caseSensitivity = caseSensitivity;
|
||||
}
|
||||
|
||||
void QuaZipDir::setFilter(QDir::Filters filters)
|
||||
{
|
||||
d->filter = filters;
|
||||
}
|
||||
|
||||
void QuaZipDir::setNameFilters(const QStringList &nameFilters)
|
||||
{
|
||||
d->nameFilters = nameFilters;
|
||||
}
|
||||
|
||||
void QuaZipDir::setPath(const QString &path)
|
||||
{
|
||||
QString newDir = path;
|
||||
if (newDir == QLatin1String("/")) {
|
||||
d->dir = QLatin1String("");
|
||||
} else {
|
||||
if (newDir.endsWith(QLatin1String("/")))
|
||||
newDir.chop(1);
|
||||
if (newDir.startsWith(QLatin1String("/")))
|
||||
newDir = newDir.mid(1);
|
||||
d->dir = newDir;
|
||||
}
|
||||
}
|
||||
|
||||
void QuaZipDir::setSorting(QDir::SortFlags sort)
|
||||
{
|
||||
d->sorting = sort;
|
||||
}
|
||||
|
||||
QDir::SortFlags QuaZipDir::sorting() const
|
||||
{
|
||||
return d->sorting;
|
||||
}
|
|
@ -0,0 +1,223 @@
|
|||
#ifndef QUAZIP_QUAZIPDIR_H
|
||||
#define QUAZIP_QUAZIPDIR_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
class QuaZipDirPrivate;
|
||||
|
||||
#include "quazip.h"
|
||||
#include "quazipfileinfo.h"
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QSharedDataPointer>
|
||||
|
||||
/// Provides ZIP archive navigation.
|
||||
/**
|
||||
* This class is modelled after QDir, and is designed to provide similar
|
||||
* features for ZIP archives.
|
||||
*
|
||||
* The only significant difference from QDir is that the root path is not
|
||||
* '/', but an empty string since that's how the file paths are stored in
|
||||
* the archive. However, QuaZipDir understands the paths starting with
|
||||
* '/'. It is important in a few places:
|
||||
*
|
||||
* - In the cd() function.
|
||||
* - In the constructor.
|
||||
* - In the exists() function.
|
||||
* - In the relativePath() function.
|
||||
*
|
||||
* Note that since ZIP uses '/' on all platforms, the '\' separator is
|
||||
* not supported.
|
||||
*/
|
||||
class QUAZIP_EXPORT QuaZipDir {
|
||||
private:
|
||||
QSharedDataPointer<QuaZipDirPrivate> d;
|
||||
public:
|
||||
/// The copy constructor.
|
||||
QuaZipDir(const QuaZipDir &that);
|
||||
/// Constructs a QuaZipDir instance pointing to the specified directory.
|
||||
/**
|
||||
If \a dir is not specified, points to the root of the archive.
|
||||
The same happens if the \a dir is "/".
|
||||
*/
|
||||
QuaZipDir(QuaZip *zip, const QString &dir = QString());
|
||||
/// Destructor.
|
||||
~QuaZipDir();
|
||||
/// The assignment operator.
|
||||
bool operator==(const QuaZipDir &that);
|
||||
/// operator!=
|
||||
/**
|
||||
\return \c true if either this and \a that use different QuaZip
|
||||
instances or if they point to different directories.
|
||||
*/
|
||||
inline bool operator!=(const QuaZipDir &that) {return !operator==(that);}
|
||||
/// operator==
|
||||
/**
|
||||
\return \c true if both this and \a that use the same QuaZip
|
||||
instance and point to the same directory.
|
||||
*/
|
||||
QuaZipDir& operator=(const QuaZipDir &that);
|
||||
/// Returns the name of the entry at the specified position.
|
||||
QString operator[](int pos) const;
|
||||
/// Returns the current case sensitivity mode.
|
||||
QuaZip::CaseSensitivity caseSensitivity() const;
|
||||
/// Changes the 'current' directory.
|
||||
/**
|
||||
* If the path starts with '/', it is interpreted as an absolute
|
||||
* path from the root of the archive. Otherwise, it is interpreted
|
||||
* as a path relative to the current directory as was set by the
|
||||
* previous cd() or the constructor.
|
||||
*
|
||||
* Note that the subsequent path() call will not return a path
|
||||
* starting with '/' in all cases.
|
||||
*/
|
||||
bool cd(const QString &dirName);
|
||||
/// Goes up.
|
||||
bool cdUp();
|
||||
/// Returns the number of entries in the directory.
|
||||
uint count() const;
|
||||
/// Returns the current directory name.
|
||||
/**
|
||||
The name doesn't include the path.
|
||||
*/
|
||||
QString dirName() const;
|
||||
/// Returns the list of the entries in the directory.
|
||||
/**
|
||||
\param nameFilters The list of file patterns to list, uses the same
|
||||
syntax as QDir.
|
||||
\param filters The entry type filters, only Files and Dirs are
|
||||
accepted.
|
||||
\param sort Sorting mode.
|
||||
*/
|
||||
QList<QuaZipFileInfo> entryInfoList(const QStringList &nameFilters,
|
||||
QDir::Filters filters = QDir::NoFilter,
|
||||
QDir::SortFlags sort = QDir::NoSort) const;
|
||||
/// Returns the list of the entries in the directory.
|
||||
/**
|
||||
\overload
|
||||
|
||||
The same as entryInfoList(QStringList(), filters, sort).
|
||||
*/
|
||||
QList<QuaZipFileInfo> entryInfoList(QDir::Filters filters = QDir::NoFilter,
|
||||
QDir::SortFlags sort = QDir::NoSort) const;
|
||||
/// Returns the list of the entries in the directory with zip64 support.
|
||||
/**
|
||||
\param nameFilters The list of file patterns to list, uses the same
|
||||
syntax as QDir.
|
||||
\param filters The entry type filters, only Files and Dirs are
|
||||
accepted.
|
||||
\param sort Sorting mode.
|
||||
*/
|
||||
QList<QuaZipFileInfo64> entryInfoList64(const QStringList &nameFilters,
|
||||
QDir::Filters filters = QDir::NoFilter,
|
||||
QDir::SortFlags sort = QDir::NoSort) const;
|
||||
/// Returns the list of the entries in the directory with zip64 support.
|
||||
/**
|
||||
\overload
|
||||
|
||||
The same as entryInfoList64(QStringList(), filters, sort).
|
||||
*/
|
||||
QList<QuaZipFileInfo64> entryInfoList64(QDir::Filters filters = QDir::NoFilter,
|
||||
QDir::SortFlags sort = QDir::NoSort) const;
|
||||
/// Returns the list of the entry names in the directory.
|
||||
/**
|
||||
The same as entryInfoList(nameFilters, filters, sort), but only
|
||||
returns entry names.
|
||||
*/
|
||||
QStringList entryList(const QStringList &nameFilters,
|
||||
QDir::Filters filters = QDir::NoFilter,
|
||||
QDir::SortFlags sort = QDir::NoSort) const;
|
||||
/// Returns the list of the entry names in the directory.
|
||||
/**
|
||||
\overload
|
||||
|
||||
The same as entryList(QStringList(), filters, sort).
|
||||
*/
|
||||
QStringList entryList(QDir::Filters filters = QDir::NoFilter,
|
||||
QDir::SortFlags sort = QDir::NoSort) const;
|
||||
/// Returns \c true if the entry with the specified name exists.
|
||||
/**
|
||||
The ".." is considered to exist if the current directory
|
||||
is not root. The "." and "/" are considered to
|
||||
always exist. Paths starting with "/" are relative to
|
||||
the archive root, other paths are relative to the current dir.
|
||||
*/
|
||||
bool exists(const QString &fileName) const;
|
||||
/// Return \c true if the directory pointed by this QuaZipDir exists.
|
||||
bool exists() const;
|
||||
/// Returns the full path to the specified file.
|
||||
/**
|
||||
Doesn't check if the file actually exists.
|
||||
*/
|
||||
QString filePath(const QString &fileName) const;
|
||||
/// Returns the default filter.
|
||||
QDir::Filters filter();
|
||||
/// Returns if the QuaZipDir points to the root of the archive.
|
||||
/**
|
||||
Not that the root path is the empty string, not '/'.
|
||||
*/
|
||||
bool isRoot() const;
|
||||
/// Return the default name filter.
|
||||
QStringList nameFilters() const;
|
||||
/// Returns the path to the current dir.
|
||||
/**
|
||||
The path never starts with '/', and the root path is an empty
|
||||
string.
|
||||
*/
|
||||
QString path() const;
|
||||
/// Returns the path to the specified file relative to the current dir.
|
||||
/**
|
||||
* This function is mostly useless, provided only for the sake of
|
||||
* completeness.
|
||||
*
|
||||
* @param fileName The path to the file, should start with "/"
|
||||
* if relative to the archive root.
|
||||
* @return Path relative to the current dir.
|
||||
*/
|
||||
QString relativeFilePath(const QString &fileName) const;
|
||||
/// Sets the default case sensitivity mode.
|
||||
void setCaseSensitivity(QuaZip::CaseSensitivity caseSensitivity);
|
||||
/// Sets the default filter.
|
||||
void setFilter(QDir::Filters filters);
|
||||
/// Sets the default name filter.
|
||||
void setNameFilters(const QStringList &nameFilters);
|
||||
/// Goes to the specified path.
|
||||
/**
|
||||
The difference from cd() is that this function never checks if the
|
||||
path actually exists and doesn't use relative paths, so it's
|
||||
possible to go to the root directory with setPath("").
|
||||
|
||||
Note that this function still chops the trailing and/or leading
|
||||
'/' and treats a single '/' as the root path (path() will still
|
||||
return an empty string).
|
||||
*/
|
||||
void setPath(const QString &path);
|
||||
/// Sets the default sorting mode.
|
||||
void setSorting(QDir::SortFlags sort);
|
||||
/// Returns the default sorting mode.
|
||||
QDir::SortFlags sorting() const;
|
||||
};
|
||||
|
||||
#endif // QUAZIP_QUAZIPDIR_H
|
|
@ -0,0 +1,570 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant, see
|
||||
quazip/(un)zip.h files for details, basically it's zlib license.
|
||||
**/
|
||||
|
||||
#include "quazipfile.h"
|
||||
|
||||
#include "quazipfileinfo.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define QUAZIP_VERSION_MADE_BY 0x1Eu
|
||||
|
||||
/// The implementation class for QuaZip.
|
||||
/**
|
||||
\internal
|
||||
|
||||
This class contains all the private stuff for the QuaZipFile class, thus
|
||||
allowing to preserve binary compatibility between releases, the
|
||||
technique known as the Pimpl (private implementation) idiom.
|
||||
*/
|
||||
class QuaZipFilePrivate {
|
||||
friend class QuaZipFile;
|
||||
private:
|
||||
Q_DISABLE_COPY(QuaZipFilePrivate)
|
||||
/// The pointer to the associated QuaZipFile instance.
|
||||
QuaZipFile *q;
|
||||
/// The QuaZip object to work with.
|
||||
QuaZip *zip;
|
||||
/// The file name.
|
||||
QString fileName;
|
||||
/// Case sensitivity mode.
|
||||
QuaZip::CaseSensitivity caseSensitivity;
|
||||
/// Whether this file is opened in the raw mode.
|
||||
bool raw;
|
||||
/// Write position to keep track of.
|
||||
/**
|
||||
QIODevice::pos() is broken for non-seekable devices, so we need
|
||||
our own position.
|
||||
*/
|
||||
qint64 writePos;
|
||||
/// Uncompressed size to write along with a raw file.
|
||||
quint64 uncompressedSize;
|
||||
/// CRC to write along with a raw file.
|
||||
quint32 crc;
|
||||
/// Whether \ref zip points to an internal QuaZip instance.
|
||||
/**
|
||||
This is true if the archive was opened by name, rather than by
|
||||
supplying an existing QuaZip instance.
|
||||
*/
|
||||
bool internal;
|
||||
/// The last error.
|
||||
int zipError;
|
||||
/// Resets \ref zipError.
|
||||
inline void resetZipError() const {setZipError(UNZ_OK);}
|
||||
/// Sets the zip error.
|
||||
/**
|
||||
This function is marked as const although it changes one field.
|
||||
This allows to call it from const functions that don't change
|
||||
anything by themselves.
|
||||
*/
|
||||
void setZipError(int zipError) const;
|
||||
/// The constructor for the corresponding QuaZipFile constructor.
|
||||
inline QuaZipFilePrivate(QuaZipFile *q):
|
||||
q(q),
|
||||
zip(nullptr),
|
||||
caseSensitivity(QuaZip::csDefault),
|
||||
raw(false),
|
||||
writePos(0),
|
||||
uncompressedSize(0),
|
||||
crc(0),
|
||||
internal(true),
|
||||
zipError(UNZ_OK) {}
|
||||
/// The constructor for the corresponding QuaZipFile constructor.
|
||||
inline QuaZipFilePrivate(QuaZipFile *q, const QString &zipName):
|
||||
q(q),
|
||||
caseSensitivity(QuaZip::csDefault),
|
||||
raw(false),
|
||||
writePos(0),
|
||||
uncompressedSize(0),
|
||||
crc(0),
|
||||
internal(true),
|
||||
zipError(UNZ_OK)
|
||||
{
|
||||
zip=new QuaZip(zipName);
|
||||
}
|
||||
/// The constructor for the corresponding QuaZipFile constructor.
|
||||
inline QuaZipFilePrivate(QuaZipFile *q, const QString &zipName, const QString &fileName,
|
||||
QuaZip::CaseSensitivity cs):
|
||||
q(q),
|
||||
raw(false),
|
||||
writePos(0),
|
||||
uncompressedSize(0),
|
||||
crc(0),
|
||||
internal(true),
|
||||
zipError(UNZ_OK)
|
||||
{
|
||||
zip=new QuaZip(zipName);
|
||||
this->fileName=fileName;
|
||||
if (this->fileName.startsWith(QLatin1String("/")))
|
||||
this->fileName = this->fileName.mid(1);
|
||||
this->caseSensitivity=cs;
|
||||
}
|
||||
/// The constructor for the QuaZipFile constructor accepting a file name.
|
||||
inline QuaZipFilePrivate(QuaZipFile *q, QuaZip *zip):
|
||||
q(q),
|
||||
zip(zip),
|
||||
raw(false),
|
||||
writePos(0),
|
||||
uncompressedSize(0),
|
||||
crc(0),
|
||||
internal(false),
|
||||
zipError(UNZ_OK) {}
|
||||
/// The destructor.
|
||||
inline ~QuaZipFilePrivate()
|
||||
{
|
||||
if (internal)
|
||||
delete zip;
|
||||
}
|
||||
};
|
||||
|
||||
QuaZipFile::QuaZipFile():
|
||||
p(new QuaZipFilePrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
QuaZipFile::QuaZipFile(QObject *parent):
|
||||
QIODevice(parent),
|
||||
p(new QuaZipFilePrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
QuaZipFile::QuaZipFile(const QString& zipName, QObject *parent):
|
||||
QIODevice(parent),
|
||||
p(new QuaZipFilePrivate(this, zipName))
|
||||
{
|
||||
}
|
||||
|
||||
QuaZipFile::QuaZipFile(const QString& zipName, const QString& fileName,
|
||||
QuaZip::CaseSensitivity cs, QObject *parent):
|
||||
QIODevice(parent),
|
||||
p(new QuaZipFilePrivate(this, zipName, fileName, cs))
|
||||
{
|
||||
}
|
||||
|
||||
QuaZipFile::QuaZipFile(QuaZip *zip, QObject *parent):
|
||||
QIODevice(parent),
|
||||
p(new QuaZipFilePrivate(this, zip))
|
||||
{
|
||||
}
|
||||
|
||||
QuaZipFile::~QuaZipFile()
|
||||
{
|
||||
if (isOpen())
|
||||
close();
|
||||
delete p;
|
||||
}
|
||||
|
||||
QString QuaZipFile::getZipName() const
|
||||
{
|
||||
return p->zip==nullptr ? QString() : p->zip->getZipName();
|
||||
}
|
||||
|
||||
QuaZip *QuaZipFile::getZip() const
|
||||
{
|
||||
return p->internal ? nullptr : p->zip;
|
||||
}
|
||||
|
||||
QString QuaZipFile::getActualFileName()const
|
||||
{
|
||||
p->setZipError(UNZ_OK);
|
||||
if (p->zip == nullptr || (openMode() & WriteOnly))
|
||||
return QString();
|
||||
QString name=p->zip->getCurrentFileName();
|
||||
if(name.isNull())
|
||||
p->setZipError(p->zip->getZipError());
|
||||
return name;
|
||||
}
|
||||
|
||||
void QuaZipFile::setZipName(const QString& zipName)
|
||||
{
|
||||
if(isOpen()) {
|
||||
qWarning("QuaZipFile::setZipName(): file is already open - can not set ZIP name");
|
||||
return;
|
||||
}
|
||||
if(p->zip!=nullptr && p->internal)
|
||||
delete p->zip;
|
||||
p->zip=new QuaZip(zipName);
|
||||
p->internal=true;
|
||||
}
|
||||
|
||||
void QuaZipFile::setZip(QuaZip *zip)
|
||||
{
|
||||
if(isOpen()) {
|
||||
qWarning("QuaZipFile::setZip(): file is already open - can not set ZIP");
|
||||
return;
|
||||
}
|
||||
if(p->zip!=nullptr && p->internal)
|
||||
delete p->zip;
|
||||
p->zip=zip;
|
||||
p->fileName=QString();
|
||||
p->internal=false;
|
||||
}
|
||||
|
||||
void QuaZipFile::setFileName(const QString& fileName, QuaZip::CaseSensitivity cs)
|
||||
{
|
||||
if(p->zip==nullptr) {
|
||||
qWarning("QuaZipFile::setFileName(): call setZipName() first");
|
||||
return;
|
||||
}
|
||||
if(!p->internal) {
|
||||
qWarning("QuaZipFile::setFileName(): should not be used when not using internal QuaZip");
|
||||
return;
|
||||
}
|
||||
if(isOpen()) {
|
||||
qWarning("QuaZipFile::setFileName(): can not set file name for already opened file");
|
||||
return;
|
||||
}
|
||||
p->fileName=fileName;
|
||||
if (p->fileName.startsWith(QLatin1String("/")))
|
||||
p->fileName = p->fileName.mid(1);
|
||||
p->caseSensitivity=cs;
|
||||
}
|
||||
|
||||
void QuaZipFilePrivate::setZipError(int zipError) const
|
||||
{
|
||||
QuaZipFilePrivate *fakeThis = const_cast<QuaZipFilePrivate*>(this); // non-const
|
||||
fakeThis->zipError=zipError;
|
||||
if(zipError==UNZ_OK)
|
||||
q->setErrorString(QString());
|
||||
else
|
||||
q->setErrorString(QuaZipFile::tr("ZIP/UNZIP API error %1").arg(zipError));
|
||||
}
|
||||
|
||||
bool QuaZipFile::open(OpenMode mode)
|
||||
{
|
||||
return open(mode, nullptr);
|
||||
}
|
||||
|
||||
bool QuaZipFile::open(OpenMode mode, int *method, int *level, bool raw, const char *password)
|
||||
{
|
||||
p->resetZipError();
|
||||
if(isOpen()) {
|
||||
qWarning("QuaZipFile::open(): already opened");
|
||||
return false;
|
||||
}
|
||||
if(mode&Unbuffered) {
|
||||
qWarning("QuaZipFile::open(): Unbuffered mode is not supported");
|
||||
return false;
|
||||
}
|
||||
if((mode&ReadOnly)&&!(mode&WriteOnly)) {
|
||||
if(p->internal) {
|
||||
if(!p->zip->open(QuaZip::mdUnzip)) {
|
||||
p->setZipError(p->zip->getZipError());
|
||||
return false;
|
||||
}
|
||||
if(!p->zip->setCurrentFile(p->fileName, p->caseSensitivity)) {
|
||||
p->setZipError(p->zip->getZipError());
|
||||
p->zip->close();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(p->zip==nullptr) {
|
||||
qWarning("QuaZipFile::open(): zip is null");
|
||||
return false;
|
||||
}
|
||||
if(p->zip->getMode()!=QuaZip::mdUnzip) {
|
||||
qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
|
||||
(int)mode, (int)p->zip->getMode());
|
||||
return false;
|
||||
}
|
||||
if(!p->zip->hasCurrentFile()) {
|
||||
qWarning("QuaZipFile::open(): zip does not have current file");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
p->setZipError(unzOpenCurrentFile3(p->zip->getUnzFile(), method, level, (int)raw, password));
|
||||
if(p->zipError==UNZ_OK) {
|
||||
setOpenMode(mode);
|
||||
p->raw=raw;
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
qWarning("QuaZipFile::open(): open mode %d not supported by this function", (int)mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuaZipFile::open(OpenMode mode, const QuaZipNewInfo& info,
|
||||
const char *password, quint32 crc,
|
||||
int method, int level, bool raw,
|
||||
int windowBits, int memLevel, int strategy)
|
||||
{
|
||||
zip_fileinfo info_z;
|
||||
p->resetZipError();
|
||||
if(isOpen()) {
|
||||
qWarning("QuaZipFile::open(): already opened");
|
||||
return false;
|
||||
}
|
||||
if((mode&WriteOnly)&&!(mode&ReadOnly)) {
|
||||
if(p->internal) {
|
||||
qWarning("QuaZipFile::open(): write mode is incompatible with internal QuaZip approach");
|
||||
return false;
|
||||
}
|
||||
if(p->zip==nullptr) {
|
||||
qWarning("QuaZipFile::open(): zip is null");
|
||||
return false;
|
||||
}
|
||||
if(p->zip->getMode()!=QuaZip::mdCreate&&p->zip->getMode()!=QuaZip::mdAppend&&p->zip->getMode()!=QuaZip::mdAdd) {
|
||||
qWarning("QuaZipFile::open(): file open mode %d incompatible with ZIP open mode %d",
|
||||
(int)mode, (int)p->zip->getMode());
|
||||
return false;
|
||||
}
|
||||
info_z.tmz_date.tm_year=info.dateTime.date().year();
|
||||
info_z.tmz_date.tm_mon=info.dateTime.date().month() - 1;
|
||||
info_z.tmz_date.tm_mday=info.dateTime.date().day();
|
||||
info_z.tmz_date.tm_hour=info.dateTime.time().hour();
|
||||
info_z.tmz_date.tm_min=info.dateTime.time().minute();
|
||||
info_z.tmz_date.tm_sec=info.dateTime.time().second();
|
||||
info_z.dosDate = 0;
|
||||
info_z.internal_fa=(uLong)info.internalAttr;
|
||||
info_z.external_fa=(uLong)info.externalAttr;
|
||||
if (p->zip->isDataDescriptorWritingEnabled())
|
||||
zipSetFlags(p->zip->getZipFile(), ZIP_WRITE_DATA_DESCRIPTOR);
|
||||
else
|
||||
zipClearFlags(p->zip->getZipFile(), ZIP_WRITE_DATA_DESCRIPTOR);
|
||||
p->setZipError(zipOpenNewFileInZip4_64(p->zip->getZipFile(),
|
||||
p->zip->isUtf8Enabled()
|
||||
? info.name.toUtf8().constData()
|
||||
: p->zip->getFileNameCodec()->fromUnicode(info.name).constData(),
|
||||
&info_z,
|
||||
info.extraLocal.constData(), info.extraLocal.length(),
|
||||
info.extraGlobal.constData(), info.extraGlobal.length(),
|
||||
p->zip->isUtf8Enabled()
|
||||
? info.comment.toUtf8().constData()
|
||||
: p->zip->getCommentCodec()->fromUnicode(info.comment).constData(),
|
||||
method, level, (int)raw,
|
||||
windowBits, memLevel, strategy,
|
||||
password, (uLong)crc,
|
||||
(p->zip->getOsCode() << 8) | QUAZIP_VERSION_MADE_BY,
|
||||
0,
|
||||
p->zip->isZip64Enabled()));
|
||||
if(p->zipError==UNZ_OK) {
|
||||
p->writePos=0;
|
||||
setOpenMode(mode);
|
||||
p->raw=raw;
|
||||
if(raw) {
|
||||
p->crc=crc;
|
||||
p->uncompressedSize=info.uncompressedSize;
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
qWarning("QuaZipFile::open(): open mode %d not supported by this function", (int)mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool QuaZipFile::isSequential()const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
qint64 QuaZipFile::pos()const
|
||||
{
|
||||
if(p->zip==nullptr) {
|
||||
qWarning("QuaZipFile::pos(): call setZipName() or setZip() first");
|
||||
return -1;
|
||||
}
|
||||
if(!isOpen()) {
|
||||
qWarning("QuaZipFile::pos(): file is not open");
|
||||
return -1;
|
||||
}
|
||||
if(openMode()&ReadOnly)
|
||||
// QIODevice::pos() is broken for sequential devices,
|
||||
// but thankfully bytesAvailable() returns the number of
|
||||
// bytes buffered, so we know how far ahead we are.
|
||||
return unztell64(p->zip->getUnzFile()) - QIODevice::bytesAvailable();
|
||||
else
|
||||
return p->writePos;
|
||||
}
|
||||
|
||||
bool QuaZipFile::atEnd()const
|
||||
{
|
||||
if(p->zip==nullptr) {
|
||||
qWarning("QuaZipFile::atEnd(): call setZipName() or setZip() first");
|
||||
return false;
|
||||
}
|
||||
if(!isOpen()) {
|
||||
qWarning("QuaZipFile::atEnd(): file is not open");
|
||||
return false;
|
||||
}
|
||||
if(openMode()&ReadOnly)
|
||||
// the same problem as with pos()
|
||||
return QIODevice::bytesAvailable() == 0
|
||||
&& unzeof(p->zip->getUnzFile())==1;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
qint64 QuaZipFile::size()const
|
||||
{
|
||||
if(!isOpen()) {
|
||||
qWarning("QuaZipFile::atEnd(): file is not open");
|
||||
return -1;
|
||||
}
|
||||
if(openMode()&ReadOnly)
|
||||
return p->raw?csize():usize();
|
||||
else
|
||||
return p->writePos;
|
||||
}
|
||||
|
||||
qint64 QuaZipFile::csize()const
|
||||
{
|
||||
unz_file_info64 info_z;
|
||||
p->setZipError(UNZ_OK);
|
||||
if(p->zip==nullptr||p->zip->getMode()!=QuaZip::mdUnzip) return -1;
|
||||
p->setZipError(unzGetCurrentFileInfo64(p->zip->getUnzFile(), &info_z, nullptr, 0, nullptr, 0, nullptr, 0));
|
||||
if(p->zipError!=UNZ_OK)
|
||||
return -1;
|
||||
return info_z.compressed_size;
|
||||
}
|
||||
|
||||
qint64 QuaZipFile::usize()const
|
||||
{
|
||||
unz_file_info64 info_z;
|
||||
p->setZipError(UNZ_OK);
|
||||
if(p->zip==nullptr||p->zip->getMode()!=QuaZip::mdUnzip) return -1;
|
||||
p->setZipError(unzGetCurrentFileInfo64(p->zip->getUnzFile(), &info_z, nullptr, 0, nullptr, 0, nullptr, 0));
|
||||
if(p->zipError!=UNZ_OK)
|
||||
return -1;
|
||||
return info_z.uncompressed_size;
|
||||
}
|
||||
|
||||
bool QuaZipFile::getFileInfo(QuaZipFileInfo *info)
|
||||
{
|
||||
QuaZipFileInfo64 info64;
|
||||
if (getFileInfo(&info64)) {
|
||||
info64.toQuaZipFileInfo(*info);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool QuaZipFile::getFileInfo(QuaZipFileInfo64 *info)
|
||||
{
|
||||
if(p->zip==nullptr||p->zip->getMode()!=QuaZip::mdUnzip) return false;
|
||||
p->zip->getCurrentFileInfo(info);
|
||||
p->setZipError(p->zip->getZipError());
|
||||
return p->zipError==UNZ_OK;
|
||||
}
|
||||
|
||||
void QuaZipFile::close()
|
||||
{
|
||||
p->resetZipError();
|
||||
if(p->zip==nullptr||!p->zip->isOpen()) return;
|
||||
if(!isOpen()) {
|
||||
qWarning("QuaZipFile::close(): file isn't open");
|
||||
return;
|
||||
}
|
||||
if(openMode()&ReadOnly)
|
||||
p->setZipError(unzCloseCurrentFile(p->zip->getUnzFile()));
|
||||
else if(openMode()&WriteOnly)
|
||||
if(isRaw()) p->setZipError(zipCloseFileInZipRaw64(p->zip->getZipFile(), p->uncompressedSize, p->crc));
|
||||
else p->setZipError(zipCloseFileInZip(p->zip->getZipFile()));
|
||||
else {
|
||||
qWarning("Wrong open mode: %d", (int)openMode());
|
||||
return;
|
||||
}
|
||||
if(p->zipError==UNZ_OK) setOpenMode(QIODevice::NotOpen);
|
||||
else return;
|
||||
if(p->internal) {
|
||||
p->zip->close();
|
||||
p->setZipError(p->zip->getZipError());
|
||||
}
|
||||
}
|
||||
|
||||
qint64 QuaZipFile::readData(char *data, qint64 maxSize)
|
||||
{
|
||||
p->setZipError(UNZ_OK);
|
||||
qint64 bytesRead=unzReadCurrentFile(p->zip->getUnzFile(), data, (unsigned)maxSize);
|
||||
if (bytesRead < 0) {
|
||||
p->setZipError((int) bytesRead);
|
||||
return -1;
|
||||
}
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
qint64 QuaZipFile::writeData(const char* data, qint64 maxSize)
|
||||
{
|
||||
p->setZipError(ZIP_OK);
|
||||
p->setZipError(zipWriteInFileInZip(p->zip->getZipFile(), data, (uint)maxSize));
|
||||
if(p->zipError!=ZIP_OK) return -1;
|
||||
else {
|
||||
p->writePos+=maxSize;
|
||||
return maxSize;
|
||||
}
|
||||
}
|
||||
|
||||
QString QuaZipFile::getFileName() const
|
||||
{
|
||||
return p->fileName;
|
||||
}
|
||||
|
||||
QuaZip::CaseSensitivity QuaZipFile::getCaseSensitivity() const
|
||||
{
|
||||
return p->caseSensitivity;
|
||||
}
|
||||
|
||||
bool QuaZipFile::isRaw() const
|
||||
{
|
||||
return p->raw;
|
||||
}
|
||||
|
||||
int QuaZipFile::getZipError() const
|
||||
{
|
||||
return p->zipError;
|
||||
}
|
||||
|
||||
qint64 QuaZipFile::bytesAvailable() const
|
||||
{
|
||||
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);
|
||||
}
|
|
@ -0,0 +1,508 @@
|
|||
#ifndef QUA_ZIPFILE_H
|
||||
#define QUA_ZIPFILE_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant, see
|
||||
quazip/(un)zip.h files for details, basically it's zlib license.
|
||||
**/
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
|
||||
#include "quazip_global.h"
|
||||
#include "quazip.h"
|
||||
#include "quazipnewinfo.h"
|
||||
|
||||
class QuaZipFilePrivate;
|
||||
|
||||
/// A file inside ZIP archive.
|
||||
/** \class QuaZipFile quazipfile.h <quazip/quazipfile.h>
|
||||
* This is the most interesting class. Not only it provides C++
|
||||
* interface to the ZIP/UNZIP package, but also integrates it with Qt by
|
||||
* subclassing QIODevice. This makes possible to access files inside ZIP
|
||||
* archive using QTextStream or QDataStream, for example. Actually, this
|
||||
* is the main purpose of the whole QuaZip library.
|
||||
*
|
||||
* 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
|
||||
* it will create internal QuaZip object. See constructors' descriptions
|
||||
* for details. Writing is only possible with the existing instance.
|
||||
*
|
||||
* Note that due to the underlying library's limitation it is not
|
||||
* possible to use multiple QuaZipFile instances to open several files
|
||||
* in the same archive at the same time. If you need to write to
|
||||
* multiple files in parallel, then you should write to temporary files
|
||||
* first, then pack them all at once when you have finished writing. If
|
||||
* you need to read multiple files inside the same archive in parallel,
|
||||
* you should extract them all into a temporary directory first.
|
||||
*
|
||||
* \section quazipfile-sequential Sequential or random-access?
|
||||
*
|
||||
* At the first thought, QuaZipFile has fixed size, the start and the
|
||||
* end and should be therefore considered random-access device. But
|
||||
* there is one major obstacle to making it random-access: ZIP/UNZIP API
|
||||
* does not support seek() operation and the only way to implement it is
|
||||
* through reopening the file and re-reading to the required position,
|
||||
* but this is prohibitively slow.
|
||||
*
|
||||
* Therefore, QuaZipFile is considered to be a sequential device. This
|
||||
* has advantage of availability of the ungetChar() operation (QIODevice
|
||||
* does not implement it properly for non-sequential devices unless they
|
||||
* support seek()). Disadvantage is a somewhat strange behaviour of the
|
||||
* size() and pos() functions. This should be kept in mind while using
|
||||
* this class.
|
||||
*
|
||||
**/
|
||||
class QUAZIP_EXPORT QuaZipFile: public QIODevice {
|
||||
friend class QuaZipFilePrivate;
|
||||
Q_OBJECT
|
||||
private:
|
||||
QuaZipFilePrivate *p;
|
||||
// these are not supported nor implemented
|
||||
QuaZipFile(const QuaZipFile& that);
|
||||
QuaZipFile& operator=(const QuaZipFile& that);
|
||||
protected:
|
||||
/// Implementation of the QIODevice::readData().
|
||||
qint64 readData(char *data, qint64 maxSize);
|
||||
/// Implementation of the QIODevice::writeData().
|
||||
qint64 writeData(const char *data, qint64 maxSize);
|
||||
public:
|
||||
/// Constructs a QuaZipFile instance.
|
||||
/** You should use setZipName() and setFileName() or setZip() before
|
||||
* trying to call open() on the constructed object.
|
||||
**/
|
||||
QuaZipFile();
|
||||
/// Constructs a QuaZipFile instance.
|
||||
/** \a parent argument specifies this object's parent object.
|
||||
*
|
||||
* You should use setZipName() and setFileName() or setZip() before
|
||||
* trying to call open() on the constructed object.
|
||||
**/
|
||||
QuaZipFile(QObject *parent);
|
||||
/// Constructs a QuaZipFile instance.
|
||||
/** \a parent argument specifies this object's parent object and \a
|
||||
* zipName specifies ZIP archive file name.
|
||||
*
|
||||
* You should use setFileName() before trying to call open() on the
|
||||
* constructed object.
|
||||
*
|
||||
* QuaZipFile constructed by this constructor can be used for read
|
||||
* only access. Use QuaZipFile(QuaZip*,QObject*) for writing.
|
||||
**/
|
||||
QuaZipFile(const QString& zipName, QObject *parent =nullptr);
|
||||
/// Constructs a QuaZipFile instance.
|
||||
/** \a parent argument specifies this object's parent object, \a
|
||||
* zipName specifies ZIP archive file name and \a fileName and \a cs
|
||||
* specify a name of the file to open inside archive.
|
||||
*
|
||||
* QuaZipFile constructed by this constructor can be used for read
|
||||
* only access. Use QuaZipFile(QuaZip*,QObject*) for writing.
|
||||
*
|
||||
* \sa QuaZip::setCurrentFile()
|
||||
**/
|
||||
QuaZipFile(const QString& zipName, const QString& fileName,
|
||||
QuaZip::CaseSensitivity cs =QuaZip::csDefault, QObject *parent =nullptr);
|
||||
/// Constructs a QuaZipFile instance.
|
||||
/** \a parent argument specifies this object's parent object.
|
||||
*
|
||||
* \a zip is the pointer to the existing QuaZip object. This
|
||||
* QuaZipFile object then can be used to read current file in the
|
||||
* \a zip or to write to the file inside it.
|
||||
*
|
||||
* \warning Using this constructor for reading current file can be
|
||||
* tricky. Let's take the following example:
|
||||
* \code
|
||||
* QuaZip zip("archive.zip");
|
||||
* zip.open(QuaZip::mdUnzip);
|
||||
* zip.setCurrentFile("file-in-archive");
|
||||
* QuaZipFile file(&zip);
|
||||
* file.open(QIODevice::ReadOnly);
|
||||
* // ok, now we can read from the file
|
||||
* file.read(somewhere, some);
|
||||
* zip.setCurrentFile("another-file-in-archive"); // oops...
|
||||
* QuaZipFile anotherFile(&zip);
|
||||
* anotherFile.open(QIODevice::ReadOnly);
|
||||
* anotherFile.read(somewhere, some); // this is still ok...
|
||||
* file.read(somewhere, some); // and this is NOT
|
||||
* \endcode
|
||||
* So, what exactly happens here? When we change current file in the
|
||||
* \c zip archive, \c file that references it becomes invalid
|
||||
* (actually, as far as I understand ZIP/UNZIP sources, it becomes
|
||||
* closed, but QuaZipFile has no means to detect it).
|
||||
*
|
||||
* Summary: do not close \c zip object or change its current file as
|
||||
* long as QuaZipFile is open. Even better - use another constructors
|
||||
* which create internal QuaZip instances, one per object, and
|
||||
* therefore do not cause unnecessary trouble. This constructor may
|
||||
* be useful, though, if you already have a QuaZip instance and do
|
||||
* not want to access several files at once. Good example:
|
||||
* \code
|
||||
* QuaZip zip("archive.zip");
|
||||
* zip.open(QuaZip::mdUnzip);
|
||||
* // first, we need some information about archive itself
|
||||
* QByteArray comment=zip.getComment();
|
||||
* // and now we are going to access files inside it
|
||||
* QuaZipFile file(&zip);
|
||||
* for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) {
|
||||
* file.open(QIODevice::ReadOnly);
|
||||
* // do something cool with file here
|
||||
* file.close(); // do not forget to close!
|
||||
* }
|
||||
* zip.close();
|
||||
* \endcode
|
||||
**/
|
||||
QuaZipFile(QuaZip *zip, QObject *parent =nullptr);
|
||||
/// Destroys a QuaZipFile instance.
|
||||
/** Closes file if open, destructs internal QuaZip object (if it
|
||||
* exists and \em is internal, of course).
|
||||
**/
|
||||
virtual ~QuaZipFile();
|
||||
/// Returns the ZIP archive file name.
|
||||
/** If this object was created by passing QuaZip pointer to the
|
||||
* constructor, this function will return that QuaZip's file name
|
||||
* (or null string if that object does not have file name yet).
|
||||
*
|
||||
* Otherwise, returns associated ZIP archive file name or null
|
||||
* string if there are no name set yet.
|
||||
*
|
||||
* \sa setZipName() getFileName()
|
||||
**/
|
||||
QString getZipName()const;
|
||||
/// Returns a pointer to the associated QuaZip object.
|
||||
/** Returns \c NULL if there is no associated QuaZip or it is
|
||||
* internal (so you will not mess with it).
|
||||
**/
|
||||
QuaZip* getZip()const;
|
||||
/// Returns file name.
|
||||
/** This function returns file name you passed to this object either
|
||||
* by using
|
||||
* QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*)
|
||||
* or by calling setFileName(). Real name of the file may differ in
|
||||
* case if you used case-insensitivity.
|
||||
*
|
||||
* Returns null string if there is no file name set yet. This is the
|
||||
* case when this QuaZipFile operates on the existing QuaZip object
|
||||
* (constructor QuaZipFile(QuaZip*,QObject*) or setZip() was used).
|
||||
*
|
||||
* \sa getActualFileName
|
||||
**/
|
||||
QString getFileName() const;
|
||||
/// Returns case sensitivity of the file name.
|
||||
/** This function returns case sensitivity argument you passed to
|
||||
* this object either by using
|
||||
* QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*)
|
||||
* or by calling setFileName().
|
||||
*
|
||||
* Returns unpredictable value if getFileName() returns null string
|
||||
* (this is the case when you did not used setFileName() or
|
||||
* constructor above).
|
||||
*
|
||||
* \sa getFileName
|
||||
**/
|
||||
QuaZip::CaseSensitivity getCaseSensitivity() const;
|
||||
/// Returns the actual file name in the archive.
|
||||
/** This is \em not a ZIP archive file name, but a name of file inside
|
||||
* archive. It is not necessary the same name that you have passed
|
||||
* to the
|
||||
* QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*),
|
||||
* setFileName() or QuaZip::setCurrentFile() - this is the real file
|
||||
* name inside archive, so it may differ in case if the file name
|
||||
* search was case-insensitive.
|
||||
*
|
||||
* Equivalent to calling getCurrentFileName() on the associated
|
||||
* QuaZip object. Returns null string if there is no associated
|
||||
* QuaZip object or if it does not have a current file yet. And this
|
||||
* is the case if you called setFileName() but did not open the
|
||||
* file yet. So this is perfectly fine:
|
||||
* \code
|
||||
* QuaZipFile file("somezip.zip");
|
||||
* file.setFileName("somefile");
|
||||
* QString name=file.getName(); // name=="somefile"
|
||||
* QString actual=file.getActualFileName(); // actual is null string
|
||||
* file.open(QIODevice::ReadOnly);
|
||||
* QString actual=file.getActualFileName(); // actual can be "SoMeFiLe" on Windows
|
||||
* \endcode
|
||||
*
|
||||
* \sa getZipName(), getFileName(), QuaZip::CaseSensitivity
|
||||
**/
|
||||
QString getActualFileName()const;
|
||||
/// Sets the ZIP archive file name.
|
||||
/** Automatically creates internal QuaZip object and destroys
|
||||
* previously created internal QuaZip object, if any.
|
||||
*
|
||||
* Will do nothing if this file is already open. You must close() it
|
||||
* first.
|
||||
**/
|
||||
void setZipName(const QString& zipName);
|
||||
/// Returns \c true if the file was opened in raw mode.
|
||||
/** If the file is not open, the returned value is undefined.
|
||||
*
|
||||
* \sa open(OpenMode,int*,int*,bool,const char*)
|
||||
**/
|
||||
bool isRaw() const;
|
||||
/// Binds to the existing QuaZip instance.
|
||||
/** This function destroys internal QuaZip object, if any, and makes
|
||||
* this QuaZipFile to use current file in the \a zip object for any
|
||||
* further operations. See QuaZipFile(QuaZip*,QObject*) for the
|
||||
* possible pitfalls.
|
||||
*
|
||||
* Will do nothing if the file is currently open. You must close()
|
||||
* it first.
|
||||
**/
|
||||
void setZip(QuaZip *zip);
|
||||
/// Sets the file name.
|
||||
/** Will do nothing if at least one of the following conditions is
|
||||
* met:
|
||||
* - ZIP name has not been set yet (getZipName() returns null
|
||||
* string).
|
||||
* - This QuaZipFile is associated with external QuaZip. In this
|
||||
* case you should call that QuaZip's setCurrentFile() function
|
||||
* instead!
|
||||
* - File is already open so setting the name is meaningless.
|
||||
*
|
||||
* \sa QuaZip::setCurrentFile
|
||||
**/
|
||||
void setFileName(const QString& fileName, QuaZip::CaseSensitivity cs =QuaZip::csDefault);
|
||||
/// Opens a file for reading.
|
||||
/** Returns \c true on success, \c false otherwise.
|
||||
* Call getZipError() to get error code.
|
||||
*
|
||||
* \note Since ZIP/UNZIP API provides buffered reading only,
|
||||
* QuaZipFile does not support unbuffered reading. So do not pass
|
||||
* QIODevice::Unbuffered flag in \a mode, or open will fail.
|
||||
**/
|
||||
virtual bool open(OpenMode mode);
|
||||
/// Opens a file for reading.
|
||||
/** \overload
|
||||
* Argument \a password specifies a password to decrypt the file. If
|
||||
* it is NULL then this function behaves just like open(OpenMode).
|
||||
**/
|
||||
inline bool open(OpenMode mode, const char *password)
|
||||
{return open(mode, nullptr, nullptr, false, password);}
|
||||
/// Opens a file for reading.
|
||||
/** \overload
|
||||
* Argument \a password specifies a password to decrypt the file.
|
||||
*
|
||||
* An integers pointed by \a method and \a level will receive codes
|
||||
* of the compression method and level used. See unzip.h.
|
||||
*
|
||||
* If raw is \c true then no decompression is performed.
|
||||
*
|
||||
* \a method should not be \c NULL. \a level can be \c NULL if you
|
||||
* don't want to know the compression level.
|
||||
**/
|
||||
bool open(OpenMode mode, int *method, int *level, bool raw, const char *password =nullptr);
|
||||
/// Opens a file for writing.
|
||||
/** \a info argument specifies information about file. It should at
|
||||
* least specify a correct file name. Also, it is a good idea to
|
||||
* specify correct timestamp (by default, current time will be
|
||||
* used). See QuaZipNewInfo.
|
||||
*
|
||||
* The \a password argument specifies the password for crypting. Pass NULL
|
||||
* if you don't need any crypting. The \a crc argument was supposed
|
||||
* to be used for crypting too, but then it turned out that it's
|
||||
* false information, so you need to set it to 0 unless you want to
|
||||
* use the raw mode (see below).
|
||||
*
|
||||
* Arguments \a method and \a level specify compression method and
|
||||
* level. The only method supported is Z_DEFLATED, but you may also
|
||||
* specify 0 for no compression. If all of the files in the archive
|
||||
* use both method 0 and either level 0 is explicitly specified or
|
||||
* data descriptor writing is disabled with
|
||||
* QuaZip::setDataDescriptorWritingEnabled(), then the
|
||||
* resulting archive is supposed to be compatible with the 1.0 ZIP
|
||||
* format version, should you need that. Except for this, \a level
|
||||
* has no other effects with method 0.
|
||||
*
|
||||
* If \a raw is \c true, no compression is performed. In this case,
|
||||
* \a crc and uncompressedSize field of the \a info are required.
|
||||
*
|
||||
* Arguments \a windowBits, \a memLevel, \a strategy provide zlib
|
||||
* algorithms tuning. See deflateInit2() in zlib.
|
||||
**/
|
||||
bool open(OpenMode mode, const QuaZipNewInfo& info,
|
||||
const char *password =nullptr, quint32 crc =0,
|
||||
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);
|
||||
/// Returns \c true, but \ref quazipfile-sequential "beware"!
|
||||
virtual bool isSequential()const;
|
||||
/// Returns current position in the file.
|
||||
/** Implementation of the QIODevice::pos(). When reading, this
|
||||
* function is a wrapper to the ZIP/UNZIP unztell(), therefore it is
|
||||
* unable to keep track of the ungetChar() calls (which is
|
||||
* non-virtual and therefore is dangerous to reimplement). So if you
|
||||
* are using ungetChar() feature of the QIODevice, this function
|
||||
* reports incorrect value until you get back characters which you
|
||||
* ungot.
|
||||
*
|
||||
* When writing, pos() returns number of bytes already written
|
||||
* (uncompressed unless you use raw mode).
|
||||
*
|
||||
* \note Although
|
||||
* \ref quazipfile-sequential "QuaZipFile is a sequential device"
|
||||
* and therefore pos() should always return zero, it does not,
|
||||
* because it would be misguiding. Keep this in mind.
|
||||
*
|
||||
* This function returns -1 if the file or archive is not open.
|
||||
*
|
||||
* Error code returned by getZipError() is not affected by this
|
||||
* function call.
|
||||
**/
|
||||
virtual qint64 pos()const;
|
||||
/// Returns \c true if the end of file was reached.
|
||||
/** This function returns \c false in the case of error. This means
|
||||
* that you called this function on either not open file, or a file
|
||||
* in the not open archive or even on a QuaZipFile instance that
|
||||
* does not even have QuaZip instance associated. Do not do that
|
||||
* because there is no means to determine whether \c false is
|
||||
* returned because of error or because end of file was reached.
|
||||
* Well, on the other side you may interpret \c false return value
|
||||
* as "there is no file open to check for end of file and there is
|
||||
* no end of file therefore".
|
||||
*
|
||||
* When writing, this function always returns \c true (because you
|
||||
* are always writing to the end of file).
|
||||
*
|
||||
* Error code returned by getZipError() is not affected by this
|
||||
* function call.
|
||||
**/
|
||||
virtual bool atEnd()const;
|
||||
/// Returns file size.
|
||||
/** This function returns csize() if the file is open for reading in
|
||||
* raw mode, usize() if it is open for reading in normal mode and
|
||||
* pos() if it is open for writing.
|
||||
*
|
||||
* Returns -1 on error, call getZipError() to get error code.
|
||||
*
|
||||
* \note This function returns file size despite that
|
||||
* \ref quazipfile-sequential "QuaZipFile is considered to be sequential device",
|
||||
* for which size() should return bytesAvailable() instead. But its
|
||||
* name would be very misguiding otherwise, so just keep in mind
|
||||
* this inconsistence.
|
||||
**/
|
||||
virtual qint64 size()const;
|
||||
/// Returns compressed file size.
|
||||
/** Equivalent to calling getFileInfo() and then getting
|
||||
* compressedSize field, but more convenient and faster.
|
||||
*
|
||||
* File must be open for reading before calling this function.
|
||||
*
|
||||
* Returns -1 on error, call getZipError() to get error code.
|
||||
**/
|
||||
qint64 csize()const;
|
||||
/// Returns uncompressed file size.
|
||||
/** Equivalent to calling getFileInfo() and then getting
|
||||
* uncompressedSize field, but more convenient and faster. See
|
||||
* getFileInfo() for a warning.
|
||||
*
|
||||
* File must be open for reading before calling this function.
|
||||
*
|
||||
* Returns -1 on error, call getZipError() to get error code.
|
||||
**/
|
||||
qint64 usize()const;
|
||||
/// Gets information about current file.
|
||||
/** This function does the same thing as calling
|
||||
* QuaZip::getCurrentFileInfo() on the associated QuaZip object,
|
||||
* but you can not call getCurrentFileInfo() if the associated
|
||||
* QuaZip is internal (because you do not have access to it), while
|
||||
* you still can call this function in that case.
|
||||
*
|
||||
* File must be open for reading before calling this function.
|
||||
*
|
||||
* \return \c false in the case of an error.
|
||||
*
|
||||
* This function doesn't support zip64, but will still work fine on zip64
|
||||
* archives if file sizes are below 4 GB, otherwise the values will be set
|
||||
* as if converted using QuaZipFileInfo64::toQuaZipFileInfo().
|
||||
*
|
||||
* \sa getFileInfo(QuaZipFileInfo64*)
|
||||
**/
|
||||
bool getFileInfo(QuaZipFileInfo *info);
|
||||
/// Gets information about current file with zip64 support.
|
||||
/**
|
||||
* @overload
|
||||
*
|
||||
* \sa getFileInfo(QuaZipFileInfo*)
|
||||
*/
|
||||
bool getFileInfo(QuaZipFileInfo64 *info);
|
||||
/// Closes the file.
|
||||
/** Call getZipError() to determine if the close was successful.
|
||||
**/
|
||||
virtual void close();
|
||||
/// Returns the error code returned by the last ZIP/UNZIP API call.
|
||||
int getZipError() const;
|
||||
/// Returns the number of bytes available for reading.
|
||||
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
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "quazipfileinfo.h"
|
||||
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr) {
|
||||
quint32 uPerm = (externalAttr & 0xFFFF0000u) >> 16;
|
||||
QFile::Permissions perm;
|
||||
if ((uPerm & 0400) != 0)
|
||||
perm |= QFile::ReadOwner;
|
||||
if ((uPerm & 0200) != 0)
|
||||
perm |= QFile::WriteOwner;
|
||||
if ((uPerm & 0100) != 0)
|
||||
perm |= QFile::ExeOwner;
|
||||
if ((uPerm & 0040) != 0)
|
||||
perm |= QFile::ReadGroup;
|
||||
if ((uPerm & 0020) != 0)
|
||||
perm |= QFile::WriteGroup;
|
||||
if ((uPerm & 0010) != 0)
|
||||
perm |= QFile::ExeGroup;
|
||||
if ((uPerm & 0004) != 0)
|
||||
perm |= QFile::ReadOther;
|
||||
if ((uPerm & 0002) != 0)
|
||||
perm |= QFile::WriteOther;
|
||||
if ((uPerm & 0001) != 0)
|
||||
perm |= QFile::ExeOther;
|
||||
return perm;
|
||||
|
||||
}
|
||||
|
||||
QFile::Permissions QuaZipFileInfo::getPermissions() const
|
||||
{
|
||||
return permissionsFromExternalAttr(externalAttr);
|
||||
}
|
||||
|
||||
QFile::Permissions QuaZipFileInfo64::getPermissions() const
|
||||
{
|
||||
return permissionsFromExternalAttr(externalAttr);
|
||||
}
|
||||
|
||||
bool QuaZipFileInfo64::isSymbolicLink() const
|
||||
{
|
||||
quint32 uPerm = (externalAttr & 0xFFFF0000u) >> 16;
|
||||
return (uPerm & 0170000) == 0120000;
|
||||
}
|
||||
|
||||
bool QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo &info) const
|
||||
{
|
||||
bool noOverflow = true;
|
||||
info.name = name;
|
||||
info.versionCreated = versionCreated;
|
||||
info.versionNeeded = versionNeeded;
|
||||
info.flags = flags;
|
||||
info.method = method;
|
||||
info.dateTime = dateTime;
|
||||
info.crc = crc;
|
||||
if (compressedSize > 0xFFFFFFFFu) {
|
||||
info.compressedSize = 0xFFFFFFFFu;
|
||||
noOverflow = false;
|
||||
} else {
|
||||
info.compressedSize = compressedSize;
|
||||
}
|
||||
if (uncompressedSize > 0xFFFFFFFFu) {
|
||||
info.uncompressedSize = 0xFFFFFFFFu;
|
||||
noOverflow = false;
|
||||
} else {
|
||||
info.uncompressedSize = uncompressedSize;
|
||||
}
|
||||
info.diskNumberStart = diskNumberStart;
|
||||
info.internalAttr = internalAttr;
|
||||
info.externalAttr = externalAttr;
|
||||
info.comment = comment;
|
||||
info.extra = extra;
|
||||
return noOverflow;
|
||||
}
|
||||
|
||||
static QDateTime getNTFSTime(const QByteArray &extra, int position,
|
||||
int *fineTicks)
|
||||
{
|
||||
QDateTime dateTime;
|
||||
QuaExtraFieldHash extraHash = QuaZipFileInfo64::parseExtraField(extra);
|
||||
QList<QByteArray> ntfsExtraFields = extraHash[QUAZIP_EXTRA_NTFS_MAGIC];
|
||||
if (ntfsExtraFields.isEmpty())
|
||||
return dateTime;
|
||||
QByteArray ntfsExtraField = ntfsExtraFields.at(0);
|
||||
if (ntfsExtraField.length() <= 4)
|
||||
return dateTime;
|
||||
QByteArray ntfsAttributes = ntfsExtraField.mid(4);
|
||||
QuaExtraFieldHash ntfsHash = QuaZipFileInfo64::parseExtraField(ntfsAttributes);
|
||||
QList<QByteArray> ntfsTimeAttributes = ntfsHash[QUAZIP_EXTRA_NTFS_TIME_MAGIC];
|
||||
if (ntfsTimeAttributes.isEmpty())
|
||||
return dateTime;
|
||||
QByteArray ntfsTimes = ntfsTimeAttributes.at(0);
|
||||
if (ntfsTimes.size() < 24)
|
||||
return dateTime;
|
||||
QDataStream timeReader(ntfsTimes);
|
||||
timeReader.setByteOrder(QDataStream::LittleEndian);
|
||||
timeReader.device()->seek(position);
|
||||
quint64 time;
|
||||
timeReader >> time;
|
||||
if (time == 0)
|
||||
return dateTime;
|
||||
QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
dateTime = base.addMSecs(time / 10000);
|
||||
if (fineTicks != nullptr) {
|
||||
*fineTicks = static_cast<int>(time % 10000);
|
||||
}
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
QDateTime QuaZipFileInfo64::getNTFSmTime(int *fineTicks) const
|
||||
{
|
||||
return getNTFSTime(extra, 0, fineTicks);
|
||||
}
|
||||
|
||||
QDateTime QuaZipFileInfo64::getNTFSaTime(int *fineTicks) const
|
||||
{
|
||||
return getNTFSTime(extra, 8, fineTicks);
|
||||
}
|
||||
|
||||
QDateTime QuaZipFileInfo64::getNTFScTime(int *fineTicks) const
|
||||
{
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,232 @@
|
|||
#ifndef QUA_ZIPFILEINFO_H
|
||||
#define QUA_ZIPFILEINFO_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QHash>
|
||||
|
||||
#include "quazip_global.h"
|
||||
|
||||
/// The typedef to store extra field parse results
|
||||
typedef QHash<quint16, QList<QByteArray> > QuaExtraFieldHash;
|
||||
|
||||
/// Information about a file inside archive.
|
||||
/**
|
||||
* \deprecated Use QuaZipFileInfo64 instead. Not only it supports large files,
|
||||
* but also more convenience methods as well.
|
||||
*
|
||||
* Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to
|
||||
* fill this structure. */
|
||||
struct QUAZIP_EXPORT QuaZipFileInfo {
|
||||
/// File name.
|
||||
QString name;
|
||||
/// Version created by.
|
||||
quint16 versionCreated;
|
||||
/// Version needed to extract.
|
||||
quint16 versionNeeded;
|
||||
/// General purpose flags.
|
||||
quint16 flags;
|
||||
/// Compression method.
|
||||
quint16 method;
|
||||
/// Last modification date and time.
|
||||
QDateTime dateTime;
|
||||
/// CRC.
|
||||
quint32 crc;
|
||||
/// Compressed file size.
|
||||
quint32 compressedSize;
|
||||
/// Uncompressed file size.
|
||||
quint32 uncompressedSize;
|
||||
/// Disk number start.
|
||||
quint16 diskNumberStart;
|
||||
/// Internal file attributes.
|
||||
quint16 internalAttr;
|
||||
/// External file attributes.
|
||||
quint32 externalAttr;
|
||||
/// Comment.
|
||||
QString comment;
|
||||
/// Extra field.
|
||||
QByteArray extra;
|
||||
/// Get the file permissions.
|
||||
/**
|
||||
Returns the high 16 bits of external attributes converted to
|
||||
QFile::Permissions.
|
||||
*/
|
||||
QFile::Permissions getPermissions() const;
|
||||
};
|
||||
|
||||
/// Information about a file inside archive (with zip64 support).
|
||||
/** Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to
|
||||
* fill this structure. */
|
||||
struct QUAZIP_EXPORT QuaZipFileInfo64 {
|
||||
/// File name.
|
||||
QString name;
|
||||
/// Version created by.
|
||||
quint16 versionCreated;
|
||||
/// Version needed to extract.
|
||||
quint16 versionNeeded;
|
||||
/// General purpose flags.
|
||||
quint16 flags;
|
||||
/// Compression method.
|
||||
quint16 method;
|
||||
/// Last modification date and time.
|
||||
/**
|
||||
* This is the time stored in the standard ZIP header. This format only allows
|
||||
* to store time with 2-second precision, so the seconds will always be even
|
||||
* and the milliseconds will always be zero. If you need more precise
|
||||
* date and time, you can try to call the getNTFSmTime() function or
|
||||
* its siblings, provided that the archive itself contains these NTFS times.
|
||||
*/
|
||||
QDateTime dateTime;
|
||||
/// CRC.
|
||||
quint32 crc;
|
||||
/// Compressed file size.
|
||||
quint64 compressedSize;
|
||||
/// Uncompressed file size.
|
||||
quint64 uncompressedSize;
|
||||
/// Disk number start.
|
||||
quint16 diskNumberStart;
|
||||
/// Internal file attributes.
|
||||
quint16 internalAttr;
|
||||
/// External file attributes.
|
||||
quint32 externalAttr;
|
||||
/// Comment.
|
||||
QString comment;
|
||||
/// Extra field.
|
||||
QByteArray extra;
|
||||
/// Get the file permissions.
|
||||
/**
|
||||
Returns the high 16 bits of external attributes converted to
|
||||
QFile::Permissions.
|
||||
*/
|
||||
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
|
||||
/**
|
||||
If any of the fields are greater than 0xFFFFFFFFu, they are set to
|
||||
0xFFFFFFFFu exactly, not just truncated. This function should be mainly used
|
||||
for compatibility with the old code expecting QuaZipFileInfo, in the cases
|
||||
when it's impossible or otherwise unadvisable (due to ABI compatibility
|
||||
reasons, for example) to modify that old code to use QuaZipFileInfo64.
|
||||
|
||||
\return \c true if all fields converted correctly, \c false if an overflow
|
||||
occured.
|
||||
*/
|
||||
bool toQuaZipFileInfo(QuaZipFileInfo &info) const;
|
||||
/// Returns the NTFS modification time
|
||||
/**
|
||||
* The getNTFS*Time() functions only work if there is an NTFS extra field
|
||||
* present. Otherwise, they all return invalid null timestamps.
|
||||
* @param fineTicks If not null, the fractional part of milliseconds returned
|
||||
* there, measured in 100-nanosecond ticks. Will be set to
|
||||
* zero if there is no NTFS extra field.
|
||||
* @sa dateTime
|
||||
* @sa getNTFSaTime()
|
||||
* @sa getNTFScTime()
|
||||
* @return The NTFS modification time, UTC
|
||||
*/
|
||||
QDateTime getNTFSmTime(int *fineTicks = nullptr) const;
|
||||
/// Returns the NTFS access time
|
||||
/**
|
||||
* The getNTFS*Time() functions only work if there is an NTFS extra field
|
||||
* present. Otherwise, they all return invalid null timestamps.
|
||||
* @param fineTicks If not null, the fractional part of milliseconds returned
|
||||
* there, measured in 100-nanosecond ticks. Will be set to
|
||||
* zero if there is no NTFS extra field.
|
||||
* @sa dateTime
|
||||
* @sa getNTFSmTime()
|
||||
* @sa getNTFScTime()
|
||||
* @return The NTFS access time, UTC
|
||||
*/
|
||||
QDateTime getNTFSaTime(int *fineTicks = nullptr) const;
|
||||
/// Returns the NTFS creation time
|
||||
/**
|
||||
* The getNTFS*Time() functions only work if there is an NTFS extra field
|
||||
* present. Otherwise, they all return invalid null timestamps.
|
||||
* @param fineTicks If not null, the fractional part of milliseconds returned
|
||||
* there, measured in 100-nanosecond ticks. Will be set to
|
||||
* zero if there is no NTFS extra field.
|
||||
* @sa dateTime
|
||||
* @sa getNTFSmTime()
|
||||
* @sa getNTFSaTime()
|
||||
* @return The NTFS creation time, UTC
|
||||
*/
|
||||
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.
|
||||
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
|
|
@ -0,0 +1,278 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QFileInfo>
|
||||
|
||||
#include "quazipnewinfo.h"
|
||||
#include "quazip_qt_compat.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static void QuaZipNewInfo_setPermissions(QuaZipNewInfo *info,
|
||||
QFile::Permissions perm, bool isDir, bool isSymLink = false)
|
||||
{
|
||||
quint32 uPerm = isDir ? 0040000 : 0100000;
|
||||
|
||||
if ( isSymLink ) {
|
||||
#ifdef Q_OS_WIN
|
||||
uPerm = 0200000;
|
||||
#else
|
||||
uPerm = 0120000;
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((perm & QFile::ReadOwner) != 0)
|
||||
uPerm |= 0400;
|
||||
if ((perm & QFile::WriteOwner) != 0)
|
||||
uPerm |= 0200;
|
||||
if ((perm & QFile::ExeOwner) != 0)
|
||||
uPerm |= 0100;
|
||||
if ((perm & QFile::ReadGroup) != 0)
|
||||
uPerm |= 0040;
|
||||
if ((perm & QFile::WriteGroup) != 0)
|
||||
uPerm |= 0020;
|
||||
if ((perm & QFile::ExeGroup) != 0)
|
||||
uPerm |= 0010;
|
||||
if ((perm & QFile::ReadOther) != 0)
|
||||
uPerm |= 0004;
|
||||
if ((perm & QFile::WriteOther) != 0)
|
||||
uPerm |= 0002;
|
||||
if ((perm & QFile::ExeOther) != 0)
|
||||
uPerm |= 0001;
|
||||
info->externalAttr = (info->externalAttr & ~0xFFFF0000u) | (uPerm << 16);
|
||||
}
|
||||
|
||||
template<typename FileInfo>
|
||||
void QuaZipNewInfo_init(QuaZipNewInfo &self, const FileInfo &existing)
|
||||
{
|
||||
self.name = existing.name;
|
||||
self.dateTime = existing.dateTime;
|
||||
self.internalAttr = existing.internalAttr;
|
||||
self.externalAttr = existing.externalAttr;
|
||||
self.comment = existing.comment;
|
||||
self.extraLocal = existing.extra;
|
||||
self.extraGlobal = existing.extra;
|
||||
self.uncompressedSize = existing.uncompressedSize;
|
||||
}
|
||||
|
||||
QuaZipNewInfo::QuaZipNewInfo(const QuaZipFileInfo &existing)
|
||||
{
|
||||
QuaZipNewInfo_init(*this, existing);
|
||||
}
|
||||
|
||||
QuaZipNewInfo::QuaZipNewInfo(const QuaZipFileInfo64 &existing)
|
||||
{
|
||||
QuaZipNewInfo_init(*this, existing);
|
||||
}
|
||||
|
||||
QuaZipNewInfo::QuaZipNewInfo(const QString& name):
|
||||
name(name), dateTime(QDateTime::currentDateTime()), internalAttr(0), externalAttr(0),
|
||||
uncompressedSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
QuaZipNewInfo::QuaZipNewInfo(const QString& name, const QString& file):
|
||||
name(name), internalAttr(0), externalAttr(0), uncompressedSize(0)
|
||||
{
|
||||
QFileInfo info(file);
|
||||
QDateTime lm = info.lastModified();
|
||||
if (!info.exists()) {
|
||||
dateTime = QDateTime::currentDateTime();
|
||||
} else {
|
||||
dateTime = lm;
|
||||
QuaZipNewInfo_setPermissions(this, info.permissions(), info.isDir(), quazip_is_symlink(info));
|
||||
}
|
||||
}
|
||||
|
||||
void QuaZipNewInfo::setFileDateTime(const QString& file)
|
||||
{
|
||||
QFileInfo info(file);
|
||||
QDateTime lm = info.lastModified();
|
||||
if (info.exists())
|
||||
dateTime = lm;
|
||||
}
|
||||
|
||||
void QuaZipNewInfo::setFilePermissions(const QString &file)
|
||||
{
|
||||
QFileInfo info = QFileInfo(file);
|
||||
QFile::Permissions perm = info.permissions();
|
||||
QuaZipNewInfo_setPermissions(this, perm, info.isDir(), quazip_is_symlink(info));
|
||||
}
|
||||
|
||||
void QuaZipNewInfo::setPermissions(QFile::Permissions permissions)
|
||||
{
|
||||
QuaZipNewInfo_setPermissions(this, permissions, name.endsWith(QLatin1String("/")));
|
||||
}
|
||||
|
||||
void QuaZipNewInfo::setFileNTFSTimes(const QString &fileName)
|
||||
{
|
||||
QFileInfo fi(fileName);
|
||||
if (!fi.exists()) {
|
||||
qWarning("QuaZipNewInfo::setFileNTFSTimes(): '%s' doesn't exist",
|
||||
fileName.toUtf8().constData());
|
||||
return;
|
||||
}
|
||||
setFileNTFSmTime(fi.lastModified());
|
||||
setFileNTFSaTime(fi.lastRead());
|
||||
setFileNTFScTime(quazip_ctime(fi));
|
||||
}
|
||||
|
||||
static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position,
|
||||
int fineTicks) {
|
||||
int ntfsPos = -1, timesPos = -1;
|
||||
unsigned ntfsLength = 0, ntfsTimesLength = 0;
|
||||
for (int i = 0; i <= extra.size() - 4; ) {
|
||||
unsigned type = static_cast<unsigned>(static_cast<unsigned char>(
|
||||
extra.at(i)))
|
||||
| (static_cast<unsigned>(static_cast<unsigned char>(
|
||||
extra.at(i + 1))) << 8);
|
||||
i += 2;
|
||||
unsigned length = static_cast<unsigned>(static_cast<unsigned char>(
|
||||
extra.at(i)))
|
||||
| (static_cast<unsigned>(static_cast<unsigned char>(
|
||||
extra.at(i + 1))) << 8);
|
||||
i += 2;
|
||||
if (type == QUAZIP_EXTRA_NTFS_MAGIC) {
|
||||
ntfsPos = i - 4; // the beginning of the NTFS record
|
||||
ntfsLength = length;
|
||||
if (length <= 4) {
|
||||
break; // no times in the NTFS record
|
||||
}
|
||||
i += 4; // reserved
|
||||
while (i <= extra.size() - 4) {
|
||||
unsigned tag = static_cast<unsigned>(
|
||||
static_cast<unsigned char>(extra.at(i)))
|
||||
| (static_cast<unsigned>(
|
||||
static_cast<unsigned char>(extra.at(i + 1)))
|
||||
<< 8);
|
||||
i += 2;
|
||||
unsigned tagsize = static_cast<unsigned>(
|
||||
static_cast<unsigned char>(extra.at(i)))
|
||||
| (static_cast<unsigned>(
|
||||
static_cast<unsigned char>(extra.at(i + 1)))
|
||||
<< 8);
|
||||
i += 2;
|
||||
if (tag == QUAZIP_EXTRA_NTFS_TIME_MAGIC) {
|
||||
timesPos = i - 4; // the beginning of the NTFS times tag
|
||||
ntfsTimesLength = tagsize;
|
||||
break;
|
||||
} else {
|
||||
i += tagsize;
|
||||
}
|
||||
}
|
||||
break; // I ain't going to search for yet another NTFS record!
|
||||
} else {
|
||||
i += length;
|
||||
}
|
||||
}
|
||||
if (ntfsPos == -1) {
|
||||
// No NTFS record, need to create one.
|
||||
ntfsPos = extra.size();
|
||||
ntfsLength = 32;
|
||||
extra.resize(extra.size() + 4 + ntfsLength);
|
||||
// the NTFS record header
|
||||
extra[ntfsPos] = static_cast<char>(QUAZIP_EXTRA_NTFS_MAGIC);
|
||||
extra[ntfsPos + 1] = static_cast<char>(QUAZIP_EXTRA_NTFS_MAGIC >> 8);
|
||||
extra[ntfsPos + 2] = 32; // the 2-byte size in LittleEndian
|
||||
extra[ntfsPos + 3] = 0;
|
||||
// zero the record
|
||||
memset(extra.data() + ntfsPos + 4, 0, 32);
|
||||
timesPos = ntfsPos + 8;
|
||||
// now set the tag data
|
||||
extra[timesPos] = static_cast<char>(QUAZIP_EXTRA_NTFS_TIME_MAGIC);
|
||||
extra[timesPos + 1] = static_cast<char>(QUAZIP_EXTRA_NTFS_TIME_MAGIC
|
||||
>> 8);
|
||||
// the size:
|
||||
extra[timesPos + 2] = 24;
|
||||
extra[timesPos + 3] = 0;
|
||||
ntfsTimesLength = 24;
|
||||
}
|
||||
if (timesPos == -1) {
|
||||
// No time tag in the NTFS record, need to add one.
|
||||
timesPos = ntfsPos + 4 + ntfsLength;
|
||||
extra.resize(extra.size() + 28);
|
||||
// Now we need to move the rest of the field
|
||||
// (possibly zero bytes, but memmove() is OK with that).
|
||||
// 0 ......... ntfsPos .. ntfsPos + 4 ... timesPos
|
||||
// <some data> <header> <NTFS record> <need-to-move data> <end>
|
||||
memmove(extra.data() + timesPos + 28, extra.data() + timesPos,
|
||||
extra.size() - 28 - timesPos);
|
||||
ntfsLength += 28;
|
||||
// now set the tag data
|
||||
extra[timesPos] = static_cast<char>(QUAZIP_EXTRA_NTFS_TIME_MAGIC);
|
||||
extra[timesPos + 1] = static_cast<char>(QUAZIP_EXTRA_NTFS_TIME_MAGIC
|
||||
>> 8);
|
||||
// the size:
|
||||
extra[timesPos + 2] = 24;
|
||||
extra[timesPos + 3] = 0;
|
||||
// zero the record
|
||||
memset(extra.data() + timesPos + 4, 0, 24);
|
||||
ntfsTimesLength = 24;
|
||||
}
|
||||
if (ntfsTimesLength < 24) {
|
||||
// Broken times field. OK, this is really unlikely, but just in case...
|
||||
size_t timesEnd = timesPos + 4 + ntfsTimesLength;
|
||||
extra.resize(extra.size() + (24 - ntfsTimesLength));
|
||||
// Move it!
|
||||
// 0 ......... timesPos .... timesPos + 4 .. timesEnd
|
||||
// <some data> <time header> <broken times> <need-to-move data> <end>
|
||||
memmove(extra.data() + timesEnd + (24 - ntfsTimesLength),
|
||||
extra.data() + timesEnd,
|
||||
extra.size() - (24 - ntfsTimesLength) - timesEnd);
|
||||
// Now we have to increase the NTFS record and time tag lengths.
|
||||
ntfsLength += (24 - ntfsTimesLength);
|
||||
ntfsTimesLength = 24;
|
||||
extra[ntfsPos + 2] = static_cast<char>(ntfsLength);
|
||||
extra[ntfsPos + 3] = static_cast<char>(ntfsLength >> 8);
|
||||
extra[timesPos + 2] = static_cast<char>(ntfsTimesLength);
|
||||
extra[timesPos + 3] = static_cast<char>(ntfsTimesLength >> 8);
|
||||
}
|
||||
quint64 ticks = quazip_ntfs_ticks(time, fineTicks);
|
||||
extra[timesPos + 4 + position] = static_cast<char>(ticks);
|
||||
extra[timesPos + 5 + position] = static_cast<char>(ticks >> 8);
|
||||
extra[timesPos + 6 + position] = static_cast<char>(ticks >> 16);
|
||||
extra[timesPos + 7 + position] = static_cast<char>(ticks >> 24);
|
||||
extra[timesPos + 8 + position] = static_cast<char>(ticks >> 32);
|
||||
extra[timesPos + 9 + position] = static_cast<char>(ticks >> 40);
|
||||
extra[timesPos + 10 + position] = static_cast<char>(ticks >> 48);
|
||||
extra[timesPos + 11 + position] = static_cast<char>(ticks >> 56);
|
||||
}
|
||||
|
||||
void QuaZipNewInfo::setFileNTFSmTime(const QDateTime &mTime, int fineTicks)
|
||||
{
|
||||
setNTFSTime(extraLocal, mTime, 0, fineTicks);
|
||||
setNTFSTime(extraGlobal, mTime, 0, fineTicks);
|
||||
}
|
||||
|
||||
void QuaZipNewInfo::setFileNTFSaTime(const QDateTime &aTime, int fineTicks)
|
||||
{
|
||||
setNTFSTime(extraLocal, aTime, 8, fineTicks);
|
||||
setNTFSTime(extraGlobal, aTime, 8, fineTicks);
|
||||
}
|
||||
|
||||
void QuaZipNewInfo::setFileNTFScTime(const QDateTime &cTime, int fineTicks)
|
||||
{
|
||||
setNTFSTime(extraLocal, cTime, 16, fineTicks);
|
||||
setNTFSTime(extraGlobal, cTime, 16, fineTicks);
|
||||
}
|
|
@ -0,0 +1,208 @@
|
|||
#ifndef QUA_ZIPNEWINFO_H
|
||||
#define QUA_ZIPNEWINFO_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant, see
|
||||
quazip/(un)zip.h files for details, basically it's zlib license.
|
||||
**/
|
||||
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include "quazip_global.h"
|
||||
|
||||
#include "quazipfileinfo.h"
|
||||
|
||||
/// Information about a file to be created.
|
||||
/** This structure holds information about a file to be created inside
|
||||
* ZIP archive. At least name should be set to something correct before
|
||||
* passing this structure to
|
||||
* QuaZipFile::open(OpenMode,const QuaZipNewInfo&,int,int,bool).
|
||||
*
|
||||
* Zip64 support of this structure is slightly limited: in the raw mode (when
|
||||
* a pre-compressed file is written into a ZIP file as-is), it is necessary
|
||||
* to specify the uncompressed file size and the appropriate field is 32 bit.
|
||||
* Since the raw mode is used extremely rare, there is no real need to have
|
||||
* a separate QuaZipNewInfo64 structure like QuaZipFileInfo64. It may be added
|
||||
* in the future though, if there is a demand for the raw mode with zip64
|
||||
* archives.
|
||||
**/
|
||||
struct QUAZIP_EXPORT QuaZipNewInfo {
|
||||
/// File name.
|
||||
/** This field holds file name inside archive, including path relative
|
||||
* to archive root.
|
||||
**/
|
||||
QString name;
|
||||
/// File timestamp.
|
||||
/** This is the last file modification date and time. Will be stored
|
||||
* in the archive central directory. It is a good practice to set it
|
||||
* to the source file timestamp instead of archive creating time. Use
|
||||
* setFileDateTime() or QuaZipNewInfo(const QString&, const QString&).
|
||||
**/
|
||||
QDateTime dateTime;
|
||||
/// File internal attributes.
|
||||
quint16 internalAttr;
|
||||
/// File external attributes.
|
||||
/**
|
||||
The highest 16 bits contain Unix file permissions and type (dir or
|
||||
file). The constructor QuaZipNewInfo(const QString&, const QString&)
|
||||
takes permissions from the provided file.
|
||||
*/
|
||||
quint32 externalAttr;
|
||||
/// File comment.
|
||||
/** Will be encoded in UTF-8 encoding.
|
||||
**/
|
||||
QString comment;
|
||||
/// File local extra field.
|
||||
QByteArray extraLocal;
|
||||
/// File global extra field.
|
||||
QByteArray extraGlobal;
|
||||
/// Uncompressed file size.
|
||||
/** This is only needed if you are using raw file zipping mode, i. e.
|
||||
* adding precompressed file in the zip archive.
|
||||
**/
|
||||
ulong uncompressedSize;
|
||||
/// Constructs QuaZipNewInfo instance.
|
||||
/** Initializes name with \a name, dateTime with current date and
|
||||
* time. Attributes are initialized with zeros, comment and extra
|
||||
* field with null values.
|
||||
**/
|
||||
QuaZipNewInfo(const QString& name);
|
||||
/// Constructs QuaZipNewInfo instance.
|
||||
/** Initializes name with \a name. Timestamp and permissions are taken
|
||||
* from the specified file. If the \a file does not exists or its timestamp
|
||||
* is inaccessible (e. g. you do not have read permission for the
|
||||
* directory file in), uses current time and zero permissions. Other attributes are
|
||||
* initialized with zeros, comment and extra field with null values.
|
||||
*
|
||||
* \sa setFileDateTime()
|
||||
**/
|
||||
QuaZipNewInfo(const QString& name, const QString& file);
|
||||
/// Initializes the new instance from existing file info.
|
||||
/** Mainly used when copying files between archives.
|
||||
*
|
||||
* Both extra fields are initialized to existing.extra.
|
||||
* @brief QuaZipNewInfo
|
||||
* @param existing
|
||||
*/
|
||||
QuaZipNewInfo(const QuaZipFileInfo &existing);
|
||||
/// Initializes the new instance from existing file info.
|
||||
/** Mainly used when copying files between archives.
|
||||
*
|
||||
* Both extra fields are initialized to existing.extra.
|
||||
* @brief QuaZipNewInfo
|
||||
* @param existing
|
||||
*/
|
||||
QuaZipNewInfo(const QuaZipFileInfo64 &existing);
|
||||
/// Sets the file timestamp from the existing file.
|
||||
/** Use this function to set the file timestamp from the existing
|
||||
* file. Use it like this:
|
||||
* \code
|
||||
* QuaZipFile zipFile(&zip);
|
||||
* QFile file("file-to-add");
|
||||
* file.open(QIODevice::ReadOnly);
|
||||
* QuaZipNewInfo info("file-name-in-archive");
|
||||
* info.setFileDateTime("file-to-add"); // take the timestamp from file
|
||||
* zipFile.open(QIODevice::WriteOnly, info);
|
||||
* \endcode
|
||||
*
|
||||
* This function does not change dateTime if some error occured (e. g.
|
||||
* file is inaccessible).
|
||||
**/
|
||||
void setFileDateTime(const QString& file);
|
||||
/// Sets the file permissions from the existing file.
|
||||
/**
|
||||
Takes permissions from the file and sets the high 16 bits of
|
||||
external attributes. Uses QFileInfo to get permissions on all
|
||||
platforms.
|
||||
*/
|
||||
void setFilePermissions(const QString &file);
|
||||
/// Sets the file permissions.
|
||||
/**
|
||||
Modifies the highest 16 bits of external attributes. The type part
|
||||
is set to dir if the name ends with a slash, and to regular file
|
||||
otherwise.
|
||||
*/
|
||||
void setPermissions(QFile::Permissions permissions);
|
||||
/// Sets the NTFS times from an existing file.
|
||||
/**
|
||||
* If the file doesn't exist, a warning is printed to the stderr and nothing
|
||||
* is done. Otherwise, all three times, as reported by
|
||||
* QFileInfo::lastModified(), QFileInfo::lastRead() and
|
||||
* QFileInfo::birthTime() (>=Qt5.10) or QFileInfo::created(), are written to
|
||||
* the NTFS extra field record.
|
||||
*
|
||||
* The NTFS record is written to
|
||||
* both the local and the global extra fields, updating the existing record
|
||||
* if there is one, or creating a new one and appending it to the end
|
||||
* of each extra field.
|
||||
*
|
||||
* The microseconds will be zero, as they aren't reported by QFileInfo.
|
||||
* @param fileName
|
||||
*/
|
||||
void setFileNTFSTimes(const QString &fileName);
|
||||
/// Sets the NTFS modification time.
|
||||
/**
|
||||
* The time is written into the NTFS record in
|
||||
* both the local and the global extra fields, updating the existing record
|
||||
* if there is one, or creating a new one and appending it to the end
|
||||
* of each extra field. When updating an existing record, all other fields
|
||||
* are left intact.
|
||||
* @param mTime The new modification time.
|
||||
* @param fineTicks The fractional part of milliseconds, in 100-nanosecond
|
||||
* ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than
|
||||
* 9999 will add milliseconds or even seconds, but this can be
|
||||
* confusing and therefore is discouraged.
|
||||
*/
|
||||
void setFileNTFSmTime(const QDateTime &mTime, int fineTicks = 0);
|
||||
/// Sets the NTFS access time.
|
||||
/**
|
||||
* The time is written into the NTFS record in
|
||||
* both the local and the global extra fields, updating the existing record
|
||||
* if there is one, or creating a new one and appending it to the end
|
||||
* of each extra field. When updating an existing record, all other fields
|
||||
* are left intact.
|
||||
* @param aTime The new access time.
|
||||
* @param fineTicks The fractional part of milliseconds, in 100-nanosecond
|
||||
* ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than
|
||||
* 9999 will add milliseconds or even seconds, but this can be
|
||||
* confusing and therefore is discouraged.
|
||||
*/
|
||||
void setFileNTFSaTime(const QDateTime &aTime, int fineTicks = 0);
|
||||
/// Sets the NTFS creation time.
|
||||
/**
|
||||
* The time is written into the NTFS record in
|
||||
* both the local and the global extra fields, updating the existing record
|
||||
* if there is one, or creating a new one and appending it to the end
|
||||
* of each extra field. When updating an existing record, all other fields
|
||||
* are left intact.
|
||||
* @param cTime The new creation time.
|
||||
* @param fineTicks The fractional part of milliseconds, in 100-nanosecond
|
||||
* ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than
|
||||
* 9999 will add milliseconds or even seconds, but this can be
|
||||
* confusing and therefore is discouraged.
|
||||
*/
|
||||
void setFileNTFScTime(const QDateTime &cTime, int fineTicks = 0);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,461 @@
|
|||
/* unzip.h -- IO for uncompress .zip files using zlib
|
||||
Version 1.1, February 14h, 2010
|
||||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Modifications of Unzip for Zip64
|
||||
Copyright (C) 2007-2008 Even Rouault
|
||||
|
||||
Modifications for Zip64 support on both zip and unzip
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
|
||||
For more info read MiniZip_info.txt
|
||||
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
---------------------------------------------------------------------------------
|
||||
|
||||
Changes
|
||||
|
||||
See header of unzip64.c
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
As per the requirement above, this file is plainly marked as modified
|
||||
by Sergey A. Tachenov. Most modifications include the I/O API redesign
|
||||
to support QIODevice interface. Some improvements and small fixes were also made.
|
||||
*/
|
||||
|
||||
#ifndef _unz64_H
|
||||
#define _unz64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
#include "bzlib.h"
|
||||
#endif
|
||||
|
||||
#define Z_BZIP2ED 12
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unzFile__;
|
||||
typedef unzFile__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
#endif
|
||||
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (Z_ERRNO)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
#define UNZ_INTERNALERROR (-104)
|
||||
#define UNZ_CRCERROR (-105)
|
||||
|
||||
#define UNZ_AUTO_CLOSE 0x01u
|
||||
#define UNZ_DEFAULT_FLAGS UNZ_AUTO_CLOSE
|
||||
#define UNZ_ENCODING_UTF8 0x0800u
|
||||
|
||||
/* tm_unz contain date/time info */
|
||||
typedef struct tm_unz_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_unz;
|
||||
|
||||
/* unz_global_info structure contain global data about the ZIPfile
|
||||
These data comes from the end of central dir */
|
||||
typedef struct unz_global_info64_s
|
||||
{
|
||||
ZPOS64_T number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info64;
|
||||
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uLong number_entry; /* total number of entries in
|
||||
the central dir on this disk */
|
||||
uLong size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_info64_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
ZPOS64_T compressed_size; /* compressed size 8 bytes */
|
||||
ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
} unz_file_info64;
|
||||
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uLong version; /* version made by 2 bytes */
|
||||
uLong version_needed; /* version needed to extract 2 bytes */
|
||||
uLong flag; /* general purpose bit flag 2 bytes */
|
||||
uLong compression_method; /* compression method 2 bytes */
|
||||
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
uLong crc; /* crc-32 4 bytes */
|
||||
uLong compressed_size; /* compressed size 4 bytes */
|
||||
uLong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uLong size_filename; /* filename length 2 bytes */
|
||||
uLong size_file_extra; /* extra field length 2 bytes */
|
||||
uLong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uLong disk_num_start; /* disk number start 2 bytes */
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
tm_unz tmu_date;
|
||||
} unz_file_info;
|
||||
|
||||
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
||||
const char* fileName2,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Compare two filename (fileName1,fileName2).
|
||||
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
||||
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
||||
or strcasecmp)
|
||||
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
||||
(like 1 on Unix, 2 on Windows)
|
||||
*/
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen OF((voidpf file));
|
||||
extern unzFile ZEXPORT unzOpen64 OF((voidpf file));
|
||||
/*
|
||||
Open a Zip file. path contain the full pathname (by example,
|
||||
on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
||||
"zlib/zlib113.zip".
|
||||
If the zipfile cannot be opened (file don't exist or in not valid), the
|
||||
return value is NULL.
|
||||
Else, the return value is a unzFile Handle, usable with other function
|
||||
of this unzip package.
|
||||
the "64" function take a const void* pointer, because the path is just the
|
||||
value passed to the open64_file_func callback.
|
||||
Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
|
||||
is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
|
||||
does not describe the reality
|
||||
*/
|
||||
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2 OF((voidpf file,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
/*
|
||||
Open a Zip file, like unzOpen, but provide a set of file low level API
|
||||
for read/write the zip file (see ioapi.h)
|
||||
*/
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2_64 OF((voidpf file,
|
||||
zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
/*
|
||||
Open a Zip file, like unz64Open, but provide a set of file low level API
|
||||
for read/write the zip file (see ioapi.h)
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Exported by Sergey A. Tachenov to implement some QuaZip features. This
|
||||
* function MAY change signature in order to implement even more features.
|
||||
* You have been warned!
|
||||
* */
|
||||
extern unzFile unzOpenInternal (voidpf file,
|
||||
zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
|
||||
int is64bitOpenFunction, unsigned flags);
|
||||
|
||||
|
||||
|
||||
extern int ZEXPORT unzClose OF((unzFile file));
|
||||
/*
|
||||
Close a ZipFile opened with unzipOpen.
|
||||
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
||||
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
||||
unz_global_info *pglobal_info));
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
|
||||
unz_global_info64 *pglobal_info));
|
||||
|
||||
extern int ZEXPORT unzGetFileFlags OF((unzFile file, unsigned* pflags));
|
||||
/*
|
||||
Write info about the ZipFile in the *pglobal_info structure.
|
||||
No preparation of the structure is needed
|
||||
return UNZ_OK if there is no problem. */
|
||||
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
||||
char *szComment,
|
||||
uLong uSizeBuf));
|
||||
/*
|
||||
Get the global comment string of the ZipFile, in the szComment buffer.
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
return the number of byte copied or an error code <0
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Unzip package allow you browse the directory of the zipfile */
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the first file.
|
||||
return UNZ_OK if there is no problem
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
||||
/*
|
||||
Set the current file of the zipfile to the next file.
|
||||
return UNZ_OK if there is no problem
|
||||
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzLocateFile OF((unzFile file,
|
||||
const char *szFileName,
|
||||
int iCaseSensitivity));
|
||||
/*
|
||||
Try locate the file szFileName in the zipfile.
|
||||
For the iCaseSensitivity signification, see unzStringFileNameCompare
|
||||
|
||||
return value :
|
||||
UNZ_OK if the file is found. It becomes the current file.
|
||||
UNZ_END_OF_LIST_OF_FILE if the file is not found
|
||||
*/
|
||||
|
||||
|
||||
/* ****************************************** */
|
||||
/* Ryan supplied functions */
|
||||
/* unz_file_info contain information about a file in the zipfile */
|
||||
typedef struct unz_file_pos_s
|
||||
{
|
||||
uLong pos_in_zip_directory; /* offset in zip file directory */
|
||||
uLong num_of_file; /* # of file */
|
||||
} unz_file_pos;
|
||||
|
||||
extern int ZEXPORT unzGetFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
extern int ZEXPORT unzGoToFilePos(
|
||||
unzFile file,
|
||||
unz_file_pos* file_pos);
|
||||
|
||||
typedef struct unz64_file_pos_s
|
||||
{
|
||||
ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
|
||||
ZPOS64_T num_of_file; /* # of file */
|
||||
} unz64_file_pos;
|
||||
|
||||
extern int ZEXPORT unzGetFilePos64(
|
||||
unzFile file,
|
||||
unz64_file_pos* file_pos);
|
||||
|
||||
extern int ZEXPORT unzGoToFilePos64(
|
||||
unzFile file,
|
||||
const unz64_file_pos* file_pos);
|
||||
|
||||
/* ****************************************** */
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
|
||||
unz_file_info64 *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
||||
unz_file_info *pfile_info,
|
||||
char *szFileName,
|
||||
uLong fileNameBufferSize,
|
||||
void *extraField,
|
||||
uLong extraFieldBufferSize,
|
||||
char *szComment,
|
||||
uLong commentBufferSize));
|
||||
/*
|
||||
Get Info about the current file
|
||||
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
||||
the current file
|
||||
if szFileName!=NULL, the filemane string will be copied in szFileName
|
||||
(fileNameBufferSize is the size of the buffer)
|
||||
if extraField!=NULL, the extra field information will be copied in extraField
|
||||
(extraFieldBufferSize is the size of the buffer).
|
||||
This is the Central-header version of the extra field
|
||||
if szComment!=NULL, the comment string of the file will be copied in szComment
|
||||
(commentBufferSize is the size of the buffer)
|
||||
*/
|
||||
|
||||
|
||||
/** Addition for GDAL : START */
|
||||
|
||||
extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
|
||||
|
||||
/** Addition for GDAL : END */
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* for reading the content of the current zipfile, you can open it, read data
|
||||
from it, and close it (you can close it before reading all the file)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
||||
const char* password));
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
password is a crypting password
|
||||
If there is no error, the return value is UNZ_OK.
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
||||
int* method,
|
||||
int* level,
|
||||
int raw,
|
||||
const char* password));
|
||||
/*
|
||||
Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
||||
if raw==1
|
||||
*method will receive method of compression, *level will receive level of
|
||||
compression
|
||||
note : you can set level parameter as NULL (if you did not want known level,
|
||||
but you CANNOT set method parameter as NULL
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
||||
/*
|
||||
Close the file in zip opened with unzOpenCurrentFile
|
||||
Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read bytes from the current file (opened by unzOpenCurrentFile)
|
||||
buf contain buffer where data must be copied
|
||||
len the size of buf.
|
||||
|
||||
return the number of byte copied if somes bytes are copied
|
||||
return 0 if the end of file was reached
|
||||
return <0 with error code if there is an error
|
||||
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
||||
*/
|
||||
|
||||
extern z_off_t ZEXPORT unztell OF((unzFile file));
|
||||
|
||||
extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
|
||||
/*
|
||||
Give the current position in uncompressed data
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzeof OF((unzFile file));
|
||||
/*
|
||||
return 1 if the end of file was reached, 0 elsewhere
|
||||
*/
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
||||
voidp buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Read extra field from the current file (opened by unzOpenCurrentFile)
|
||||
This is the local-header version of the extra field (sometimes, there is
|
||||
more info in the local-header version than in the central-header)
|
||||
|
||||
if buf==NULL, it return the size of the local extra field
|
||||
|
||||
if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
||||
buf.
|
||||
the return value is the number of bytes copied in buf, or (if <0)
|
||||
the error code
|
||||
*/
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* Get the current file offset */
|
||||
extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
|
||||
extern uLong ZEXPORT unzGetOffset (unzFile file);
|
||||
|
||||
/* Set the current file offset */
|
||||
extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
|
||||
extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
|
||||
|
||||
extern int ZEXPORT unzSetFlags(unzFile file, unsigned flags);
|
||||
extern int ZEXPORT unzClearFlags(unzFile file, unsigned flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _unz64_H */
|
|
@ -0,0 +1,391 @@
|
|||
/* zip.h -- IO on .zip files using zlib
|
||||
Version 1.1, February 14h, 2010
|
||||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
||||
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
|
||||
For more info read MiniZip_info.txt
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Condition of use and distribution are the same than zlib :
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Changes
|
||||
|
||||
See header of zip.h
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
As per the requirement above, this file is plainly marked as modified
|
||||
by Sergey A. Tachenov. Most modifications include the I/O API redesign
|
||||
to support QIODevice interface. Some improvements and small fixes were also made.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _zip12_H
|
||||
#define _zip12_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//#define HAVE_BZIP2
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIBIOAPI_H
|
||||
#include "ioapi.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
#include "bzlib.h"
|
||||
#endif
|
||||
|
||||
#define Z_BZIP2ED 12
|
||||
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagzipFile__ { int unused; } zipFile__;
|
||||
typedef zipFile__ *zipFile;
|
||||
#else
|
||||
typedef voidp zipFile;
|
||||
#endif
|
||||
|
||||
#define ZIP_OK (0)
|
||||
#define ZIP_EOF (0)
|
||||
#define ZIP_ERRNO (Z_ERRNO)
|
||||
#define ZIP_PARAMERROR (-102)
|
||||
#define ZIP_BADZIPFILE (-103)
|
||||
#define ZIP_INTERNALERROR (-104)
|
||||
|
||||
#define ZIP_WRITE_DATA_DESCRIPTOR 0x8u
|
||||
#define ZIP_AUTO_CLOSE 0x1u
|
||||
#define ZIP_SEQUENTIAL 0x2u
|
||||
#define ZIP_ENCODING_UTF8 0x0800u
|
||||
#define ZIP_DEFAULT_FLAGS (ZIP_AUTO_CLOSE | ZIP_WRITE_DATA_DESCRIPTOR)
|
||||
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
# else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
# endif
|
||||
#endif
|
||||
/* default memLevel */
|
||||
|
||||
/* tm_zip contain date/time info */
|
||||
typedef struct tm_zip_s
|
||||
{
|
||||
uInt tm_sec; /* seconds after the minute - [0,59] */
|
||||
uInt tm_min; /* minutes after the hour - [0,59] */
|
||||
uInt tm_hour; /* hours since midnight - [0,23] */
|
||||
uInt tm_mday; /* day of the month - [1,31] */
|
||||
uInt tm_mon; /* months since January - [0,11] */
|
||||
uInt tm_year; /* years - [1980..2044] */
|
||||
} tm_zip;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tm_zip tmz_date; /* date in understandable format */
|
||||
uLong dosDate; /* if dos_date == 0, tmu_date is used */
|
||||
/* uLong flag; */ /* general purpose bit flag 2 bytes */
|
||||
|
||||
uLong internal_fa; /* internal file attributes 2 bytes */
|
||||
uLong external_fa; /* external file attributes 4 bytes */
|
||||
} zip_fileinfo;
|
||||
|
||||
typedef const char* zipcharpc;
|
||||
|
||||
|
||||
#define APPEND_STATUS_CREATE (0)
|
||||
#define APPEND_STATUS_CREATEAFTER (1)
|
||||
#define APPEND_STATUS_ADDINZIP (2)
|
||||
|
||||
extern zipFile ZEXPORT zipOpen OF((voidpf file, int append));
|
||||
extern zipFile ZEXPORT zipOpen64 OF((voidpf file, int append));
|
||||
/*
|
||||
Create a zipfile.
|
||||
the file argument depends on the API used, for QuaZip it's a QIODevice
|
||||
pointer.
|
||||
if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
|
||||
will be created at the end of the file.
|
||||
(useful if the file contain a self extractor code)
|
||||
if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
|
||||
add files in existing zip (be sure you don't add file that doesn't exist)
|
||||
If the zipfile cannot be opened, the return value is NULL.
|
||||
Else, the return value is a zipFile Handle, usable with other function
|
||||
of this zip package.
|
||||
*/
|
||||
|
||||
/* Note : there is no delete function into a zipfile.
|
||||
If you want delete file into a zipfile, you must open a zipfile, and create another
|
||||
Of couse, you can use RAW reading and writing to copy the file you did not want delte
|
||||
*/
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2 OF((voidpf file,
|
||||
int append,
|
||||
zipcharpc* globalcomment,
|
||||
zlib_filefunc_def* pzlib_filefunc_def));
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2_64 OF((voidpf file,
|
||||
int append,
|
||||
zipcharpc* globalcomment,
|
||||
zlib_filefunc64_def* pzlib_filefunc_def));
|
||||
|
||||
/*
|
||||
* Exported by Sergey A. Tachenov to suit the needs of QuaZip.
|
||||
* Note that this function MAY change signature in order to
|
||||
* provide new QuaZip features. You have been warned!
|
||||
* */
|
||||
extern zipFile ZEXPORT zipOpen3 (voidpf file,
|
||||
int append,
|
||||
zipcharpc* globalcomment,
|
||||
zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
|
||||
unsigned flags);
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level));
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int zip64));
|
||||
|
||||
/*
|
||||
Open a file in the ZIP for writing.
|
||||
filename : the filename in zip (if NULL, '-' without quote will be used
|
||||
*zipfi contain supplemental information
|
||||
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
|
||||
contains the extrafield data the the local header
|
||||
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
|
||||
contains the extrafield data the the local header
|
||||
if comment != NULL, comment contain the comment string
|
||||
method contain the compression method (0 for store, Z_DEFLATED for deflate)
|
||||
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
|
||||
zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
|
||||
this MUST be '1' if the uncompressed size is >= 0xffffffff.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw));
|
||||
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int zip64));
|
||||
/*
|
||||
Same than zipOpenNewFileInZip, except if raw=1, we write raw file
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCrypting));
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCrypting,
|
||||
int zip64
|
||||
));
|
||||
|
||||
/*
|
||||
Same than zipOpenNewFileInZip2, except
|
||||
windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
|
||||
password : crypting password (NULL for no crypting)
|
||||
crcForCrypting : crc of file to compress (needed for crypting)
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCrypting,
|
||||
uLong versionMadeBy,
|
||||
uLong flagBase
|
||||
));
|
||||
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
|
||||
const char* filename,
|
||||
const zip_fileinfo* zipfi,
|
||||
const void* extrafield_local,
|
||||
uInt size_extrafield_local,
|
||||
const void* extrafield_global,
|
||||
uInt size_extrafield_global,
|
||||
const char* comment,
|
||||
int method,
|
||||
int level,
|
||||
int raw,
|
||||
int windowBits,
|
||||
int memLevel,
|
||||
int strategy,
|
||||
const char* password,
|
||||
uLong crcForCrypting,
|
||||
uLong versionMadeBy,
|
||||
uLong flagBase,
|
||||
int zip64
|
||||
));
|
||||
/*
|
||||
Same than zipOpenNewFileInZip4, except
|
||||
versionMadeBy : value for Version made by field
|
||||
flag : value for flag field (compression level info will be added)
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
|
||||
const void* buf,
|
||||
unsigned len));
|
||||
/*
|
||||
Write data in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
|
||||
/*
|
||||
Close the current file in the zipfile
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
|
||||
uLong uncompressed_size,
|
||||
uLong crc32));
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
|
||||
ZPOS64_T uncompressed_size,
|
||||
uLong crc32));
|
||||
|
||||
/*
|
||||
Close the current file in the zipfile, for file opened with
|
||||
parameter raw=1 in zipOpenNewFileInZip2
|
||||
uncompressed_size and crc32 are value for the uncompressed size
|
||||
*/
|
||||
|
||||
extern int ZEXPORT zipClose OF((zipFile file,
|
||||
const char* global_comment));
|
||||
/*
|
||||
Close the zipfile
|
||||
*/
|
||||
|
||||
|
||||
extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
|
||||
/*
|
||||
zipRemoveExtraInfoBlock - Added by Mathias Svensson
|
||||
|
||||
Remove extra information block from a extra information data for the local file header or central directory header
|
||||
|
||||
It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
|
||||
|
||||
0x0001 is the signature header for the ZIP64 extra information blocks
|
||||
|
||||
usage.
|
||||
Remove ZIP64 Extra information from a central director extra field data
|
||||
zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
|
||||
|
||||
Remove ZIP64 Extra information from a Local File Header extra field data
|
||||
zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
|
||||
*/
|
||||
|
||||
/*
|
||||
Added by Sergey A. Tachenov to tweak zipping behaviour.
|
||||
*/
|
||||
extern int ZEXPORT zipSetFlags(zipFile file, unsigned flags);
|
||||
extern int ZEXPORT zipClearFlags(zipFile file, unsigned flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _zip64_H */
|
|
@ -0,0 +1,37 @@
|
|||
project(qztest)
|
||||
|
||||
set(QZTEST_SOURCES
|
||||
qztest.h
|
||||
testjlcompress.h
|
||||
testquachecksum32.h
|
||||
testquagzipfile.h
|
||||
testquaziodevice.h
|
||||
testquazip.h
|
||||
testquazipdir.h
|
||||
testquazipfile.h
|
||||
testquazipfileinfo.h
|
||||
testquazipnewinfo.h
|
||||
qztest.cpp
|
||||
testjlcompress.cpp
|
||||
testquachecksum32.cpp
|
||||
testquagzipfile.cpp
|
||||
testquaziodevice.cpp
|
||||
testquazip.cpp
|
||||
testquazipdir.cpp
|
||||
testquazipfile.cpp
|
||||
testquazipfileinfo.cpp
|
||||
testquazipnewinfo.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${QZTEST_SOURCES} qztest.qrc)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES AUTORCC ON)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${QUAZIP_TEST_QT_LIBRARIES}
|
||||
QuaZip::QuaZip
|
||||
)
|
||||
|
||||
add_test(NAME qztest_test
|
||||
COMMAND qztest
|
||||
WORKING_DIRECTORY ${QUAZIP_BINARY_DIR}/quazip # preliminary hack to find the dll on windows
|
||||
)
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose DEPENDS qztest)
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip test suite.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "qztest.h"
|
||||
#include "testquazip.h"
|
||||
#include "testquazipfile.h"
|
||||
#include "testquachecksum32.h"
|
||||
#include "testjlcompress.h"
|
||||
#include "testquazipdir.h"
|
||||
#include "testquagzipfile.h"
|
||||
#include "testquaziodevice.h"
|
||||
#include "testquazipnewinfo.h"
|
||||
#include "testquazipfileinfo.h"
|
||||
|
||||
#include <quazip.h>
|
||||
#include <quazipfile.h>
|
||||
#include <quazip_qt_compat.h>
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QTextStream>
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
bool createTestFiles(const QStringList &fileNames, int size, const QString &dir)
|
||||
{
|
||||
QDir curDir;
|
||||
foreach (QString fileName, fileNames) {
|
||||
QString filePath = QDir(dir).filePath(fileName);
|
||||
QDir testDir = QFileInfo(filePath).dir();
|
||||
if (!testDir.exists()) {
|
||||
if (!curDir.mkpath(testDir.path())) {
|
||||
qWarning("Couldn't mkpath %s",
|
||||
testDir.path().toUtf8().constData());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (fileName.endsWith('/')) {
|
||||
if (!curDir.mkpath(filePath)) {
|
||||
qWarning("Couldn't mkpath %s",
|
||||
fileName.toUtf8().constData());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
QFile testFile(filePath);
|
||||
if (!testFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qWarning("Couldn't create %s",
|
||||
fileName.toUtf8().constData());
|
||||
return false;
|
||||
}
|
||||
if (size == -1) {
|
||||
QTextStream testStream(&testFile);
|
||||
testStream << "This is a test file named " << fileName << quazip_endl;
|
||||
} else {
|
||||
for (int i = 0; i < size; ++i) {
|
||||
testFile.putChar(static_cast<char>('0' + i % 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool createTestArchive(QuaZip &zip, const QString &zipName,
|
||||
const QStringList &fileNames,
|
||||
QTextCodec *codec,
|
||||
const QString &dir)
|
||||
{
|
||||
if (codec != NULL) {
|
||||
zip.setFileNameCodec(codec);
|
||||
}
|
||||
if (!zip.open(QuaZip::mdCreate)) {
|
||||
qWarning("Couldn't open %s", zipName.toUtf8().constData());
|
||||
return false;
|
||||
}
|
||||
int i = 0;
|
||||
QDateTime dt1;
|
||||
foreach (QString fileName, fileNames) {
|
||||
QuaZipFile zipFile(&zip);
|
||||
QString filePath = QDir(dir).filePath(fileName);
|
||||
QFileInfo fileInfo(filePath);
|
||||
QuaZipNewInfo newInfo(fileName, filePath);
|
||||
if (i == 0) // to test code that needs different timestamps
|
||||
newInfo.dateTime = newInfo.dateTime.addSecs(-60);
|
||||
else if (i == 1) // will use for the next file too
|
||||
dt1 = newInfo.dateTime;
|
||||
else if (i == 2) // to test identical timestamps
|
||||
newInfo.dateTime = dt1;
|
||||
if (!zipFile.open(QIODevice::WriteOnly,
|
||||
newInfo, NULL, 0,
|
||||
fileInfo.isDir() ? 0 : 8)) {
|
||||
qWarning("Couldn't open %s in %s", fileName.toUtf8()
|
||||
.constData(), zipName.toUtf8().constData());
|
||||
return false;
|
||||
}
|
||||
if (!fileInfo.isDir()) {
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qWarning("Couldn't open %s", filePath.toUtf8()
|
||||
.constData());
|
||||
return false;
|
||||
}
|
||||
while (!file.atEnd()) {
|
||||
char buf[4096];
|
||||
qint64 l = file.read(buf, 4096);
|
||||
if (l <= 0) {
|
||||
qWarning("Couldn't read %s", filePath.toUtf8()
|
||||
.constData());
|
||||
return false;
|
||||
}
|
||||
if (zipFile.write(buf, l) != l) {
|
||||
qWarning("Couldn't write to %s in %s",
|
||||
filePath.toUtf8().constData(),
|
||||
zipName.toUtf8().constData());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
zipFile.close();
|
||||
++i;
|
||||
}
|
||||
zip.setComment(QString("This is the test archive"));
|
||||
zip.close();
|
||||
if (zipName.startsWith("<")) { // something like "<QIODevice pointer>"
|
||||
return true;
|
||||
} else {
|
||||
return QFileInfo(zipName).exists();
|
||||
}
|
||||
}
|
||||
|
||||
bool createTestArchive(const QString &zipName,
|
||||
const QStringList &fileNames,
|
||||
const QString &dir) {
|
||||
return createTestArchive(zipName, fileNames, NULL, dir);
|
||||
}
|
||||
|
||||
bool createTestArchive(QIODevice *ioDevice,
|
||||
const QStringList &fileNames,
|
||||
QTextCodec *codec,
|
||||
const QString &dir)
|
||||
{
|
||||
QuaZip zip(ioDevice);
|
||||
return createTestArchive(zip, "<QIODevice pointer>", fileNames, codec, dir);
|
||||
}
|
||||
|
||||
bool createTestArchive(const QString &zipName,
|
||||
const QStringList &fileNames,
|
||||
QTextCodec *codec,
|
||||
const QString &dir) {
|
||||
QuaZip zip(zipName);
|
||||
return createTestArchive(zip, zipName, fileNames, codec, dir);
|
||||
}
|
||||
|
||||
void removeTestFiles(const QStringList &fileNames, const QString &dir)
|
||||
{
|
||||
QDir curDir;
|
||||
foreach (QString fileName, fileNames) {
|
||||
curDir.remove(QDir(dir).filePath(fileName));
|
||||
}
|
||||
foreach (QString fileName, fileNames) {
|
||||
QDir fileDir = QFileInfo(QDir(dir).filePath(fileName)).dir();
|
||||
if (fileDir.exists()) {
|
||||
// Non-empty dirs won't get removed, and that's good.
|
||||
curDir.rmpath(fileDir.path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
int err = 0;
|
||||
{
|
||||
TestQuaZip testQuaZip;
|
||||
err = qMax(err, QTest::qExec(&testQuaZip, app.arguments()));
|
||||
}
|
||||
{
|
||||
TestQuaZipFile testQuaZipFile;
|
||||
err = qMax(err, QTest::qExec(&testQuaZipFile, app.arguments()));
|
||||
}
|
||||
{
|
||||
TestQuaChecksum32 testQuaChecksum32;
|
||||
err = qMax(err, QTest::qExec(&testQuaChecksum32, app.arguments()));
|
||||
}
|
||||
{
|
||||
TestJlCompress testJlCompress;
|
||||
err = qMax(err, QTest::qExec(&testJlCompress, app.arguments()));
|
||||
}
|
||||
{
|
||||
TestQuaZipDir testQuaZipDir;
|
||||
err = qMax(err, QTest::qExec(&testQuaZipDir, app.arguments()));
|
||||
}
|
||||
{
|
||||
TestQuaZIODevice testQuaZIODevice;
|
||||
err = qMax(err, QTest::qExec(&testQuaZIODevice, app.arguments()));
|
||||
}
|
||||
{
|
||||
TestQuaGzipFile testQuaGzipFile;
|
||||
err = qMax(err, QTest::qExec(&testQuaGzipFile, app.arguments()));
|
||||
}
|
||||
{
|
||||
TestQuaZipNewInfo testQuaZipNewInfo;
|
||||
err = qMax(err, QTest::qExec(&testQuaZipNewInfo, app.arguments()));
|
||||
}
|
||||
{
|
||||
TestQuaZipFileInfo testQuaZipFileInfo;
|
||||
err = qMax(err, QTest::qExec(&testQuaZipFileInfo, app.arguments()));
|
||||
}
|
||||
if (err == 0) {
|
||||
qDebug("All tests executed successfully");
|
||||
} else {
|
||||
qWarning("There were errors in some of the tests above.");
|
||||
}
|
||||
return err;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
#ifndef QUAZIP_TEST_QZTEST_H
|
||||
#define QUAZIP_TEST_QZTEST_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip test suite.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
#include <quazip_qt_compat.h>
|
||||
|
||||
extern bool createTestFiles(const QStringList &fileNames,
|
||||
int size = -1,
|
||||
const QString &dir = "tmp");
|
||||
extern void removeTestFiles(const QStringList &fileNames, const QString
|
||||
&dir = "tmp");
|
||||
extern bool createTestArchive(const QString &zipName,
|
||||
const QStringList &fileNames,
|
||||
const QString &dir = "tmp");
|
||||
extern bool createTestArchive(const QString &zipName,
|
||||
const QStringList &fileNames,
|
||||
QTextCodec *codec,
|
||||
const QString &dir = "tmp");
|
||||
extern bool createTestArchive(QIODevice *ioDevice,
|
||||
const QStringList &fileNames,
|
||||
QTextCodec *codec,
|
||||
const QString &dir = "tmp");
|
||||
|
||||
#endif // QUAZIP_TEST_QZTEST_H
|
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>test_files/issue43_cant_get_dates.zip</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -0,0 +1,468 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip test suite.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "testjlcompress.h"
|
||||
|
||||
#include "qztest.h"
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <quazip_qt_compat.h>
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include <JlCompress.h>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
void TestJlCompress::compressFile_data()
|
||||
{
|
||||
QTest::addColumn<QString>("zipName");
|
||||
QTest::addColumn<QString>("fileName");
|
||||
QTest::newRow("simple") << "jlsimplefile.zip" << "test0.txt";
|
||||
}
|
||||
|
||||
void TestJlCompress::compressFile()
|
||||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QString, fileName);
|
||||
QDir curDir;
|
||||
if (curDir.exists(zipName)) {
|
||||
if (!curDir.remove(zipName))
|
||||
QFAIL("Can't remove zip file");
|
||||
}
|
||||
if (!createTestFiles(QStringList() << fileName)) {
|
||||
QFAIL("Can't create test file");
|
||||
}
|
||||
QVERIFY(JlCompress::compressFile(zipName, "tmp/" + fileName));
|
||||
// get the file list and check it
|
||||
QStringList fileList = JlCompress::getFileList(zipName);
|
||||
QCOMPARE(fileList.count(), 1);
|
||||
QVERIFY(fileList[0] == fileName);
|
||||
// now test the QIODevice* overload of getFileList()
|
||||
QFile zipFile(zipName);
|
||||
QVERIFY(zipFile.open(QIODevice::ReadOnly));
|
||||
fileList = JlCompress::getFileList(zipName);
|
||||
QCOMPARE(fileList.count(), 1);
|
||||
QVERIFY(fileList[0] == fileName);
|
||||
zipFile.close();
|
||||
removeTestFiles(QStringList() << fileName);
|
||||
curDir.remove(zipName);
|
||||
}
|
||||
|
||||
void TestJlCompress::compressFiles_data()
|
||||
{
|
||||
QTest::addColumn<QString>("zipName");
|
||||
QTest::addColumn<QStringList>("fileNames");
|
||||
QTest::newRow("simple") << "jlsimplefiles.zip" <<
|
||||
(QStringList() << "test0.txt" << "test00.txt");
|
||||
QTest::newRow("different subdirs") << "jlsubdirfiles.zip" <<
|
||||
(QStringList() << "subdir1/test1.txt" << "subdir2/test2.txt");
|
||||
}
|
||||
|
||||
void TestJlCompress::compressFiles()
|
||||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QStringList, fileNames);
|
||||
QDir curDir;
|
||||
if (curDir.exists(zipName)) {
|
||||
if (!curDir.remove(zipName))
|
||||
QFAIL("Can't remove zip file");
|
||||
}
|
||||
if (!createTestFiles(fileNames)) {
|
||||
QFAIL("Can't create test files");
|
||||
}
|
||||
QStringList realNamesList, shortNamesList;
|
||||
foreach (QString fileName, fileNames) {
|
||||
QString realName = "tmp/" + fileName;
|
||||
realNamesList += realName;
|
||||
shortNamesList += QFileInfo(realName).fileName();
|
||||
}
|
||||
QVERIFY(JlCompress::compressFiles(zipName, realNamesList));
|
||||
// get the file list and check it
|
||||
QStringList fileList = JlCompress::getFileList(zipName);
|
||||
QCOMPARE(fileList, shortNamesList);
|
||||
removeTestFiles(fileNames);
|
||||
curDir.remove(zipName);
|
||||
}
|
||||
|
||||
void TestJlCompress::compressDir_data()
|
||||
{
|
||||
QTest::addColumn<QString>("zipName");
|
||||
QTest::addColumn<QStringList>("fileNames");
|
||||
QTest::addColumn<QStringList>("expected");
|
||||
QTest::newRow("simple") << "jldir.zip"
|
||||
<< (QStringList() << "test0.txt" << "testdir1/test1.txt"
|
||||
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt")
|
||||
<< (QStringList() << "test0.txt"
|
||||
<< "testdir1/" << "testdir1/test1.txt"
|
||||
<< "testdir2/" << "testdir2/test2.txt"
|
||||
<< "testdir2/subdir/" << "testdir2/subdir/test2sub.txt");
|
||||
QTest::newRow("empty dirs") << "jldir_empty.zip"
|
||||
<< (QStringList() << "testdir1/" << "testdir2/testdir3/")
|
||||
<< (QStringList() << "testdir1/" << "testdir2/"
|
||||
<< "testdir2/testdir3/");
|
||||
QTest::newRow("hidden files") << "jldir_hidden.zip"
|
||||
<< (QStringList() << ".test0.txt" << "test1.txt")
|
||||
<< (QStringList() << ".test0.txt" << "test1.txt");
|
||||
}
|
||||
|
||||
void TestJlCompress::compressDir()
|
||||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QStringList, fileNames);
|
||||
QFETCH(QStringList, expected);
|
||||
QDir curDir;
|
||||
if (curDir.exists(zipName)) {
|
||||
if (!curDir.remove(zipName))
|
||||
QFAIL("Can't remove zip file");
|
||||
}
|
||||
if (!createTestFiles(fileNames, -1, "compressDir_tmp")) {
|
||||
QFAIL("Can't create test files");
|
||||
}
|
||||
#ifdef Q_OS_WIN
|
||||
for (int i = 0; i < fileNames.size(); ++i) {
|
||||
if (fileNames.at(i).startsWith(".")) {
|
||||
QString fn = "compressDir_tmp\\" + fileNames.at(i);
|
||||
SetFileAttributesW(reinterpret_cast<LPCWSTR>(fn.utf16()),
|
||||
FILE_ATTRIBUTE_HIDDEN);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
QVERIFY(JlCompress::compressDir(zipName, "compressDir_tmp", true, QDir::Hidden));
|
||||
// get the file list and check it
|
||||
QStringList fileList = JlCompress::getFileList(zipName);
|
||||
fileList.sort();
|
||||
expected.sort();
|
||||
QCOMPARE(fileList, expected);
|
||||
removeTestFiles(fileNames, "compressDir_tmp");
|
||||
curDir.remove(zipName);
|
||||
}
|
||||
|
||||
void TestJlCompress::extractFile_data()
|
||||
{
|
||||
QTest::addColumn<QString>("zipName");
|
||||
QTest::addColumn<QStringList>("fileNames");
|
||||
QTest::addColumn<QString>("fileToExtract");
|
||||
QTest::addColumn<QString>("destName");
|
||||
QTest::addColumn<QByteArray>("encoding");
|
||||
QTest::newRow("simple") << "jlextfile.zip" << (
|
||||
QStringList() << "test0.txt" << "testdir1/test1.txt"
|
||||
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt")
|
||||
<< "testdir2/test2.txt" << "test2.txt" << QByteArray();
|
||||
QTest::newRow("russian") << "jlextfilerus.zip" << (
|
||||
QStringList() << "test0.txt" << "testdir1/test1.txt"
|
||||
<< QString::fromUtf8("testdir2/тест2.txt")
|
||||
<< "testdir2/subdir/test2sub.txt")
|
||||
<< QString::fromUtf8("testdir2/тест2.txt")
|
||||
<< QString::fromUtf8("тест2.txt") << QByteArray("IBM866");
|
||||
QTest::newRow("extract dir") << "jlextdir.zip" << (
|
||||
QStringList() << "testdir1/")
|
||||
<< "testdir1/" << "testdir1/" << QByteArray();
|
||||
}
|
||||
|
||||
void TestJlCompress::extractFile()
|
||||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QStringList, fileNames);
|
||||
QFETCH(QString, fileToExtract);
|
||||
QFETCH(QString, destName);
|
||||
QFETCH(QByteArray, encoding);
|
||||
QDir curDir;
|
||||
if (!curDir.mkpath("jlext/jlfile")) {
|
||||
QFAIL("Couldn't mkpath jlext/jlfile");
|
||||
}
|
||||
if (!createTestFiles(fileNames)) {
|
||||
QFAIL("Couldn't create test files");
|
||||
}
|
||||
QFile srcFile("tmp/" + fileToExtract);
|
||||
QFile::Permissions srcPerm = srcFile.permissions();
|
||||
// Invert the "write other" flag so permissions
|
||||
// are NOT default any more. Otherwise it's impossible
|
||||
// to figure out whether the permissions were set correctly
|
||||
// or JlCompress failed to set them completely,
|
||||
// thus leaving them at the default setting.
|
||||
srcPerm ^= QFile::WriteOther;
|
||||
QVERIFY(srcFile.setPermissions(srcPerm));
|
||||
if (!createTestArchive(zipName, fileNames,
|
||||
QTextCodec::codecForName(encoding))) {
|
||||
QFAIL("Can't create test archive");
|
||||
}
|
||||
QuaZip::setDefaultFileNameCodec(encoding);
|
||||
QVERIFY(!JlCompress::extractFile(zipName, fileToExtract,
|
||||
"jlext/jlfile/" + destName).isEmpty());
|
||||
QFileInfo destInfo("jlext/jlfile/" + destName), srcInfo("tmp/" +
|
||||
fileToExtract);
|
||||
QCOMPARE(destInfo.size(), srcInfo.size());
|
||||
QCOMPARE(destInfo.permissions(), srcInfo.permissions());
|
||||
curDir.remove("jlext/jlfile/" + destName);
|
||||
// now test the QIODevice* overload
|
||||
QFile zipFile(zipName);
|
||||
QVERIFY(zipFile.open(QIODevice::ReadOnly));
|
||||
QVERIFY(!JlCompress::extractFile(&zipFile, fileToExtract,
|
||||
"jlext/jlfile/" + destName).isEmpty());
|
||||
destInfo = QFileInfo("jlext/jlfile/" + destName);
|
||||
QCOMPARE(destInfo.size(), srcInfo.size());
|
||||
QCOMPARE(destInfo.permissions(), srcInfo.permissions());
|
||||
curDir.remove("jlext/jlfile/" + destName);
|
||||
if (!fileToExtract.endsWith("/")) {
|
||||
// If we aren't extracting a directory, we need to check
|
||||
// that extractFile() fails if there is a directory
|
||||
// with the same name as the file being extracted.
|
||||
curDir.mkdir("jlext/jlfile/" + destName);
|
||||
QVERIFY(JlCompress::extractFile(zipName, fileToExtract,
|
||||
"jlext/jlfile/" + destName).isEmpty());
|
||||
}
|
||||
zipFile.close();
|
||||
// Here we either delete the target dir or the dir created in the
|
||||
// test above.
|
||||
curDir.rmpath("jlext/jlfile/" + destName);
|
||||
removeTestFiles(fileNames);
|
||||
curDir.remove(zipName);
|
||||
}
|
||||
|
||||
void TestJlCompress::extractFiles_data()
|
||||
{
|
||||
QTest::addColumn<QString>("zipName");
|
||||
QTest::addColumn<QStringList>("fileNames");
|
||||
QTest::addColumn<QStringList>("filesToExtract");
|
||||
QTest::newRow("simple") << "jlextfiles.zip" << (
|
||||
QStringList() << "test0.txt" << "testdir1/test1.txt"
|
||||
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt")
|
||||
<< (QStringList() << "testdir2/test2.txt" << "testdir1/test1.txt");
|
||||
}
|
||||
|
||||
void TestJlCompress::extractFiles()
|
||||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QStringList, fileNames);
|
||||
QFETCH(QStringList, filesToExtract);
|
||||
QDir curDir;
|
||||
if (!curDir.mkpath("jlext/jlfiles")) {
|
||||
QFAIL("Couldn't mkpath jlext/jlfiles");
|
||||
}
|
||||
if (!createTestFiles(fileNames)) {
|
||||
QFAIL("Couldn't create test files");
|
||||
}
|
||||
if (!JlCompress::compressDir(zipName, "tmp")) {
|
||||
QFAIL("Couldn't create test archive");
|
||||
}
|
||||
QVERIFY(!JlCompress::extractFiles(zipName, filesToExtract,
|
||||
"jlext/jlfiles").isEmpty());
|
||||
foreach (QString fileName, filesToExtract) {
|
||||
QFileInfo fileInfo("jlext/jlfiles/" + fileName);
|
||||
QFileInfo extInfo("tmp/" + fileName);
|
||||
QCOMPARE(fileInfo.size(), extInfo.size());
|
||||
QCOMPARE(fileInfo.permissions(), extInfo.permissions());
|
||||
curDir.remove("jlext/jlfiles/" + fileName);
|
||||
curDir.rmpath(fileInfo.dir().path());
|
||||
}
|
||||
// now test the QIODevice* overload
|
||||
QFile zipFile(zipName);
|
||||
QVERIFY(zipFile.open(QIODevice::ReadOnly));
|
||||
QVERIFY(!JlCompress::extractFiles(&zipFile, filesToExtract,
|
||||
"jlext/jlfiles").isEmpty());
|
||||
foreach (QString fileName, filesToExtract) {
|
||||
QFileInfo fileInfo("jlext/jlfiles/" + fileName);
|
||||
QFileInfo extInfo("tmp/" + fileName);
|
||||
QCOMPARE(fileInfo.size(), extInfo.size());
|
||||
QCOMPARE(fileInfo.permissions(), extInfo.permissions());
|
||||
curDir.remove("jlext/jlfiles/" + fileName);
|
||||
curDir.rmpath(fileInfo.dir().path());
|
||||
}
|
||||
zipFile.close();
|
||||
curDir.rmpath("jlext/jlfiles");
|
||||
removeTestFiles(fileNames);
|
||||
curDir.remove(zipName);
|
||||
}
|
||||
|
||||
void TestJlCompress::extractDir_data()
|
||||
{
|
||||
QTest::addColumn<QString>("zipName");
|
||||
QTest::addColumn<QStringList>("fileNames");
|
||||
QTest::addColumn<QStringList>("expectedExtracted");
|
||||
QTest::addColumn<QByteArray>("fileNameCodecName");
|
||||
QTest::newRow("simple") << "jlextdir.zip"
|
||||
<< (QStringList() << "test0.txt" << "testdir1/test1.txt"
|
||||
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt")
|
||||
<< (QStringList() << "test0.txt" << "testdir1/test1.txt"
|
||||
<< "testdir2/test2.txt" << "testdir2/subdir/test2sub.txt")
|
||||
<< QByteArray();
|
||||
QTest::newRow("separate dir") << "sepdir.zip"
|
||||
<< (QStringList() << "laj/" << "laj/lajfile.txt")
|
||||
<< (QStringList() << "laj/" << "laj/lajfile.txt")
|
||||
<< QByteArray();
|
||||
QTest::newRow("Zip Slip") << "zipslip.zip"
|
||||
<< (QStringList() << "test0.txt" << "../zipslip.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()
|
||||
{
|
||||
QFETCH(QString, zipName);
|
||||
QFETCH(QStringList, fileNames);
|
||||
QFETCH(QStringList, expectedExtracted);
|
||||
QFETCH(QByteArray, fileNameCodecName);
|
||||
QTextCodec *fileNameCodec = NULL;
|
||||
if (!fileNameCodecName.isEmpty())
|
||||
fileNameCodec = QTextCodec::codecForName(fileNameCodecName);
|
||||
QDir curDir;
|
||||
if (!curDir.mkpath("jlext/jldir")) {
|
||||
QFAIL("Couldn't mkpath jlext/jldir");
|
||||
}
|
||||
if (!createTestFiles(fileNames)) {
|
||||
QFAIL("Couldn't create test files");
|
||||
}
|
||||
if (!createTestArchive(zipName, fileNames, fileNameCodec)) {
|
||||
QFAIL("Couldn't create test archive");
|
||||
}
|
||||
QStringList extracted;
|
||||
if (fileNameCodec == NULL)
|
||||
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/";
|
||||
foreach (QString fileName, expectedExtracted) {
|
||||
QString fullName = dir + fileName;
|
||||
QFileInfo fileInfo(fullName);
|
||||
QFileInfo extInfo("tmp/" + fileName);
|
||||
if (!fileInfo.isDir())
|
||||
QCOMPARE(fileInfo.size(), extInfo.size());
|
||||
QCOMPARE(fileInfo.permissions(), extInfo.permissions());
|
||||
curDir.remove(fullName);
|
||||
curDir.rmpath(fileInfo.dir().path());
|
||||
QString absolutePath = QDir(dir).absoluteFilePath(fileName);
|
||||
if (fileInfo.isDir() && !absolutePath.endsWith('/'))
|
||||
absolutePath += '/';
|
||||
QVERIFY(extracted.contains(absolutePath));
|
||||
}
|
||||
// now test the QIODevice* overload
|
||||
QFile zipFile(zipName);
|
||||
QVERIFY(zipFile.open(QIODevice::ReadOnly));
|
||||
if (fileNameCodec == NULL)
|
||||
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) {
|
||||
QString fullName = dir + fileName;
|
||||
QFileInfo fileInfo(fullName);
|
||||
QFileInfo extInfo("tmp/" + fileName);
|
||||
if (!fileInfo.isDir())
|
||||
QCOMPARE(fileInfo.size(), extInfo.size());
|
||||
QCOMPARE(fileInfo.permissions(), extInfo.permissions());
|
||||
curDir.remove(fullName);
|
||||
curDir.rmpath(fileInfo.dir().path());
|
||||
QString absolutePath = QDir(dir).absoluteFilePath(fileName);
|
||||
if (fileInfo.isDir() && !absolutePath.endsWith('/'))
|
||||
absolutePath += '/';
|
||||
QVERIFY(extracted.contains(absolutePath));
|
||||
}
|
||||
zipFile.close();
|
||||
curDir.rmpath("jlext/jldir");
|
||||
removeTestFiles(fileNames);
|
||||
curDir.remove(zipName);
|
||||
}
|
||||
|
||||
void TestJlCompress::zeroPermissions()
|
||||
{
|
||||
QuaZip zipCreator("zero.zip");
|
||||
QVERIFY(zipCreator.open(QuaZip::mdCreate));
|
||||
QuaZipFile zeroFile(&zipCreator);
|
||||
QuaZipNewInfo newInfo("zero.txt");
|
||||
newInfo.externalAttr = 0; // should be zero anyway, but just in case
|
||||
QVERIFY(zeroFile.open(QIODevice::WriteOnly, newInfo));
|
||||
zeroFile.close();
|
||||
zipCreator.close();
|
||||
QVERIFY(!JlCompress::extractFile("zero.zip", "zero.txt").isEmpty());
|
||||
QVERIFY(QFile("zero.txt").permissions() != 0);
|
||||
QDir curDir;
|
||||
curDir.remove("zero.zip");
|
||||
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
|
|
@ -0,0 +1,62 @@
|
|||
#ifndef QUAZIP_TEST_JLCOMPRESS_H
|
||||
#define QUAZIP_TEST_JLCOMPRESS_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip test suite.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#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 {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void compressFile_data();
|
||||
void compressFile();
|
||||
void compressFiles_data();
|
||||
void compressFiles();
|
||||
void compressDir_data();
|
||||
void compressDir();
|
||||
void extractFile_data();
|
||||
void extractFile();
|
||||
void extractFiles_data();
|
||||
void extractFiles();
|
||||
void extractDir_data();
|
||||
void extractDir();
|
||||
void zeroPermissions();
|
||||
#ifdef QUAZIP_SYMLINK_TEST
|
||||
void symlinkHandling();
|
||||
#endif
|
||||
#ifdef QUAZIP_SYMLINK_EXTRACTION_ON_WINDOWS_TEST
|
||||
void symlinkExtractionOnWindows();
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // QUAZIP_TEST_JLCOMPRESS_H
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip test suite.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include "testquachecksum32.h"
|
||||
|
||||
#include <quaadler32.h>
|
||||
#include <quacrc32.h>
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
void TestQuaChecksum32::calculate()
|
||||
{
|
||||
QuaCrc32 crc32;
|
||||
QCOMPARE(crc32.calculate("Wikipedia"), 0xADAAC02Eu);
|
||||
QuaAdler32 adler32;
|
||||
QCOMPARE(adler32.calculate("Wikipedia"), 0x11E60398u);
|
||||
}
|
||||
|
||||
void TestQuaChecksum32::update()
|
||||
{
|
||||
QuaCrc32 crc32;
|
||||
crc32.update("Wiki");
|
||||
crc32.update("pedia");
|
||||
QCOMPARE(crc32.value(), 0xADAAC02Eu);
|
||||
QuaAdler32 adler32;
|
||||
adler32.update("Wiki");
|
||||
adler32.update("pedia");
|
||||
QCOMPARE(adler32.value(), 0x11E60398u);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef QUAZIP_TEST_QUACHECKSUM32_H
|
||||
#define QUAZIP_TEST_QUACHECKSUM32_H
|
||||
|
||||
/*
|
||||
Copyright (C) 2005-2014 Sergey A. Tachenov
|
||||
|
||||
This file is part of QuaZip test suite.
|
||||
|
||||
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
|
||||
the Free Software Foundation, either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QuaZip is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with QuaZip. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
See COPYING file for the full LGPL text.
|
||||
|
||||
Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
||||
see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
||||
*/
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
class TestQuaChecksum32: public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void calculate();
|
||||
void update();
|
||||
};
|
||||
|
||||
#endif // QUAZIP_TEST_QUACHECKSUM32_H
|