From 14d84907a09f1216dc067721b806434787291e4c Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Thu, 19 Feb 2026 13:43:36 +0300 Subject: ark: autodetect date order unzip-6 can be configured at build time to return date in several different fromats. There is no easy way to query unzip itself which one it uses, but in the wild only to formats were seen: MM-DD-YYYY (default for *nix) and YYYY-MM-DD (some linux distros; e.g. debian). So we will be guestimating before those two. Generic Arch class is not flexible enough, so it was necessary to override whole processLine() and parse everything with RegExes. Closes: https://mirror.git.trinitydesktop.org/gitea/TDE/tdeutils/issues/115 See-also: https://mirror.git.trinitydesktop.org/gitea/TDE/tdeutils/pulls/102 Signed-off-by: Alexander Golubev --- ark/zip.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 17 deletions(-) (limited to 'ark/zip.cpp') diff --git a/ark/zip.cpp b/ark/zip.cpp index 598f5fd..b95c7d5 100644 --- a/ark/zip.cpp +++ b/ark/zip.cpp @@ -28,6 +28,7 @@ // TQt includes #include +#include // KDE includes #include @@ -41,6 +42,7 @@ #include "zip.h" #include "arkwidget.h" #include "settings.h" +#include "filelistview.h" ZipArch::ZipArch( ArkWidget *_gui, const TQString & _fileName ) @@ -52,24 +54,7 @@ ZipArch::ZipArch( ArkWidget *_gui, const TQString & _fileName ) verifyUncompressUtilityIsAvailable( m_unarchiver_program ); m_headerString = "----"; - m_fixYear = 7; - m_fixMonth = 8; - m_fixDay = 9; - m_fixTime = 10; - m_dateCol = 5; m_numCols = 7; - - m_archCols.append( new ArchColumns( 1, TQRegExp( "[0-9]+" ) ) ); - m_archCols.append( new ArchColumns( 2, TQRegExp( "[^\\s]+" ) ) ); - m_archCols.append( new ArchColumns( 3, TQRegExp( "[0-9]+" ) ) ); - m_archCols.append( new ArchColumns( 4, TQRegExp( "[0-9.]+%" ) ) ); - m_archCols.append( new ArchColumns( 7, TQRegExp( "[0-9]{4}" ), 4 ) ); - m_archCols.append( new ArchColumns( 8, TQRegExp( "[01][0-9]" ), 2 ) ); - m_archCols.append( new ArchColumns( 9, TQRegExp( "[0-3][0-9]" ), 2 ) ); - m_archCols.append( new ArchColumns( 10, TQRegExp( "[0-9:]+" ), 6 ) ); - m_archCols.append( new ArchColumns( 6, TQRegExp( "[a-fA-F0-9]+ {2}" ) ) ); - m_archCols.append( new ArchColumns( 0, TQRegExp( "[^\\n]+" ), 4096 ) ); - } void ZipArch::setHeaders() @@ -314,4 +299,61 @@ void ZipArch::test() } } +bool ZipArch::processLine( const TQCString &line ) +{ + TQTextCodec *codec = TQTextCodec::codecForLocale(); + TQString tqunicode_line = codec->toUnicode( line ); + + // Header structure: + // Length Method Size Cmpr Date Time CRC-32 Name + // -------- ------ ------- ---- ---------- ----- -------- ---- + + TQRegExp lineRx { "^" + "\\s*" "(" "[0-9]+" ")" // 1 Length + "\\s+" "(" "\\S+" ")" // 2 Method + "\\s+" "(" "[0-9]+" ")" // 3 Size + "\\s+" "(" "[0-9.]+%" ")" // 4 Compression rate + "\\s+" "(" "[0-9\\-]+" ")" // 5 Date + "\\s+" "(" "[0-9:]+" ")" // 6 Time + "\\s+" "(" "[a-fA-F0-9]+" ")" // 7 CRC-32 + " " "(" "[^\\n]+" ")" // 8 Name + "\\n?$" + }; + if( lineRx.search(tqunicode_line) == -1 ) { + kdDebug(1601) << "processLine failed to match unzip line: " << line << endl; + return false; + } + + // unzip-6 can be configured at build time to return date in either of three + // formats: + // - MM-DD-YYYY (the default on *nix systems) + // - DD-MM-YYYY (not used by default) + // - YYYY-MM-DD (used in several linux distribution e.g. debian) + // Unfortunately there is no easy way to query unzip which format it does + // use, so we will have to guestimate here. Also since the DMY is not widely + // used and in general case indistinguishable from MDY we will ignore it and + // concentrate on distinguishing between MDY and YMD. Luckily unzip-6 unlike + // unzip-5 uses 4 digits for years, so it will be relatively painless. + TQString date = lineRx.cap(5); + TQString time = lineRx.cap(6); + TQRegExp mdyDateRx{"^([01][0-9])-([0-3][0-9])-([0-9]{4,})$"}; + + if(mdyDateRx.search(date) != -1) { + date = mdyDateRx.cap(3) + "-" + mdyDateRx.cap(1) + "-" + mdyDateRx.cap(2); + } + TQString timestamp = date + " " + time; + + TQStringList l; + l << lineRx.cap(8); // FILENAME_COLUMN + l << lineRx.cap(1); // SIZE_COLUMN + l << lineRx.cap(2); // METHOD_COLUMN + l << lineRx.cap(3); // PACKED_COLUMN + l << lineRx.cap(4); // RATIO_COLUMN + l << timestamp; // TIMESTAMP_COLUMN + l << lineRx.cap(7); // CRC_COLUMN + m_gui->fileList()->addItem(l); + + return true; +} + #include "zip.moc" -- cgit v1.2.3