From 72db0af91807624d98c4a6e3ffd8e382215b3791 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 4 Jan 2017 23:25:50 +0800 Subject: [PATCH] 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; };