mirror of
https://github.com/suloku/savegame-manager.git
synced 2026-04-25 07:27:24 -05:00
- Fixes (?) fileExists() on dsiwarehax
- Implements a preliminary backup/restore method for DSi/SD (dsiwarehax) mode. If you know how to unlock Slot 1 so that this mode actually works, please implement "dsiUnlockSlot1" in dsi.cpp. - Bumps version to 0.3.0 RC2
This commit is contained in:
parent
9452868030
commit
f731795b31
|
|
@ -276,13 +276,20 @@ void fileSelect(const char *startdir, char *out_dir, char *out_fname, netbuf *bu
|
|||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
// This is a standard textbook-style "fileExists" function.
|
||||
bool fileExists(const char *fname)
|
||||
{
|
||||
struct stat statbuf;
|
||||
memset(&statbuf, 0, sizeof(statbuf));
|
||||
if (stat(fname, &statbuf) != 0)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
else {
|
||||
// on dsiwarehaxx, this additional check is required
|
||||
if (statbuf.st_size)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 fileSize(const char *fname)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 3
|
||||
#define VERSION_MICRO 0
|
||||
#define VERSION_EXTRA "rc1"
|
||||
#define VERSION_EXTRA "RC2"
|
||||
|
||||
extern u8 *data;
|
||||
extern u32 size_buf;
|
||||
|
|
|
|||
|
|
@ -246,26 +246,134 @@ void hwFormatNor(uint32 page, uint32 count)
|
|||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
// uncomment this to enable slot 1 operations... but implement "dsiUnlockSlot1()" before!
|
||||
// the following two functions are *untested* and may not work at all!
|
||||
//#define SLOT_1_UNLOCKED
|
||||
|
||||
void hwBackupDSi()
|
||||
{
|
||||
// only works from dsiwarehax
|
||||
if (!sdslot)
|
||||
return;
|
||||
|
||||
#ifdef SLOT_1_UNLOCKED
|
||||
// swap game
|
||||
swap_cart();
|
||||
displayPrintUpper();
|
||||
#endif
|
||||
|
||||
uint8 size = auxspi_save_size_log_2(slot_1_type);
|
||||
int size_blocks = 1 << max(0, (int8(size) - 18)); // ... in units of 0x40000 bytes - that's 256 kB
|
||||
uint8 type = auxspi_save_type(slot_1_type);
|
||||
|
||||
// select target filename
|
||||
displayMessageF(STR_HW_SELECT_FILE_OW);
|
||||
|
||||
// only works from dsiwarehax
|
||||
char path[256];
|
||||
char fname[256] = "";
|
||||
fileSelect("sd:/", path, fname, 0, false, false);
|
||||
fileSelect("sd:/", path, fname, 0, true, false);
|
||||
|
||||
// look for an unused filename
|
||||
if (!fname[0]) {
|
||||
char *gamename = (char*)0x080000a0;
|
||||
uint32 cnt = 0;
|
||||
sprintf(fname, "/%.12s.%i.sav", gamename, cnt);
|
||||
displayMessage2F(STR_HW_SEEK_UNUSED_FNAME, fname);
|
||||
while (fileExists(fname)) {
|
||||
if (cnt < 65536)
|
||||
cnt++;
|
||||
else {
|
||||
displayWarning2F(STR_ERR_NO_FNAME);
|
||||
while(1);
|
||||
}
|
||||
sprintf(fname, "%s.%i.sav", gamename, cnt);
|
||||
}
|
||||
}
|
||||
char fullpath[256];
|
||||
sprintf(fullpath, "%s/%s", path, fname);
|
||||
displayMessage2F(STR_HW_WRITE_FILE, fullpath);
|
||||
|
||||
// backup the file
|
||||
FILE *file = fopen(fullpath, "wb");
|
||||
if (size < 16)
|
||||
size_blocks = 1;
|
||||
else
|
||||
size_blocks = 1 << (size - 16);
|
||||
u32 LEN = min(1 << size, 1 << 16);
|
||||
for (int i = 0; i < size_blocks; i++) {
|
||||
displayProgressBar(i+1, size_blocks);
|
||||
auxspi_read_data(i << 8, data, LEN, type, slot_1_type);
|
||||
fwrite(data, 1, LEN, file);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
displayProgressBar(0,0);
|
||||
displayMessageF(STR_EMPTY);
|
||||
}
|
||||
|
||||
void hwRestoreDSi()
|
||||
{
|
||||
// only works from dsiwarehax
|
||||
if (!sdslot)
|
||||
return;
|
||||
|
||||
// only works from dsiwarehax
|
||||
#ifdef SLOT_1_UNLOCKED
|
||||
// swap game
|
||||
swap_cart();
|
||||
displayPrintUpper();
|
||||
#endif
|
||||
|
||||
uint8 size = auxspi_save_size_log_2(slot_1_type);
|
||||
uint8 type = auxspi_save_type(slot_1_type);
|
||||
|
||||
// select source filename
|
||||
char path[256];
|
||||
char fname[256] = "";
|
||||
fileSelect("sd:/", path, fname, 0, true, false);
|
||||
|
||||
// format game if required
|
||||
if (type == 3) {
|
||||
displayMessage2F(STR_HW_FORMAT_GAME);
|
||||
auxspi_erase(slot_1_type);
|
||||
}
|
||||
|
||||
// and finally, write save
|
||||
displayMessage2F(STR_HW_WRITE_GAME);
|
||||
u32 LEN = 0, num_blocks = 0, shift = 0;
|
||||
switch (type) {
|
||||
case 1:
|
||||
shift = 4; // 16 bytes
|
||||
break;
|
||||
case 2:
|
||||
shift = 5; // 32 bytes
|
||||
break;
|
||||
case 3:
|
||||
shift = 8; // 256 bytes
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
LEN = 1 << shift;
|
||||
num_blocks = 1 << (size - shift);
|
||||
|
||||
char msg[256];
|
||||
sprintf(msg, "%s/%s", path, fname);
|
||||
FILE *file = fopen(msg, "rb");
|
||||
if (!file) {
|
||||
iprintf("Error!");
|
||||
while (1);
|
||||
}
|
||||
for (unsigned int i = 0; i < num_blocks; i++) {
|
||||
if (i % (num_blocks >> 6) == 0)
|
||||
displayProgressBar(i+1, num_blocks);
|
||||
fread(data, 1, LEN, file);
|
||||
sysSetBusOwners(true, true);
|
||||
auxspi_write_data(i << shift, data, LEN, type, slot_1_type);
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
displayProgressBar(0,0);
|
||||
displayMessageF(STR_EMPTY);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
|
@ -575,7 +683,6 @@ void hwRestoreSlot2()
|
|||
displayMessageF(STR_HW_SELECT_FILE); // lower screen is used for file browser
|
||||
fileSelect("/", path, fname, 0, false, false);
|
||||
char msg[256];
|
||||
// This does not have to be translated.
|
||||
sprintf(msg, "%s/%s", path, fname);
|
||||
|
||||
FILE *file = fopen(msg, "rb");
|
||||
|
|
@ -669,12 +776,7 @@ void hwBackupFTP(bool dlp)
|
|||
swap_cart();
|
||||
displayPrintUpper();
|
||||
uint8 size = auxspi_save_size_log_2(slot_1_type);
|
||||
int size_blocks = 1 << max(0, (int8(size) - 18)); // ... in units of 0x40000 bytes - that's 256 kB
|
||||
uint8 type = auxspi_save_type(slot_1_type);
|
||||
if (size < 15)
|
||||
size_blocks = 1;
|
||||
else
|
||||
size_blocks = 1 << (uint8(size) - 15);
|
||||
|
||||
// Second: connect to FTP server
|
||||
if (!ftp_active)
|
||||
|
|
@ -688,11 +790,6 @@ void hwBackupFTP(bool dlp)
|
|||
fileSelect("/", fdir, fname, buf, true, false);
|
||||
displayMessageF(STR_EMPTY);
|
||||
displayStateF(STR_EMPTY);
|
||||
bool newfile;
|
||||
if (!fname[0])
|
||||
newfile = true;
|
||||
else
|
||||
newfile = false;
|
||||
|
||||
// Third: get a new target filename
|
||||
FtpChdir(fdir, buf);
|
||||
|
|
@ -772,8 +869,8 @@ bool hwRestoreFTPPartial(u32 ofs, u32 size, u32 type, netbuf *ndata)
|
|||
pdata += 512;
|
||||
}
|
||||
|
||||
// Write to game (safe mode)
|
||||
u32 LEN = 0, num_blocks = 0, shift = 0;
|
||||
// Write to game
|
||||
u32 LEN = 0, shift = 0;
|
||||
switch (type) {
|
||||
case 1:
|
||||
shift = 4; // 16 bytes
|
||||
|
|
@ -788,7 +885,6 @@ bool hwRestoreFTPPartial(u32 ofs, u32 size, u32 type, netbuf *ndata)
|
|||
return false;
|
||||
}
|
||||
LEN = 1 << shift;
|
||||
num_blocks = 1 << (size - shift);
|
||||
if (type == 3) {
|
||||
displayMessage2F(STR_HW_FORMAT_GAME);
|
||||
u32 sector = ofs >> 16;
|
||||
|
|
|
|||
|
|
@ -57,6 +57,14 @@ using std::max;
|
|||
char bootdir[256] = "/";
|
||||
|
||||
|
||||
#define LIBNDS_VER ((_LIBNDS_MAJOR_ << 16) | (_LIBNDS_MINOR_ << 8) | (_LIBNDS_PATCH_))
|
||||
|
||||
// needs libnds version 1.5.4, for the SDHC driver on the DSi.
|
||||
#if (LIBNDS_VER < 0x00010504)
|
||||
#error "Your libnds version is outdated! Please use 1.5.4 or higher!"
|
||||
#endif
|
||||
|
||||
|
||||
#define REBOOT_WIFI
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<Project name="Savegame Manager"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm9" path="arm9\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="auxspi.d"></File><File path="auxspi.o"></File><File path="display.d"></File><File path="display.o"></File><File path="dsCard.d"></File><File path="dsCard.o"></File><File path="dsi.d"></File><File path="dsi.o"></File><File path="fileselect.d"></File><File path="fileselect.o"></File><File path="ftplib.d"></File><File path="ftplib.o"></File><File path="gba.d"></File><File path="gba.o"></File><File path="globals.d"></File><File path="globals.o"></File><File path="hardware.d"></File><File path="hardware.o"></File><File path="ini.d"></File><File path="ini.o"></File><File path="main.d"></File><File path="main.o"></File><File path="strings.d"></File><File path="strings.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="debug" path="debug\"></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="auxspi.cpp"></File><File path="auxspi.h"></File><File path="auxspi_core.inc"></File><File path="display.cpp"></File><File path="display.h"></File><File path="dsCard.cpp"></File><File path="dsCard.h"></File><File path="dsi.cpp"></File><File path="dsi.h"></File><File path="fileselect.cpp"></File><File path="fileselect.h"></File><File path="ftplib.c"></File><File path="ftplib.h"></File><File path="gba.cpp"></File><File path="gba.h"></File><File path="globals.cpp"></File><File path="globals.h"></File><File path="hardware.cpp"></File><File path="hardware.h"></File><File path="headings.i"></File><File path="ini.cpp"></File><File path="ini.h"></File><File path="iniconfig.h"></File><File path="iniheadings.h"></File><File path="inikeys.h"></File><File path="inilist.h"></File><File path="keys.i"></File><File path="libini.h"></File><File path="list.i"></File><File path="main.cpp"></File><File path="strings.cpp"></File><File path="strings.h"></File><File path="types.i"></File></MagicFolder><File path="Makefile"></File><File path="Makefile.debug"></File><File path="savegame_manager-debug.elf"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm7" path="arm7\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="arm7.d"></File><File path="arm7.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="debug" path="debug\"></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="arm7.c"></File></MagicFolder><File path="Makefile"></File><File path="Makefile.debug"></File><File path="savegame_manager-debug.elf"></File></MagicFolder><File path="Makefile"></File></Project>
|
||||
<Project name="Savegame Manager"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm9" path="arm9\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="auxspi.d"></File><File path="auxspi.o"></File><File path="display.d"></File><File path="display.o"></File><File path="dsCard.d"></File><File path="dsCard.o"></File><File path="dsi.d"></File><File path="dsi.o"></File><File path="fileselect.d"></File><File path="fileselect.o"></File><File path="ftplib.d"></File><File path="ftplib.o"></File><File path="gba.d"></File><File path="gba.o"></File><File path="globals.d"></File><File path="globals.o"></File><File path="hardware.d"></File><File path="hardware.o"></File><File path="ini.d"></File><File path="ini.o"></File><File path="main.d"></File><File path="main.o"></File><File path="strings.d"></File><File path="strings.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="debug" path="debug\"></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="auxspi.cpp"></File><File path="auxspi.h"></File><File path="auxspi_core.inc"></File><File path="display.cpp"></File><File path="display.h"></File><File path="dsCard.cpp"></File><File path="dsCard.h"></File><File path="dsi.cpp"></File><File path="dsi.h"></File><File path="fileselect.cpp"></File><File path="fileselect.h"></File><File path="ftplib.c"></File><File path="ftplib.h"></File><File path="gba.cpp"></File><File path="gba.h"></File><File path="globals.cpp"></File><File path="globals.h"></File><File path="hardware.cpp"></File><File path="hardware.h"></File><File path="headings.i"></File><File path="ini.cpp"></File><File path="ini.h"></File><File path="iniconfig.h"></File><File path="iniheadings.h"></File><File path="inikeys.h"></File><File path="inilist.h"></File><File path="keys.i"></File><File path="libini.h"></File><File path="list.i"></File><File path="main.cpp"></File><File path="strings.cpp"></File><File path="strings.h"></File><File path="types.i"></File></MagicFolder><File path="Makefile"></File><File path="Makefile.debug"></File><File path="savegame_manager.elf"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="arm7" path="arm7\"><MagicFolder excludeFolders="CVS;.svn" filter="*" name="build" path="build\"><File path=".map"></File><File path="arm7.d"></File><File path="arm7.o"></File></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="debug" path="debug\"></MagicFolder><MagicFolder excludeFolders="CVS;.svn" filter="*" name="source" path="source\"><File path="arm7.c"></File></MagicFolder><File path="Makefile"></File><File path="Makefile.debug"></File><File path="savegame_manager.elf"></File></MagicFolder><File path="Makefile"></File></Project>
|
||||
Loading…
Reference in New Issue
Block a user