From b23d86b5bc9dcf54eb0d89585b2cb615d1309cac Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Mon, 5 Mar 2012 09:48:13 +0000 Subject: [PATCH] -added more accurate progress bar for copy gc game from usb to sd -made the gc disc installer progress bar more accurate too ;) -deleting a gamecube game will now delete all files found in the directory, more accurate lol --- source/gc/fileOps.c | 45 ++++++++++++++++++++++++++++++++------- source/gc/fileOps.h | 1 + source/gc/gc.c | 43 +++++++------------------------------ source/gc/gc.h | 1 - source/loader/gc_disc.cpp | 2 ++ source/menu/menu_wbfs.cpp | 6 +++++- 6 files changed, 53 insertions(+), 45 deletions(-) diff --git a/source/gc/fileOps.c b/source/gc/fileOps.c index caee318d..1556be4b 100644 --- a/source/gc/fileOps.c +++ b/source/gc/fileOps.c @@ -32,6 +32,7 @@ static u32 blockIdx = 0; static u32 blockInfo[2] = {0,0}; static u32 blockReady = 0; static u32 stopThread; +static u64 folderSize = 0; // return false if the file doesn't exist bool fsop_GetFileSizeBytes (char *path, size_t *filesize) // for me stats st_size report always 0 :( @@ -198,12 +199,6 @@ bool fsop_CopyFile (char *source, char *target, progress_callback_t spinner, voi usleep (5); bytes = 0; - bool spinnerFlag = false; - if (strstr (source, "game.iso")) { - spinner(bytes, size, spinner_data); - spinnerFlag = true; - } - u32 bi; do { @@ -223,7 +218,8 @@ bool fsop_CopyFile (char *source, char *target, progress_callback_t spinner, voi if (rb == 0) err = 1; bytes += rb; - if (spinnerFlag) spinner(bytes, size, spinner_data); + if (spinner) + spinner(bytes, folderSize, spinner_data); } while (bytes < size && err == 0); @@ -295,10 +291,43 @@ static bool doCopyFolder (char *source, char *target, progress_callback_t spinne return ret; } - + bool fsop_CopyFolder (char *source, char *target, progress_callback_t spinner, void *spinner_data) { gprintf("DML game USB->SD job started!\n"); + folderSize = fsop_GetFolderBytes(source); return doCopyFolder(source, target, spinner, spinner_data); } + +void fsop_deleteFolder(char *source) +{ + DIR *pdir; + struct dirent *pent; + char newSource[300]; + + pdir = opendir(source); + + while ((pent=readdir(pdir)) != NULL) + { + // Skip it + if (strcmp (pent->d_name, ".") == 0 || strcmp (pent->d_name, "..") == 0) + continue; + + sprintf (newSource, "%s/%s", source, pent->d_name); + + // If it is a folder... recurse... + if (fsop_DirExist(newSource)) + { + fsop_deleteFolder(newSource); + } + else // It is a file ! + { + gprintf("Deleting file: %s\n",newSource); + remove(newSource); + } + } + closedir(pdir); + gprintf("Deleting directory: %s\n",source); + unlink(source); +} diff --git a/source/gc/fileOps.h b/source/gc/fileOps.h index a48d7808..19f02011 100644 --- a/source/gc/fileOps.h +++ b/source/gc/fileOps.h @@ -15,6 +15,7 @@ u32 fsop_GetFreeSpaceKb (char *path); bool fsop_DirExist (char *path); bool fsop_CopyFile (char *source, char *target, progress_callback_t spinner, void *spinner_data); bool fsop_CopyFolder (char *source, char *target, progress_callback_t spinner, void *spinner_data); +void fsop_deleteFolder(char *source); #endif diff --git a/source/gc/gc.c b/source/gc/gc.c index 9c29a58c..09cc0bb1 100644 --- a/source/gc/gc.c +++ b/source/gc/gc.c @@ -6,6 +6,7 @@ #include "gecko.h" #include "fileOps.h" #include "utils.h" +#include "defines.h" #define SRAM_ENGLISH 0 #define SRAM_GERMAN 1 @@ -94,48 +95,20 @@ void set_language(u8 lang) while(!__SYS_SyncSram()); } -void DML_RemoveGame(const char *discid, const char* partition) -{ - int num = 6; - const char *fl[6] = {"%s:/games/%s/game.iso","%s:/games/%s/sys/boot.bin","%s:/games/%s/sys/bi2.bin", - "%s:/games/%s/sys/apploader.img","%s:/games/%s/sys","%s:/games/%s"}; - char fname[MAX_FAT_PATH]; - FILE *f; - DIR *dir; - int i; - for(i = 0; i < num; i++) - { - sprintf(fname, fl[i], partition, discid); - f = fopen((char*)fname, "r"); - if(f) - { - gprintf("Deleting %s...\n",fname); - fclose(f); - remove(fname); - } - dir = opendir((char*)fname); - if(dir) - { - gprintf("Deleting %s...\n",fname); - closedir(dir); - unlink((char*)fname); - } - } -} - bool DML_GameIsInstalled(char *discid, const char* partition) { - char filepath[MAX_FAT_PATH]; - sprintf(filepath, "%s:/games/%s/game.iso", partition, discid); + char folder[12]; + char source[300]; + snprintf(folder, sizeof(folder), DML_DIR, partition); + snprintf(source, sizeof(source), "%s/%s", folder, discid); - gprintf("Filepath on SD: %s\n", filepath); - - FILE *f = fopen(filepath, "r"); + FILE *f = fopen(source, "r"); if (f) { + gprintf("Found on %s: %s\n", partition, source); fclose(f); return true; } - gprintf("Not found\n"); + gprintf("Not found on %s: %s\n", partition, source); return false; } diff --git a/source/gc/gc.h b/source/gc/gc.h index 2ef50ae4..1764344f 100644 --- a/source/gc/gc.h +++ b/source/gc/gc.h @@ -7,7 +7,6 @@ extern "C" #define GC_H_ void set_video_mode(int i); void set_language(u8 lang); -void DML_RemoveGame(const char *discid, const char* partition); bool DML_GameIsInstalled(char *discid, const char* partition); #endif //GC_H_ diff --git a/source/loader/gc_disc.cpp b/source/loader/gc_disc.cpp index 1efd905e..c656b2a4 100644 --- a/source/loader/gc_disc.cpp +++ b/source/loader/gc_disc.cpp @@ -273,6 +273,8 @@ s32 GCDump::DumpGame(progress_callback_t spinner, message_callback_t message, vo memset(ReadBuffer,0,toread); fwrite(ReadBuffer,1,toread,f); correction -= toread; + if(spinner) + spinner(wrote+toread, DiscSizeCalculated, spinner_data); } break; } diff --git a/source/menu/menu_wbfs.cpp b/source/menu/menu_wbfs.cpp index 1c29ab85..dbd5b80d 100644 --- a/source/menu/menu_wbfs.cpp +++ b/source/menu/menu_wbfs.cpp @@ -370,7 +370,11 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) } else { - DML_RemoveGame(m_cf.getHdr()->path, DeviceName[currentPartition]); + char folder[12]; + char source[300]; + snprintf(folder, sizeof(folder), DML_DIR, DeviceName[currentPartition]); + snprintf(source, sizeof(source), "%s/%s", folder, m_cf.getHdr()->path); + fsop_deleteFolder(source); upd_dml = true; } if(m_cfg.getBool("GENERAL", "delete_cover_and_game", true))