From bf1e7f19c5366e09264ce0df6ef67ae7a628d9f6 Mon Sep 17 00:00:00 2001 From: dborth Date: Mon, 16 Mar 2009 06:58:50 +0000 Subject: [PATCH] --- source/ngc/filebrowser.cpp | 46 +++++++++++++++++++-- source/ngc/filebrowser.h | 2 +- source/ngc/fileop.cpp | 27 ++++++------ source/ngc/freeze.cpp | 22 +++++++--- source/ngc/gui/gui_savebrowser.cpp | 7 ++-- source/ngc/images/button_gamesave.png | Bin 546 -> 549 bytes source/ngc/images/button_gamesave_over.png | Bin 539 -> 546 bytes source/ngc/memcardop.cpp | 3 +- source/ngc/menu.cpp | 28 +++++++------ source/ngc/sram.cpp | 19 +++++++-- 10 files changed, 109 insertions(+), 45 deletions(-) diff --git a/source/ngc/filebrowser.cpp b/source/ngc/filebrowser.cpp index 4d01c50..d378f0f 100644 --- a/source/ngc/filebrowser.cpp +++ b/source/ngc/filebrowser.cpp @@ -190,7 +190,7 @@ int UpdateDirName(int method) } } -bool MakeFilePath(char filepath[], int type, int method) +bool MakeFilePath(char filepath[], int type, int method, char * filename, int filenum) { char file[512]; char folder[1024]; @@ -216,11 +216,49 @@ bool MakeFilePath(char filepath[], int type, int method) { case FILE_SRAM: sprintf(folder, GCSettings.SaveFolder); - sprintf(file, "%s.srm", Memory.ROMFilename); + + if(filenum >= 0) + { + if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) + { + filename[26] = 0; // truncate filename + sprintf(file, "%s%i.srm", filename, filenum); + } + else + { + if(filenum == 0) + sprintf(file, "%s Auto.srm", filename); + else + sprintf(file, "%s %i.srm", filename, filenum); + } + } + else + { + sprintf(file, "%s.srm", filename); + } break; case FILE_SNAPSHOT: sprintf(folder, GCSettings.SaveFolder); - sprintf(file, "%s.frz", Memory.ROMFilename); + + if(filenum >= 0) + { + if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) + { + filename[26] = 0; // truncate filename + sprintf(file, "%s%i.frz", filename, filenum); + } + else + { + if(filenum == 0) + sprintf(file, "%s Auto.frz", filename); + else + sprintf(file, "%s %i.frz", filename, filenum); + } + } + else + { + sprintf(file, "%s.frz", filename); + } break; case FILE_CHEAT: sprintf(folder, GCSettings.CheatFolder); @@ -247,7 +285,7 @@ bool MakeFilePath(char filepath[], int type, int method) break; } } - strcpy(filepath, temppath); + strncpy(filepath, temppath, MAXPATHLEN); return true; } diff --git a/source/ngc/filebrowser.h b/source/ngc/filebrowser.h index 10c773f..fd7305e 100644 --- a/source/ngc/filebrowser.h +++ b/source/ngc/filebrowser.h @@ -44,7 +44,7 @@ extern char rootdir[10]; extern unsigned long SNESROMSize; -bool MakeFilePath(char filepath[], int type, int method); +bool MakeFilePath(char filepath[], int type, int method, char * filename = NULL, int filenum = -1); int UpdateDirName(int method); int OpenGameList(); int autoLoadMethod(); diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 949e17e..a1972be 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -559,6 +559,9 @@ u32 LoadFile(char * filepath, int method, bool silent) u32 SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent) { + if(datasize == 0) + return 0; + u32 written = 0; if(!ChangeInterface(method, silent)) @@ -566,17 +569,14 @@ SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent) ShowAction("Saving..."); - switch(method) + if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { - case METHOD_MC_SLOTA: - return SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent); - break; - case METHOD_MC_SLOTB: - return SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent); - break; + if(method == METHOD_MC_SLOTA) + written = SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent); + else + written = SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent); } - - if (datasize) + else { // stop checking if devices were removed/inserted // since we're saving a file @@ -595,15 +595,16 @@ SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent) fclose (file); } - if(!written && !silent) - { + if(!written) unmountRequired[method] = true; - ErrorPrompt("Error saving file!"); - } // go back to checking if devices were inserted/removed LWP_ResumeThread (devicethread); } + + if(!written && !silent) + ErrorPrompt("Error saving file!"); + CancelAction(); return written; } diff --git a/source/ngc/freeze.cpp b/source/ngc/freeze.cpp index d211874..044f88c 100644 --- a/source/ngc/freeze.cpp +++ b/source/ngc/freeze.cpp @@ -166,7 +166,7 @@ NGCFreezeGame (char * filepath, int method, bool silent) if(err!=Z_OK) { - sprintf (msg, "zip error %s ",zError(err)); + sprintf (msg, "Zip error %s",zError(err)); ErrorPrompt(msg); goto done; } @@ -224,6 +224,12 @@ done: int NGCFreezeGameAuto (int method, bool silent) { + if(method == METHOD_AUTO) + method = autoSaveMethod(silent); + + if(method == METHOD_AUTO) + return false; + char filepath[1024]; if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) @@ -316,7 +322,7 @@ NGCUnfreezeGame (char * filepath, int method, bool silent) if ( err!=Z_OK ) { - sprintf (msg, "Unzip error %s ",zError(err)); + sprintf (msg, "Unzip error %s",zError(err)); ErrorPrompt(msg); } else if ( DestBuffSize != decompressedsize ) @@ -351,12 +357,16 @@ NGCUnfreezeGame (char * filepath, int method, bool silent) int NGCUnfreezeGameAuto (int method, bool silent) { + if(method == METHOD_AUTO) + method = autoSaveMethod(silent); + + if(method == METHOD_AUTO) + return false; + char filepath[1024]; - if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) - sprintf(filepath, "%s Auto.frz", Memory.ROMFilename); - else - sprintf(filepath, "%s/%s Auto.frz", GCSettings.SaveFolder, Memory.ROMFilename); + if(!MakeFilePath(filepath, FILE_SNAPSHOT, method, Memory.ROMFilename, 0)) + return false; return NGCUnfreezeGame(filepath, method, silent); } diff --git a/source/ngc/gui/gui_savebrowser.cpp b/source/ngc/gui/gui_savebrowser.cpp index 5951ffb..9e249bc 100644 --- a/source/ngc/gui/gui_savebrowser.cpp +++ b/source/ngc/gui/gui_savebrowser.cpp @@ -111,7 +111,7 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a) saveBtn[i]->SetImageOver(saveBgOverImg[i]); saveBtn[i]->SetIcon(savePreviewImg[i]); saveBtn[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - saveBtn[i]->SetPosition(247*(i % 2),87*(i/2)); + saveBtn[i]->SetPosition(257*(i % 2),87*(i/2)); saveBtn[i]->SetTrigger(trigA); saveBtn[i]->SetState(STATE_DISABLED); saveBtn[i]->SetEffectGrow(); @@ -347,10 +347,11 @@ void GuiSaveBrowser::Update(GuiTrigger * t) len = strlen(saves->filename[listOffset+i]); if(len > 10 && - saves->filename[listOffset+i][len-8] == 'A' && + ((saves->filename[listOffset+i][len-8] == 'A' && saves->filename[listOffset+i][len-7] == 'u' && saves->filename[listOffset+i][len-6] == 't' && - saves->filename[listOffset+i][len-5] == 'o' + saves->filename[listOffset+i][len-5] == 'o') || + saves->filename[listOffset+i][len-5] == '0') ) { strcat(savetext, " (Auto)"); diff --git a/source/ngc/images/button_gamesave.png b/source/ngc/images/button_gamesave.png index bb49e811d2a3fb34e00e59590c8d447f2c16a82e..0f44608a3e4a93b50c6398d7dd348fb71f1f6133 100644 GIT binary patch literal 549 zcmeAS@N?(olHy`uVBq!ia0vp^Ux3(ygAGU?RKM{7NJ*BsMwA5SrA%>EaktaqGOR^O=-r>Y+xkOMdfJ=U z%eP*tlG`k`S-?2FVfQ9xzNSNRmEm=>+yB2++Dhvse{4Hv z{`vQeb6;}S``E>4&8?ms##$azTpOw9Z#V7p<9}y!ee#v`)*C%zH|~D=aI*L|mZ>Mi z^UZGm`5DT#yn1eq<^Cf3)9wB9^ll4;ya?NUm#6C0v*RVt_nmcU&D&~inkV}~{%9_% zLWaYIh6Rj{%|OiD#KywQAqBz$CLjr#N;cN>{ZisT{A_!!Lu=dN)fYdev;9@|PrqND z!=_bIw!zlwUHS!S!?O=c*8j1n37_@4k=K!R)72ca+h=d*R4VE1&b_k!eE)A%_7&%j z)s%le{K9{ux#8X!YiB6$Zq$<5diI;rvz#4&L=zY~)k91#m#=yUjCTf4S3j3^P6l%bzein>R`1B<449hku~yj3ewZc9~@W7 zeDk*C@{yo<{+0KhWvV_{$onbhd1QRX_qt=fGfy@@wfSo!f0T1-rmxhS|2Jbh)q<7x zJ3c=9Q`!IHn^1Mrc)ewh3NNpE&^R@G`O7c=*O&ZRUtc|Q`Dcy#nqG_f`zoeCdv^b} zP>4!g&&7nw+Iep5(XLx0;|uQ}IsAOR{SARD2j+_17JTvMZU4nboo5|*?_?I19kW_+ zY-1E7hlqd%2rC4@u)_j{00?eya9jYvjEzkW5X{8H+6cugTuiJG%ptO5#d}^+$%d(Y-}W#6l$GKf z(3qhw)g$)U=vEFeBp)YPo?j*Em|GK<@%`GedZD#XUp~2c!g!1HiX#P=64W2{NSib9 aFqD1?P~Ks4Xaz9R89ZJ6T-G@yGywq8%i?$d diff --git a/source/ngc/images/button_gamesave_over.png b/source/ngc/images/button_gamesave_over.png index 2d042da82d695cf5bc08a96170eb33d98715dd39..1e44a737e6f7d09772e0aa73b0de81309ae7e884 100644 GIT binary patch literal 546 zcmeAS@N?(olHy`uVBq!ia0vp^Ux3(ygAGU?RKM{7NJ*BsMwA5SrAr>EaktaqG?Xjb1W=A`K6%1686U*DQFT%n~B7hRG{v z*;cOuYWWFICrxk?So~-&a zN-xLieczV+E!iwNjN9P#F~h?%>Yi_sd(!>N?nU#Azp8xt&##%EK6G=XuH)%D`|5(1E&lUK zubJmpxQy8R{(V!kN{^N;$Tk1EL$Cgt`KOAhj^>qJ@AGFjPW!d@%X_1`G|>+w98xU2 z98v-%3K<~maG_xVqhm7=GdHn;Bxox6;m3mYpDy%d-)<1gdevUG-uQ)l<*YY*w@YR$ zJh{8QtX=ZU@fj~mOmrsS-M)0^k4)zaZL=+-&Zcd?n`05ZE^pWAp9KQNIj$F?_MS_v z{bc`Qi|l6k&7zx=>p(y^|LE`T--I!PC{xWt~$(69D>N B-%$Vn literal 539 zcmeAS@N?(olHy`uVBq!ia0vp^FM!yCgAGXj*}8KYkdiEMjVKAuPb(=;EJ|f?Ovz75 zRq)JBOiv9;O-!jQJeg|4z`(fI)5S5Q;?|q%8@*%#MH(JjYbl0_iE-IAO%P?#cD!hm zyNcz~6W%o5W+H$Hq1t+cSv;oo2P?6E?cEwgR^;a4fyJ8LYgx2j5P{(bg*>V>oVcQ2iD z_5z0F+bktSzY?`e$=VQXI+l{{9>%-m(gObd(J0<-DJ9h&~RJG*->Pl^o+*X95K diff --git a/source/ngc/memcardop.cpp b/source/ngc/memcardop.cpp index 51d96da..04742c6 100644 --- a/source/ngc/memcardop.cpp +++ b/source/ngc/memcardop.cpp @@ -335,8 +335,7 @@ SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent) while (bytesleft > 0) { CardError = - CARD_Write (&CardFile, buf + byteswritten, - SectorSize, byteswritten); + CARD_Write (&CardFile, buf + byteswritten, SectorSize, byteswritten); if(CardError) { diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 6813069..47da890 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -484,14 +484,14 @@ void AutoSave() else if (GCSettings.AutoSave == 2) { if (WindowPrompt("Save", "Save Snapshot?", "Save", "Don't Save") ) - NGCFreezeGameAuto(GCSettings.SaveMethod, SILENT); + NGCFreezeGameAuto(GCSettings.SaveMethod, NOTSILENT); } else if (GCSettings.AutoSave == 3) { if (WindowPrompt("Save", "Save SRAM and Snapshot?", "Save", "Don't Save") ) { - SaveSRAMAuto(GCSettings.SaveMethod, SILENT); - NGCFreezeGameAuto(GCSettings.SaveMethod, SILENT); + SaveSRAMAuto(GCSettings.SaveMethod, NOTSILENT); + NGCFreezeGameAuto(GCSettings.SaveMethod, NOTSILENT); } } } @@ -1212,10 +1212,11 @@ static int MenuGame() resetBtn.SetEffect(EFFECT_FADE, 15); controllerBtn.SetEffect(EFFECT_FADE, 15); cheatsBtn.SetEffect(EFFECT_FADE, 15); + + AutoSave(); } ResumeGui(); - AutoSave(); while(menu == MENU_NONE) { @@ -1229,7 +1230,6 @@ static int MenuGame() { level = (userInput[i].wpad.battery_level / 100.0) * 4; batteryBarImg[i]->SetTile(level); - batteryBtn[i]->SetAlpha(255); if(level == 0) batteryImg[i]->SetImage(&batteryRed); @@ -1241,6 +1241,7 @@ static int MenuGame() else // controller not connected { batteryBarImg[i]->SetTile(0); + batteryImg[i]->SetImage(&battery); batteryBtn[i]->SetAlpha(150); } } @@ -1296,12 +1297,12 @@ static int MenuGame() titleTxt.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 35); mainmenuBtn.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); bgBottomImg->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); + btnLogo->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); #ifdef HW_RVL batteryBtn[0]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); batteryBtn[1]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); batteryBtn[2]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); batteryBtn[3]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); - btnLogo->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); #endif saveBtn.SetEffect(EFFECT_FADE, -15); @@ -1430,6 +1431,9 @@ static int MenuGameSaves(int action) len = strlen(Memory.ROMFilename); len2 = strlen(browserList[i].filename); + if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) + len = 26; // memory card filenames are a maximum of 32 chars + // find matching files if(len2 > 5 && strncmp(browserList[i].filename, Memory.ROMFilename, len) == 0) { @@ -1508,8 +1512,7 @@ static int MenuGameSaves(int action) if(action == 0) // load { - sprintf(filepath, "%s/%s", GCSettings.SaveFolder, saves.filename[ret]); - + MakeFilePath(filepath, saves.type[ret], method, saves.filename[ret]); switch(saves.type[ret]) { case FILE_SRAM: @@ -1532,7 +1535,7 @@ static int MenuGameSaves(int action) if(i < 100) { - sprintf(filepath, "%s/%s %i.srm", GCSettings.SaveFolder, Memory.ROMFilename, i); + MakeFilePath(filepath, FILE_SRAM, method, Memory.ROMFilename, i); SaveSRAM(filepath, GCSettings.SaveMethod, NOTSILENT); menu = MENU_GAME_SAVE; } @@ -1545,15 +1548,14 @@ static int MenuGameSaves(int action) if(i < 100) { - sprintf(filepath, "%s/%s %i.frz", GCSettings.SaveFolder, Memory.ROMFilename, i); + MakeFilePath(filepath, FILE_SNAPSHOT, method, Memory.ROMFilename, i); NGCFreezeGame (filepath, GCSettings.SaveMethod, NOTSILENT); menu = MENU_GAME_SAVE; } } else // overwrite SRAM/Snapshot { - sprintf(filepath, "%s/%s", GCSettings.SaveFolder, saves.filename[ret-2]); - + MakeFilePath(filepath, saves.type[ret-2], method, saves.filename[ret-2]); switch(saves.type[ret-2]) { case FILE_SRAM: @@ -1581,6 +1583,7 @@ static int MenuGameSaves(int action) titleTxt.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 35); backBtn.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); bgBottomImg->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); + btnLogo->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); w.SetEffect(EFFECT_FADE, -15); @@ -1700,6 +1703,7 @@ static int MenuGameCheats() titleTxt.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 35); backBtn.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); bgBottomImg->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); + btnLogo->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 35); w.SetEffect(EFFECT_FADE, -15); diff --git a/source/ngc/sram.cpp b/source/ngc/sram.cpp index 2d91344..04cfdf1 100644 --- a/source/ngc/sram.cpp +++ b/source/ngc/sram.cpp @@ -174,6 +174,12 @@ LoadSRAM (char * filepath, int method, bool silent) bool LoadSRAMAuto (int method, bool silent) { + if(method == METHOD_AUTO) + method = autoSaveMethod(silent); + + if(method == METHOD_AUTO) + return false; + char filepath[1024]; if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) @@ -227,11 +233,16 @@ SaveSRAM (char * filepath, int method, bool silent) bool SaveSRAMAuto (int method, bool silent) { + if(method == METHOD_AUTO) + method = autoSaveMethod(silent); + + if(method == METHOD_AUTO) + return false; + char filepath[1024]; - if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) - sprintf(filepath, "%s Auto.srm", Memory.ROMFilename); - else - sprintf(filepath, "%s/%s Auto.srm", GCSettings.SaveFolder, Memory.ROMFilename); + if(!MakeFilePath(filepath, FILE_SRAM, method, Memory.ROMFilename, 0)) + return false; + return SaveSRAM(filepath, method, silent); }