From 12b45408e482d6db123b530c133d63dfd7f79e69 Mon Sep 17 00:00:00 2001 From: giantpune Date: Thu, 17 Sep 2009 13:46:13 +0000 Subject: [PATCH] made another useless function... click the "Games:..." text to save a game list in the update path. normal txt or csv format for spreadsheets is supported. --- gui.pnproj | 2 +- source/menu.cpp | 43 +++++++++++++++++--- source/prompts/gameinfo.cpp | 80 ++++++++++++++++++++++++++++++++++++- source/prompts/gameinfo.h | 1 + 4 files changed, 119 insertions(+), 7 deletions(-) diff --git a/gui.pnproj b/gui.pnproj index 9c8c1fea..dc46785d 100644 --- a/gui.pnproj +++ b/gui.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/source/menu.cpp b/source/menu.cpp index 482c6a45..6cfcd6b3 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -375,12 +375,19 @@ int MenuDiscList() { GuiText usedSpaceTxt(spaceinfo, 18, (GXColor) {THEME.info_r, THEME.info_g, THEME.info_b, 255}); usedSpaceTxt.SetAlignment(THEME.hddInfoAlign, ALIGN_TOP); usedSpaceTxt.SetPosition(THEME.hddInfo_x, THEME.hddInfo_y); - - char GamesCnt[15]; + + char GamesCnt[15]; sprintf(GamesCnt,"%s: %i",tr("Games"), gameCnt); GuiText gamecntTxt(GamesCnt, 18, (GXColor) {THEME.info_r, THEME.info_g, THEME.info_b, 255}); - gamecntTxt.SetAlignment(THEME.gameCntAlign, ALIGN_TOP); - gamecntTxt.SetPosition(THEME.gameCnt_x,THEME.gameCnt_y); + + GuiButton gamecntBtn(100,18); + gamecntBtn.SetAlignment(THEME.gameCntAlign, ALIGN_TOP); + gamecntBtn.SetPosition(THEME.gameCnt_x,THEME.gameCnt_y); + gamecntBtn.SetLabel(&gamecntTxt); + gamecntBtn.SetEffectGrow(); + gamecntBtn.SetTrigger(&trigA); + + GuiTooltip installBtnTT(tr("Install a game")); if (Settings.wsprompt == yes) @@ -652,7 +659,7 @@ int MenuDiscList() { w.Append(&usedSpaceTxt); } if (THEME.showGameCnt == -1 || THEME.showGameCnt == 1) { //force show game cnt info - w.Append(&gamecntTxt); + w.Append(&gamecntBtn); } w.Append(&sdcardBtn); w.Append(&poweroffBtn); @@ -788,6 +795,32 @@ int MenuDiscList() { } } + } else if (gamecntBtn.GetState() == STATE_CLICKED) { + + char linebuf[150]; + snprintf(linebuf, sizeof(linebuf), tr("Save Game List to %sGameList ?"), Settings.update_path); + + choice = WindowPrompt(0,linebuf, "txt","csv",tr("Back")); + + if (choice==1) + { + if (save_gamelist(0)) + WindowPrompt(0,tr("Saved"), tr("OK")); + else + WindowPrompt(tr("Error"),tr("Could not save."), tr("OK")); + + } + else if (choice==2) + { + if (save_gamelist(1)) + WindowPrompt(0,tr("Saved"), tr("OK")); + else + WindowPrompt(tr("Error"),tr("Could not save."), tr("OK")); + + } + + gamecntBtn.ResetState(); + } else if (homeBtn.GetState() == STATE_CLICKED) { s32 thetimeofbg = bgMusic->GetPlayTime(); bgMusic->Stop(); diff --git a/source/prompts/gameinfo.cpp b/source/prompts/gameinfo.cpp index 5b987363..71476f9f 100644 --- a/source/prompts/gameinfo.cpp +++ b/source/prompts/gameinfo.cpp @@ -978,6 +978,82 @@ int showGameInfo(char *ID) { } } +bool save_gamelist(int txt) { // save gamelist + mainWindow->SetState(STATE_DISABLED); + char tmp[200]; + sprintf(tmp, "%s", Settings.update_path); + struct stat st; + if (stat(tmp, &st) != 0) { + mkdir(tmp, 0777); + } + FILE *f; + sprintf(tmp, "%sGameList.txt", Settings.update_path); + if (txt==1) + sprintf(tmp, "%sGameList.csv", Settings.update_path); + f = fopen(tmp, "w"); + if (!f) { + sleep(1); + mainWindow->SetState(STATE_DEFAULT); + return false; + } + //make sure that all games are added to the gamelist + __Menu_GetEntries(1); + + f32 size = 0.0; + f32 freespace, used; + unsigned int i; + + WBFS_DiskSpace(&used, &freespace); + + fprintf(f, "# USB Loader Has Saved this file\n"); + fprintf(f, "# This file was created based on your list of games and language settings.\n"); + fclose(f); + /* Closing and reopening because of a write issue we are having right now */ + f = fopen(tmp, "w"); + + if (txt==0) + { + fprintf(f, "# USB Loader Has Saved this file\n"); + fprintf(f, "# This file was created based on your list of games and language settings.\n\n"); + + fprintf(f, "%.2fGB %s %.2fGB %s\n\n",freespace,tr("of"),(freespace+used),tr("free")); + fprintf(f, "ID Size(GB) Name\n"); + + for (i = 0; i < gameCnt ; i++) { + struct discHdr* header = &gameList[i]; + WBFS_GameSize(header->id, &size); + if (i<500) { + fprintf(f, "%c%c%c%c%c%c", header->id[0], header->id[1], header->id[2], header->id[3], header->id[4], header->id[5]); + fprintf(f, " [%.2f] ", size); + fprintf(f, " %s",get_title(header)); + } + fprintf(f, "\n"); + } + } + else { + + fprintf(f, "ID,Size(GB),Name\n"); + + for (i = 0; i < gameCnt ; i++) { + struct discHdr* header = &gameList[i]; + WBFS_GameSize(header->id, &size); + if (i<500) { + fprintf(f, "%c%c%c%c%c%c,", header->id[0], header->id[1], header->id[2], header->id[3], header->id[4], header->id[5]); + fprintf(f, "%.2f,", size); + fprintf(f, "\"%s\"",get_title(header)); + } + fprintf(f, "\n"); + } + + } + fclose(f); + + __Menu_GetEntries(); + mainWindow->SetState(STATE_DEFAULT); + return true; +} + + bool save_XML_URL() { // save xml url as as txt file for people without wifi char tmp[200]; sprintf(tmp, "%s", Settings.update_path); @@ -1013,7 +1089,7 @@ bool save_XML_URL() { // save xml url as as txt file for people without wifi fprintf(f, "# USB Loader Has Saved this file\n"); fprintf(f, "# This URL was created based on your list of games and language settings.\n"); fclose(f); - /* Closing and reopening because of a write issue we are having right now */ + // Closing and reopening because of a write issue we are having right now f = fopen(tmp, "w"); fprintf(f, "# USB Loader Has Saved this file\n"); fprintf(f, "# This URL was created based on your list of games and language settings.\n"); @@ -1026,3 +1102,5 @@ bool save_XML_URL() { // save xml url as as txt file for people without wifi return true; } + + diff --git a/source/prompts/gameinfo.h b/source/prompts/gameinfo.h index 89871765..fd9e0bad 100644 --- a/source/prompts/gameinfo.h +++ b/source/prompts/gameinfo.h @@ -10,4 +10,5 @@ int showGameInfo(char *ID); bool save_XML_URL(); +bool save_gamelist(int txt); #endif