| 1 | #cxx . . $ `<file>/quazip/quazip_qt_compat.h`/ifndef QUAZIP_QT_COMPAT_H |
| 2 | #define QUAZIP_QT_COMPAT_Hcxx . . $ `quazip/quazip_qt_compat.h:2:9`! |
| 3 | |
| 4 | /* |
| 5 | * For some reason, Qt 5.14 and 5.15 introduced a whole mess of seemingly random |
| 6 | * moves and deprecations. To avoid populating code with #ifs, |
| 7 | * we handle this stuff here, as well as some other compatibility issues. |
| 8 | * |
| 9 | * Some includes are repeated just in case we want to split this file later. |
| 10 | */ |
| 11 | |
| 12 | #include <QtCore/Qt> |
| 13 | #include <QtCore/QtGlobal> |
| 14 | |
| 15 | #include "quazip_textcodec.h"cxx . . $ `<file>/quazip/quazip_textcodec.h`/ |
| 16 | |
| 17 | // QSaveFile terribly breaks the is-a idiom (Liskov substitution principle): |
| 18 | // QSaveFile is-a QIODevice, but it makes close() private and aborts |
| 19 | // if you call it through the base class. Hence this ugly hack: |
| 20 | #if (QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= 0x050100) |
| 21 | #include <QtCore/QSaveFile> |
| 22 | inline bool quazip_closecxx . . $ quazip_close(33ee36428ee918e7).(QIODevicecxx . . $ QIODevice# *device) { |
| 23 | QSaveFilecxx . . $ QSaveFile# *file = qobject_castcxx . . $ qobject_cast(c988cfc0ca08742e).<QSaveFilecxx . . $ QSaveFile#*>(device); |
| 24 | if (file != nullptr) { |
| 25 | // We have to call the ugly commit() instead: |
| 26 | return file->commitcxx . . $ QSaveFile#commit(c9857a73d68e59ba).(); |
| 27 | } |
| 28 | device->closecxx . . $ QIODevice#close(49f6e7a06ebc5aa8).(); |
| 29 | return true; |
| 30 | } |
| 31 | #else |
| 32 | inline bool quazip_close(QIODevice *device) { |
| 33 | device->close(); |
| 34 | return true; |
| 35 | } |
| 36 | #endif |
| 37 | |
| 38 | // this is yet another stupid move and deprecation |
| 39 | #if QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(5, 15, 0) |
| 40 | using Qtcxx . . $ Qt/::SkipEmptyPartscxx . . $ Qt/SkipEmptyParts.; |
| 41 | #else |
| 42 | #include <QtCore/QString> |
| 43 | const auto SkipEmptyParts = QString::SplitBehavior::SkipEmptyParts; |
| 44 | #endif |
| 45 | |
| 46 | // and yet another... (why didn't they just make qSort delegate to std::sort?) |
| 47 | #include <QtCore/QList> |
| 48 | #if (QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(5, 2, 0)) |
| 49 | #include <algorithm> |
| 50 | template<typename T, typename C> |
| 51 | inline void quazip_sortcxx . . $ quazip_sort(4d3091562df4e52e).(T begin, T end, C comparator) { |
| 52 | stdcxx . . $ std/::sortcxx . . $ std/sort(360855cc766c4ee5).(begin, end, comparator); |
| 53 | } |
| 54 | #else |
| 55 | #include <QtCore/QtAlgorithms> |
| 56 | template<typename T, typename C> |
| 57 | inline void quazip_sort(T begin, T end, C comparator) { |
| 58 | qSort(begin, end, comparator); |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | // this is a stupid rename... |
| 63 | #include <QtCore/QDateTime> |
| 64 | #include <QtCore/QFileInfo> |
| 65 | #if (QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(5, 10, 0)) |
| 66 | inline QDateTimecxx . . $ QDateTime# quazip_ctimecxx . . $ quazip_ctime(b660c26f576c0856).(const QFileInfocxx . . $ QFileInfo# &fi) { |
| 67 | return fi.birthTimecxx . . $ QFileInfo#birthTime(4e062b5c490497ac).(); |
| 68 | } |
| 69 | #else |
| 70 | inline QDateTime quazip_ctime(const QFileInfo &fi) { |
| 71 | return fi.created(); |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | // this is just a slightly better alternative |
| 76 | #include <QtCore/QFileInfo> |
| 77 | #if (QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(5, 14, 0)) |
| 78 | inline bool quazip_is_symlinkcxx . . $ quazip_is_symlink(106f46682d8d3287).(const QFileInfocxx . . $ QFileInfo# &fi) { |
| 79 | return fi.isSymbolicLinkcxx . . $ QFileInfo#isSymbolicLink(50ce9a9e25b4a850).(); |
| 80 | } |
| 81 | #else |
| 82 | inline bool quazip_is_symlink(const QFileInfo &fi) { |
| 83 | // also detects *.lnk on Windows, but better than nothing |
| 84 | return fi.isSymLink(); |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | // I'm not even sure what this one is, but nevertheless |
| 89 | #include <QtCore/QFileInfo> |
| 90 | #if (QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(5, 13, 0)) |
| 91 | inline QStringcxx . . $ QString# quazip_symlink_targetcxx . . $ quazip_symlink_target(6f04f200038b0b29).(const QFileInfocxx . . $ QFileInfo# &fi) { |
| 92 | return fi.symLinkTargetcxx . . $ QFileInfo#symLinkTarget(6ef7b6c27b00b43d).(); |
| 93 | } |
| 94 | #else |
| 95 | inline QString quazip_symlink_target(const QFileInfo &fi) { |
| 96 | return fi.readLink(); // What's the difference? I've no idea. |
| 97 | } |
| 98 | #endif |
| 99 | |
| 100 | // deprecation |
| 101 | #if QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(6, 8, 0) |
| 102 | #include <QtCore/QTimeZone> |
| 103 | inline QDateTimecxx . . $ QDateTime# quazip_since_epochcxx . . $ quazip_since_epoch(bf5129c8228c71c0).() { |
| 104 | return QDateTimecxx . . $ QDateTime#QDateTime(e11b09ee18775ac9).(QDatecxx . . $ QDate#QDate(b1146eedae1e1d0b).(1970, 1, 1), QTimecxx . . $ QTime#QTime(748afa4755bc9595).(0, 0), QTimeZonecxx . . $ QTimeZone#QTimeZone(f92520015aedd0f5).::UTCcxx . . $ QTimeZone#UTC.); |
| 105 | } |
| 106 | |
| 107 | inline QDateTimecxx . . $ QDateTime# quazip_since_epoch_ntfscxx . . $ quazip_since_epoch_ntfs(bf5129c8228c71c0).() { |
| 108 | return QDateTimecxx . . $ QDateTime#QDateTime(e11b09ee18775ac9).(QDatecxx . . $ QDate#QDate(b1146eedae1e1d0b).(1601, 1, 1), QTimecxx . . $ QTime#QTime(748afa4755bc9595).(0, 0), QTimeZonecxx . . $ QTimeZone#QTimeZone(f92520015aedd0f5).::UTCcxx . . $ QTimeZone#UTC.); |
| 109 | } |
| 110 | #else |
| 111 | inline QDateTime quazip_since_epoch() { |
| 112 | return QDateTime(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC); |
| 113 | } |
| 114 | |
| 115 | inline QDateTime quazip_since_epoch_ntfs() { |
| 116 | return QDateTime(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | // this is not a deprecation but an improvement, for a change |
| 121 | #include <QtCore/QDateTime> |
| 122 | #if (QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= 0x040700) |
| 123 | inline quint64cxx . . $ quint64# quazip_ntfs_tickscxx . . $ quazip_ntfs_ticks(9488bf55a16fb73f).(const QDateTimecxx . . $ QDateTime# &time, int fineTicks) { |
| 124 | QDateTimecxx . . $ QDateTime# base = quazip_since_epoch_ntfscxx . . $ quazip_since_epoch_ntfs(bf5129c8228c71c0).(); |
| 125 | return base.msecsTocxx . . $ QDateTime#msecsTo(a9fc96cd501c18ab).(time) * 10000 + fineTicks; |
| 126 | } |
| 127 | #else |
| 128 | inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) { |
| 129 | QDateTime base = quazip_since_epoch_ntfs(); |
| 130 | QDateTime utc = time.toUTC(); |
| 131 | return (static_cast<qint64>(base.date().daysTo(utc.date())) |
| 132 | * Q_INT64_C(86400000) |
| 133 | + static_cast<qint64>(base.time().msecsTo(utc.time()))) |
| 134 | * Q_INT64_C(10000) + fineTicks; |
| 135 | } |
| 136 | #endif |
| 137 | |
| 138 | // yet another improvement... |
| 139 | #include <QtCore/QDateTime> |
| 140 | #if QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(5, 8, 0) // Yay! Finally a way to get time as qint64! |
| 141 | inline qint64cxx . . $ qint64# quazip_to_time64_tcxx . . $ quazip_to_time64_t(4e97e3d45f8081eb).(const QDateTimecxx . . $ QDateTime# &time) { |
| 142 | return time.toSecsSinceEpochcxx . . $ QDateTime#toSecsSinceEpoch(98833e9ab7de59a4).(); |
| 143 | } |
| 144 | #else |
| 145 | inline qint64 quazip_to_time64_t(const QDateTime &time) { |
| 146 | return static_cast<qint64>(time.toTime_t()); // 32 bits only, but better than nothing |
| 147 | } |
| 148 | #endif |
| 149 | |
| 150 | #include <QtCore/QTextStream> |
| 151 | // and another stupid move |
| 152 | #if QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(5, 15, 0) |
| 153 | const auto quazip_endlcxx . . $ quazip_endl. = Qtcxx . . $ Qt/::endlcxx . . $ Qt/endl(e06208c9acdf85a).; |
| 154 | #else |
| 155 | const auto quazip_endl = endl; |
| 156 | #endif |
| 157 | |
| 158 | // We want to support Qt5, Qt6 up to 6.5 and Qt 6.5+ compiled without timezone feature. |
| 159 | #if QT_CONFIGcxx . . $ `<external>/7770798561591309169/qtconfigmacros.h:67:9`!(timezone) |
| 160 | #include <QTimeZone> |
| 161 | |
| 162 | #if QT_VERSIONcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:17:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/3898848398875472725/qtversionchecks.h:21:9`!(6, 5, 0) |
| 163 | // Qt 6.5+ has QTimeZone::UTC |
| 164 | #define COMPAT_UTC_TZcxx . . $ `quazip/quazip_qt_compat.h:164:9`! QTimeZone(QTimeZone::UTC) |
| 165 | #else |
| 166 | // Qt 5.x and Qt 6.0–6.4 use utc() |
| 167 | #define COMPAT_UTC_TZ QTimeZone::utc() |
| 168 | #endif |
| 169 | |
| 170 | #else // timezone feature disabled |
| 171 | #include <QtCore/Qt> |
| 172 | |
| 173 | #define COMPAT_UTC_TZ Qt::UTC |
| 174 | |
| 175 | #endif |
| 176 | |
| 177 | #endif // QUAZIP_QT_COMPAT_H |