From e1f2c7879e95b79b0446de6b0221c0481e76568e Mon Sep 17 00:00:00 2001 From: sorgelig Date: Thu, 2 Jul 2020 03:05:22 +0800 Subject: [PATCH] minimig: fix zip handling in shared folder. --- file_io.cpp | 20 ++++++++++---------- file_io.h | 6 +++--- support/minimig/minimig_share.cpp | 23 +++++++++++------------ 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/file_io.cpp b/file_io.cpp index 89ed288..9b7c552 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -116,12 +116,12 @@ struct stat64* getPathStat(const char *path) return (stat64(full_path, &st) >= 0) ? &st : NULL; } -static int isPathDirectory(const char *path) +static int isPathDirectory(const char *path, int use_zip = 1) { make_fullpath(path); char *zip_path, *file_path; - if (FileIsZipped(full_path, &zip_path, &file_path)) + if (use_zip && FileIsZipped(full_path, &zip_path, &file_path)) { mz_zip_archive z{}; if (!mz_zip_reader_init_file(&z, zip_path, 0)) @@ -172,12 +172,12 @@ static int isPathDirectory(const char *path) return 0; } -static int isPathRegularFile(const char *path) +static int isPathRegularFile(const char *path, int use_zip = 1) { make_fullpath(path); char *zip_path, *file_path; - if (FileIsZipped(full_path, &zip_path, &file_path)) + if (use_zip && FileIsZipped(full_path, &zip_path, &file_path)) { mz_zip_archive z{}; if (!mz_zip_reader_init_file(&z, zip_path, 0)) @@ -331,7 +331,7 @@ int FileOpenZip(fileTYPE *file, const char *name, uint32_t crc32) return 1; } -int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute) +int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute, int use_zip) { make_fullpath((char*)name, mode); FileClose(file); @@ -342,7 +342,7 @@ int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute) strcpy(file->name, (mode == -1) ? full_path : p + 1); char *zip_path, *file_path; - if ((mode != -1) && FileIsZipped(full_path, &zip_path, &file_path)) + if (use_zip && (mode != -1) && FileIsZipped(full_path, &zip_path, &file_path)) { if (mode & O_RDWR || mode & O_WRONLY) { @@ -709,14 +709,14 @@ int FileDeleteConfig(const char *name) return FileDelete(path); } -int FileExists(const char *name) +int FileExists(const char *name, int use_zip) { - return isPathRegularFile(name); + return isPathRegularFile(name, use_zip); } -int PathIsDir(const char *name) +int PathIsDir(const char *name, int use_zip) { - return isPathDirectory(name); + return isPathDirectory(name, use_zip); } int FileCanWrite(const char *name) diff --git a/file_io.h b/file_io.h index dbb7472..744fc8e 100644 --- a/file_io.h +++ b/file_io.h @@ -63,7 +63,7 @@ void setStorage(int dev); int isUSBMounted(); int FileOpenZip(fileTYPE *file, const char *name, uint32_t crc32); -int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute = 0); +int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute = 0, int use_zip = 1); int FileOpen(fileTYPE *file, const char *name, char mute = 0); void FileClose(fileTYPE *file); @@ -78,9 +78,9 @@ int FileWriteAdv(fileTYPE *file, void *pBuffer, int length); int FileWriteSec(fileTYPE *file, void *pBuffer); int FileCreatePath(const char *dir); -int FileExists(const char *name); +int FileExists(const char *name, int use_zip = 1); int FileCanWrite(const char *name); -int PathIsDir(const char *name); +int PathIsDir(const char *name, int use_zip = 1); struct stat64* getPathStat(const char *path); #define SAVE_DIR "saves" diff --git a/support/minimig/minimig_share.cpp b/support/minimig/minimig_share.cpp index c97c5c4..3f2be3c 100644 --- a/support/minimig/minimig_share.cpp +++ b/support/minimig/minimig_share.cpp @@ -208,7 +208,7 @@ static char* find_path(uint32_t key, const char *name) else { *p = 0; - if (!PathIsDir(str)) str[0] = 0; + if (!PathIsDir(str, 0)) str[0] = 0; else *p = '/'; } } @@ -257,7 +257,7 @@ static int process_request(void *reqres_buffer) break; } - if (!FileExists(str) && !PathIsDir(str)) + if (!FileExists(str, 0) && !PathIsDir(str, 0)) { ret = ERROR_OBJECT_NOT_FOUND; break; @@ -338,7 +338,6 @@ static int process_request(void *reqres_buffer) uint32_t key = add_lock(SHARED_LOCK, buf); res->key = SWAP_INT(key); dbg_print(" parent path: %s\n", buf); - dbg_print(" parent path: %s\n", buf); } } } @@ -374,7 +373,7 @@ static int process_request(void *reqres_buffer) } locks[key].dir_items.clear(); - if (PathIsDir(name)) + if (PathIsDir(name, 0)) { const char* full_path = getFullPath(name); DIR *d = opendir(full_path); @@ -420,8 +419,8 @@ static int process_request(void *reqres_buffer) dbg_print(" fn: %s\n", fn); int type = 0; - if (FileExists(name)) type = ST_FILE; - else if (PathIsDir(name)) type = ST_USERDIR; + if (FileExists(name, 0)) type = ST_FILE; + else if (PathIsDir(name, 0)) type = ST_USERDIR; else { ret = ERROR_OBJECT_NOT_FOUND; @@ -483,7 +482,7 @@ static int process_request(void *reqres_buffer) break; } - if (PathIsDir(name)) + if (PathIsDir(name, 0)) { ret = ERROR_OBJECT_WRONG_TYPE; break; @@ -497,7 +496,7 @@ static int process_request(void *reqres_buffer) if (rtype == MODE_NEWFILE) mode = O_RDWR | O_CREAT | O_TRUNC; if (rtype == MODE_READWRITE) mode = O_RDWR | O_CREAT; - ret = FileOpenEx(&open_file_handles[key], name, mode); + ret = FileOpenEx(&open_file_handles[key], name, mode, 0, 0); if (!ret) { open_file_handles.erase(key); @@ -624,13 +623,13 @@ static int process_request(void *reqres_buffer) break; } - if (PathIsDir(name)) + if (PathIsDir(name, 0)) { ret = DirDelete(name) ? 0 : ERROR_DIRECTORY_NOT_EMPTY; break; } - if (FileExists(name)) + if (FileExists(name, 0)) { ret = FileDelete(name) ? 0 : ERROR_OBJECT_NOT_FOUND; break; @@ -657,7 +656,7 @@ static int process_request(void *reqres_buffer) break; } - if (!FileExists(cp1) && !PathIsDir(cp1)) + if (!FileExists(cp1, 0) && !PathIsDir(cp1, 0)) { ret = ERROR_OBJECT_NOT_FOUND; break; @@ -672,7 +671,7 @@ static int process_request(void *reqres_buffer) break; } - if (FileExists(cp2) || PathIsDir(cp2)) + if (FileExists(cp2, 0) || PathIsDir(cp2, 0)) { ret = ERROR_OBJECT_EXISTS; break;