summaryrefslogtreecommitdiff
path: root/zip/zip.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zip/zip.cpp')
-rw-r--r--zip/zip.cpp94
1 files changed, 53 insertions, 41 deletions
diff --git a/zip/zip.cpp b/zip/zip.cpp
index e7dc7ed..c0ccd99 100644
--- a/zip/zip.cpp
+++ b/zip/zip.cpp
@@ -1,12 +1,12 @@
/* ZIP plugin for Tux Commander
- * version 0.6.2, designed for ZipArchive v3.2.0
- * Copyright (C) 2004-2009 Tomas Bzatek <tbzatek@users.sourceforge.net>
+ * version 0.7, designed for ZipArchive v4.6.9
+ * Copyright (C) 2004-2023 Tomas Bzatek <tbzatek@users.sourceforge.net>
* Check for updates on tuxcmd.sourceforge.net
*
* Uses ZipArchive library
- * Copyright (C) 2000 - 2007 Artpol Software - Tadeusz Dracz
+ * Copyright (C) 2000 - 2022 Artpol Software - Tadeusz Dracz
* http://www.artpol-software.com/ZipArchive/
- *
+ *
* This program is free software; you can redistribute it and/or modify
@@ -48,15 +48,15 @@
-#define VERSION "0.6.2"
-#define BUILD_DATE "2009-12-13"
+#define VERSION "0.7"
+#define BUILD_DATE "2023-12-17"
#define DEFAULT_BLOCK_SIZE 65536
using namespace std;
extern "C" {
-
+
/******************************************************************************************************/
/** Utilities */
@@ -184,7 +184,7 @@ struct ZIP_API CVFSZipActionCallback : public CZipActionCallback
virtual bool Callback(ZIP_SIZE_TYPE uProgress)
{
- fprintf (stderr, "(II) Callback called, position = %lu; m_uTotalToProcess = %lu; m_uProcessed = %lu\n",
+ fprintf (stderr, "(II) Callback called, position = %" G_GUINT32_FORMAT "; m_uTotalToProcess = %" G_GUINT32_FORMAT "; m_uProcessed = %" G_GUINT32_FORMAT "\n",
uProgress, m_uTotalToProcess, m_uProcessed);
bool ret = true;
try {
@@ -228,7 +228,7 @@ build_global_filelist (struct TVFSGlobs *globs)
for (i = 0; i < iCount; i++) {
fh = globs->zip->GetFileInfo (i);
if (fh != NULL)
- printf(" No: %lu, '%s', IsDir: %i, Size: %lu, SystemAttr = 0x%lX, OriginalAttr = 0x%lX, encrypted = %d\n",
+ printf(" No: %lu, '%s', IsDir: %i, Size: %" G_GUINT32_FORMAT ", SystemAttr = 0x%" G_GINT32_MODIFIER "X, OriginalAttr = 0x%" G_GINT32_MODIFIER "X, encrypted = %d\n",
i, (LPCTSTR)fh->GetFileName(), fh->IsDirectory(), fh->m_uUncomprSize, fh->GetSystemAttr(), fh->GetOriginalAttributes(), fh->IsEncrypted());
}
printf("\n\n");
@@ -249,9 +249,9 @@ build_global_filelist (struct TVFSGlobs *globs)
item->iMode = fh->GetSystemAttr ();
item->iUID = geteuid ();
item->iGID = getegid ();
- item->m_time = (__time_t) fh->GetTime ();
- item->c_time = item->m_time;
- item->a_time = item->m_time;
+ item->m_time = (__time_t) fh->GetModificationTime ();
+ item->c_time = (__time_t) fh->GetCreationTime ();
+ item->a_time = (__time_t) fh->GetLastAccessTime ();
if (fh->IsEncrypted ())
globs->need_password = TRUE;
@@ -340,7 +340,7 @@ VFSGetInfo ()
module_info->ID = g_strdup ("zip_plugin");
module_info->Name = g_strdup ("ZIP plugin");
module_info->About = g_strdup_printf ("version %s, build date: %s\nusing ZipArchive library v%s\n", VERSION, BUILD_DATE, CZipArchive::m_gszVersion);
- module_info->Copyright = g_strdup_printf ("Plugin Copyright (C) 2004-2009 Tomáš Bžatek\n%s", CZipArchive::m_gszCopyright);
+ module_info->Copyright = g_strdup_printf ("Plugin Copyright (C) 2004-2023 Tomáš Bžatek\n%s", CZipArchive::m_gszCopyright);
return module_info;
}
@@ -394,7 +394,7 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
return FALSE;
}
}
- catch (CZipException e) {
+ catch (CZipException& e) {
printf ("(EE) VFSOpenArchive: error opening readonly zip\n");
zip_error_to_gerror (e, error);
return FALSE;
@@ -417,9 +417,9 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
globs->zip->SetCallback (globs->extract_callback, CZipActionCallback::cbAdd);
/* set automatic flushing of changes to disk */
- globs->zip->SetAutoFlush (true);
+ globs->zip->SetAutoFinalize (true);
}
- catch (CZipException e) {
+ catch (CZipException& e) {
printf ("(EE) VFSOpenArchive: Error while processing archive %s\n%s\n", (LPCTSTR) sName, (LPCTSTR)e.GetErrorDescription());
if (e.m_szFileName.IsEmpty())
printf ("\n");
@@ -449,15 +449,15 @@ VFSClose (struct TVFSGlobs *globs, GError **error)
/* close the archive... */
fprintf (stderr, "(II) VFSClose: Closing the archive...\n");
try {
- if (globs->archive_modified)
- globs->zip->Flush ();
+ if (globs->archive_modified)
+ globs->zip->FlushBuffers ();
/* In case of inconsistency, try using afWriteDir value.
* (use when an exception was thrown, the Close method writes the
* central directory structure to the archive, so that the archive should be usable.)
*/
globs->zip->Close (CZipArchive::afNoException, false);
}
- catch (CZipException e) {
+ catch (CZipException& e) {
fprintf (stderr, "(EE) VFSClose: Error while closing archive: %s\n", (LPCTSTR)e.GetErrorDescription());
zip_error_to_gerror (e, error);
return FALSE;
@@ -616,13 +616,13 @@ VFSMkDir (struct TVFSGlobs *globs, const char *sDirName, GError **error)
printf ("(II) VFSMkDir: Going to create new directory '%s'...\n", sDirName);
try {
- try {
-// globs->zip->SetFileHeaderAttr (header, 0x41ED0010);
- globs->zip->SetFileHeaderAttr (header, 0x41ED); /* alternatively use ZipPlatform::GetDefaultAttributes(); */
+ try {
+ header.SetSystemAttr(ZipPlatform::GetDefaultDirAttributes());
s = exclude_leading_path_sep (sDirName);
header.SetFileName(s);
g_free (s);
- header.SetTime (time (NULL));
+ header.SetCreationTime (time (NULL));
+ header.SetModificationTime (time (NULL));
bRet = globs->zip->OpenNewFile (header, 0, NULL);
globs->zip->CloseNewFile ();
if (! bRet) {
@@ -634,7 +634,7 @@ VFSMkDir (struct TVFSGlobs *globs, const char *sDirName, GError **error)
build_global_filelist (globs);
return TRUE;
}
- catch (CZipException e) {
+ catch (CZipException& e) {
globs->zip->CloseNewFile (true);
fprintf (stderr, "(EE) VFSMkDir: Error creating new directory '%s': [%d] %s, archive closed = %d.\n",
sDirName, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed ());
@@ -702,7 +702,7 @@ VFSRemove (struct TVFSGlobs *globs, const char *APath, GError **error)
return TRUE;
}
- catch (CZipException e) {
+ catch (CZipException& e) {
fprintf (stderr, "(EE) VFSRemove: Delete file '%s' failed: [%d] %s, archive closed = %d.\n",
APath, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed ());
zip_error_to_gerror (e, error);
@@ -718,17 +718,21 @@ VFSRemove (struct TVFSGlobs *globs, const char *APath, GError **error)
}
-gboolean
+gboolean
VFSRename (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, GError **error)
{
char *AFile;
char *ADestFile;
+ char *s;
long int file_no;
+ CZipFileHeader *fh;
printf ("(II) VFSRename: Going to rename/move the file '%s' to '%s'...\n", sSrcName, sDstName);
AFile = exclude_trailing_path_sep (sSrcName);
- ADestFile = exclude_trailing_path_sep (sDstName);
+ s = exclude_trailing_path_sep (sDstName);
+ ADestFile = exclude_leading_path_sep (s);
+ g_free (s);
file_no = filelist_find_original_index_by_path (globs->files, AFile) - 1;
g_free (AFile);
@@ -740,7 +744,13 @@ VFSRename (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName,
try {
try {
- if (! globs->zip->RenameFile (file_no, ADestFile)) {
+ fh = globs->zip->GetFileInfo (file_no);
+ if (fh == NULL) {
+ printf ("(EE) VFSRename: can't find the file specified: '%s'\n", sSrcName);
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "Can't find the file specified.");
+ return FALSE;
+ }
+ if (! fh->SetFileName (ADestFile)) {
printf ("(EE) VFSRename: Rename/move file '%s' failed.\n", sSrcName);
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Rename/move file '%s' failed.", sSrcName);
return FALSE;
@@ -750,7 +760,7 @@ VFSRename (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName,
globs->archive_modified = TRUE;
return TRUE;
}
- catch (CZipException e) {
+ catch (CZipException& e) {
fprintf (stderr, "(EE) VFSRename: Rename/move file '%s' failed: [%d] %s, archive closed = %d.\n",
sSrcName, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed ());
zip_error_to_gerror (e, error);
@@ -816,10 +826,11 @@ VFSChmod (struct TVFSGlobs *globs, const char *FileName, guint32 Mode, GError **
// header->GetSystemAttr(), header->GetSystemAttr() & 0xF000FFFF, Mode & 0xFFF, (header->GetSystemAttr() & 0xF000FFFF) + ((Mode & 0xFFF) << 16));
// globs->zip->SetFileHeaderAttr(*header, (header->GetSystemAttr() & 0xF000FFFF) + ((Mode & 0xFFF) << 16));
- printf ("(II) VFSChmod: Current permissions: 0x%lX, stripped: 0x%lX, setting to: 0x%X, modified: 0x%lX\n",
+ printf ("(II) VFSChmod: Current permissions: 0x%" G_GINT32_MODIFIER "X, stripped: 0x%" G_GINT32_MODIFIER "X, setting to: 0x%X, modified: 0x%" G_GINT32_MODIFIER "X\n",
header->GetSystemAttr(), header->GetSystemAttr() & 0xFFFFF000,
Mode & 0xFFF, (header->GetSystemAttr() & 0xFFFFF000) + (Mode & 0xFFF));
- globs->zip->SetFileHeaderAttr (*header, (header->GetSystemAttr() & 0xFFFFF000) + (Mode & 0xFFF));
+ header->SetSystemAttr ((header->GetSystemAttr() & 0xFFFFF000) + (Mode & 0xFFF));
+// globs->zip->SetFileHeaderAttr (*header, (header->GetSystemAttr() & 0xFFFFF000) + (Mode & 0xFFF));
/* write local header information */
globs->zip->OverwriteLocalHeader (file_no);
@@ -833,14 +844,14 @@ VFSChmod (struct TVFSGlobs *globs, const char *FileName, guint32 Mode, GError **
}
#endif
globs->zip->RemoveCentralDirectoryFromArchive ();
- globs->zip->Flush ();
+ globs->zip->FlushBuffers ();
printf ("(II) VFSChmod OK.\n");
build_global_filelist (globs);
globs->archive_modified = TRUE;
return TRUE;
}
- catch (CZipException e) {
+ catch (CZipException& e) {
globs->zip->CloseNewFile (true);
fprintf (stderr, "(EE) VFSChmod: permissions modification of the file '%s' failed: [%d] %s, archive closed = %d.\n",
FileName, e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
@@ -896,8 +907,9 @@ VFSChangeTimes (struct TVFSGlobs *globs, const char *APath, guint32 mtime, guint
return FALSE;
}
/* change the header data */
- header->SetTime (mtime);
-
+ header->SetModificationTime (mtime);
+ header->SetLastAccessTime (atime);
+
/* // Re-encrypt the file
if (header->IsEncrypted()) {
printf("(II) VFSChangeTimes: Re-encrypting the file...\n");
@@ -914,7 +926,7 @@ VFSChangeTimes (struct TVFSGlobs *globs, const char *APath, guint32 mtime, guint
globs->archive_modified = TRUE;
return TRUE;
}
- catch (CZipException e) {
+ catch (CZipException& e) {
globs->zip->CloseNewFile (true);
fprintf (stderr, "(EE) VFSChangeTimes: DateTime modification of the file '%s' failed: [%d] %s, archive closed = %d.\n",
APath, e.m_iCause, (LPCTSTR)e.GetErrorDescription (), globs->zip->IsClosed ());
@@ -1009,7 +1021,7 @@ VFSStopCopyOperation (struct TVFSGlobs *globs, GError **error)
if (globs->archive_modified) {
printf ("(II) VFSStopCopyOperation: rebuilding tree.\n");
- globs->zip->Flush ();
+ globs->zip->FlushBuffers ();
build_global_filelist (globs);
} else {
printf ("(II) VFSStartCopyOperation: doing nothing for the moment.\n");
@@ -1059,8 +1071,8 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
try {
do {
try {
- try_again = FALSE;
- if (! globs->zip->ExtractFile (file_no, dest_path, false, dest_filename, globs->block_size)) {
+ try_again = FALSE;
+ if (! globs->zip->ExtractFile (file_no, dest_path, false, dest_filename, ZipPlatform::fomRegular, globs->block_size)) {
globs->zip->CloseFile (NULL, true);
fprintf (stderr, "(EE) VFSCopyToLocal: Error while copying out, archive closed = %d.\n", globs->zip->IsClosed ());
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error while copying out.");
@@ -1068,7 +1080,7 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
}
fprintf (stderr, "(II) VFSCopyToLocal: copy OK, archive closed = %d.\n", globs->zip->IsClosed ());
}
- catch (CZipException e) {
+ catch (CZipException& e) {
globs->zip->CloseFile (NULL, true);
fprintf (stderr, "(EE) VFSCopyToLocal: Error while copying out: [%d] %s, archive closed = %d.\n",
e.m_iCause, (LPCTSTR)e.GetErrorDescription(), globs->zip->IsClosed());
@@ -1163,7 +1175,7 @@ VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDs
g_free (s);
}
- catch (CZipException e) {
+ catch (CZipException& e) {
globs->zip->CloseNewFile (true);
globs->zip->CloseFile (NULL, true);
fprintf (stderr, "(EE) VFSCopyFromLocal: Error while copying in: [%d] %s, archive closed = %d.\n",