From d009275839c3d0dfeb62034f94803305623fc4b9 Mon Sep 17 00:00:00 2001 From: Maximus32 Date: Wed, 30 Dec 2020 23:36:21 +0100 Subject: [PATCH] Add sbCreatePath to create a path to a game --- include/supportbase.h | 1 + include/system.h | 2 +- src/ethsupport.c | 10 ++---- src/supportbase.c | 80 +++++++++++++++++-------------------------- src/system.c | 2 +- src/usbsupport.c | 26 ++------------ 6 files changed, 39 insertions(+), 82 deletions(-) diff --git a/include/supportbase.h b/include/supportbase.h index 8338b0012..cd6987d11 100644 --- a/include/supportbase.h +++ b/include/supportbase.h @@ -42,6 +42,7 @@ int sbReadList(base_game_info_t **list, const char *prefix, int *fsize, int *gam int sbPrepare(base_game_info_t *game, config_set_t *configSet, int size_cdvdman, void **cdvdman_irx, int *patchindex); void sbUnprepare(void *pCommon); void sbRebuildULCfg(base_game_info_t **list, const char *prefix, int gamecount, int excludeID); +void sbCreatePath(const base_game_info_t *game, char *path, const char *prefix, const char *sep, int part); void sbDelete(base_game_info_t **list, const char *prefix, const char *sep, int gamecount, int id); void sbRename(base_game_info_t **list, const char *prefix, const char *sep, int gamecount, int id, char *newname); config_set_t *sbPopulateConfig(base_game_info_t *game, const char *prefix, const char *sep); diff --git a/include/system.h b/include/system.h index b080b50ff..52e620f1b 100644 --- a/include/system.h +++ b/include/system.h @@ -7,7 +7,7 @@ #define SYS_LOAD_USB_MODULES 0x02 #define SYS_LOAD_ISOFS_MODULE 0x04 -unsigned int USBA_crc32(char *string); +unsigned int USBA_crc32(const char *string); int sysGetDiscID(char *discID); void sysInitDev9(void); void sysShutdownDev9(void); diff --git a/src/ethsupport.c b/src/ethsupport.c index ce13f3827..d8ce8922b 100644 --- a/src/ethsupport.c +++ b/src/ethsupport.c @@ -665,13 +665,7 @@ static void ethLaunchGame(int id, config_set_t *configSet) strcpy(settings->smb_password, gPCPassword); //Initialize layer 1 information. - switch (game->format) { - case GAME_FORMAT_USBLD: - sprintf(partname, "%s%s.00", ethPrefix, settings->filename); - break; - default: //Raw ISO9660 disc image; one part. - sprintf(partname, "%s%s\\%s", ethPrefix, game->media == SCECdPS2CD ? "CD" : "DVD", settings->filename); - } + sbCreatePath(game, partname, ethPrefix, "\\", 0); if (gPS2Logo) { int fd = open(partname, O_RDONLY, 0666); @@ -687,7 +681,7 @@ static void ethLaunchGame(int id, config_set_t *configSet) case GAME_FORMAT_USBLD: layer1_part = layer1_start / 0x80000; layer1_offset = layer1_start % 0x80000; - sprintf(partname, "%s%s.%02x", ethPrefix, settings->filename, layer1_part); + sbCreatePath(game, partname, ethPrefix, "\\", layer1_part); break; default: //Raw ISO9660 disc image; one part. layer1_part = 0; diff --git a/src/supportbase.c b/src/supportbase.c index a94b21e6b..e3ba73a4a 100644 --- a/src/supportbase.c +++ b/src/supportbase.c @@ -643,73 +643,55 @@ void sbRebuildULCfg(base_game_info_t **list, const char *prefix, int gamecount, } } +static void sbCreatePath_name(const base_game_info_t *game, char *path, const char *prefix, const char *sep, int part, const char *game_name) +{ + switch (game->format) { + case GAME_FORMAT_USBLD: + snprintf(path, 256, "%sul.%08X.%s.%02x", prefix, USBA_crc32(game_name), game->startup, part); + break; + case GAME_FORMAT_ISO: + snprintf(path, 256, "%s%s%s%s%s", prefix, (game->media == SCECdPS2CD) ? "CD" : "DVD", sep, game_name, game->extension); + break; + case GAME_FORMAT_OLD_ISO: + snprintf(path, 256, "%s%s%s%s.%s%s", prefix, (game->media == SCECdPS2CD) ? "CD" : "DVD", sep, game->startup, game_name, game->extension); + break; + } +} + +void sbCreatePath(const base_game_info_t *game, char *path, const char *prefix, const char *sep, int part) +{ + sbCreatePath_name(game, path, prefix, sep, part, game->name); +} + void sbDelete(base_game_info_t **list, const char *prefix, const char *sep, int gamecount, int id) { + int part; char path[256]; base_game_info_t *game = &(*list)[id]; - if (game->format != GAME_FORMAT_USBLD) { - if (game->format != GAME_FORMAT_OLD_ISO) { - if (game->media == SCECdPS2CD) - snprintf(path, sizeof(path), "%sCD%s%s.%s%s", prefix, sep, game->startup, game->name, game->extension); - else - snprintf(path, sizeof(path), "%sDVD%s%s.%s%s", prefix, sep, game->startup, game->name, game->extension); - } else { - if (game->media == SCECdPS2CD) - snprintf(path, sizeof(path), "%sCD%s%s%s", prefix, sep, game->name, game->extension); - else - snprintf(path, sizeof(path), "%sDVD%s%s%s", prefix, sep, game->name, game->extension); - } + for (part = 0; part < game->parts; part++) { + sbCreatePath(game, path, prefix, sep, part); unlink(path); - } else { - char *pathStr = "%sul.%08X.%s.%02x"; - unsigned int crc = USBA_crc32(game->name); - int i = 0; - do { - snprintf(path, sizeof(path), pathStr, prefix, crc, game->startup, i++); - unlink(path); - } while (i < game->parts); + } + if (game->format == GAME_FORMAT_USBLD) { sbRebuildULCfg(list, prefix, gamecount, id); } } void sbRename(base_game_info_t **list, const char *prefix, const char *sep, int gamecount, int id, char *newname) { + int part; char oldpath[256], newpath[256]; base_game_info_t *game = &(*list)[id]; - if (game->format != GAME_FORMAT_USBLD) { - if (game->format == GAME_FORMAT_OLD_ISO) { - if (game->media == SCECdPS2CD) { - snprintf(oldpath, sizeof(oldpath), "%sCD%s%s.%s%s", prefix, sep, game->startup, game->name, game->extension); - snprintf(newpath, sizeof(newpath), "%sCD%s%s.%s%s", prefix, sep, game->startup, newname, game->extension); - } else { - snprintf(oldpath, sizeof(oldpath), "%sDVD%s%s.%s%s", prefix, sep, game->startup, game->name, game->extension); - snprintf(newpath, sizeof(newpath), "%sDVD%s%s.%s%s", prefix, sep, game->startup, newname, game->extension); - } - } else { - if (game->media == SCECdPS2CD) { - snprintf(oldpath, sizeof(oldpath), "%sCD%s%s%s", prefix, sep, game->name, game->extension); - snprintf(newpath, sizeof(newpath), "%sCD%s%s%s", prefix, sep, newname, game->extension); - } else { - snprintf(oldpath, sizeof(oldpath), "%sDVD%s%s%s", prefix, sep, game->name, game->extension); - snprintf(newpath, sizeof(newpath), "%sDVD%s%s%s", prefix, sep, newname, game->extension); - } - } + for (part = 0; part < game->parts; part++) { + sbCreatePath_name(game, oldpath, prefix, sep, part, game->name); + sbCreatePath_name(game, newpath, prefix, sep, part, newname); rename(oldpath, newpath); - } else { - const char *pathStr = "%sul.%08X.%s.%02x"; - unsigned int oldcrc = USBA_crc32(game->name); - unsigned int newcrc = USBA_crc32(newname); - int i; - - for (i = 0; i < game->parts; i++) { - snprintf(oldpath, sizeof(oldpath), pathStr, prefix, oldcrc, game->startup, i); - snprintf(newpath, sizeof(newpath), pathStr, prefix, newcrc, game->startup, i); - rename(oldpath, newpath); - } + } + if (game->format == GAME_FORMAT_USBLD) { memset(game->name, 0, UL_GAME_NAME_MAX + 1); memcpy(game->name, newname, UL_GAME_NAME_MAX); sbRebuildULCfg(list, prefix, gamecount, -1); diff --git a/src/system.c b/src/system.c index 72022536c..a8f440eba 100644 --- a/src/system.c +++ b/src/system.c @@ -268,7 +268,7 @@ void sysPowerOff(void) static unsigned int crctab[0x400]; -unsigned int USBA_crc32(char *string) +unsigned int USBA_crc32(const char *string) { int crc, table, count, byte; diff --git a/src/usbsupport.c b/src/usbsupport.c index 84e2a2bda..a1280c303 100644 --- a/src/usbsupport.c +++ b/src/usbsupport.c @@ -291,17 +291,7 @@ static void usbLaunchGame(int id, config_set_t *configSet) compatmask = sbPrepare(game, configSet, irx_size, irx, &index); settings = (struct cdvdman_settings_usb *)((u8 *)irx + index); for (i = 0; i < game->parts; i++) { - switch (game->format) { - case GAME_FORMAT_ISO: - sprintf(partname, "%s%s/%s%s", usbPrefix, (game->media == SCECdPS2CD) ? "CD" : "DVD", game->name, game->extension); - break; - case GAME_FORMAT_OLD_ISO: - sprintf(partname, "%s%s/%s.%s%s", usbPrefix, (game->media == SCECdPS2CD) ? "CD" : "DVD", game->startup, game->name, game->extension); - break; - default: //USBExtreme format. - sprintf(partname, "%sul.%08X.%s.%02x", usbPrefix, USBA_crc32(game->name), game->startup, i); - } - + sbCreatePath(game, partname, usbPrefix, "/", i); fd = open(partname, O_RDONLY); if (fd >= 0) { settings->LBAs[i] = fileXioIoctl(fd, USBMASS_IOCTL_GET_LBA, partname); @@ -332,24 +322,14 @@ static void usbLaunchGame(int id, config_set_t *configSet) } //Initialize layer 1 information. - switch (game->format) { - case GAME_FORMAT_ISO: - sprintf(partname, "%s%s/%s%s", usbPrefix, (game->media == SCECdPS2CD) ? "CD" : "DVD", game->name, game->extension); - break; - case GAME_FORMAT_OLD_ISO: - sprintf(partname, "%s%s/%s.%s%s", usbPrefix, (game->media == SCECdPS2CD) ? "CD" : "DVD", game->startup, game->name, game->extension); - break; - default: //USBExtreme format. - sprintf(partname, "%sul.%08X.%s.00", usbPrefix, USBA_crc32(game->name), game->startup); - } - + sbCreatePath(game, partname, usbPrefix, "/", 0); layer1_start = sbGetISO9660MaxLBA(partname); switch (game->format) { case GAME_FORMAT_USBLD: layer1_part = layer1_start / 0x80000; layer1_offset = layer1_start % 0x80000; - sprintf(partname, "%sul.%08X.%s.%02x", usbPrefix, USBA_crc32(game->name), game->startup, layer1_part); + sbCreatePath(game, partname, usbPrefix, "/", layer1_part); break; default: //Raw ISO9660 disc image; one part. layer1_part = 0;