summaryrefslogtreecommitdiff
path: root/unrar/unrar.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2023-12-19 18:46:18 +0100
committerTomas Bzatek <tbzatek@redhat.com>2023-12-19 18:46:18 +0100
commite9036281ebb3a5be97e42f56667bb8dfebc5b4fe (patch)
tree4db07bedbeeb8b4d690a6bc8e4fe82ded153e701 /unrar/unrar.c
parent6d1c2e642eaf673e9e88ab08eacd5a6873659bcd (diff)
downloadtuxcmd-modules-e9036281ebb3a5be97e42f56667bb8dfebc5b4fe.tar.xz
unrar: Align with the unrar-6.2.12 release
Includes static and shared build.
Diffstat (limited to 'unrar/unrar.c')
-rw-r--r--unrar/unrar.c381
1 files changed, 163 insertions, 218 deletions
diff --git a/unrar/unrar.c b/unrar/unrar.c
index a022775..afd4dae 100644
--- a/unrar/unrar.c
+++ b/unrar/unrar.c
@@ -1,6 +1,6 @@
/* UNRAR plugin for Tux Commander
- * version 0.4.2, designed for unrar v3.8.2
- * Copyright (C) 2007-2009 Tomas Bzatek <tbzatek@users.sourceforge.net>
+ * version 0.5, designed for unrar v6.2.12
+ * Copyright (C) 2007-2023 Tomas Bzatek <tbzatek@users.sourceforge.net>
* Check for updates on tuxcmd.sourceforge.net
*
* Uses UNRAR sources
@@ -41,8 +41,8 @@
#define _UNIX
-#include "unrar/version.hpp"
-#include "unrar/dll.hpp"
+#include <version.hpp>
+#include <dll.hpp>
/* Compatibility types from headers.hpp */
@@ -57,15 +57,12 @@ enum HOST_SYSTEM {
};
-#define VERSION "0.4.2"
-#define BUILD_DATE "2009-12-12"
+#define VERSION "0.5"
+#define BUILD_DATE "2023-12-19"
#define DEFAULT_BLOCK_SIZE 65536
-
-
-
/* Declaration of the global plugin object */
struct TVFSGlobs {
TVFSLogFunc log_func;
@@ -131,7 +128,6 @@ VFSNew (TVFSLogFunc log_func)
return globs;
}
-
void
VFSSetCallbacks (struct TVFSGlobs *globs,
TVFSAskQuestionCallback ask_question_callback,
@@ -166,14 +162,19 @@ struct TVFSInfo *
VFSGetInfo ()
{
struct TVFSInfo *module_info;
+#ifdef MODULE_SHARED
+ const char *shared_module = "dynamically linked";
+#else
+ const char *shared_module = "statically linked";
+#endif
module_info = g_malloc0 (sizeof (struct TVFSInfo));
module_info->ID = g_strdup ("unrar_plugin");
module_info->Name = g_strdup ("UNRAR plugin");
- module_info->About = g_strdup_printf ("version %s, build date: %s\nusing unrar sources v%d.%d [%d-%.2d-%.2d]\n",
- VERSION, BUILD_DATE, RARVER_MAJOR, RARVER_MINOR, RARVER_YEAR, RARVER_MONTH, RARVER_DAY);
- module_info->Copyright = g_strdup ("Plugin Copyright (C) 2007-2009 Tomáš Bžatek\nUNRAR sources Copyright (C) 2002-2008 Alexander Roshal");
+ module_info->About = g_strdup_printf ("version %s, build date: %s\nusing unrar sources v%d.%d [%d-%.2d-%.2d]\n%s\n",
+ VERSION, BUILD_DATE, RARVER_MAJOR, RARVER_MINOR, RARVER_YEAR, RARVER_MONTH, RARVER_DAY, shared_module);
+ module_info->Copyright = g_strdup ("Plugin Copyright (C) 2007-2023 Tomáš Bžatek\nUNRAR sources Copyright (C) 2002-2023 Alexander Roshal");
return module_info;
}
@@ -199,122 +200,106 @@ VFSGetArchiveExts ()
static int
unrar_callback (UINT msg, LONG UserData, LONG P1, LONG P2)
{
- struct TVFSGlobs *globs;
+ struct TVFSGlobs *globs = (struct TVFSGlobs *) UserData;
-// fprintf(stderr, "(II) unrar_callback called: msg = %d, UserData = %lx, sizeof(UserData) = %ld, P1 = %ld, P2 = %ld\n", msg, UserData, sizeof(UserData), P1, P2);
- if (! UserData) {
- fprintf (stderr, "(WW) unrar_callback: UserData == NULL, exiting!\n");
+ if (globs == NULL) {
+ fprintf (stderr, "(WW) unrar_callback: UserData == NULL, aborting.\n");
return 0;
}
- globs = (struct TVFSGlobs *) UserData;
// >= 0 => Weiter, -1 => Stop
switch (msg) {
- case UCM_CHANGEVOLUME: {
- if (P2 == RAR_VOL_ASK) {
- fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK, P1 = %ld, (char*)P1 = '%s' \n", P1, (char*)P1);
- if (P1) {
- if (globs->callback_ask_question) {
- static const char *choices[] = {
- "Abort", /* response = 0 */
- "Ignore", /* response = 1 */
- NULL
- };
- char *message, *s;
- int choice = -1;
-
- s = g_filename_display_name((char *)P1);
- message = g_strdup_printf ("Archive is incomplete, volume missing: \n\n%s", s ? s : (char *)P1);
- globs->callback_ask_question (message, &choices[0], &choice, 0,
- globs->callback_data);
- g_free (message);
- g_free (s);
-
- if (choice != 1)
- globs->volume_missing_abort = TRUE;
- return -1;
- } else {
- if (access((char*)P1, R_OK) != 0) {
- fprintf (stderr, "(EE) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK: access test failed - missing part? Error = %s \n", strerror (errno));
- return -1;
- }
- }
+ case UCM_CHANGEVOLUME:
+ if (P2 == RAR_VOL_ASK) {
+ fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK, P1='%s'\n", (char *) P1);
+ if (globs->callback_ask_question) {
+ static const char *choices[] = {
+ "Abort", /* response = 0 */
+ "Ignore", /* response = 1 */
+ NULL
+ };
+ char *message;
+ char *s;
+ int choice = -1;
+
+ s = g_filename_display_name (P1 ? (char *) P1 : "<unknown>");
+ message = g_strdup_printf ("Archive is incomplete, volume missing:\n\n%s", s ? s : (char *) P1);
+ globs->callback_ask_question (message, &choices[0], &choice, 0,
+ globs->callback_data);
+ g_free (message);
+ g_free (s);
+
+ if (choice != 1)
+ globs->volume_missing_abort = TRUE;
+ return -1;
+ } else {
+ if (P1 && access ((char *) P1, R_OK) == 0)
+ return 0;
+ fprintf (stderr, "(EE) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK: access test failed: %s\n", strerror (errno));
+ return -1;
}
- } else
- if (P2 == RAR_VOL_NOTIFY) {
- fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_NOTIFY, P1 = %ld, (char*)P1 = '%s' \n", P1, (char*)P1);
- }
- break;
- }
+ return 0;
+ } else
+ if (P2 == RAR_VOL_NOTIFY) {
+ fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_NOTIFY, P1='%s'\n", (char *) P1);
+ return 0;
+ }
+ else {
+ fprintf (stderr, " (WW) unrar_callback: UCM_CHANGEVOLUME message, P1='%s', unhandled P2/action %ld, aborting.\n", (char *) P1, P2);
+ return -1;
+ }
+ break;
- case UCM_PROCESSDATA: {
- fprintf (stderr, " (II) unrar_callback: UCM_PROCESSDATA message, P1 = %ld, P2 = %ld \n", P1, P2);
-// printf(" (II) unrar_callback: globs = 0x%lX, UserData = 0x%lX \n", (unsigned long int)globs, UserData);
- if (globs && globs->callback_progress) {
-// printf(" (II) unrar_callback: globs->extract_callback_func = 0x%lX, globs->extract_callback_data = 0x%lX \n", (unsigned long int)globs->extract_callback_func, (unsigned long int)globs->extract_callback_data);
-// long int res = globs->extract_callback_func((u_int64_t)P1, (u_int64_t)((u_int64_t)P1 + (u_int64_t)P2), globs->extract_callback_data);
+ case UCM_PROCESSDATA:
+ fprintf (stderr, " (II) unrar_callback: UCM_PROCESSDATA message, P1/Addr = %p, P2/Count = %ld\n", (void *) P1, P2);
+ if (globs->callback_progress) {
+ gboolean res;
globs->extract_done += P2;
- gboolean res = globs->callback_progress(globs->extract_done, NULL, globs->callback_data);
-
-// fprintf(stderr, " (II) unrar_callback: res = %d \n", res);
- if (! res ) {
+ res = globs->callback_progress (globs->extract_done, NULL, globs->callback_data);
+ if (! res) {
globs->extract_cancelled = TRUE;
fprintf (stderr, "(WW) unrar_callback: received cancellation result\n");
- return -1; // Cancel operation
+ return -1; /* cancel the operation */
}
- }
- break;
- }
+ }
+ return 0;
+
+ case UCM_NEEDPASSWORD:
+ char *passwd = NULL;
+ gboolean res = FALSE;
+
+ fprintf (stderr, " (II) unrar_callback: UCM_NEEDPASSWORD message, P1/buf = %p, P2/bufsize = %ld\n", (void *) P1, P2);
+
+ globs->failed_passwd_callback = TRUE;
+ if (globs->callback_ask_password) {
+ res = globs->callback_ask_password ("The archive is encrypted and needs a password",
+ NULL, NULL, NULL, VFS_ASK_PASSWORD_NEED_PASSWORD | VFS_ASK_PASSWORD_ARCHIVE_MODE,
+ NULL, &passwd, NULL, NULL, NULL,
+ globs->callback_data);
+ if (res && passwd && strlen (passwd) > 0) {
+ strncpy ((char *) P1, passwd, P2);
+ g_free (globs->password);
+ globs->password = g_strdup (passwd);
+ }
+ g_free (passwd);
+ }
+ if (res)
+ return 0;
+ globs->extract_cancelled = TRUE;
+ return -1;
+
+ case UCM_NEEDPASSWORDW:
+ case UCM_CHANGEVOLUMEW:
+ /* deliberately ignoring these due to bogus data in P1 */
+ return 0;
- case UCM_NEEDPASSWORD: {
- fprintf (stderr, " (II) unrar_callback: UCM_NEEDPASSWORD message, P1 = %ld, P2 = %ld, (char*)P1 = '%s', maxlen = %ld \n", P1, P2, (char*)P1, P2);
-
- char *passwd = NULL;
- gboolean res = FALSE;
-
- globs->failed_passwd_callback = TRUE;
- if (globs->callback_ask_password) {
- res = globs->callback_ask_password ("The archive is encrypted and requires password",
- NULL, NULL, NULL, VFS_ASK_PASSWORD_NEED_PASSWORD | VFS_ASK_PASSWORD_ARCHIVE_MODE,
- NULL, &passwd, NULL, NULL, NULL,
- globs->callback_data);
- if (res && passwd) {
- fprintf(stderr, " (II) unrar_callback: setting password to '%s'\n", passwd);
- if (strlen (passwd) > 0) {
- strncpy ((char *)P1, passwd, P2);
- g_free (globs->password);
- globs->password = g_strdup (passwd);
- }
- g_free (passwd);
- }
- }
- if (res)
- return 0;
- else {
- globs->extract_cancelled = TRUE;
- return -1;
- }
- }
+ default:
+ fprintf (stderr, "(WW) unrar_callback: unhandled msg code %u, exiting!\n", msg);
+ return -1;
}
- return 0;
-}
-
-static int PASCAL
-unrar_changevol_proc (char *ArcName, int Mode)
-{
- fprintf (stderr, "(II) unrar_changevol_proc called: ArcName = '%s', Mode = %d\n", ArcName, Mode);
-
- return 0;
-}
-
-static int PASCAL
-unrar_process_data_proc (unsigned char *Addr, int Size)
-{
- fprintf (stderr, "(II) unrar_process_data_proc called: Addr = '%s', Size = %d\n", Addr, Size);
-
- return 0;
+ return -1;
}
/* ----------------------------------------------------------------------------------------------------------- */
@@ -379,6 +364,12 @@ rar_error_to_gerror (int code, GError **error)
case ERAR_MISSING_PASSWORD:
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED, "Missing password.");
break;
+ case ERAR_EREFERENCE:
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Bad reference.");
+ break;
+ case ERAR_BAD_PASSWORD:
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED, "Bad password.");
+ break;
default:
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Operation failed.");
break;
@@ -392,7 +383,7 @@ gboolean
VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
{
HANDLE PASCAL handle;
- struct RAROpenArchiveDataEx *archive_data;
+ struct RAROpenArchiveDataEx archive_data = { 0, };
guint64 inode_no;
gboolean Result;
@@ -408,95 +399,74 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
inode_no = 0;
fprintf (stderr, "(--) VFSOpenArchive: trying to open archive '%s'...\n", globs->archive_path);
- /* WARNING: do not use g_malloc0() here, leads to memory corruption */
- archive_data = malloc (sizeof (struct RAROpenArchiveDataEx));
- memset (archive_data, 0, sizeof (struct RAROpenArchiveDataEx));
- archive_data->ArcName = globs->archive_path;
- archive_data->CmtBuf = NULL;
- archive_data->CmtBufSize = 0;
- archive_data->OpenMode = RAR_OM_LIST;
-
- handle = RAROpenArchiveEx (archive_data);
-// printf(" handle = %lu \n", (unsigned long int)handle);
-// printf(" archive_data->OpenResult = %d \n", archive_data->OpenResult);
-// printf(" archive_data->CmtState = %d \n", archive_data->CmtState);
-// printf(" archive_data->CmtSize = %d \n", archive_data->CmtSize);
-
- if (handle && ! archive_data->OpenResult) {
- // Set callbacks
- RARSetCallback (handle, unrar_callback, (LONG)globs);
-// RARSetChangeVolProc(handle, unrar_changevol_proc);
-// RARSetProcessDataProc(handle, unrar_process_data_proc);
+ archive_data.ArcName = globs->archive_path;
+ archive_data.CmtBuf = NULL;
+ archive_data.CmtBufSize = 0;
+ archive_data.OpenMode = RAR_OM_LIST;
+
+ handle = RAROpenArchiveEx (&archive_data);
+ if (handle && archive_data.OpenResult == 0) {
+ struct RARHeaderDataEx header = { 0, };
+ int PASCAL res = 0;
+ RARSetCallback (handle, unrar_callback, (LONG) globs);
if (globs->password) {
fprintf (stderr, "(II) VFSOpenArchive: Setting password... \n");
RARSetPassword (handle, globs->password);
}
- struct RARHeaderDataEx *header;
- /* WARNING: do not use g_malloc0() here, leads to memory corruption */
- header = malloc (sizeof (struct RARHeaderDataEx));
- memset (header, 0, sizeof (struct RARHeaderDataEx));
-
- int PASCAL res = 0;
- while ((res = RARReadHeaderEx(handle, header)) == 0) {
-// printf(" header->FileName = '%s', Flags = 0x%x\n", header->FileName, header->Flags);
+ while ((res = RARReadHeaderEx (handle, &header)) == 0) {
+ struct TVFSItem *item;
+ char *s;
+ int PASCAL res2;
+ item = g_malloc0 (sizeof (struct TVFSItem));
+ item->iSize = (guint64)((guint64)(header.UnpSizeHigh * 0x100000000) + (guint64)header.UnpSize);
+ item->iPackedSize = (guint64)((guint64)(header.PackSizeHigh * 0x100000000) + (guint64)header.PackSize);
inode_no++;
-
- /* Create a TVFSItem entry and fill all info */
- struct TVFSItem *item = g_malloc0 (sizeof (struct TVFSItem));
-
- item->iSize = (guint64)((guint64)(header->UnpSizeHigh * 0x100000000) + (guint64)header->UnpSize);
- item->iPackedSize = (guint64)((guint64)(header->PackSizeHigh * 0x100000000) + (guint64)header->PackSize);
item->inode_no = inode_no;
globs->total_size += item->iSize;
- if ((header->Flags & 0x00e0 /* LHD_WINDOWMASK */ ) == 0x00e0 /* LHD_DIRECTORY */)
+ if ((header.Flags & RHDF_DIRECTORY) == RHDF_DIRECTORY)
item->ItemType = vDirectory;
else
item->ItemType = vRegular;
- if ((header->Flags & 0x0004) == 0x0004)
+ if ((header.Flags & RHDF_ENCRYPTED) == RHDF_ENCRYPTED)
globs->need_password = TRUE;
- switch (header->HostOS) {
+ switch (header.HostOS) {
case HOST_MSDOS:
case HOST_OS2:
case HOST_WIN32:
- if (header->FileAttr & 0x10)
- header->FileAttr = 0x41ff | header->FileAttr;
+ if (header.FileAttr & 0x10)
+ header.FileAttr = 0x41ff | header.FileAttr;
else
- if (header->FileAttr & 1)
- header->FileAttr = 0x8124 | header->FileAttr;
+ if (header.FileAttr & 1)
+ header.FileAttr = 0x8124 | header.FileAttr;
else
- header->FileAttr = 0x81b6 | header->FileAttr;
+ header.FileAttr = 0x81b6 | header.FileAttr;
break;
}
- item->iMode = header->FileAttr;
+ item->iMode = header.FileAttr;
item->iUID = geteuid ();
item->iGID = getegid ();
- item->m_time = rar_time_to_unix (header->FileTime);
+ item->m_time = rar_time_to_unix (header.FileTime);
item->c_time = item->m_time;
item->a_time = item->m_time;
-// g_print (" valid = %d\n", g_utf8_validate (header->FileName, -1, NULL));
-
- char *s;
- if (g_utf8_validate (header->FileName, -1, NULL))
- s = g_strdup (header->FileName);
+ if (g_utf8_validate (header.FileName, -1, NULL))
+ s = g_strdup (header.FileName);
else
- s = wide_to_utf8 (header->FileNameW);
-// g_print (" ansi = '%s'\n wide = '%ls'\n utf8 = '%s'\n", header->FileName, header->FileNameW, s);
+ s = wide_to_utf8 (header.FileNameW);
- // Add item to the global list and continue with next file
- filelist_tree_add_item (globs->files, s, item, header->FileName, inode_no);
+ /* Add the item to the global list and continue with next file */
+ filelist_tree_add_item (globs->files, s, item, header.FileName, inode_no);
g_free (s);
- int PASCAL res2 = RARProcessFile (handle, RAR_SKIP, NULL, NULL);
+ res2 = RARProcessFile (handle, RAR_SKIP, NULL, NULL);
if (res2)
printf ("RARProcessFile result = %d\n", res2);
}
-// printf("\nRARReadHeader result = %d\n", res);
if (res != ERAR_END_ARCHIVE || globs->volume_missing_abort) {
fprintf (stderr, "(EE) VFSOpenArchive: RARReadHeader result = %d\n", res);
rar_error_to_gerror (res, error);
@@ -506,21 +476,19 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
Result = cVFS_BadPassword;
*/
}
- free (header);
- res = RARCloseArchive(handle);
+ res = RARCloseArchive (handle);
if (res)
fprintf (stderr, "(EE) VFSOpenArchive: RARCloseArchive result = %d\n", res);
} else {
- fprintf (stderr, "(EE) VFSOpenArchive: error occured when opening archive: OpenResult = %d\n", archive_data->OpenResult);
- rar_error_to_gerror (archive_data->OpenResult, error);
+ fprintf (stderr, "(EE) VFSOpenArchive: error occured when opening archive: OpenResult = %d\n", archive_data.OpenResult);
+ rar_error_to_gerror (archive_data.OpenResult, error);
Result = FALSE;
}
- free (archive_data);
- fprintf (stderr, "(II) VFSOpenArchive: done. \n");
+ fprintf (stderr, "(II) VFSOpenArchive: done.\n");
if (globs->need_password)
- printf ("Password present.\n");
+ fprintf (stderr, "(II) VFSOpenArchive: Password present.\n");
printf ("\n\nList of items:\n");
filelist_tree_print (globs->files);
@@ -534,9 +502,9 @@ VFSClose (struct TVFSGlobs *globs, GError **error)
if (globs) {
fprintf (stderr, "(II) VFSClose: Freeing objects...\n");
if (globs->vfs_filelist)
- vfs_filelist_free(globs->vfs_filelist);
+ vfs_filelist_free (globs->vfs_filelist);
if (globs->files)
- filelist_tree_free(globs->files);
+ filelist_tree_free (globs->files);
g_free (globs->archive_path);
g_free (globs->curr_dir);
g_free (globs->password);
@@ -760,13 +728,12 @@ VFSTwoSameFiles (struct TVFSGlobs *globs, const char *Path1, const char *Path2,
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////
-
gboolean
VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error)
{
- struct RAROpenArchiveDataEx *archive_data;
+ struct RAROpenArchiveDataEx archive_data = { 0, };
HANDLE PASCAL handle;
- gboolean Result;
+ gboolean Result = FALSE;
if (globs->op_handle != NULL) {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED, "globs->op_handle != NULL");
@@ -774,26 +741,12 @@ VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error)
}
printf ("(II) VFSStartCopyOperation: opening archive '%s'\n", globs->archive_path);
- Result = FALSE;
-
- /* WARNING: do not use g_malloc0() here, leads to memory corruption */
- archive_data = malloc (sizeof (struct RAROpenArchiveDataEx));
- memset (archive_data, 0, sizeof (struct RAROpenArchiveDataEx));
- archive_data->ArcName = globs->archive_path;
- archive_data->OpenMode = RAR_OM_EXTRACT;
-
- handle = RAROpenArchiveEx (archive_data);
-// printf(" handle = %lu \n", (unsigned long int)handle);
-// printf(" archive_data->OpenResult = %d \n", archive_data->OpenResult);
-// printf(" archive_data->CmtState = %d \n", archive_data->CmtState);
-// printf(" archive_data->CmtSize = %d \n", archive_data->CmtSize);
+ archive_data.ArcName = globs->archive_path;
+ archive_data.OpenMode = RAR_OM_EXTRACT;
- if (handle && ! archive_data->OpenResult) {
- /* set callbacks */
-// printf(" setting callback: globs = 0x%lX, (unsigned long int)globs = 0x%lX, (LONG)globs = 0x%lX\n", globs, (unsigned long int)globs, (LONG)globs);
+ handle = RAROpenArchiveEx (&archive_data);
+ if (handle && archive_data.OpenResult == 0) {
RARSetCallback (handle, unrar_callback, (LONG) globs);
-// RARSetChangeVolProc(handle, unrar_changevol_proc);
-// RARSetProcessDataProc(handle, unrar_process_data_proc);
/* set password */
if (globs->password) {
@@ -804,11 +757,10 @@ VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error)
globs->op_handle = handle;
Result = TRUE;
} else {
- fprintf (stderr, "(EE) VFSStartCopyOperation: error occured when opening archive: OpenResult = %d\n", archive_data->OpenResult);
- rar_error_to_gerror (archive_data->OpenResult, error);
+ fprintf (stderr, "(EE) VFSStartCopyOperation: error occured when opening archive: OpenResult = %d\n", archive_data.OpenResult);
+ rar_error_to_gerror (archive_data.OpenResult, error);
Result = FALSE;
}
- free (archive_data);
return Result;
}
@@ -844,8 +796,10 @@ gboolean
VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append, GError **error)
{
struct PathTree *node;
- gboolean found;
- gboolean Result;
+ struct RARHeaderDataEx header = { 0, };
+ gboolean found = FALSE;
+ gboolean Result = TRUE;
+ int res = 0;
char *src;
if (globs->op_handle == NULL) {
@@ -874,24 +828,16 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
}
printf ("(II) VFSCopyToLocal: new src path: '%s'\n", src);
- struct RARHeaderDataEx *header;
- /* WARNING: do not use g_malloc0() here, leads to memory corruption */
- header = malloc (sizeof (struct RARHeaderDataEx));
- memset (header, 0, sizeof (struct RARHeaderDataEx));
-
- int res = 0;
- found = FALSE;
- Result = TRUE;
+ while ((res = RARReadHeaderEx (globs->op_handle, &header)) == 0) {
+ int res2;
- while ((res = RARReadHeaderEx(globs->op_handle, header)) == 0) {
- g_print ("VFSCopyToLocal: found '%s'\n", header->FileName);
- if (g_strcmp0 (src, header->FileName) == 0) {
-// fprintf(stderr, "(II) VFSCopyToLocal: extract_file_path(sDstName) = '%s', extract_file_name(sDstName) = '%s' \n", extract_file_path(sDstName), extract_file_name(sDstName));
+ g_print ("VFSCopyToLocal: found '%s'\n", header.FileName);
+ if (g_strcmp0 (src, header.FileName) == 0) {
globs->extract_done = 0;
globs->extract_cancelled = FALSE;
found = TRUE;
- int res2 = RARProcessFile (globs->op_handle, RAR_EXTRACT, NULL, (char *)sDstName);
+ res2 = RARProcessFile (globs->op_handle, RAR_EXTRACT, NULL, (char *)sDstName);
if (globs->extract_cancelled) {
fprintf (stderr, "(WW) VFSCopyToLocal: cancelled !\n");
@@ -906,7 +852,7 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
}
break;
} else {
- int res2 = RARProcessFile (globs->op_handle, RAR_SKIP, NULL, NULL);
+ res2 = RARProcessFile (globs->op_handle, RAR_SKIP, NULL, NULL);
if (res2) {
fprintf (stderr, "(EE) VFSCopyToLocal: RARProcessFile result = %d\n", res2);
rar_error_to_gerror (res2, error);
@@ -927,7 +873,6 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
rar_error_to_gerror (res, error);
}
}
- free (header);
if (! found && Result) {
fprintf (stderr, "(EE) VFSCopyToLocal: file not found in archive.\n");