summaryrefslogtreecommitdiff
path: root/unrar/unrar.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2008-10-05 11:04:26 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2008-10-05 11:04:26 +0200
commitd0caac91ac0a03e021d50d1de978733e11ba2ccd (patch)
treeb763e376e8f289baaccf332398d9354663115792 /unrar/unrar.c
parentc41d3e7d896492dd70cd1d548ef4fd5b3cbe4954 (diff)
downloadtuxcmd-modules-d0caac91ac0a03e021d50d1de978733e11ba2ccd.tar.xz
VFS API break: Introduce FDisplayName propertyv0.6.52
Diffstat (limited to 'unrar/unrar.c')
-rw-r--r--unrar/unrar.c142
1 files changed, 72 insertions, 70 deletions
diff --git a/unrar/unrar.c b/unrar/unrar.c
index 8a725f6..5468b94 100644
--- a/unrar/unrar.c
+++ b/unrar/unrar.c
@@ -1,28 +1,28 @@
/* UNRAR plugin for Tux Commander
- * version 0.2.3, designed for unrar v3.8.2
+ * version 0.3.0, designed for unrar v3.8.2
* Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net>
* Check for updates on tuxcmd.sourceforge.net
*
* Uses UNRAR sources
- * UnRAR - free utility for RAR archives
+ * UnRAR - free utility for RAR archives
* Copyright (C) Alexander L. Roshal
* http://www.rarlab.com/
- *
-
-
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string.h>
@@ -55,8 +55,8 @@ enum HOST_SYSTEM {
};
-#define VERSION "0.2.3"
-#define BUILD_DATE "2008-08-21"
+#define VERSION "0.3.0"
+#define BUILD_DATE "2008-10-05"
#define DEFAULT_BLOCK_SIZE 65536
@@ -65,7 +65,7 @@ enum HOST_SYSTEM {
/******************************************************************************************************/
/** Auxiliary classes */
-/************** ****************/
+/************** ****************/
@@ -74,18 +74,18 @@ struct TVFSGlobs {
TVFSLogFunc log_func;
char *curr_dir;
char *archive_path;
-
+
gboolean need_password;
gboolean passwd_callback;
char *password;
unsigned long block_size;
-
+
struct PathTree *files;
struct VfsFilelistData *vfs_filelist;
-
+
u_int64_t total_size;
-
+
void *extract_callback_data;
TVFSCopyCallBackFunc extract_callback_func;
u_int64_t extract_file_size;
@@ -125,7 +125,7 @@ void VFSDestroy(struct TVFSGlobs *globs)
int VFSVersion()
{
- return 3;
+ return cVFSVersion;
}
struct TVFSInfo VFSGetInfo()
@@ -134,7 +134,7 @@ struct TVFSInfo VFSGetInfo()
module_info.Name = "UNRAR plugin";
module_info.Description = "RAR archiving plugin";
char *s = (char*)malloc(255);
- snprintf(s, 255, "version %s, build date: %s\nusing unrar sources v%d.%d [%d-%.2d-%.2d]\n",
+ snprintf(s, 255, "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.About = strdup(s);
free(s);
@@ -163,7 +163,7 @@ int unrar_callback(UINT msg, LONG UserData, LONG P1, LONG P2)
{
// fprintf(stderr, "(II) unrar_callback called: msg = %d, UserData = %lx, sizeof(UserData) = %ld, P1 = %ld, P2 = %ld\n", msg, UserData, sizeof(UserData), P1, P2);
- // >= 0 => Weiter, -1 => Stop
+ // >= 0 => Weiter, -1 => Stop
switch(msg)
{
case UCM_CHANGEVOLUME: {
@@ -191,14 +191,14 @@ int unrar_callback(UINT msg, LONG UserData, LONG P1, LONG P2)
globs->extract_done += P2;
int res = globs->extract_callback_func(globs->extract_done, globs->extract_file_size, globs->extract_callback_data);
-
+
// fprintf(stderr, " (II) unrar_callback: res = %d \n", res);
if (! res ) {
globs->extract_cancelled = TRUE;
fprintf(stderr, "(WW) unrar_callback: received cancellation result\n");
return -1; // Cancel operation
}
- }
+ }
break;
}
@@ -208,7 +208,7 @@ int unrar_callback(UINT msg, LONG UserData, LONG P1, LONG P2)
if (globs) globs->passwd_callback = TRUE;
break;
}
- }
+ }
return 0;
}
@@ -261,16 +261,16 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
archive_data = (struct RAROpenArchiveDataEx*) malloc(sizeof(struct RAROpenArchiveDataEx));
memset(archive_data, 0, sizeof(struct RAROpenArchiveDataEx));
archive_data->ArcName = globs->archive_path;
- archive_data->CmtBuf = NULL;
+ 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
@@ -282,7 +282,7 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
fprintf(stderr, "(II) VFSOpen: Setting password... \n");
RARSetPassword(handle, globs->password);
}
-
+
struct RARHeaderDataEx *header;
header = (struct RARHeaderDataEx*) malloc(sizeof(struct RARHeaderDataEx));
memset(header, 0, sizeof(struct RARHeaderDataEx));
@@ -290,7 +290,7 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
header->CmtBufSize = 0;
int PASCAL res = 0;
- while ((res = RARReadHeaderEx(handle, header)) == 0)
+ while ((res = RARReadHeaderEx(handle, header)) == 0)
{
printf(" header->FileName = '%s', Flags = 0x%x\n", header->FileName, header->Flags);
@@ -299,7 +299,7 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
memset(item, 0, sizeof(struct TVFSItem));
item->iSize = (u_int64_t)((u_int64_t)(header->UnpSizeHigh * 0x100000000) + (u_int64_t)header->UnpSize);
- globs->total_size += item->iSize;
+ globs->total_size += item->iSize;
if ((header->Flags & 0x00e0 /* LHD_WINDOWMASK */ ) == 0x00e0 /* LHD_DIRECTORY */)
item->ItemType = vDirectory;
else item->ItemType = vRegular;
@@ -316,17 +316,17 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
else header->FileAttr = 0x81b6 | header->FileAttr;
break;
}
-
+
item->iMode = header->FileAttr;
item->iUID = geteuid();
item->iGID = getegid();
item->m_time = rar_time_to_unix(header->FileTime);
item->c_time = item->m_time;
item->a_time = item->m_time;
-
- // Add item to the global list and continue with next file
+
+ // Add item to the global list and continue with next file
filelist_tree_add_item(globs->files, header->FileName, item, 0);
- int PASCAL res2 = RARProcessFile(handle, RAR_SKIP, NULL, NULL);
+ int PASCAL res2 = RARProcessFile(handle, RAR_SKIP, NULL, NULL);
if (res2) printf("RARProcessFile result = %d\n", res2);
}
// printf("\nRARReadHeader result = %d\n", res);
@@ -346,13 +346,13 @@ TVFSResult VFSOpen(struct TVFSGlobs *globs, char *sName)
fprintf(stderr, "(EE) VFSOpen: error occured when opening archive: OpenResult = %d\n", archive_data->OpenResult);
Result = cVFS_Failed;
}
-
+
free(archive_data);
fprintf(stderr, "(II) VFSOpen: done. \n");
if (globs->need_password) printf("Password present.\n");
printf("\n\nList of items:\n");
filelist_tree_print(globs->files);
-
+
return Result;
}
@@ -366,7 +366,7 @@ TVFSResult VFSClose(struct TVFSGlobs *globs)
if (globs->archive_path) free(globs->archive_path);
if (globs->curr_dir) free(globs->curr_dir);
if (globs->password) free(globs->password);
- }
+ }
return cVFS_OK;
}
@@ -396,7 +396,7 @@ TVFSResult VFSChangeDir(struct TVFSGlobs *globs, char *NewPath)
printf("(EE) VFSChangeDir: NewPath is NULL!\n");
return cVFS_Failed;
}
-
+
globs->curr_dir = vfs_filelist_change_dir(globs->vfs_filelist, NewPath);
if (globs->curr_dir) return cVFS_OK;
else return cVFS_Failed;
@@ -432,26 +432,26 @@ TVFSResult VFSListFirst(struct TVFSGlobs *globs, char *sDir, struct TVFSItem *It
return cVFS_Failed;
}
printf ("(--) VFSListFirst: Going to list all items in '%s'\n", sDir);
-
- return vfs_filelist_list_first(globs->vfs_filelist, sDir, Item);
+
+ return vfs_filelist_list_first(globs->vfs_filelist, sDir, Item);
}
TVFSResult VFSListNext(struct TVFSGlobs *globs, char *sDir, struct TVFSItem *Item)
{
- return vfs_filelist_list_next(globs->vfs_filelist, sDir, Item);
+ return vfs_filelist_list_next(globs->vfs_filelist, sDir, Item);
}
TVFSResult VFSListClose(struct TVFSGlobs *globs)
{
- return vfs_filelist_list_close(globs->vfs_filelist);
+ return vfs_filelist_list_close(globs->vfs_filelist);
}
/******************************************************************************************************/
long VFSFileExists(struct TVFSGlobs *globs, const char *FileName, const long Use_lstat)
{
- if (! globs) return FALSE;
- return vfs_filelist_file_exists(globs->vfs_filelist, FileName, Use_lstat);
+ if (! globs) return FALSE;
+ return vfs_filelist_file_exists(globs->vfs_filelist, FileName, Use_lstat);
}
TVFSResult VFSFileInfo(struct TVFSGlobs *globs, char *AFileName, struct TVFSItem *Item)
@@ -464,7 +464,7 @@ TVFSResult VFSFileInfo(struct TVFSGlobs *globs, char *AFileName, struct TVFSItem
/******************************************************************************************************/
/** Recursive tree size counting */
-/************** ****************/
+/************** ****************/
u_int64_t VFSGetDirSize(struct TVFSGlobs *globs, char *APath)
{
@@ -481,7 +481,7 @@ void VFSBreakGetDirSize(struct TVFSGlobs *globs)
/******************************************************************************************************/
/** Methods modifying the archive */
-/************** ****************/
+/************** ****************/
TVFSResult VFSMkDir(struct TVFSGlobs *globs, const char *sDirName)
{
@@ -587,17 +587,17 @@ TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char
printf("(EE) VFSCopyOut: The value of 'sSrcName' or 'sDstName' is NULL or empty\n");
return cVFS_Failed;
}
-
+
printf("(II) VFSCopyOut: copying file '%s' out to '%s'\n", sSrcName, sDstName);
TVFSResult Result = cVFS_OK;
-
+
char *src;
if (! IS_DIR_SEP(*sSrcName)) src = g_build_path("/", globs->curr_dir, sSrcName, NULL);
else src = g_strdup(sSrcName);
printf("(II) VFSCopyOut: new src path: '%s'\n", src);
-
+
// printf("(II) VFSCopyOut: pCallBackProgress = 0x%lX, data = 0x%lX\n", (unsigned long int)pCallBackProgress, (unsigned long int)data);
globs->extract_callback_data = data;
globs->extract_callback_func = pCallBackProgress;
@@ -608,17 +608,17 @@ TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char
archive_data = (struct RAROpenArchiveDataEx*) malloc(sizeof(struct RAROpenArchiveDataEx));
memset(archive_data, 0, sizeof(struct RAROpenArchiveDataEx));
archive_data->ArcName = globs->archive_path;
- archive_data->CmtBuf = NULL;
+ archive_data->CmtBuf = NULL;
archive_data->CmtBufSize = 0;
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);
// printf("sizeof(TVFSResult) = %ld \n", sizeof(TVFSResult));
-
+
if ((handle) && (! archive_data->OpenResult))
{
// Set callbacks
@@ -639,12 +639,12 @@ TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char
header->CmtBufSize = 0;
int res = 0;
- while ((res = RARReadHeaderEx(handle, header)) == 0)
+ while ((res = RARReadHeaderEx(handle, header)) == 0)
{
- char *ssrc = src;
+ char *ssrc = src;
char *asrc = header->FileName;
if (IS_DIR_SEP(*ssrc)) ssrc++;
- if (IS_DIR_SEP(*asrc)) asrc++;
+ if (IS_DIR_SEP(*asrc)) asrc++;
if (strcmp(ssrc, asrc) == 0) {
// fprintf(stderr, "(II) VFSCopyOut: extract_file_path(sDstName) = '%s', extract_file_name(sDstName) = '%s' \n", extract_file_path(sDstName), extract_file_name(sDstName));
globs->extract_done = 0;
@@ -652,16 +652,16 @@ TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char
globs->extract_cancelled = FALSE;
int res2 = RARProcessFile(handle, RAR_EXTRACT, NULL, (char *)sDstName);
-
+
if (globs->extract_cancelled) Result = cVFS_Cancelled;
- else
+ else
if (res2) {
fprintf(stderr, "(EE) VFSCopyOut: RARProcessFile result = %d\n", res2);
Result = cVFS_ReadErr;
}
break;
} else {
- int res2 = RARProcessFile(handle, RAR_SKIP, NULL, NULL);
+ int res2 = RARProcessFile(handle, RAR_SKIP, NULL, NULL);
if (res2) {
fprintf(stderr, "(EE) VFSCopyOut: RARProcessFile result = %d\n", res2);
Result = cVFS_ReadErr;
@@ -692,12 +692,12 @@ TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char
Result = cVFS_BadPassword;
break;
case ERAR_UNKNOWN:
- default:
+ default:
Result = cVFS_WriteErr;
break;
}
}
-
+
free(header);
res = RARCloseArchive(handle);
@@ -709,10 +709,10 @@ TVFSResult VFSCopyOut(struct TVFSGlobs *globs, const char *sSrcName, const char
fprintf(stderr, "(EE) VFSCopyOut: error occured when opening archive: OpenResult = %d\n", archive_data->OpenResult);
Result = cVFS_ReadErr;
}
-
+
free(archive_data);
g_free(src);
-
+
fprintf(stderr, "(II) VFSCopyOut: finished. \n");
return Result;
}
@@ -728,7 +728,9 @@ TVFSResult VFSCopyIn(struct TVFSGlobs *globs, const char *sSrcName, const char *
/**********
* TODO:
+ *
+ * - UTF-8, FName/FDisplayName and absolute/relative paths revision needed!
* - no error reporting when archive is corrupted
* - archive testing (needs new VFS API)
- *
+ *
***/