From a4a7f6a7a936fcd9c3083e97b0573a87b8c54db8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jan 2017 22:58:55 +0800 Subject: [PATCH 1/6] Add rar archive support! --- CMakeLists.txt | 6 +- archiveRAR.c | 219 ++++++++++++++++++++++++++++++ archiveRAR.h | 28 ++++ file.c | 7 +- file.h | 1 + hex.c | 13 +- io_process.c | 48 ++++++- io_process.h | 1 + language.c | 1 + language.h | 1 + main.c | 28 +++- main.h | 1 + photo.c | 21 ++- property_dialog.c | 18 ++- resources/english_us.txt | 1 + sfo.c | 18 ++- text.c | 14 +- unrarlib/unrar_c_wrapper.h | 155 +++++++++++++++++++++ unrarlib/unrarlibutils.c | 267 +++++++++++++++++++++++++++++++++++++ unrarlib/unrarlibutils.h | 52 ++++++++ 20 files changed, 880 insertions(+), 20 deletions(-) create mode 100644 archiveRAR.c create mode 100644 archiveRAR.h create mode 100644 unrarlib/unrar_c_wrapper.h create mode 100644 unrarlib/unrarlibutils.c create mode 100644 unrarlib/unrarlibutils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b55e36..ee2dec1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ set(VITA_TITLEID "VITASHELL") set(VITA_VERSION "01.43") # Flags and includes -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -Wno-unused-variable -Wno-unused-but-set-variable -fno-lto") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -Wno-unused-variable -Wno-unused-but-set-variable ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions") set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1") set(VITA_MAKE_FSELF_FLAGS "${VITA_MAKE_FSELF_FLAGS} -a 0x2800000000000001") @@ -100,6 +100,8 @@ add_executable(VitaShell libmad/stream.c libmad/synth.c libmad/timer.c + unrarlib/unrarlibutils.c + archiveRAR.c ) target_link_libraries(VitaShell @@ -137,6 +139,8 @@ target_link_libraries(VitaShell ScePower_stub ScePromoterUtil_stub SceTouch_stub + unrar + stdc++ ) # Create Vita artifacts diff --git a/archiveRAR.c b/archiveRAR.c new file mode 100644 index 0000000..24a2b5e --- /dev/null +++ b/archiveRAR.c @@ -0,0 +1,219 @@ +#include "archiveRAR.h" +#include "main.h" + +static ArchiveFileNode* root = NULL; +static int32_t filePathLength = -1; + + +int archiveRAROpen(char *file) { + root = openRARFile(file); + if(!root) { + return -1; + } + filePathLength = strlen(file); + return 1; +} + +int fileListGetRARArchiveEntries(FileList *list, char *path, int sort) { + if(!root) + return -1; + + FileListEntry *entry = malloc(sizeof(FileListEntry)); + strcpy(entry->name, DIR_UP); + entry->name_length = strlen(DIR_UP); + entry->is_folder = 1; + entry->type = FILE_TYPE_UNKNOWN; + fileListAddEntry(list, entry, sort); + + ArchiveFileNode* node = NULL; + if(strlen(path) == (filePathLength + sizeof(char))) + node = root; + else + node = getFloderNodeFromPath(root,path + filePathLength + sizeof(char)); + + uint32_t i = 0; + for(; i < node->childCount; i++) { + ArchiveFileNode* _t = (ArchiveFileNode*)(node->childPt[i]); + FileListEntry * childentry = malloc(sizeof(FileListEntry)); + + strcpy(childentry->name,_t->nodeName); + childentry->name_length = strlen(childentry->name); + childentry->size = _t->data.UnpSize; + childentry->size2 = _t->data.PackSize; + + sceRtcSetDosTime(&childentry->atime,_t->data.FileTime); + sceRtcSetDosTime(&childentry->ctime,_t->data.FileTime); + sceRtcSetDosTime(&childentry->mtime,_t->data.FileTime); + + if(_t->data.Flags == 0x20) { + addEndSlash(childentry->name); + childentry->is_folder = 1; + list->folders++; + } else { + childentry->type = getFileType(childentry->name); + childentry->is_folder = 0; + list->files++; + } + fileListAddEntry(list, childentry, sort); + } + return 1; +} + +int ReadArchiveRARFile(char *file, void *buf, int size) { + if(filePathLength < 0) + return -1; + + char filepath[filePathLength + sizeof(char)]; + strncpy(filepath,file,filePathLength); + filepath[filePathLength] = '\0'; + struct ExtractHeader header = {memPtr:buf,offset:0,bufferSize:size,file:0,param:NULL}; + if(extractRAR(filepath,file + (filePathLength + sizeof(char)),&header) > 0) + return header.offset; + else + return -1; +} + +int archiveRARFileGetstat(const char *file, SceIoStat *stat) { + if(!root) + return -1; + + const char* p = file + (filePathLength + sizeof(char)); + uint32_t p_length = strlen(p); + + if(p[p_length - 1] == '/') + return -1; + + ArchiveFileNode* filenode = getFileNodeFromFilePath(root,p); + if(!filenode) + return -1; + + if(stat) { + stat->st_size = filenode->data.UnpSize; + sceRtcSetDosTime(&stat->st_atime,filenode->data.FileTime); + sceRtcSetDosTime(&stat->st_ctime,filenode->data.FileTime); + sceRtcSetDosTime(&stat->st_mtime,filenode->data.FileTime); + } + + return 1; +} + +int getRARArchivePathInfo(char *path, uint64_t *size, uint32_t *folders, uint32_t *files) { + if(!root) + return -1; + + SceIoStat stat; + memset(&stat, 0, sizeof(SceIoStat)); + if (archiveRARFileGetstat(path, &stat) < 0) { + FileList list; + memset(&list, 0, sizeof(FileList)); + fileListGetRARArchiveEntries(&list, path, SORT_NONE); + + FileListEntry *entry = list.head->next; // Ignore .. + + int i; + for (i = 0; i < list.length - 1; i++) { + char *new_path = malloc(strlen(path) + strlen(entry->name) + 2); + snprintf(new_path, MAX_PATH_LENGTH, "%s%s", path, entry->name); + + getRARArchivePathInfo(new_path, size, folders, files); + + free(new_path); + + entry = entry->next; + } + + if (folders) + (*folders)++; + + fileListEmpty(&list); + } else { + if (size) + (*size) += stat.st_size; + + if (files) + (*files)++; + } + + return 0; +} + +int extractRARArchivePath(char *src, char *dst, FileProcessParam *param){ + if(!root) + return -1; + + SceIoStat stat; + memset(&stat, 0, sizeof(SceIoStat)); + if (archiveRARFileGetstat(src, &stat) < 0) { + FileList list; + memset(&list, 0, sizeof(FileList)); + fileListGetRARArchiveEntries(&list, src, SORT_NONE); + + int ret = sceIoMkdir(dst, 0777); + if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) { + fileListEmpty(&list); + return ret; + } + + if (param) { + if (param->value) + (*param->value) += DIRECTORY_SIZE; + + if (param->SetProgress) + param->SetProgress(param->value ? *param->value : 0, param->max); + + if (param->cancelHandler && param->cancelHandler()) { + fileListEmpty(&list); + return 0; + } + } + + FileListEntry *entry = list.head->next; // Ignore .. + + int i; + for (i = 0; i < list.length - 1; i++) { + char *src_path = malloc(strlen(src) + strlen(entry->name) + 2); + snprintf(src_path, MAX_PATH_LENGTH, "%s%s", src, entry->name); + + char *dst_path = malloc(strlen(dst) + strlen(entry->name) + 2); + snprintf(dst_path, MAX_PATH_LENGTH, "%s%s", dst, entry->name); + + int ret = extractRARArchivePath(src_path, dst_path, param); + + free(dst_path); + free(src_path); + + if (ret <= 0) { + fileListEmpty(&list); + return ret; + } + + entry = entry->next; + } + + fileListEmpty(&list); + }else{ + char filepath[filePathLength + sizeof(char)]; + strncpy(filepath,src,filePathLength); + filepath[filePathLength] = '\0'; + + SceUID fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777); + + struct ExtractHeader header = {file:fddst,offset:0,memPtr:NULL,bufferSize:0,param:param}; + + int result = extractRAR(filepath,src + (filePathLength + sizeof(char)),&header); + sceIoClose(fddst); + + return result; + } + + return 1; +} + +int archiveRARClose() { + filePathLength = -1; + if (!root) { + closeRARFile(root); + root = NULL; + } + return 1; +} \ No newline at end of file diff --git a/archiveRAR.h b/archiveRAR.h new file mode 100644 index 0000000..af5489a --- /dev/null +++ b/archiveRAR.h @@ -0,0 +1,28 @@ +#ifndef ARCHIVERAR_H_INC +#define ARCHIVERAR_H_INC + +#include +#include +#include + +#include "file.h" +#include "unrarlib/unrarlibutils.h" +#include "utils.h" + + +int fileListGetRARArchiveEntries(FileList *list, char *path, int sort); + +int getRARArchivePathInfo(char *path, uint64_t *size, uint32_t *folders, uint32_t *files); +int extractRARArchivePath(char *src, char *dst, FileProcessParam *param); + +int archiveRARFileGetstat(const char *file, SceIoStat *stat); +int archiveRARFileOpen(const char *file, int flags, SceMode mode); +int archiveRARFileRead(SceUID fd, void *data, SceSize size); +int archiveRARFileClose(SceUID fd); + +int ReadArchiveRARFile(char *file, void *buf, int size); + +int archiveRARClose(); +int archiveRAROpen(char *file); + +#endif // ARCHIVERAR_H_INC diff --git a/file.c b/file.c index 5904dfe..71e42e9 100644 --- a/file.c +++ b/file.c @@ -611,6 +611,7 @@ static ExtensionType extension_types[] = { { ".VPK", FILE_TYPE_VPK }, { ".XML", FILE_TYPE_XML }, { ".ZIP", FILE_TYPE_ZIP }, + { ".RAR", FILE_TYPE_RAR }, }; int getFileType(char *file) { @@ -976,7 +977,11 @@ int fileListGetDirectoryEntries(FileList *list, char *path, int sort) { int fileListGetEntries(FileList *list, char *path, int sort) { if (isInArchive()) { - return fileListGetArchiveEntries(list, path, sort); + enum FileTypes type = getArchiveType(); + if(type == FILE_TYPE_ZIP) + return fileListGetArchiveEntries(list, path, sort); + else if(type == FILE_TYPE_RAR) + return fileListGetRARArchiveEntries(list,path,sort); } if (strcasecmp(path, HOME_PATH) == 0) { diff --git a/file.h b/file.h index cd0a965..3ff371c 100644 --- a/file.h +++ b/file.h @@ -45,6 +45,7 @@ enum FileTypes { FILE_TYPE_VPK, FILE_TYPE_XML, FILE_TYPE_ZIP, + FILE_TYPE_RAR, }; enum FileSortFlags { diff --git a/hex.c b/hex.c index 0147e35..a956d14 100644 --- a/hex.c +++ b/hex.c @@ -81,7 +81,18 @@ int hexViewer(char *file) { int size = 0; if (isInArchive()) { - size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); + break; + case FILE_TYPE_RAR: + size = ReadArchiveRARFile(file,buffer,BIG_BUFFER_SIZE); + break; + default: + size = -1; + break; + } } else { size = ReadFile(file, buffer, BIG_BUFFER_SIZE); } diff --git a/io_process.c b/io_process.c index abe7f70..616a30f 100644 --- a/io_process.c +++ b/io_process.c @@ -19,6 +19,7 @@ #include "main.h" #include "io_process.h" #include "archive.h" +#include "archiveRAR.h" #include "file.h" #include "message_dialog.h" #include "language.h" @@ -222,7 +223,17 @@ int copy_thread(SceSize args_size, CopyArguments *args) { } else { // Copy // Open archive, because when you copy from an archive, you leave the archive to paste if (args->copy_mode == COPY_MODE_EXTRACT) { - int res = archiveOpen(args->archive_path); + int res = -1; + switch(args->file_type){ + case FILE_TYPE_ZIP: + res = archiveOpen(args->archive_path); + break; + case FILE_TYPE_RAR: + res = archiveRAROpen(args->archive_path); + break; + default: + res = -1; + } if (res < 0) { closeWaitDialog(); errorDialog(res); @@ -241,7 +252,16 @@ int copy_thread(SceSize args_size, CopyArguments *args) { snprintf(src_path, MAX_PATH_LENGTH, "%s%s", args->copy_list->path, copy_entry->name); if (args->copy_mode == COPY_MODE_EXTRACT) { - getArchivePathInfo(src_path, &size, &folders, &files); + switch(args->file_type){ + case FILE_TYPE_ZIP: + getArchivePathInfo(src_path, &size, &folders, &files); + break; + case FILE_TYPE_RAR: + getRARArchivePathInfo(src_path,&size,&folders,&files); + break; + default: + break; + } } else { getPathInfo(src_path, &size, &folders, &files, NULL); } @@ -272,7 +292,17 @@ int copy_thread(SceSize args_size, CopyArguments *args) { param.cancelHandler = cancelHandler; if (args->copy_mode == COPY_MODE_EXTRACT) { - int res = extractArchivePath(src_path, dst_path, ¶m); + int res = -1; + switch(args->file_type){ + case FILE_TYPE_ZIP: + res = extractArchivePath(src_path, dst_path, ¶m); + break; + case FILE_TYPE_RAR: + res = extractRARArchivePath(src_path,dst_path,¶m); + break; + default: + break; + } if (res <= 0) { closeWaitDialog(); dialog_step = DIALOG_STEP_CANCELLED; @@ -294,7 +324,17 @@ int copy_thread(SceSize args_size, CopyArguments *args) { // Close archive if (args->copy_mode == COPY_MODE_EXTRACT) { - int res = archiveClose(); + int res = -1; + switch(args->file_type){ + case FILE_TYPE_ZIP: + res = archiveClose(); + break; + case FILE_TYPE_RAR: + res = archiveRARClose(); + break; + default: + break; + } if (res < 0) { closeWaitDialog(); errorDialog(res); diff --git a/io_process.h b/io_process.h index 41f317e..5ec7c8d 100644 --- a/io_process.h +++ b/io_process.h @@ -43,6 +43,7 @@ typedef struct { FileList *copy_list; char *archive_path; int copy_mode; + int file_type; } CopyArguments; typedef struct { diff --git a/language.c b/language.c index 9156489..1364789 100644 --- a/language.c +++ b/language.c @@ -139,6 +139,7 @@ void loadLanguage(int id) { LANGUAGE_ENTRY(PROPERTY_TYPE_VPK), LANGUAGE_ENTRY(PROPERTY_TYPE_XML), LANGUAGE_ENTRY(PROPERTY_TYPE_ZIP), + LANGUAGE_ENTRY(PROPERTY_TYPE_RAR), LANGUAGE_ENTRY(PROPERTY_TYPE_FSELF), LANGUAGE_ENTRY(PROPERTY_FSELF_MODE_SAFE), LANGUAGE_ENTRY(PROPERTY_FSELF_MODE_UNSAFE), diff --git a/language.h b/language.h index a6bbb4c..db8db4e 100644 --- a/language.h +++ b/language.h @@ -98,6 +98,7 @@ enum LanguageContainer { PROPERTY_TYPE_VPK, PROPERTY_TYPE_XML, PROPERTY_TYPE_ZIP, + PROPERTY_TYPE_RAR, PROPERTY_TYPE_FSELF, PROPERTY_FSELF_MODE_SAFE, PROPERTY_FSELF_MODE_UNSAFE, diff --git a/main.c b/main.c index 796a22f..4f20255 100644 --- a/main.c +++ b/main.c @@ -38,6 +38,7 @@ #include "utils.h" #include "sfo.h" #include "list_dialog.h" +#include "archiveRAR.h" #include "audio/vita_audio.h" @@ -66,10 +67,13 @@ static int dir_level = 0; // Copy mode static int copy_mode = COPY_MODE_NORMAL; +static int file_type = FILE_TYPE_UNKNOWN; +static char archive_copy_path[MAX_PATH_LENGTH]; // Archive int is_in_archive = 0; int dir_level_archive = -1; +enum FileTypes archive_type = FILE_TYPE_ZIP; // FTP static char vita_ip[16]; @@ -102,6 +106,10 @@ void dirLevelUp() { rel_pos = 0; } +enum FileTypes getArchiveType(){ + return archive_type; +} + int isInArchive() { return is_in_archive; } @@ -109,7 +117,11 @@ int isInArchive() { void dirUpCloseArchive() { if (isInArchive() && dir_level_archive >= dir_level) { is_in_archive = 0; - archiveClose(); + enum FileTypes archiveType = getArchiveType(); + if(archiveType == FILE_TYPE_RAR) + archiveRARClose(); + else if(archiveType == FILE_TYPE_ZIP) + archiveClose(); dir_level_archive = -1; } } @@ -273,6 +285,7 @@ int handleFile(char *file, FileListEntry *entry) { case FILE_TYPE_OGG: case FILE_TYPE_VPK: case FILE_TYPE_ZIP: + case FILE_TYPE_RAR: if (isInArchive()) type = FILE_TYPE_UNKNOWN; @@ -306,6 +319,9 @@ int handleFile(char *file, FileListEntry *entry) { case FILE_TYPE_ZIP: res = archiveOpen(file); break; + case FILE_TYPE_RAR: + res = archiveRAROpen(file); + break; case FILE_TYPE_SFO: res = SFOReader(file); @@ -723,6 +739,9 @@ int contextMenuEnterCallback(int pos, void* context) { } else { copy_mode = isInArchive() ? COPY_MODE_EXTRACT : COPY_MODE_NORMAL; } + + file_type = getArchiveType(); + strcpy(archive_copy_path,archive_path); // Empty copy list at first fileListEmpty(©_list); @@ -1136,8 +1155,9 @@ int dialogSteps() { CopyArguments args; args.file_list = &file_list; args.copy_list = ©_list; - args.archive_path = archive_path; + args.archive_path = archive_copy_path; args.copy_mode = copy_mode; + args.file_type = file_type; dialog_step = DIALOG_STEP_COPYING; @@ -1585,8 +1605,9 @@ int fileBrowserMenuCtrl() { int type = handleFile(cur_file, file_entry); // Archive mode - if (type == FILE_TYPE_ZIP) { + if ((type == FILE_TYPE_ZIP) | (type == FILE_TYPE_RAR)) { is_in_archive = 1; + archive_type = type; dir_level_archive = dir_level; snprintf(archive_path, MAX_PATH_LENGTH, "%s%s", file_list.path, file_entry->name); @@ -1751,6 +1772,7 @@ int shellMain() { case FILE_TYPE_VPK: case FILE_TYPE_ZIP: + case FILE_TYPE_RAR: color = ARCHIVE_COLOR; icon = archive_icon; break; diff --git a/main.h b/main.h index 16b4d62..0e2ca4f 100644 --- a/main.h +++ b/main.h @@ -228,6 +228,7 @@ void drawScrollBar(int pos, int n); void drawShellInfo(char *path); int isInArchive(); +enum FileTypes getArchiveType(); void ftpvita_PROM(ftpvita_client_info_t *client); void install_unassisted_sync(char *path); diff --git a/photo.c b/photo.c index f10721a..1c3f0b9 100644 --- a/photo.c +++ b/photo.c @@ -29,11 +29,22 @@ vita2d_texture *loadImage(char *file, int type, char *buffer) { if (isInArchive()) { int size = 0; - if (isInArchive()) { - size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); - } else { - size = ReadFile(file, buffer, BIG_BUFFER_SIZE); - } + if (isInArchive()) { + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); + break; + case FILE_TYPE_RAR: + size = ReadArchiveRARFile(file,buffer,BIG_BUFFER_SIZE); + break; + default: + size = -1; + break; + } + } else { + size = ReadFile(file, buffer, BIG_BUFFER_SIZE); + } if (size <= 0) { return NULL; diff --git a/property_dialog.c b/property_dialog.c index 0abf0d1..a8fe1ea 100644 --- a/property_dialog.c +++ b/property_dialog.c @@ -18,6 +18,7 @@ #include "main.h" #include "archive.h" +#include "archiveRAR.h" #include "init.h" #include "theme.h" #include "language.h" @@ -185,7 +186,18 @@ int initPropertyDialog(char *path, FileListEntry *entry) { uint32_t buffer[0x88/4]; if (isInArchive()) { - size = ReadArchiveFile(path, buffer, sizeof(buffer)); + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + size = ReadArchiveFile(path, buffer, sizeof(buffer)); + break; + case FILE_TYPE_RAR: + size = ReadArchiveRARFile(path,buffer,sizeof(buffer)); + break; + default: + size = -1; + break; + } } else { size = ReadFile(path, buffer, sizeof(buffer)); } @@ -256,6 +268,10 @@ int initPropertyDialog(char *path, FileListEntry *entry) { case FILE_TYPE_ZIP: type = PROPERTY_TYPE_ZIP; break; + + case FILE_TYPE_RAR: + type = PROPERTY_TYPE_RAR; + break; } width = copyStringLimited(property_type, language_container[type], PROPERTY_DIALOG_ENTRY_MAX_WIDTH); diff --git a/resources/english_us.txt b/resources/english_us.txt index 6cdaabb..33ccd8a 100644 --- a/resources/english_us.txt +++ b/resources/english_us.txt @@ -78,6 +78,7 @@ PROPERTY_TYPE_TXT = "Text document" PROPERTY_TYPE_VPK = "VPK package" PROPERTY_TYPE_XML = "XML file" PROPERTY_TYPE_ZIP = "ZIP archive" +PROPERTY_TYPE_RAR = "RAR archive" PROPERTY_TYPE_FSELF = "FSELF file" PROPERTY_FSELF_MODE_SAFE = "Safe" PROPERTY_FSELF_MODE_UNSAFE = "Unsafe" diff --git a/sfo.c b/sfo.c index 0710d22..5a64919 100644 --- a/sfo.c +++ b/sfo.c @@ -17,7 +17,8 @@ */ #include "main.h" -#include "archive.h" +#include "archive.h" +#include "archiveRAR.h" #include "file.h" #include "text.h" #include "hex.h" @@ -109,8 +110,19 @@ int SFOReader(char *file) { int size = 0; if (isInArchive()) { - size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); - } else { + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); + break; + case FILE_TYPE_RAR: + size = ReadArchiveRARFile(file,buffer,BIG_BUFFER_SIZE); + break; + default: + size = -1; + break; + } + }else { size = ReadFile(file, buffer, BIG_BUFFER_SIZE); } diff --git a/text.c b/text.c index d7e5a4a..cc29791 100644 --- a/text.c +++ b/text.c @@ -19,6 +19,7 @@ #include "main.h" #include "context_menu.h" #include "archive.h" +#include "archiveRAR.h" #include "file.h" #include "text.h" #include "hex.h" @@ -531,7 +532,18 @@ int textViewer(char *file) { s->edit_line = -1; if (isInArchive()) { - s->size = ReadArchiveFile(file, buffer_base, BIG_BUFFER_SIZE); + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + s->size = ReadArchiveFile(file, buffer_base, BIG_BUFFER_SIZE); + break; + case FILE_TYPE_RAR: + s->size = ReadArchiveRARFile(file,buffer_base,BIG_BUFFER_SIZE); + break; + default: + s->size = -1; + break; + } s->modify_allowed = 0; } else { s->size = ReadFile(file, buffer_base, BIG_BUFFER_SIZE); diff --git a/unrarlib/unrar_c_wrapper.h b/unrarlib/unrar_c_wrapper.h new file mode 100644 index 0000000..04cff39 --- /dev/null +++ b/unrarlib/unrar_c_wrapper.h @@ -0,0 +1,155 @@ +#include + +#ifndef _UNRAR_C_WRAPPER_H_INC +#define _UNRAR_C_WRAPPER_H_INC + +#define ERAR_SUCCESS 0 +#define ERAR_END_ARCHIVE 10 +#define ERAR_NO_MEMORY 11 +#define ERAR_BAD_DATA 12 +#define ERAR_BAD_ARCHIVE 13 +#define ERAR_UNKNOWN_FORMAT 14 +#define ERAR_EOPEN 15 +#define ERAR_ECREATE 16 +#define ERAR_ECLOSE 17 +#define ERAR_EREAD 18 +#define ERAR_EWRITE 19 +#define ERAR_SMALL_BUF 20 +#define ERAR_UNKNOWN 21 +#define ERAR_MISSING_PASSWORD 22 +#define ERAR_EREFERENCE 23 +#define ERAR_BAD_PASSWORD 24 + +#define RAR_OM_LIST 0 +#define RAR_OM_EXTRACT 1 +#define RAR_OM_LIST_INCSPLIT 2 + +#define RAR_SKIP 0 +#define RAR_TEST 1 +#define RAR_EXTRACT 2 + +#define RAR_VOL_ASK 0 +#define RAR_VOL_NOTIFY 1 + +#define RAR_DLL_VERSION 6 + +#define RAR_HASH_NONE 0 +#define RAR_HASH_CRC32 1 +#define RAR_HASH_BLAKE2 2 + + +#ifdef _UNIX +#define CALLBACK +#define PASCAL +#define LONG long +#define HANDLE void * +#define LPARAM long +#define UINT unsigned int +#endif + +#define RHDF_SPLITBEFORE 0x01 +#define RHDF_SPLITAFTER 0x02 +#define RHDF_ENCRYPTED 0x04 +#define RHDF_SOLID 0x10 +#define RHDF_DIRECTORY 0x20 + + +struct RARHeaderData +{ + char ArcName[260]; + char FileName[260]; + unsigned int Flags; + unsigned int PackSize; + unsigned int UnpSize; + unsigned int HostOS; + unsigned int FileCRC; + unsigned int FileTime; + unsigned int UnpVer; + unsigned int Method; + unsigned int FileAttr; + char *CmtBuf; + unsigned int CmtBufSize; + unsigned int CmtSize; + unsigned int CmtState; +}; + + +struct RARHeaderDataEx +{ + char ArcName[1024]; + wchar_t ArcNameW[1024]; + char FileName[1024]; + wchar_t FileNameW[1024]; + unsigned int Flags; + unsigned int PackSize; + unsigned int PackSizeHigh; + unsigned int UnpSize; + unsigned int UnpSizeHigh; + unsigned int HostOS; + unsigned int FileCRC; + unsigned int FileTime; + unsigned int UnpVer; + unsigned int Method; + unsigned int FileAttr; + char *CmtBuf; + unsigned int CmtBufSize; + unsigned int CmtSize; + unsigned int CmtState; + unsigned int DictSize; + unsigned int HashType; + char Hash[32]; + unsigned int Reserved[1014]; +}; + + +struct RAROpenArchiveData +{ + char *ArcName; + unsigned int OpenMode; + unsigned int OpenResult; + char *CmtBuf; + unsigned int CmtBufSize; + unsigned int CmtSize; + unsigned int CmtState; +}; + +typedef int (CALLBACK *UNRARCALLBACK)(UINT msg,LPARAM UserData,LPARAM P1,LPARAM P2); + +struct RAROpenArchiveDataEx +{ + char *ArcName; + wchar_t *ArcNameW; + unsigned int OpenMode; + unsigned int OpenResult; + char *CmtBuf; + unsigned int CmtBufSize; + unsigned int CmtSize; + unsigned int CmtState; + unsigned int Flags; + UNRARCALLBACK Callback; + LPARAM UserData; + unsigned int Reserved[28]; +}; + +enum UNRARCALLBACK_MESSAGES { + UCM_CHANGEVOLUME,UCM_PROCESSDATA,UCM_NEEDPASSWORD,UCM_CHANGEVOLUMEW, + UCM_NEEDPASSWORDW +}; + +typedef int (PASCAL *CHANGEVOLPROC)(char *ArcName,int Mode); +typedef int (PASCAL *PROCESSDATAPROC)(unsigned char *Addr,int Size); + +extern HANDLE PASCAL RAROpenArchive(struct RAROpenArchiveData *ArchiveData); +extern HANDLE PASCAL RAROpenArchiveEx(struct RAROpenArchiveDataEx *ArchiveData); +extern int PASCAL RARCloseArchive(HANDLE hArcData); +extern int PASCAL RARReadHeader(HANDLE hArcData,struct RARHeaderData *HeaderData); +extern int PASCAL RARReadHeaderEx(HANDLE hArcData,struct RARHeaderDataEx *HeaderData); +extern int PASCAL RARProcessFile(HANDLE hArcData,int Operation,char *DestPath,char *DestName, bool TestMode); +extern int PASCAL RARProcessFileW(HANDLE hArcData,int Operation,wchar_t *DestPath,wchar_t *DestName, bool TestMode); +extern void PASCAL RARSetCallback(HANDLE hArcData,UNRARCALLBACK Callback,LPARAM UserData); +extern void PASCAL RARSetChangeVolProc(HANDLE hArcData,CHANGEVOLPROC ChangeVolProc); +extern void PASCAL RARSetProcessDataProc(HANDLE hArcData,PROCESSDATAPROC ProcessDataProc); +extern void PASCAL RARSetPassword(HANDLE hArcData,char *Password); +extern int PASCAL RARGetDllVersion(); + +#endif diff --git a/unrarlib/unrarlibutils.c b/unrarlib/unrarlibutils.c new file mode 100644 index 0000000..04d7e2f --- /dev/null +++ b/unrarlib/unrarlibutils.c @@ -0,0 +1,267 @@ +#include "unrarlibutils.h" + +static void* rar_open(const char *filename, unsigned int om) { + struct RAROpenArchiveData arc_open; + arc_open.ArcName = (char*)filename; + arc_open.OpenMode = om; + arc_open.CmtBuf = NULL; + HANDLE rar_file = RAROpenArchive(&arc_open); + if (arc_open.OpenResult != 0) { + return NULL; + } + return rar_file; +} + +ArchiveFileNode* createNode(const char* name) { + ArchiveFileNode* node = malloc(sizeof(ArchiveFileNode)); + node->nodeName = malloc((strlen(name) + 2) * sizeof(char)); + strcpy(node->nodeName, name); + node->childCount = 0; + node->childPt = NULL; + node->fatherPt = NULL; + node->maxCount = 0; + return node; +} + +void add_node(ArchiveFileNode* father,ArchiveFileNode* child) { + uint32_t count = father->childCount; + if( (count + 1) > father->maxCount ) { + if(father->maxCount == 0) { + father->maxCount = 16; + father->childPt = malloc(16 * sizeof(void*)); + } else { + void* n_ptr = realloc((void*)father->childPt,2 * father->maxCount * sizeof(void*)); + if(n_ptr) { + father->childPt = n_ptr; + father->maxCount *= 2; + } + } + } + father->childPt[count] = (void*)child; + father->childCount++; + + child->fatherPt = father; +} + +ArchiveFileNode* getChildNodeByName(ArchiveFileNode* node,char* name) { + if(node->childCount <= 0 ) + return NULL; + uint32_t i; + for(i = 0; i < node->childCount; i++) { + ArchiveFileNode* _n = (ArchiveFileNode*)(node->childPt[i]); + if(strcmp(_n->nodeName,name) == 0) { + return _n; + } + } + return NULL; +} + +void free_node(ArchiveFileNode* node) { + uint32_t count = node->childCount; + int i = 0; + + for(; i < count; i++) { + ArchiveFileNode* _n = (ArchiveFileNode*)(node->childPt[i]); + free_node(_n); + } + if(node->childPt != NULL) { + free(node->childPt); + } + if(node->nodeName != NULL) { + free(node->nodeName); + } + free(node); +} + +void parse_path(const char* name, struct filelayer* layer) { + char* p; + char _name[RARMAX_FILENAME]; + strcpy(_name, name); + uint32_t depth = 0; + while(1) { + p = strrchr(_name, '/'); + if(!p) + break; + strcpy(&(layer->name[depth][0]), p + sizeof(char)); + layer->depth = ++depth; + *p = '\0'; + } + strcpy(&(layer->name[depth][0]), _name); +} + +ArchiveFileNode* openRARFile(char* filename) { + ArchiveFileNode* root = createNode("root"); + HANDLE RARFile = rar_open(filename,RAR_OM_LIST); + if(!RARFile) { + free_node(root); + return NULL; + } + + struct RARHeaderData data; + while (!RARReadHeader(RARFile, &data)) { + struct filelayer layer = {0}; + parse_path(data.FileName,&layer); + ArchiveFileNode* _up = root; + int i = layer.depth; + for(; i > 0; i--) { + ArchiveFileNode* father = getChildNodeByName(_up, &(layer.name[i][0])); + if(!father) { + father = createNode(&(layer.name[i][0])); + add_node(_up,father); + } + _up = father; + } + ArchiveFileNode* filenode = getChildNodeByName(_up,&(layer.name[0][0])); + + if(!filenode) { + filenode = createNode(&(layer.name[0][0])); + add_node(_up, filenode); + } + + filenode->data = data; + + RARProcessFile(RARFile, RAR_SKIP,NULL,NULL,false); + } + + RARCloseArchive(RARFile); + return root; +} + +int extractToMem(struct ExtractHeader* header,char* extractBuffer,uint64_t bufferSize) { + if(header->offset >= header->bufferSize) + return -1; + + if((header->offset + bufferSize) > header->bufferSize) + bufferSize = (header->bufferSize - header->offset);//no enough memory + + memcpy((header->memPtr + header->offset),extractBuffer,bufferSize); + header->offset += bufferSize; + return 1; +} + +int extractToFile(struct ExtractHeader* header,char* extractBuffer,uint64_t bufferSize) { + if(!header->file) + return -1; + + FileProcessParam* param = header->param; + if (param) { + if (param->value) + (*param->value) += bufferSize; + + if (param->SetProgress) + param->SetProgress(param->value ? *param->value : 0, param->max); + + if (param->cancelHandler && param->cancelHandler()) { + return -1; + } + } + + sceIoLseek(header->file,header->offset,SCE_SEEK_SET); + sceIoWrite(header->file,extractBuffer,bufferSize); + header->offset += bufferSize; + + + return 1; +} + +static int CALLBACK rarCallback(UINT msg,LPARAM UserData,LPARAM P1,LPARAM P2) { + struct ExtractHeader* header; + int rtn = 1; + switch(msg) { + case UCM_CHANGEVOLUME: + if(P2 != RAR_VOL_NOTIFY) { + rtn = -1; + } + break; + case UCM_PROCESSDATA: + header = (struct ExtractHeader*)UserData; + if(header->memPtr) + extractToMem(header,(char*)P1,P2); + else + rtn = extractToFile(header,(char*)P1,P2); + break; + default: + rtn = -1; + break; + } + return rtn; +} + +int extractRAR(char* path,char* filename,struct ExtractHeader* header) { + + HANDLE RARFile = rar_open(path,RAR_OM_EXTRACT); + if(!RARFile) + return -1; + + struct RARHeaderData data; + int rtn = -1; + while (!RARReadHeader(RARFile, &data)) { + if(!(strcmp(data.FileName,filename))) { + rtn = 1; + break; + } + RARProcessFile(RARFile, RAR_SKIP,NULL,NULL,false); + } + + if(rtn > 0) { + RARSetCallback(RARFile,rarCallback,(LPARAM)header); + int result = RARProcessFile(RARFile, RAR_TEST,NULL,NULL,false); + if(result >= 0) + rtn = 1; + else if(result == -2) + rtn = 0; + } + + RARCloseArchive(RARFile); + return rtn; +} + +ArchiveFileNode* getFileNodeFromFilePath(ArchiveFileNode* root,const char* filepath) { + struct filelayer layer = {0}; + parse_path(filepath,&layer); + int i = layer.depth; + ArchiveFileNode* _up = root; + + for(; i > 0; i--) { + _up = getChildNodeByName(_up, &(layer.name[i][0])); + if(!_up) + return NULL; + } + + return getChildNodeByName(_up,&(layer.name[0][0])); +} + +int getRARArchiveNodeInfo(ArchiveFileNode* root, uint64_t *size, uint32_t *folders, uint32_t *files) { + if(root->childCount > 0) { + uint32_t count = root->childCount; + int i = 0; + for(; i < count; i++) { + ArchiveFileNode* _n = (ArchiveFileNode*)(root->childPt[i]); + getRARArchiveNodeInfo(_n,size,folders,files); + } + } + if(root->data.Flags == 0x20) { + if(folders) + (*folders)++; + } else { + if(size) + (*size) += root->data.UnpSize; + if(files) + (*files) ++; + } + + return 1; +} + +ArchiveFileNode* getFloderNodeFromPath(ArchiveFileNode* root,const char* path) { + uint32_t pathlen = strlen(path); + char temp[pathlen]; + strcpy(temp,path); + temp[pathlen - 1] ='\0'; + return getFileNodeFromFilePath(root,temp); +} + + +void closeRARFile(ArchiveFileNode* root) { + free_node(root); +} diff --git a/unrarlib/unrarlibutils.h b/unrarlib/unrarlibutils.h new file mode 100644 index 0000000..341460a --- /dev/null +++ b/unrarlib/unrarlibutils.h @@ -0,0 +1,52 @@ +#ifndef UNRARLIBUTILS_H_INC +#define UNRARLIBUTILS_H_INC + +#include +#include +#include +#include +#include + +#include "../file.h" + +#define _UNIX +#include "unrar_c_wrapper.h" + +#define RARMAX_HIERARCHY 32//max hierarchy for folder +#define RARMAX_FILENAME 262 + + +typedef struct{ + char* nodeName; + void* fatherPt; + void** childPt; + uint32_t childCount; + uint32_t maxCount; + struct RARHeaderData data; +}ArchiveFileNode; + +struct filelayer{ + uint32_t depth; + char name[RARMAX_HIERARCHY][RARMAX_FILENAME]; +}; + +struct ExtractHeader{ + SceUID file; + uint64_t offset; + char* memPtr; + uint64_t bufferSize; + FileProcessParam * param; +}; + + +ArchiveFileNode* openRARFile(char* filename);//returns the number of files in the rar document archive +void closeRARFile(ArchiveFileNode* root); +ArchiveFileNode* createNode(const char* name); +ArchiveFileNode* getChildNodeByName(ArchiveFileNode* node,char* name); +int extractRAR(char* path,char* filename,struct ExtractHeader* header); +ArchiveFileNode* getFileNodeFromFilePath(ArchiveFileNode* root, const char* filepath); +int getRARArchiveNodeInfo(ArchiveFileNode* root, uint64_t *size, uint32_t *folders, uint32_t *files); +void free_node(ArchiveFileNode* node); +ArchiveFileNode* getFloderNodeFromPath(ArchiveFileNode* root,const char* path); + +#endif // UNRARLIBUTILS_H_INC From 9cfb980e7edbc947744de9d263ff8fd6bf165678 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jan 2017 23:11:49 +0800 Subject: [PATCH 2/6] Format fix --- io_process.c | 86 ++++++++++++++++++++++++++-------------------------- main.c | 9 +++--- sfo.c | 26 ++++++++-------- 3 files changed, 60 insertions(+), 61 deletions(-) diff --git a/io_process.c b/io_process.c index 616a30f..053358f 100644 --- a/io_process.c +++ b/io_process.c @@ -223,17 +223,17 @@ int copy_thread(SceSize args_size, CopyArguments *args) { } else { // Copy // Open archive, because when you copy from an archive, you leave the archive to paste if (args->copy_mode == COPY_MODE_EXTRACT) { - int res = -1; - switch(args->file_type){ - case FILE_TYPE_ZIP: - res = archiveOpen(args->archive_path); - break; - case FILE_TYPE_RAR: - res = archiveRAROpen(args->archive_path); - break; - default: - res = -1; - } + int res = -1; + switch(args->file_type){ + case FILE_TYPE_ZIP: + res = archiveOpen(args->archive_path); + break; + case FILE_TYPE_RAR: + res = archiveRAROpen(args->archive_path); + break; + default: + res = -1; + } if (res < 0) { closeWaitDialog(); errorDialog(res); @@ -252,16 +252,16 @@ int copy_thread(SceSize args_size, CopyArguments *args) { snprintf(src_path, MAX_PATH_LENGTH, "%s%s", args->copy_list->path, copy_entry->name); if (args->copy_mode == COPY_MODE_EXTRACT) { - switch(args->file_type){ - case FILE_TYPE_ZIP: - getArchivePathInfo(src_path, &size, &folders, &files); - break; - case FILE_TYPE_RAR: - getRARArchivePathInfo(src_path,&size,&folders,&files); - break; - default: - break; - } + switch(args->file_type){ + case FILE_TYPE_ZIP: + getArchivePathInfo(src_path, &size, &folders, &files); + break; + case FILE_TYPE_RAR: + getRARArchivePathInfo(src_path,&size,&folders,&files); + break; + default: + break; + } } else { getPathInfo(src_path, &size, &folders, &files, NULL); } @@ -292,17 +292,17 @@ int copy_thread(SceSize args_size, CopyArguments *args) { param.cancelHandler = cancelHandler; if (args->copy_mode == COPY_MODE_EXTRACT) { - int res = -1; - switch(args->file_type){ - case FILE_TYPE_ZIP: - res = extractArchivePath(src_path, dst_path, ¶m); - break; - case FILE_TYPE_RAR: - res = extractRARArchivePath(src_path,dst_path,¶m); - break; - default: - break; - } + int res = -1; + switch(args->file_type){ + case FILE_TYPE_ZIP: + res = extractArchivePath(src_path, dst_path, ¶m); + break; + case FILE_TYPE_RAR: + res = extractRARArchivePath(src_path,dst_path,¶m); + break; + default: + break; + } if (res <= 0) { closeWaitDialog(); dialog_step = DIALOG_STEP_CANCELLED; @@ -324,17 +324,17 @@ int copy_thread(SceSize args_size, CopyArguments *args) { // Close archive if (args->copy_mode == COPY_MODE_EXTRACT) { - int res = -1; - switch(args->file_type){ - case FILE_TYPE_ZIP: - res = archiveClose(); - break; - case FILE_TYPE_RAR: - res = archiveRARClose(); - break; - default: - break; - } + int res = -1; + switch(args->file_type){ + case FILE_TYPE_ZIP: + res = archiveClose(); + break; + case FILE_TYPE_RAR: + res = archiveRARClose(); + break; + default: + break; + } if (res < 0) { closeWaitDialog(); errorDialog(res); diff --git a/main.c b/main.c index 4f20255..4d464cc 100644 --- a/main.c +++ b/main.c @@ -120,7 +120,7 @@ void dirUpCloseArchive() { enum FileTypes archiveType = getArchiveType(); if(archiveType == FILE_TYPE_RAR) archiveRARClose(); - else if(archiveType == FILE_TYPE_ZIP) + else if(archiveType == FILE_TYPE_ZIP) archiveClose(); dir_level_archive = -1; } @@ -319,10 +319,9 @@ int handleFile(char *file, FileListEntry *entry) { case FILE_TYPE_ZIP: res = archiveOpen(file); break; - case FILE_TYPE_RAR: - res = archiveRAROpen(file); - break; - + case FILE_TYPE_RAR: + res = archiveRAROpen(file); + break; case FILE_TYPE_SFO: res = SFOReader(file); break; diff --git a/sfo.c b/sfo.c index 5a64919..b3e8131 100644 --- a/sfo.c +++ b/sfo.c @@ -109,19 +109,19 @@ int SFOReader(char *file) { int size = 0; - if (isInArchive()) { - enum FileTypes archiveType = getArchiveType(); - switch(archiveType){ - case FILE_TYPE_ZIP: - size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); - break; - case FILE_TYPE_RAR: - size = ReadArchiveRARFile(file,buffer,BIG_BUFFER_SIZE); - break; - default: - size = -1; - break; - } + if (isInArchive()) { + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); + break; + case FILE_TYPE_RAR: + size = ReadArchiveRARFile(file,buffer,BIG_BUFFER_SIZE); + break; + default: + size = -1; + break; + } }else { size = ReadFile(file, buffer, BIG_BUFFER_SIZE); } From 72db0af91807624d98c4a6e3ffd8e382215b3791 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jan 2017 23:25:50 +0800 Subject: [PATCH 3/6] Format fix #2 --- archiveRAR.c | 244 +++++++++++------------ hex.c | 24 +-- io_process.c | 76 ++++---- photo.c | 24 +-- property_dialog.c | 24 +-- text.c | 24 +-- unrarlib/unrarlibutils.c | 410 +++++++++++++++++++-------------------- unrarlib/unrarlibutils.h | 34 ++-- 8 files changed, 430 insertions(+), 430 deletions(-) diff --git a/archiveRAR.c b/archiveRAR.c index 24a2b5e..5eeac26 100644 --- a/archiveRAR.c +++ b/archiveRAR.c @@ -6,142 +6,142 @@ static int32_t filePathLength = -1; int archiveRAROpen(char *file) { - root = openRARFile(file); - if(!root) { - return -1; - } - filePathLength = strlen(file); - return 1; + root = openRARFile(file); + if(!root) { + return -1; + } + filePathLength = strlen(file); + return 1; } int fileListGetRARArchiveEntries(FileList *list, char *path, int sort) { - if(!root) - return -1; + if(!root) + return -1; - FileListEntry *entry = malloc(sizeof(FileListEntry)); - strcpy(entry->name, DIR_UP); - entry->name_length = strlen(DIR_UP); - entry->is_folder = 1; - entry->type = FILE_TYPE_UNKNOWN; - fileListAddEntry(list, entry, sort); - - ArchiveFileNode* node = NULL; - if(strlen(path) == (filePathLength + sizeof(char))) - node = root; - else - node = getFloderNodeFromPath(root,path + filePathLength + sizeof(char)); + FileListEntry *entry = malloc(sizeof(FileListEntry)); + strcpy(entry->name, DIR_UP); + entry->name_length = strlen(DIR_UP); + entry->is_folder = 1; + entry->type = FILE_TYPE_UNKNOWN; + fileListAddEntry(list, entry, sort); - uint32_t i = 0; - for(; i < node->childCount; i++) { - ArchiveFileNode* _t = (ArchiveFileNode*)(node->childPt[i]); - FileListEntry * childentry = malloc(sizeof(FileListEntry)); + ArchiveFileNode* node = NULL; + if(strlen(path) == (filePathLength + sizeof(char))) + node = root; + else + node = getFloderNodeFromPath(root,path + filePathLength + sizeof(char)); - strcpy(childentry->name,_t->nodeName); - childentry->name_length = strlen(childentry->name); - childentry->size = _t->data.UnpSize; - childentry->size2 = _t->data.PackSize; + uint32_t i = 0; + for(; i < node->childCount; i++) { + ArchiveFileNode* _t = (ArchiveFileNode*)(node->childPt[i]); + FileListEntry * childentry = malloc(sizeof(FileListEntry)); - sceRtcSetDosTime(&childentry->atime,_t->data.FileTime); - sceRtcSetDosTime(&childentry->ctime,_t->data.FileTime); - sceRtcSetDosTime(&childentry->mtime,_t->data.FileTime); + strcpy(childentry->name,_t->nodeName); + childentry->name_length = strlen(childentry->name); + childentry->size = _t->data.UnpSize; + childentry->size2 = _t->data.PackSize; - if(_t->data.Flags == 0x20) { - addEndSlash(childentry->name); - childentry->is_folder = 1; - list->folders++; - } else { - childentry->type = getFileType(childentry->name); - childentry->is_folder = 0; - list->files++; - } - fileListAddEntry(list, childentry, sort); - } - return 1; + sceRtcSetDosTime(&childentry->atime,_t->data.FileTime); + sceRtcSetDosTime(&childentry->ctime,_t->data.FileTime); + sceRtcSetDosTime(&childentry->mtime,_t->data.FileTime); + + if(_t->data.Flags == 0x20) { + addEndSlash(childentry->name); + childentry->is_folder = 1; + list->folders++; + } else { + childentry->type = getFileType(childentry->name); + childentry->is_folder = 0; + list->files++; + } + fileListAddEntry(list, childentry, sort); + } + return 1; } int ReadArchiveRARFile(char *file, void *buf, int size) { - if(filePathLength < 0) - return -1; + if(filePathLength < 0) + return -1; - char filepath[filePathLength + sizeof(char)]; - strncpy(filepath,file,filePathLength); - filepath[filePathLength] = '\0'; - struct ExtractHeader header = {memPtr:buf,offset:0,bufferSize:size,file:0,param:NULL}; - if(extractRAR(filepath,file + (filePathLength + sizeof(char)),&header) > 0) - return header.offset; - else - return -1; + char filepath[filePathLength + sizeof(char)]; + strncpy(filepath,file,filePathLength); + filepath[filePathLength] = '\0'; +struct ExtractHeader header = {memPtr:buf,offset:0,bufferSize:size,file:0,param:NULL}; + if(extractRAR(filepath,file + (filePathLength + sizeof(char)),&header) > 0) + return header.offset; + else + return -1; } int archiveRARFileGetstat(const char *file, SceIoStat *stat) { - if(!root) - return -1; + if(!root) + return -1; - const char* p = file + (filePathLength + sizeof(char)); - uint32_t p_length = strlen(p); + const char* p = file + (filePathLength + sizeof(char)); + uint32_t p_length = strlen(p); - if(p[p_length - 1] == '/') - return -1; + if(p[p_length - 1] == '/') + return -1; - ArchiveFileNode* filenode = getFileNodeFromFilePath(root,p); - if(!filenode) - return -1; + ArchiveFileNode* filenode = getFileNodeFromFilePath(root,p); + if(!filenode) + return -1; - if(stat) { - stat->st_size = filenode->data.UnpSize; - sceRtcSetDosTime(&stat->st_atime,filenode->data.FileTime); - sceRtcSetDosTime(&stat->st_ctime,filenode->data.FileTime); - sceRtcSetDosTime(&stat->st_mtime,filenode->data.FileTime); - } + if(stat) { + stat->st_size = filenode->data.UnpSize; + sceRtcSetDosTime(&stat->st_atime,filenode->data.FileTime); + sceRtcSetDosTime(&stat->st_ctime,filenode->data.FileTime); + sceRtcSetDosTime(&stat->st_mtime,filenode->data.FileTime); + } - return 1; + return 1; } int getRARArchivePathInfo(char *path, uint64_t *size, uint32_t *folders, uint32_t *files) { - if(!root) - return -1; + if(!root) + return -1; - SceIoStat stat; - memset(&stat, 0, sizeof(SceIoStat)); - if (archiveRARFileGetstat(path, &stat) < 0) { - FileList list; - memset(&list, 0, sizeof(FileList)); - fileListGetRARArchiveEntries(&list, path, SORT_NONE); + SceIoStat stat; + memset(&stat, 0, sizeof(SceIoStat)); + if (archiveRARFileGetstat(path, &stat) < 0) { + FileList list; + memset(&list, 0, sizeof(FileList)); + fileListGetRARArchiveEntries(&list, path, SORT_NONE); - FileListEntry *entry = list.head->next; // Ignore .. + FileListEntry *entry = list.head->next; // Ignore .. - int i; - for (i = 0; i < list.length - 1; i++) { - char *new_path = malloc(strlen(path) + strlen(entry->name) + 2); - snprintf(new_path, MAX_PATH_LENGTH, "%s%s", path, entry->name); + int i; + for (i = 0; i < list.length - 1; i++) { + char *new_path = malloc(strlen(path) + strlen(entry->name) + 2); + snprintf(new_path, MAX_PATH_LENGTH, "%s%s", path, entry->name); - getRARArchivePathInfo(new_path, size, folders, files); + getRARArchivePathInfo(new_path, size, folders, files); - free(new_path); + free(new_path); - entry = entry->next; - } + entry = entry->next; + } - if (folders) - (*folders)++; + if (folders) + (*folders)++; - fileListEmpty(&list); - } else { - if (size) - (*size) += stat.st_size; + fileListEmpty(&list); + } else { + if (size) + (*size) += stat.st_size; - if (files) - (*files)++; - } + if (files) + (*files)++; + } - return 0; + return 0; } -int extractRARArchivePath(char *src, char *dst, FileProcessParam *param){ - if(!root) - return -1; - - SceIoStat stat; +int extractRARArchivePath(char *src, char *dst, FileProcessParam *param) { + if(!root) + return -1; + + SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); if (archiveRARFileGetstat(src, &stat) < 0) { FileList list; @@ -160,7 +160,7 @@ int extractRARArchivePath(char *src, char *dst, FileProcessParam *param){ if (param->SetProgress) param->SetProgress(param->value ? *param->value : 0, param->max); - + if (param->cancelHandler && param->cancelHandler()) { fileListEmpty(&list); return 0; @@ -191,29 +191,29 @@ int extractRARArchivePath(char *src, char *dst, FileProcessParam *param){ } fileListEmpty(&list); - }else{ - char filepath[filePathLength + sizeof(char)]; - strncpy(filepath,src,filePathLength); - filepath[filePathLength] = '\0'; - - SceUID fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777); - - struct ExtractHeader header = {file:fddst,offset:0,memPtr:NULL,bufferSize:0,param:param}; - - int result = extractRAR(filepath,src + (filePathLength + sizeof(char)),&header); - sceIoClose(fddst); - - return result; + } else { + char filepath[filePathLength + sizeof(char)]; + strncpy(filepath,src,filePathLength); + filepath[filePathLength] = '\0'; + + SceUID fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777); + +struct ExtractHeader header = {file:fddst,offset:0,memPtr:NULL,bufferSize:0,param:param}; + + int result = extractRAR(filepath,src + (filePathLength + sizeof(char)),&header); + sceIoClose(fddst); + + return result; } - + return 1; } int archiveRARClose() { - filePathLength = -1; - if (!root) { - closeRARFile(root); - root = NULL; - } - return 1; + filePathLength = -1; + if (!root) { + closeRARFile(root); + root = NULL; + } + return 1; } \ No newline at end of file diff --git a/hex.c b/hex.c index a956d14..95a6d91 100644 --- a/hex.c +++ b/hex.c @@ -81,18 +81,18 @@ int hexViewer(char *file) { int size = 0; if (isInArchive()) { - enum FileTypes archiveType = getArchiveType(); - switch(archiveType){ - case FILE_TYPE_ZIP: - size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); - break; - case FILE_TYPE_RAR: - size = ReadArchiveRARFile(file,buffer,BIG_BUFFER_SIZE); - break; - default: - size = -1; - break; - } + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); + break; + case FILE_TYPE_RAR: + size = ReadArchiveRARFile(file,buffer,BIG_BUFFER_SIZE); + break; + default: + size = -1; + break; + } } else { size = ReadFile(file, buffer, BIG_BUFFER_SIZE); } diff --git a/io_process.c b/io_process.c index 053358f..c8a3c67 100644 --- a/io_process.c +++ b/io_process.c @@ -225,14 +225,14 @@ int copy_thread(SceSize args_size, CopyArguments *args) { if (args->copy_mode == COPY_MODE_EXTRACT) { int res = -1; switch(args->file_type){ - case FILE_TYPE_ZIP: - res = archiveOpen(args->archive_path); - break; - case FILE_TYPE_RAR: - res = archiveRAROpen(args->archive_path); - break; - default: - res = -1; + case FILE_TYPE_ZIP: + res = archiveOpen(args->archive_path); + break; + case FILE_TYPE_RAR: + res = archiveRAROpen(args->archive_path); + break; + default: + res = -1; } if (res < 0) { closeWaitDialog(); @@ -253,15 +253,15 @@ int copy_thread(SceSize args_size, CopyArguments *args) { if (args->copy_mode == COPY_MODE_EXTRACT) { switch(args->file_type){ - case FILE_TYPE_ZIP: - getArchivePathInfo(src_path, &size, &folders, &files); - break; - case FILE_TYPE_RAR: - getRARArchivePathInfo(src_path,&size,&folders,&files); - break; - default: - break; - } + case FILE_TYPE_ZIP: + getArchivePathInfo(src_path, &size, &folders, &files); + break; + case FILE_TYPE_RAR: + getRARArchivePathInfo(src_path,&size,&folders,&files); + break; + default: + break; + } } else { getPathInfo(src_path, &size, &folders, &files, NULL); } @@ -293,16 +293,16 @@ int copy_thread(SceSize args_size, CopyArguments *args) { if (args->copy_mode == COPY_MODE_EXTRACT) { int res = -1; - switch(args->file_type){ - case FILE_TYPE_ZIP: - res = extractArchivePath(src_path, dst_path, ¶m); - break; - case FILE_TYPE_RAR: - res = extractRARArchivePath(src_path,dst_path,¶m); - break; - default: - break; - } + switch(args->file_type){ + case FILE_TYPE_ZIP: + res = extractArchivePath(src_path, dst_path, ¶m); + break; + case FILE_TYPE_RAR: + res = extractRARArchivePath(src_path,dst_path,¶m); + break; + default: + break; + } if (res <= 0) { closeWaitDialog(); dialog_step = DIALOG_STEP_CANCELLED; @@ -324,17 +324,17 @@ int copy_thread(SceSize args_size, CopyArguments *args) { // Close archive if (args->copy_mode == COPY_MODE_EXTRACT) { - int res = -1; - switch(args->file_type){ - case FILE_TYPE_ZIP: - res = archiveClose(); - break; - case FILE_TYPE_RAR: - res = archiveRARClose(); - break; - default: - break; - } + int res = -1; + switch(args->file_type){ + case FILE_TYPE_ZIP: + res = archiveClose(); + break; + case FILE_TYPE_RAR: + res = archiveRARClose(); + break; + default: + break; + } if (res < 0) { closeWaitDialog(); errorDialog(res); diff --git a/photo.c b/photo.c index 1c3f0b9..894d751 100644 --- a/photo.c +++ b/photo.c @@ -30,18 +30,18 @@ vita2d_texture *loadImage(char *file, int type, char *buffer) { int size = 0; if (isInArchive()) { - enum FileTypes archiveType = getArchiveType(); - switch(archiveType){ - case FILE_TYPE_ZIP: - size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); - break; - case FILE_TYPE_RAR: - size = ReadArchiveRARFile(file,buffer,BIG_BUFFER_SIZE); - break; - default: - size = -1; - break; - } + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + size = ReadArchiveFile(file, buffer, BIG_BUFFER_SIZE); + break; + case FILE_TYPE_RAR: + size = ReadArchiveRARFile(file,buffer,BIG_BUFFER_SIZE); + break; + default: + size = -1; + break; + } } else { size = ReadFile(file, buffer, BIG_BUFFER_SIZE); } diff --git a/property_dialog.c b/property_dialog.c index a8fe1ea..5eeb615 100644 --- a/property_dialog.c +++ b/property_dialog.c @@ -186,18 +186,18 @@ int initPropertyDialog(char *path, FileListEntry *entry) { uint32_t buffer[0x88/4]; if (isInArchive()) { - enum FileTypes archiveType = getArchiveType(); - switch(archiveType){ - case FILE_TYPE_ZIP: - size = ReadArchiveFile(path, buffer, sizeof(buffer)); - break; - case FILE_TYPE_RAR: - size = ReadArchiveRARFile(path,buffer,sizeof(buffer)); - break; - default: - size = -1; - break; - } + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + size = ReadArchiveFile(path, buffer, sizeof(buffer)); + break; + case FILE_TYPE_RAR: + size = ReadArchiveRARFile(path,buffer,sizeof(buffer)); + break; + default: + size = -1; + break; + } } else { size = ReadFile(path, buffer, sizeof(buffer)); } diff --git a/text.c b/text.c index cc29791..36ad7de 100644 --- a/text.c +++ b/text.c @@ -532,18 +532,18 @@ int textViewer(char *file) { s->edit_line = -1; if (isInArchive()) { - enum FileTypes archiveType = getArchiveType(); - switch(archiveType){ - case FILE_TYPE_ZIP: - s->size = ReadArchiveFile(file, buffer_base, BIG_BUFFER_SIZE); - break; - case FILE_TYPE_RAR: - s->size = ReadArchiveRARFile(file,buffer_base,BIG_BUFFER_SIZE); - break; - default: - s->size = -1; - break; - } + enum FileTypes archiveType = getArchiveType(); + switch(archiveType){ + case FILE_TYPE_ZIP: + s->size = ReadArchiveFile(file, buffer_base, BIG_BUFFER_SIZE); + break; + case FILE_TYPE_RAR: + s->size = ReadArchiveRARFile(file,buffer_base,BIG_BUFFER_SIZE); + break; + default: + s->size = -1; + break; + } s->modify_allowed = 0; } else { s->size = ReadFile(file, buffer_base, BIG_BUFFER_SIZE); diff --git a/unrarlib/unrarlibutils.c b/unrarlib/unrarlibutils.c index 04d7e2f..e41b644 100644 --- a/unrarlib/unrarlibutils.c +++ b/unrarlib/unrarlibutils.c @@ -1,267 +1,267 @@ #include "unrarlibutils.h" static void* rar_open(const char *filename, unsigned int om) { - struct RAROpenArchiveData arc_open; - arc_open.ArcName = (char*)filename; - arc_open.OpenMode = om; - arc_open.CmtBuf = NULL; - HANDLE rar_file = RAROpenArchive(&arc_open); - if (arc_open.OpenResult != 0) { - return NULL; - } - return rar_file; + struct RAROpenArchiveData arc_open; + arc_open.ArcName = (char*)filename; + arc_open.OpenMode = om; + arc_open.CmtBuf = NULL; + HANDLE rar_file = RAROpenArchive(&arc_open); + if (arc_open.OpenResult != 0) { + return NULL; + } + return rar_file; } ArchiveFileNode* createNode(const char* name) { - ArchiveFileNode* node = malloc(sizeof(ArchiveFileNode)); - node->nodeName = malloc((strlen(name) + 2) * sizeof(char)); - strcpy(node->nodeName, name); - node->childCount = 0; - node->childPt = NULL; - node->fatherPt = NULL; - node->maxCount = 0; - return node; + ArchiveFileNode* node = malloc(sizeof(ArchiveFileNode)); + node->nodeName = malloc((strlen(name) + 2) * sizeof(char)); + strcpy(node->nodeName, name); + node->childCount = 0; + node->childPt = NULL; + node->fatherPt = NULL; + node->maxCount = 0; + return node; } void add_node(ArchiveFileNode* father,ArchiveFileNode* child) { - uint32_t count = father->childCount; - if( (count + 1) > father->maxCount ) { - if(father->maxCount == 0) { - father->maxCount = 16; - father->childPt = malloc(16 * sizeof(void*)); - } else { - void* n_ptr = realloc((void*)father->childPt,2 * father->maxCount * sizeof(void*)); - if(n_ptr) { - father->childPt = n_ptr; - father->maxCount *= 2; - } - } - } - father->childPt[count] = (void*)child; - father->childCount++; + uint32_t count = father->childCount; + if( (count + 1) > father->maxCount ) { + if(father->maxCount == 0) { + father->maxCount = 16; + father->childPt = malloc(16 * sizeof(void*)); + } else { + void* n_ptr = realloc((void*)father->childPt,2 * father->maxCount * sizeof(void*)); + if(n_ptr) { + father->childPt = n_ptr; + father->maxCount *= 2; + } + } + } + father->childPt[count] = (void*)child; + father->childCount++; - child->fatherPt = father; + child->fatherPt = father; } ArchiveFileNode* getChildNodeByName(ArchiveFileNode* node,char* name) { - if(node->childCount <= 0 ) - return NULL; - uint32_t i; - for(i = 0; i < node->childCount; i++) { - ArchiveFileNode* _n = (ArchiveFileNode*)(node->childPt[i]); - if(strcmp(_n->nodeName,name) == 0) { - return _n; - } - } - return NULL; + if(node->childCount <= 0 ) + return NULL; + uint32_t i; + for(i = 0; i < node->childCount; i++) { + ArchiveFileNode* _n = (ArchiveFileNode*)(node->childPt[i]); + if(strcmp(_n->nodeName,name) == 0) { + return _n; + } + } + return NULL; } void free_node(ArchiveFileNode* node) { - uint32_t count = node->childCount; - int i = 0; + uint32_t count = node->childCount; + int i = 0; - for(; i < count; i++) { - ArchiveFileNode* _n = (ArchiveFileNode*)(node->childPt[i]); - free_node(_n); - } - if(node->childPt != NULL) { - free(node->childPt); - } - if(node->nodeName != NULL) { - free(node->nodeName); - } - free(node); + for(; i < count; i++) { + ArchiveFileNode* _n = (ArchiveFileNode*)(node->childPt[i]); + free_node(_n); + } + if(node->childPt != NULL) { + free(node->childPt); + } + if(node->nodeName != NULL) { + free(node->nodeName); + } + free(node); } void parse_path(const char* name, struct filelayer* layer) { - char* p; - char _name[RARMAX_FILENAME]; - strcpy(_name, name); - uint32_t depth = 0; - while(1) { - p = strrchr(_name, '/'); - if(!p) - break; - strcpy(&(layer->name[depth][0]), p + sizeof(char)); - layer->depth = ++depth; - *p = '\0'; - } - strcpy(&(layer->name[depth][0]), _name); + char* p; + char _name[RARMAX_FILENAME]; + strcpy(_name, name); + uint32_t depth = 0; + while(1) { + p = strrchr(_name, '/'); + if(!p) + break; + strcpy(&(layer->name[depth][0]), p + sizeof(char)); + layer->depth = ++depth; + *p = '\0'; + } + strcpy(&(layer->name[depth][0]), _name); } ArchiveFileNode* openRARFile(char* filename) { - ArchiveFileNode* root = createNode("root"); - HANDLE RARFile = rar_open(filename,RAR_OM_LIST); - if(!RARFile) { - free_node(root); - return NULL; - } + ArchiveFileNode* root = createNode("root"); + HANDLE RARFile = rar_open(filename,RAR_OM_LIST); + if(!RARFile) { + free_node(root); + return NULL; + } - struct RARHeaderData data; - while (!RARReadHeader(RARFile, &data)) { - struct filelayer layer = {0}; - parse_path(data.FileName,&layer); - ArchiveFileNode* _up = root; - int i = layer.depth; - for(; i > 0; i--) { - ArchiveFileNode* father = getChildNodeByName(_up, &(layer.name[i][0])); - if(!father) { - father = createNode(&(layer.name[i][0])); - add_node(_up,father); - } - _up = father; - } - ArchiveFileNode* filenode = getChildNodeByName(_up,&(layer.name[0][0])); + struct RARHeaderData data; + while (!RARReadHeader(RARFile, &data)) { + struct filelayer layer = {0}; + parse_path(data.FileName,&layer); + ArchiveFileNode* _up = root; + int i = layer.depth; + for(; i > 0; i--) { + ArchiveFileNode* father = getChildNodeByName(_up, &(layer.name[i][0])); + if(!father) { + father = createNode(&(layer.name[i][0])); + add_node(_up,father); + } + _up = father; + } + ArchiveFileNode* filenode = getChildNodeByName(_up,&(layer.name[0][0])); - if(!filenode) { - filenode = createNode(&(layer.name[0][0])); - add_node(_up, filenode); - } + if(!filenode) { + filenode = createNode(&(layer.name[0][0])); + add_node(_up, filenode); + } - filenode->data = data; + filenode->data = data; - RARProcessFile(RARFile, RAR_SKIP,NULL,NULL,false); - } + RARProcessFile(RARFile, RAR_SKIP,NULL,NULL,false); + } - RARCloseArchive(RARFile); - return root; + RARCloseArchive(RARFile); + return root; } int extractToMem(struct ExtractHeader* header,char* extractBuffer,uint64_t bufferSize) { - if(header->offset >= header->bufferSize) - return -1; - - if((header->offset + bufferSize) > header->bufferSize) - bufferSize = (header->bufferSize - header->offset);//no enough memory - - memcpy((header->memPtr + header->offset),extractBuffer,bufferSize); - header->offset += bufferSize; - return 1; + if(header->offset >= header->bufferSize) + return -1; + + if((header->offset + bufferSize) > header->bufferSize) + bufferSize = (header->bufferSize - header->offset);//no enough memory + + memcpy((header->memPtr + header->offset),extractBuffer,bufferSize); + header->offset += bufferSize; + return 1; } int extractToFile(struct ExtractHeader* header,char* extractBuffer,uint64_t bufferSize) { - if(!header->file) - return -1; - - FileProcessParam* param = header->param; - if (param) { - if (param->value) - (*param->value) += bufferSize; + if(!header->file) + return -1; - if (param->SetProgress) - param->SetProgress(param->value ? *param->value : 0, param->max); + FileProcessParam* param = header->param; + if (param) { + if (param->value) + (*param->value) += bufferSize; - if (param->cancelHandler && param->cancelHandler()) { - return -1; - } - } - - sceIoLseek(header->file,header->offset,SCE_SEEK_SET); - sceIoWrite(header->file,extractBuffer,bufferSize); - header->offset += bufferSize; - - - return 1; + if (param->SetProgress) + param->SetProgress(param->value ? *param->value : 0, param->max); + + if (param->cancelHandler && param->cancelHandler()) { + return -1; + } + } + + sceIoLseek(header->file,header->offset,SCE_SEEK_SET); + sceIoWrite(header->file,extractBuffer,bufferSize); + header->offset += bufferSize; + + + return 1; } static int CALLBACK rarCallback(UINT msg,LPARAM UserData,LPARAM P1,LPARAM P2) { - struct ExtractHeader* header; - int rtn = 1; - switch(msg) { - case UCM_CHANGEVOLUME: - if(P2 != RAR_VOL_NOTIFY) { - rtn = -1; - } - break; - case UCM_PROCESSDATA: - header = (struct ExtractHeader*)UserData; - if(header->memPtr) - extractToMem(header,(char*)P1,P2); - else - rtn = extractToFile(header,(char*)P1,P2); - break; - default: - rtn = -1; - break; - } - return rtn; + struct ExtractHeader* header; + int rtn = 1; + switch(msg) { + case UCM_CHANGEVOLUME: + if(P2 != RAR_VOL_NOTIFY) { + rtn = -1; + } + break; + case UCM_PROCESSDATA: + header = (struct ExtractHeader*)UserData; + if(header->memPtr) + extractToMem(header,(char*)P1,P2); + else + rtn = extractToFile(header,(char*)P1,P2); + break; + default: + rtn = -1; + break; + } + return rtn; } int extractRAR(char* path,char* filename,struct ExtractHeader* header) { - - HANDLE RARFile = rar_open(path,RAR_OM_EXTRACT); - if(!RARFile) - return -1; - struct RARHeaderData data; - int rtn = -1; - while (!RARReadHeader(RARFile, &data)) { - if(!(strcmp(data.FileName,filename))) { - rtn = 1; - break; - } - RARProcessFile(RARFile, RAR_SKIP,NULL,NULL,false); - } + HANDLE RARFile = rar_open(path,RAR_OM_EXTRACT); + if(!RARFile) + return -1; - if(rtn > 0) { - RARSetCallback(RARFile,rarCallback,(LPARAM)header); - int result = RARProcessFile(RARFile, RAR_TEST,NULL,NULL,false); - if(result >= 0) - rtn = 1; - else if(result == -2) - rtn = 0; - } + struct RARHeaderData data; + int rtn = -1; + while (!RARReadHeader(RARFile, &data)) { + if(!(strcmp(data.FileName,filename))) { + rtn = 1; + break; + } + RARProcessFile(RARFile, RAR_SKIP,NULL,NULL,false); + } - RARCloseArchive(RARFile); - return rtn; + if(rtn > 0) { + RARSetCallback(RARFile,rarCallback,(LPARAM)header); + int result = RARProcessFile(RARFile, RAR_TEST,NULL,NULL,false); + if(result >= 0) + rtn = 1; + else if(result == -2) + rtn = 0; + } + + RARCloseArchive(RARFile); + return rtn; } ArchiveFileNode* getFileNodeFromFilePath(ArchiveFileNode* root,const char* filepath) { - struct filelayer layer = {0}; - parse_path(filepath,&layer); - int i = layer.depth; - ArchiveFileNode* _up = root; + struct filelayer layer = {0}; + parse_path(filepath,&layer); + int i = layer.depth; + ArchiveFileNode* _up = root; - for(; i > 0; i--) { - _up = getChildNodeByName(_up, &(layer.name[i][0])); - if(!_up) - return NULL; - } + for(; i > 0; i--) { + _up = getChildNodeByName(_up, &(layer.name[i][0])); + if(!_up) + return NULL; + } - return getChildNodeByName(_up,&(layer.name[0][0])); + return getChildNodeByName(_up,&(layer.name[0][0])); } int getRARArchiveNodeInfo(ArchiveFileNode* root, uint64_t *size, uint32_t *folders, uint32_t *files) { - if(root->childCount > 0) { - uint32_t count = root->childCount; - int i = 0; - for(; i < count; i++) { - ArchiveFileNode* _n = (ArchiveFileNode*)(root->childPt[i]); - getRARArchiveNodeInfo(_n,size,folders,files); - } - } - if(root->data.Flags == 0x20) { - if(folders) - (*folders)++; - } else { - if(size) - (*size) += root->data.UnpSize; - if(files) - (*files) ++; - } + if(root->childCount > 0) { + uint32_t count = root->childCount; + int i = 0; + for(; i < count; i++) { + ArchiveFileNode* _n = (ArchiveFileNode*)(root->childPt[i]); + getRARArchiveNodeInfo(_n,size,folders,files); + } + } + if(root->data.Flags == 0x20) { + if(folders) + (*folders)++; + } else { + if(size) + (*size) += root->data.UnpSize; + if(files) + (*files) ++; + } - return 1; + return 1; } ArchiveFileNode* getFloderNodeFromPath(ArchiveFileNode* root,const char* path) { - uint32_t pathlen = strlen(path); - char temp[pathlen]; - strcpy(temp,path); - temp[pathlen - 1] ='\0'; - return getFileNodeFromFilePath(root,temp); + uint32_t pathlen = strlen(path); + char temp[pathlen]; + strcpy(temp,path); + temp[pathlen - 1] ='\0'; + return getFileNodeFromFilePath(root,temp); } void closeRARFile(ArchiveFileNode* root) { - free_node(root); + free_node(root); } diff --git a/unrarlib/unrarlibutils.h b/unrarlib/unrarlibutils.h index 341460a..1606f9a 100644 --- a/unrarlib/unrarlibutils.h +++ b/unrarlib/unrarlibutils.h @@ -16,26 +16,26 @@ #define RARMAX_FILENAME 262 -typedef struct{ - char* nodeName; - void* fatherPt; - void** childPt; - uint32_t childCount; - uint32_t maxCount; - struct RARHeaderData data; -}ArchiveFileNode; +typedef struct { + char* nodeName; + void* fatherPt; + void** childPt; + uint32_t childCount; + uint32_t maxCount; + struct RARHeaderData data; +} ArchiveFileNode; -struct filelayer{ - uint32_t depth; - char name[RARMAX_HIERARCHY][RARMAX_FILENAME]; +struct filelayer { + uint32_t depth; + char name[RARMAX_HIERARCHY][RARMAX_FILENAME]; }; -struct ExtractHeader{ - SceUID file; - uint64_t offset; - char* memPtr; - uint64_t bufferSize; - FileProcessParam * param; +struct ExtractHeader { + SceUID file; + uint64_t offset; + char* memPtr; + uint64_t bufferSize; + FileProcessParam * param; }; From 6299e3395c9b78abd95d481cbef1972c949bf5ba Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jan 2017 23:28:09 +0800 Subject: [PATCH 4/6] Format fix #3 --- main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 4d464cc..b0d3af5 100644 --- a/main.c +++ b/main.c @@ -117,12 +117,12 @@ int isInArchive() { void dirUpCloseArchive() { if (isInArchive() && dir_level_archive >= dir_level) { is_in_archive = 0; - enum FileTypes archiveType = getArchiveType(); - if(archiveType == FILE_TYPE_RAR) - archiveRARClose(); - else if(archiveType == FILE_TYPE_ZIP) - archiveClose(); - dir_level_archive = -1; + enum FileTypes archiveType = getArchiveType(); + if(archiveType == FILE_TYPE_RAR) + archiveRARClose(); + else if(archiveType == FILE_TYPE_ZIP) + archiveClose(); + dir_level_archive = -1; } } From d1d9c57526ffbc924f7b72ebb51a2d8bac82fb3a Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jan 2017 23:30:05 +0800 Subject: [PATCH 5/6] Format fix #4 --- property_dialog.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/property_dialog.c b/property_dialog.c index 5eeb615..9370260 100644 --- a/property_dialog.c +++ b/property_dialog.c @@ -268,10 +268,10 @@ int initPropertyDialog(char *path, FileListEntry *entry) { case FILE_TYPE_ZIP: type = PROPERTY_TYPE_ZIP; break; - - case FILE_TYPE_RAR: - type = PROPERTY_TYPE_RAR; - break; + + case FILE_TYPE_RAR: + type = PROPERTY_TYPE_RAR; + break; } width = copyStringLimited(property_type, language_container[type], PROPERTY_DIALOG_ENTRY_MAX_WIDTH); From 93ae800f15f76557410edf957bb69b16bb42938e Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jan 2017 23:34:29 +0800 Subject: [PATCH 6/6] Update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 030c749..c27509f 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ Be sure you pull request your customized design or language file there. * ftpvitalib https://github.com/xerpi/ftpvitalib * EasyRPG libraries: https://ci.easyrpg.org/view/Toolchains/job/toolchain-vita/ * Onigmo library https://github.com/k-takata/Onigmo +* UnRAR http://www.rarlab.com/ ### Credits ### * Team Molecule for HENkaku