diff --git a/source/gc/gc.c b/source/gc/gc.c index bc99e27d..4ef91840 100644 --- a/source/gc/gc.c +++ b/source/gc/gc.c @@ -1,5 +1,11 @@ #include +#include +#include +#include #include "gc.h" +#include "gecko.h" + +#define MAX_FAT_PATH 1024 #define SRAM_ENGLISH 0 #define SRAM_GERMAN 1 @@ -86,4 +92,50 @@ void set_language(u8 lang) __SYS_UnlockSram(1); // 1 -> write changes while(!__SYS_SyncSram()); -} \ No newline at end of file +} + +void DML_RemoveGame(const char *discid) +{ + int num = 6; + const char *fl[6] = {"sd:/games/%s/game.iso","sd:/games/%s/sys/boot.bin","sd:/games/%s/sys/bi2.bin", + "sd:/games/%s/sys/apploader.img","sd:/games/%s/sys","sd:/games/%s"}; + char fname[MAX_FAT_PATH]; + FILE *f; + DIR *dir; + int i; + for(i = 0; i < num; i++) + { + sprintf(fname, fl[i], 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) +{ + char filepath[64]; + sprintf(filepath, "sd:/games/%s/game.iso", discid); + + gprintf("Filepath on SD: %s\n", filepath); + + FILE *f = fopen(filepath, "r"); + if (f) + { + fclose(f); + return true; + } + gprintf("Not found\n"); + return false; +} diff --git a/source/gc/gc.h b/source/gc/gc.h index 15dc530f..9578f8d7 100644 --- a/source/gc/gc.h +++ b/source/gc/gc.h @@ -7,6 +7,8 @@ extern "C" #define GC_H_ void set_video_mode(int i); void set_language(u8 lang); +void DML_RemoveGame(const char *discid); +bool DML_GameIsInstalled(char *discid); #endif //GC_H_ #ifdef __cplusplus diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 3a6ebc8c..d50768a6 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -512,7 +512,7 @@ void CMenu::_game(bool launch) m_btnMgr.show(m_gameBtnSettings); } - if (m_current_view == COVERFLOW_USB && !m_locked) + if ((m_current_view == COVERFLOW_USB || m_current_view == COVERFLOW_DML) && !m_locked) m_btnMgr.show(m_gameBtnDelete); } else diff --git a/source/menu/menu_wbfs.cpp b/source/menu/menu_wbfs.cpp index e594f8e0..9934b8e2 100644 --- a/source/menu/menu_wbfs.cpp +++ b/source/menu/menu_wbfs.cpp @@ -3,6 +3,7 @@ #include "loader/wbfs.h" #include "lockMutex.hpp" #include "loader/gc_disc.hpp" +#include "gc.h" using namespace std; @@ -178,7 +179,6 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) bool upd_usb = false; bool upd_dml = false; bool out = false; - bool del_cover = true; struct AutoLight { AutoLight(void) { } ~AutoLight(void) { slotLight(false); } } aw; string cfPos = m_cf.getNextId(); @@ -258,7 +258,9 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) { Disc_ReadGCHeader(&gcheader); - if (_searchGamesByID((const char *) gcheader.id).size() != 0) + char gcfolder[64]; + sprintf(gcfolder, "%s [%s]", gcheader.title, (char *)gcheader.id); + if (_searchGamesByID((const char *) gcheader.id).size() != 0 || DML_GameIsInstalled((char *)gcheader.id) || DML_GameIsInstalled(gcfolder)) { error(_t("wbfsoperr4", L"Game already installed")); out = true; @@ -278,12 +280,14 @@ bool CMenu::_wbfsOp(CMenu::WBFS_OP op) error(_t("wbfsoperr3", L"This is not a Wii or GC disc!")); out = true; break; - } + } break; case CMenu::WO_REMOVE_GAME: - WBFS_RemoveGame((u8 *)m_cf.getId().c_str(), (char *) m_cf.getHdr()->path); - del_cover = m_cfg.getBool("GENERAL", "delete_cover_and_game", true); - if(del_cover) + if(m_current_view == COVERFLOW_USB) + WBFS_RemoveGame((u8 *)m_cf.getId().c_str(), (char *) m_cf.getHdr()->path); + else + DML_RemoveGame(m_cf.getHdr()->path); + if(m_cfg.getBool("GENERAL", "delete_cover_and_game", true)) RemoveCover((char *)m_cf.getId().c_str()); m_btnMgr.show(m_wbfsPBar); m_btnMgr.setProgress(m_wbfsPBar, 0.f, true);