diff options
| -rw-r--r-- | unrar/Makefile | 7 | ||||
| l--------- | unrar/logutils.c | 1 | ||||
| l--------- | unrar/logutils.h | 1 | ||||
| -rw-r--r-- | unrar/unrar.c | 130 |
4 files changed, 68 insertions, 71 deletions
diff --git a/unrar/Makefile b/unrar/Makefile index 77d5f17..5286737 100644 --- a/unrar/Makefile +++ b/unrar/Makefile @@ -10,7 +10,7 @@ CPP = g++ CFLAGS = -I. \ -Wall -Wtype-limits -fPIC -O2 -g -ggdb \ -DG_DISABLE_DEPRECATED -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE \ - -D__VERBOSE_DEBUGx + -D__DEBUG_INTERNALx -D_LOG_DOMAIN="unrar" LIB_SUFFIX = `if test \`uname -m\` = x86_64 -o \`uname -m\` = ppc64; then echo 64; fi` @@ -34,7 +34,7 @@ UNRAR_OBJECTS = $(DIR_UNRAR)/rar.o $(DIR_UNRAR)/strlist.o $(DIR_UNRAR)/strfn.o \ $(DIR_UNRAR)/threadpool.o $(DIR_UNRAR)/rs16.o $(DIR_UNRAR)/cmddata.o \ $(DIR_UNRAR)/ui.o -VFS_COMMON_OBJECTS = filelist.o filelist-vfs-intf.o strutils.o vfsutils.o +VFS_COMMON_OBJECTS = filelist.o filelist-vfs-intf.o strutils.o vfsutils.o logutils.o VFS_OBJECTS = unrar.o @@ -48,7 +48,7 @@ VFS_OBJECTS = unrar.o all: shared -shared: CFLAGS += -DMODULE_SHARED -I/usr/include/libunrar6 +shared: CFLAGS += -DMODULE_SHARED -I/usr/include/libunrar -I/usr/include/libunrar6 shared: $(VFS_COMMON_OBJECTS) $(VFS_OBJECTS) $(CPP) -shared -o libunrar_plugin.so $(VFS_COMMON_OBJECTS) $(VFS_OBJECTS) $(CFLAGS) `pkg-config glib-2.0 gio-2.0 --libs` -lunrar @@ -63,6 +63,7 @@ filelist.o: filelist.h filelist.c filelist-vfs-intf.o: filelist-vfs-intf.h filelist-vfs-intf.c strutils.o: strutils.h strutils.c vfsutils.o: vfsutils.h vfsutils.c +logutils.o: logutils.h logutils.c install:: $(INSTALL) ./libunrar_plugin.so $(DESTDIR)/lib$(LIB_SUFFIX)/tuxcmd/ diff --git a/unrar/logutils.c b/unrar/logutils.c new file mode 120000 index 0000000..c1e4fc5 --- /dev/null +++ b/unrar/logutils.c @@ -0,0 +1 @@ +../common/logutils.c
\ No newline at end of file diff --git a/unrar/logutils.h b/unrar/logutils.h new file mode 120000 index 0000000..ed79bd9 --- /dev/null +++ b/unrar/logutils.h @@ -0,0 +1 @@ +../common/logutils.h
\ No newline at end of file diff --git a/unrar/unrar.c b/unrar/unrar.c index afd4dae..9793738 100644 --- a/unrar/unrar.c +++ b/unrar/unrar.c @@ -1,6 +1,6 @@ /* UNRAR plugin for Tux Commander - * version 0.5, designed for unrar v6.2.12 - * Copyright (C) 2007-2023 Tomas Bzatek <tbzatek@users.sourceforge.net> + * version 0.5.1, designed for unrar v6.2.12 + * Copyright (C) 2007-2024 Tomas Bzatek <tbzatek@users.sourceforge.net> * Check for updates on tuxcmd.sourceforge.net * * Uses UNRAR sources @@ -36,6 +36,7 @@ #include "tuxcmd-vfs.h" #include "vfsutils.h" #include "strutils.h" +#include "logutils.h" #include "filelist.h" #include "filelist-vfs-intf.h" @@ -57,8 +58,8 @@ enum HOST_SYSTEM { }; -#define VERSION "0.5" -#define BUILD_DATE "2023-12-19" +#define VERSION "0.5.1" +#define BUILD_DATE "2024-01-19" #define DEFAULT_BLOCK_SIZE 65536 @@ -107,23 +108,11 @@ VFSNew (TVFSLogFunc log_func) { struct TVFSGlobs * globs; - globs = g_malloc0 (sizeof (struct TVFSGlobs)); + log_init (); + globs = g_malloc0 (sizeof (struct TVFSGlobs)); globs->block_size = DEFAULT_BLOCK_SIZE; - globs->need_password = FALSE; - globs->failed_passwd_callback = FALSE; - globs->volume_missing_abort = FALSE; - globs->password = NULL; - globs->op_handle = NULL; - - globs->callback_data = NULL; - globs->callback_ask_question = NULL; - globs->callback_ask_password = NULL; - globs->callback_progress = NULL; - globs->log_func = log_func; - if (globs->log_func) - globs->log_func("unrar plugin: VFSInit"); return globs; } @@ -145,8 +134,11 @@ VFSSetCallbacks (struct TVFSGlobs *globs, void VFSFree (struct TVFSGlobs *globs) { - if (globs->log_func) - globs->log_func("unrar plugin: VFSDestroy"); + g_free (globs->curr_dir); + g_free (globs->archive_path); + g_free (globs->password); + filelist_tree_free (globs->files); + vfs_filelist_free (globs->vfs_filelist); g_free (globs); } @@ -174,7 +166,7 @@ VFSGetInfo () 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%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"); + module_info->Copyright = g_strdup ("Plugin Copyright (C) 2007-2024 Tomáš Bžatek\nUNRAR sources Copyright (C) 2002-2023 Alexander Roshal"); return module_info; } @@ -203,7 +195,7 @@ unrar_callback (UINT msg, LONG UserData, LONG P1, LONG P2) struct TVFSGlobs *globs = (struct TVFSGlobs *) UserData; if (globs == NULL) { - fprintf (stderr, "(WW) unrar_callback: UserData == NULL, aborting.\n"); + log_warn ("unrar_callback: UserData == NULL, aborting."); return 0; } @@ -211,7 +203,7 @@ unrar_callback (UINT msg, LONG UserData, LONG P1, LONG P2) switch (msg) { case UCM_CHANGEVOLUME: if (P2 == RAR_VOL_ASK) { - fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK, P1='%s'\n", (char *) P1); + log_info (" unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK, P1='%s'", (char *) P1); if (globs->callback_ask_question) { static const char *choices[] = { "Abort", /* response = 0 */ @@ -235,23 +227,23 @@ unrar_callback (UINT msg, LONG UserData, LONG P1, LONG P2) } 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)); + log_error ("unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK: access test failed: %s", strerror (errno)); return -1; } return 0; } else if (P2 == RAR_VOL_NOTIFY) { - fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_NOTIFY, P1='%s'\n", (char *) P1); + log_info (" unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_NOTIFY, P1='%s'", (char *) P1); return 0; } else { - fprintf (stderr, " (WW) unrar_callback: UCM_CHANGEVOLUME message, P1='%s', unhandled P2/action %ld, aborting.\n", (char *) P1, P2); + log_error (" unrar_callback: UCM_CHANGEVOLUME message, P1='%s', unhandled P2/action %ld, aborting.", (char *) P1, P2); return -1; } break; case UCM_PROCESSDATA: - fprintf (stderr, " (II) unrar_callback: UCM_PROCESSDATA message, P1/Addr = %p, P2/Count = %ld\n", (void *) P1, P2); + log_info (" unrar_callback: UCM_PROCESSDATA message, P1/Addr = %p, P2/Count = %ld", (void *) P1, P2); if (globs->callback_progress) { gboolean res; @@ -259,7 +251,7 @@ unrar_callback (UINT msg, LONG UserData, LONG P1, LONG P2) 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"); + log_warn ("unrar_callback: received cancellation result"); return -1; /* cancel the operation */ } } @@ -269,7 +261,7 @@ unrar_callback (UINT msg, LONG UserData, LONG P1, LONG P2) char *passwd = NULL; gboolean res = FALSE; - fprintf (stderr, " (II) unrar_callback: UCM_NEEDPASSWORD message, P1/buf = %p, P2/bufsize = %ld\n", (void *) P1, P2); + log_notice (" unrar_callback: UCM_NEEDPASSWORD message, P1/buf = %p, P2/bufsize = %ld", (void *) P1, P2); globs->failed_passwd_callback = TRUE; if (globs->callback_ask_password) { @@ -295,7 +287,7 @@ unrar_callback (UINT msg, LONG UserData, LONG P1, LONG P2) return 0; default: - fprintf (stderr, "(WW) unrar_callback: unhandled msg code %u, exiting!\n", msg); + log_warn ("unrar_callback: unhandled msg code %u, exiting!", msg); return -1; } @@ -397,7 +389,7 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error) globs->failed_passwd_callback = FALSE; globs->volume_missing_abort = FALSE; inode_no = 0; - fprintf (stderr, "(--) VFSOpenArchive: trying to open archive '%s'...\n", globs->archive_path); + log_notice ("VFSOpenArchive: opening archive '%s':", globs->archive_path); archive_data.ArcName = globs->archive_path; archive_data.CmtBuf = NULL; @@ -411,7 +403,7 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error) RARSetCallback (handle, unrar_callback, (LONG) globs); if (globs->password) { - fprintf (stderr, "(II) VFSOpenArchive: Setting password... \n"); + log_notice ("VFSOpenArchive: Setting password..."); RARSetPassword (handle, globs->password); } @@ -465,10 +457,10 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error) res2 = RARProcessFile (handle, RAR_SKIP, NULL, NULL); if (res2) - printf ("RARProcessFile result = %d\n", res2); + log_debug ("RARProcessFile result = %d", res2); } if (res != ERAR_END_ARCHIVE || globs->volume_missing_abort) { - fprintf (stderr, "(EE) VFSOpenArchive: RARReadHeader result = %d\n", res); + log_error ("VFSOpenArchive: RARReadHeader result = %d", res); rar_error_to_gerror (res, error); Result = FALSE; /* TODO: @@ -479,17 +471,16 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error) res = RARCloseArchive (handle); if (res) - fprintf (stderr, "(EE) VFSOpenArchive: RARCloseArchive result = %d\n", res); + log_warn ("VFSOpenArchive: RARCloseArchive result = %d", res); } else { - fprintf (stderr, "(EE) VFSOpenArchive: error occured when opening archive: OpenResult = %d\n", archive_data.OpenResult); + log_error ("VFSOpenArchive: error occured when opening archive: OpenResult = %d", archive_data.OpenResult); rar_error_to_gerror (archive_data.OpenResult, error); Result = FALSE; } - fprintf (stderr, "(II) VFSOpenArchive: done.\n"); + log_info ("VFSOpenArchive: done."); if (globs->need_password) - fprintf (stderr, "(II) VFSOpenArchive: Password present.\n"); - printf ("\n\nList of items:\n"); + log_notice ("VFSOpenArchive: Password present."); filelist_tree_print (globs->files); return Result; @@ -500,14 +491,17 @@ gboolean 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); - if (globs->files) - filelist_tree_free (globs->files); + log_debug ("VFSClose: Freeing objects..."); + vfs_filelist_free (globs->vfs_filelist); + globs->vfs_filelist = NULL; + filelist_tree_free (globs->files); + globs->files = NULL; g_free (globs->archive_path); + globs->archive_path = NULL; g_free (globs->curr_dir); + globs->curr_dir = NULL; g_free (globs->password); + globs->password = NULL; } return TRUE; } @@ -569,7 +563,7 @@ VFSResetPassword (struct TVFSGlobs *globs) struct TVFSItem * VFSListFirst (struct TVFSGlobs *globs, const char *sDir, gboolean FollowSymlinks, gboolean AddFullPath, GError **error) { - printf ("(--) VFSListFirst: Going to list all items in '%s'\n", sDir); + log_debug ("VFSListFirst: Going to list all items in '%s'", sDir); return vfs_filelist_list_first (globs->vfs_filelist, sDir, FollowSymlinks, AddFullPath, error); } @@ -592,7 +586,7 @@ VFSListClose (struct TVFSGlobs *globs, GError **error) struct TVFSItem * VFSFileInfo (struct TVFSGlobs *globs, const char *AFileName, gboolean FollowSymlinks, gboolean AddFullPath, GError **error) { - printf ("(--) VFSFileInfo: requested info for object '%s'\n", AFileName); + log_debug ("VFSFileInfo: requested info for object '%s'", AFileName); return vfs_filelist_file_info (globs->vfs_filelist, AFileName, FollowSymlinks, AddFullPath, error); } @@ -614,7 +608,7 @@ VFSGetDirSize (struct TVFSGlobs *globs, const char *APath) void VFSBreakGetDirSize (struct TVFSGlobs *globs) { - printf ("(WW) VFSBreakGetDirSize: calling break\n"); + log_debug ("VFSBreakGetDirSize: calling break"); if (globs) vfs_filelist_get_dir_size_break (globs->vfs_filelist); } @@ -713,14 +707,14 @@ VFSSetBlockSize (struct TVFSGlobs *globs, guint32 Value) gboolean VFSIsOnSameFS (struct TVFSGlobs *globs, const char *Path1, const char *Path2, gboolean FollowSymlinks) { - printf ("(WW) VFSIsOnSameFS: Not supported in UNRAR plugin.\n"); + log_debug ("VFSIsOnSameFS: Not supported in UNRAR plugin."); return TRUE; } gboolean VFSTwoSameFiles (struct TVFSGlobs *globs, const char *Path1, const char *Path2, gboolean FollowSymlinks) { - printf ("(WW) VFSTwoSameFiles: Not supported in RAR archives, comparing by paths.\n"); + log_debug ("VFSTwoSameFiles: Not supported in RAR archives, comparing by paths."); return compare_two_same_files (Path1, Path2); } @@ -739,7 +733,7 @@ VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error) g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED, "globs->op_handle != NULL"); return FALSE; } - printf ("(II) VFSStartCopyOperation: opening archive '%s'\n", globs->archive_path); + log_debug ("VFSStartCopyOperation: opening archive '%s'", globs->archive_path); archive_data.ArcName = globs->archive_path; archive_data.OpenMode = RAR_OM_EXTRACT; @@ -750,14 +744,14 @@ VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error) /* set password */ if (globs->password) { - printf ("(II) VFSStartCopyOperation: Setting password... \n"); + log_info ("VFSStartCopyOperation: Setting password..."); RARSetPassword (handle, globs->password); } globs->op_handle = handle; Result = TRUE; } else { - fprintf (stderr, "(EE) VFSStartCopyOperation: error occured when opening archive: OpenResult = %d\n", archive_data.OpenResult); + log_error ("VFSStartCopyOperation: error occured when opening archive: OpenResult = %d", archive_data.OpenResult); rar_error_to_gerror (archive_data.OpenResult, error); Result = FALSE; } @@ -777,12 +771,12 @@ VFSStopCopyOperation (struct TVFSGlobs *globs, GError **error) return FALSE; } - printf ("(II) VFSStopCopyOperation: closing archive.\n"); + log_debug ("VFSStopCopyOperation: closing archive."); Result = TRUE; res = RARCloseArchive (globs->op_handle); if (res) { - fprintf (stderr, "(EE) VFSCopyToLocal: RARCloseArchive result = %d\n", res); + log_warn ("VFSCopyToLocal: RARCloseArchive result = %d", res); rar_error_to_gerror (res, error); Result = FALSE; } @@ -807,31 +801,31 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN return FALSE; } if (sSrcName == NULL || sDstName == NULL || strlen (sSrcName) < 1 || strlen (sDstName) < 1) { - printf ("(EE) VFSCopyToLocal: The value of 'sSrcName' or 'sDstName' is NULL or empty\n"); + log_error ("VFSCopyToLocal: The value of 'sSrcName' or 'sDstName' is NULL or empty"); g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "The value of 'sSrcName' or 'sDstName' is NULL or empty."); return FALSE; } - printf ("(II) VFSCopyToLocal: copying file '%s' out to '%s'\n", sSrcName, sDstName); + log_notice ("VFSCopyToLocal: copying file '%s' out to '%s'", sSrcName, sDstName); node = filelist_tree_find_node_by_path (globs->files, sSrcName); if (! node) { - fprintf (stderr, "(EE) VFSCopyToLocal: cannot find file '%s'\n", sSrcName); + log_error ("VFSCopyToLocal: cannot find file '%s'", sSrcName); g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "cannot find file '%s'", sSrcName); return FALSE; } src = node->original_pathstr; if (! src) { - fprintf (stderr, "(WW) VFSCopyToLocal: cannot determine original filename\n"); + log_warn ("VFSCopyToLocal: cannot determine original filename"); src = (char *) sSrcName; } - printf ("(II) VFSCopyToLocal: new src path: '%s'\n", src); + log_debug ("VFSCopyToLocal: new src path: '%s'", src); while ((res = RARReadHeaderEx (globs->op_handle, &header)) == 0) { int res2; - g_print ("VFSCopyToLocal: found '%s'\n", header.FileName); + log_debug ("VFSCopyToLocal: found '%s'", header.FileName); if (g_strcmp0 (src, header.FileName) == 0) { globs->extract_done = 0; globs->extract_cancelled = FALSE; @@ -840,13 +834,13 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN res2 = RARProcessFile (globs->op_handle, RAR_EXTRACT, NULL, (char *)sDstName); if (globs->extract_cancelled) { - fprintf (stderr, "(WW) VFSCopyToLocal: cancelled !\n"); + log_debug ("VFSCopyToLocal: cancelled!"); g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Operation has been cancelled."); Result = FALSE; } else if (res2) { - fprintf (stderr, "(EE) VFSCopyToLocal: RARProcessFile result = %d\n", res2); + log_error ("VFSCopyToLocal: RARProcessFile result = %d", res2); rar_error_to_gerror (res2, error); Result = FALSE; } @@ -854,7 +848,7 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN } else { res2 = RARProcessFile (globs->op_handle, RAR_SKIP, NULL, NULL); if (res2) { - fprintf (stderr, "(EE) VFSCopyToLocal: RARProcessFile result = %d\n", res2); + log_error ("VFSCopyToLocal: RARProcessFile result = %d", res2); rar_error_to_gerror (res2, error); Result = FALSE; } @@ -864,30 +858,30 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN /* TODO: reopen archive on 'Unexpected end of archive' */ if (res != ERAR_END_ARCHIVE && res) { if (globs->extract_cancelled) { - fprintf (stderr, "(WW) VFSCopyToLocal: cancelled !\n"); + log_debug ("VFSCopyToLocal: cancelled!"); g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "Operation has been cancelled."); Result = FALSE; } else { - fprintf (stderr, "(EE) VFSCopyToLocal: RARReadHeader result = %d\n", res); + log_error ("VFSCopyToLocal: RARReadHeader result = %d", res); rar_error_to_gerror (res, error); } } if (! found && Result) { - fprintf (stderr, "(EE) VFSCopyToLocal: file not found in archive.\n"); + log_error ("VFSCopyToLocal: file not found in archive."); g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "File not found in archive."); Result = FALSE; } - fprintf (stderr, "(II) VFSCopyToLocal: finished. \n"); + log_debug ("VFSCopyToLocal: finished."); return Result; } gboolean VFSCopyFromLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append, GError **error) { - printf ("(WW) VFSCopyFromLocal: Not supported in UNRAR plugin.\n"); + log_warn ("VFSCopyFromLocal: Not supported in UNRAR plugin."); g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Not supported in UNRAR plugin."); return FALSE; } |
