Skip to content

Commit

Permalink
webMAN MOD 1.47.47a
Browse files Browse the repository at this point in the history
- Fixed segfault scanning large number of ROMS
- Added sanity checks to content scanning process and covers detection
- Combo R2+O now can be used to cancel the scanning process
  • Loading branch information
aldostools committed Oct 7, 2024
1 parent 9ba6688 commit 5a0a042
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 44 deletions.
Binary file modified _Projects_/updater/pkgfiles/USRDIR/webftp_server_full.sprx
Binary file not shown.
Binary file modified _Projects_/updater/pkgfiles/USRDIR/webftp_server_lite.sprx
Binary file not shown.
Binary file modified _Projects_/updater/pkgfiles/USRDIR/webftp_server_noncobra.sprx
Binary file not shown.
Binary file not shown.
Binary file modified _Projects_/updater/update/dev_hdd0/plugins/webftp_server.sprx
Binary file not shown.
Binary file modified _Projects_/updater/update/dev_hdd0/plugins/webftp_server_lite.sprx
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions include/init/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ static char *to_upper(char *text)
return switch_case(text, 'a', 'z');
}

#ifdef COBRA_ONLY
static char *to_lower(char *text)
{
return switch_case(text, 'A', 'Z');
}
#endif

static char *remove_brackets(char *title)
{
Expand Down
2 changes: 2 additions & 0 deletions include/poll/combos.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,8 @@
char path[STD_PATH_LEN];
set_param_sfo(path);

refreshing_xml = 0; // cancel content scanning

if(file_exists(path) || IS_INGAME)
{
char title[128], title_id[12], app_ver[8];
Expand Down
8 changes: 5 additions & 3 deletions include/scan/games_covers.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,14 +743,16 @@ static int get_name_iso_or_sfo(char *param_sfo, char *title_id, char *icon, cons
// use CD sector size
if(memcmp(buf + 1, "CD001", 5))
{
read_file(iso_file, buf, 0x200, 0x9318);
sector = *((u32*)(buf + 0xA2)) * 0x930 + 0x18;
if(read_file(iso_file, buf, 0x200, 0x9318) == 0x200)
sector = *((u32*)(buf + 0xA2)) * 0x930 + 0x18;
else
return FAILED;
}
else
sector = *((u32*)(buf + 0xA2)) * 0x800;

// read root directory
read_file(iso_file, buf, 0x800, sector);
if(read_file(iso_file, buf, 0x800, sector) != 0x800) return FAILED;

// find executable
for(u16 i = 0; i < 0x7D0; i += buf[i])
Expand Down
89 changes: 49 additions & 40 deletions include/scan/games_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,14 @@ static void build_roms_xml(char *sysmem_buf, char *templn, char *tempstr, u16 ro
save_file(HTML_BASE_PATH "/ROMS.xml", myxml.str, myxml.size);

// patch mygames.xml
read_file(MY_GAMES_XML, tempstr, KB, 200);
char *pos = strstr(tempstr, " ROM");
if(pos)
if(read_file(MY_GAMES_XML, tempstr, KB, 200) == KB)
{
sprintf(templn, "%'8i", t_count); memcpy(pos, templn, 8);
patch_file(MY_GAMES_XML, tempstr, 200, KB);
char *pos = strstr(tempstr, " ROM");
if(pos)
{
sprintf(templn, "%'8i", t_count); memcpy(pos, templn, 8);
patch_file(MY_GAMES_XML, tempstr, 200, KB);
}
}
}
#endif
Expand Down Expand Up @@ -709,22 +711,23 @@ static bool scan_mygames_xml(u64 conn_s_p)
sys_addr_t sysmem_psp = sysmem + (BUFFER_SIZE) + (BUFFER_SIZE_PSX);
sys_addr_t sysmem_ps2 = sysmem + (BUFFER_SIZE) + (BUFFER_SIZE_PSX) + (BUFFER_SIZE_PSP);
sys_addr_t sysmem_dvd = sysmem + (BUFFER_SIZE) + (BUFFER_SIZE_PSX) + (BUFFER_SIZE_PSP) + (BUFFER_SIZE_PS2);
sys_addr_t sysmem_ngp = sysmem + BUFFER_SIZE_ALL - _128KB_;

char *ignore_files = NULL;
if(webman_config->ignore && file_exists(WM_IGNORE_FILES))
{
size_t size = file_size(WM_IGNORE_FILES) + 1;
size_t size = file_size(WM_IGNORE_FILES);
if(size < _32KB_)
{
ignore_files = malloc(size);
if(ignore_files) read_file(WM_IGNORE_FILES, ignore_files, size, 0);
ignore_files = malloc(size + 1);
if(ignore_files) {read_file(WM_IGNORE_FILES, ignore_files, size, 0); ignore_files[size] = '\0';}
}
}

#if defined(LAUNCHPAD) || defined(MOUNT_ROMS)
char *sysmem_buf = (char*)sysmem;
#endif
char *sysmem_xml = (char*)sysmem + (BUFFER_SIZE) - 4300;
char *sysmem_xml = (char*)sysmem + (BUFFER_SIZE - 4300);

cellFsMkdir(XML_HOST_PATH, DMODE);
cellFsMkdir(HTML_BASE_PATH, DMODE);
Expand Down Expand Up @@ -769,16 +772,17 @@ static bool scan_mygames_xml(u64 conn_s_p)
#ifdef MOUNT_ROMS

#define ROM_PATHS 99
char cur_roms_path[16];
char cur_roms_path[16]; *cur_roms_path = 0;
const char *roms_path[ROM_PATHS] = { "2048", "CAP32", "MAME", "MAME2000", "MAME2003", "MIDWAY", "MAMEPLUS", "FBA", "FBA2012", "FBNEO", "ATARI", "ATARI2600", "STELLA", "ATARI800", "ATARI5200", "ATARI7800", "JAGUAR", "LYNX", "HANDY", "HATARI", "CANNONBALL", "NXENGINE", "COLECO", "AMIGA", "CD32", "VICE", "X64", "X64SC", "X64DTV", "XSCPU64", "X128", "XCBM2", "XCMB25X0", "XPET", "XPLUS4", "XVIC", "DOSBOX", "GME", "GW", "DOOM", "QUAKE", "JAVAME", "JUMP", "O2EM", "INTV", "MSX", "FMSX", "MSX2", "BMSX", "NEOCD", "NEO", "NEOGEO", "PCE", "PCECD", "PCFX", "SGX", "NGP", "NGPC", "NES", "FCEUMM", "NESTOPIA", "QNES", "GB", "GBC", "GAMBATTE", "TGBDUAL", "GBA", "VBA", "MGBA", "VBOY", "PALM", "PSXISO", "PS2ISO", "PS3ISO", "PSPISO", "POKEMINI", "SCUMMVM", "GENESIS", "GEN", "SEGACD", "MEGAD", "MEGADRIVE", "GG", "GEARBOY", "MASTER", "PICO", "SG1000", "FUSE", "ZX81", "SNES", "MSNES", "SNES9X", "SNES9X2005", "SNES9X2010", "SNES9X_NEXT", "THEODORE", "VECX", "WSWAM", "WSWAMC" };
u16 roms_count[ROM_PATHS]; u32 count_roms = 0;
u16 roms_count[ROM_PATHS]; u32 count_roms = 0; memset(roms_count, 0, ROM_PATHS);

// remove paths not listed in roms_paths.txt
if(file_exists(WM_ROMS_PATHS))
u8 len = read_file(WM_ROMS_PATHS, templn, 640, 0);
if(len)
{
read_file(WM_ROMS_PATHS, templn, 640, 0); templn[640] = '\0'; to_upper(templn);
templn[len] = '\0'; to_upper(templn);
for(u8 i = 0; i < ROM_PATHS; i++)
if(!strstr(templn, roms_path[i])) roms_path[i] = NULL;
if(roms_path[i] && !strstr(templn, roms_path[i])) roms_path[i] = NULL;
}
#endif
u8 roms_index = 0;
Expand All @@ -800,7 +804,7 @@ static bool scan_mygames_xml(u64 conn_s_p)
t_string myxml_psp; _alloc(&myxml_psp, (char*)sysmem_psp);
t_string myxml_dvd; _alloc(&myxml_dvd, (char*)sysmem_dvd);
t_string myxml ; _alloc(&myxml, (char*)sysmem_xml);
t_string myxml_ngp; _alloc(&myxml_ngp, (char*)sysmem_dvd);
t_string myxml_ngp; _alloc(&myxml_ngp, (char*)sysmem_ngp);

// --- build group headers ---
char *tempstr, *folder_name; tempstr = sysmem_xml; folder_name = sysmem_xml + (3*KB);
Expand Down Expand Up @@ -872,6 +876,9 @@ static bool scan_mygames_xml(u64 conn_s_p)
#endif
#endif

#ifdef MOUNT_ROMS
if(!scanning_roms || roms_path[roms_index])
#endif
for(u8 f0 = 0; f0 < MAX_DRIVES; f0++) // drives: 0="/dev_hdd0", 1="/dev_usb000", 2="/dev_usb001", 3="/dev_usb002", 4="/dev_usb003", 5="/dev_usb006", 6="/dev_usb007", 7="/net0", 8="/net1", 9="/net2", 10="/net3", 11="/net4", 12="/ext", 13="/dev_sd", 14="/dev_ms", 15="/dev_cf"
{
if(!refreshing_xml) break;
Expand Down Expand Up @@ -907,6 +914,8 @@ static bool scan_mygames_xml(u64 conn_s_p)
{
if(!refreshing_xml) break;

if(key >= max_xmb_items) break;

_f1_ = f1; // _f1_ changes to id_PS2ISO for CD/DVD folders (9="CD" / 10="DVD")

if(scanning_roms)
Expand All @@ -915,8 +924,6 @@ static bool scan_mygames_xml(u64 conn_s_p)
}
else
{
if(key >= max_xmb_items) break;

#ifndef COBRA_ONLY
if(IS_ISO_FOLDER && !(IS_PS2ISO)) continue; // 0="GAMES", 1="GAMEZ", 5="PS2ISO", 10="video"
#endif
Expand Down Expand Up @@ -950,18 +957,20 @@ static bool scan_mygames_xml(u64 conn_s_p)
subfolder = 0; if(all_profiles) uprofile = 1; else uprofile = profile;
read_folder_xml:
//
if(!refreshing_xml) break;
if(!refreshing_xml || key >= max_xmb_items) break;
#ifdef MOUNT_ROMS
if(scanning_roms)
{
if(!roms_path[roms_index]) continue;
//if(!roms_path[roms_index]) break;

if(is_net)
sprintf(param, "%s/ROMS%s/%s", "", SUFIX(uprofile), roms_path[roms_index]);
else if(IS_NTFS)
sprintf(param, "%s/USRDIR/%s%s", RETROARCH_DIR, cores_roms, roms_path[roms_index]);
else
sprintf(param, "%s/ROMS%s/%s", drives[f0], SUFIX(uprofile), roms_path[roms_index]);

show_progress(param, OV_SCAN);
}
else
#endif
Expand Down Expand Up @@ -991,19 +1000,19 @@ static bool scan_mygames_xml(u64 conn_s_p)
#ifdef MOUNT_ROMS
if(isDir(param) == false)
{
if(f1 != id_ROMS || !IS_HDD0 || !roms_path[roms_index]) goto continue_reading_folder_xml; //continue;
if(f1 != id_ROMS || !IS_HDD0 || !cur_roms_path[0]) goto continue_reading_folder_xml; //continue;

sprintf(param, "%s/ROMS%s/%s", drives[f0], SUFIX(uprofile), cur_roms_path); // try folder name in lower case (e.g. /ROMS/snes)
if(isDir(param) == false)
{
strcpy(tempstr, cur_roms_path); *tempstr ^= 0x20; // capitalize first letter of folder name (e.g. /ROMS/Snes)
sprintf(tempstr, "%s", cur_roms_path); *tempstr ^= 0x20; // capitalize first letter of folder name (e.g. /ROMS/Snes)

sprintf(param, "%s/ROMS%s/%s", drives[f0], SUFIX(uprofile), tempstr);
if(isDir(param) == false) goto continue_reading_folder_xml; //continue;
if(isDir(param) == false) continue;
}
}
#endif

#endif
if(!is_net && cellFsOpendir(param, &fd) != CELL_FS_SUCCEEDED) goto continue_reading_folder_xml; //continue;

plen = strlen(param);
Expand Down Expand Up @@ -1063,7 +1072,7 @@ static bool scan_mygames_xml(u64 conn_s_p)

//////////////////////////////
subfolder = 0;
if(IS_ISO_FOLDER || IS_VIDEO_FOLDER)
if((IS_ISO_FOLDER || IS_VIDEO_FOLDER) && !scanning_roms)
{
sprintf(subpath, "%s/%s", param, entry.entry_name.d_name);
if(isDir(subpath) && cellFsOpendir(subpath, &fd2) == CELL_FS_SUCCEEDED)
Expand Down Expand Up @@ -1229,7 +1238,7 @@ static bool scan_mygames_xml(u64 conn_s_p)
}
//
continue_reading_folder_xml:
if(scanning_roms || (f1 < id_ISO && !IS_NTFS))
if(IS_ROMS_FOLDER || (f1 < id_ISO && !IS_NTFS))
{
if(uprofile > 0) {subfolder = 0; if(all_profiles && (uprofile < 4)) ++uprofile; else uprofile = 0; goto read_folder_xml;}
if(is_net && BETWEEN(id_PS3ISO, f1, id_PSPISO) && !scanning_roms)
Expand Down Expand Up @@ -1259,7 +1268,7 @@ static bool scan_mygames_xml(u64 conn_s_p)
#endif
}
else
_alloc(&myxml_ngp, (char*)sysmem_dvd);
_alloc(&myxml_ngp, (char*)sysmem_ngp);

led(YELLOW, OFF);
led(GREEN, ON);
Expand Down Expand Up @@ -1312,36 +1321,36 @@ static bool scan_mygames_xml(u64 conn_s_p)
// --- add sorted items to xml
if( webman_config->nogrp || scanning_roms)
{
u32 max_size = (BUFFER_SIZE - 1000);
u32 max_size = (BUFFER_SIZE - 4300);

for(u16 a = 0; a < key; a++)
for(u16 len, a = 0; a < key; a++)
{
if(myxml_ngp.size >= max_size) break;
sprintf(templn, ADD_XMB_ITEM("%s"), skey[a].value + XML_KEY_LEN, skey[a].value + XML_KEY_LEN);
_concat2(&myxml_ngp, XML_ITEM, templn);
len = sprintf(templn, "%s" ADD_XMB_ITEM("%s"), XML_ITEM, skey[a].value + XML_KEY_LEN, skey[a].value + XML_KEY_LEN);
if(myxml_ngp.size + len >= max_size) break;
myxml_ngp.size += sprintf(myxml_ngp.str + myxml_ngp.size, "%s", templn);
}
}
else
{
u32 max_size = (BUFFER_SIZE - 5000);

for(u16 a = 0; a < key; a++)
for(u16 len, a = 0; a < key; a++)
{
sprintf(templn, "%s" ADD_XMB_ITEM("%s"), XML_ITEM, skey[a].value + XML_KEY_LEN, skey[a].value + XML_KEY_LEN);
if(*skey[a].value == PS3_&& myxml_ps3.size < max_size)
len = sprintf(templn, "%s" ADD_XMB_ITEM("%s"), XML_ITEM, skey[a].value + XML_KEY_LEN, skey[a].value + XML_KEY_LEN);
if(*skey[a].value == PS3_&& ((myxml_ps3.size + len) < max_size))
_concat(&myxml_ps3, templn);
else
if(*skey[a].value == PS2 && myxml_ps2.size < (BUFFER_SIZE_PS2 - 128))
if(*skey[a].value == PS2 && ((myxml_ps2.size + len) < (BUFFER_SIZE_PS2 - 128)))
_concat(&myxml_ps2, templn);
#ifdef COBRA_ONLY
else
if(*skey[a].value == PS1 && myxml_psx.size < (BUFFER_SIZE_PSX - 128))
if(*skey[a].value == PS1 && ((myxml_psx.size + len) < (BUFFER_SIZE_PSX - 128)))
_concat(&myxml_psx, templn);
else
if(*skey[a].value == PSP && myxml_psp.size < (BUFFER_SIZE_PSP - 128))
if(*skey[a].value == PSP && ((myxml_psp.size + len) < (BUFFER_SIZE_PSP - 128)))
_concat(&myxml_psp, templn);
else
if(*skey[a].value == BLU && myxml_dvd.size < (BUFFER_SIZE_DVD - 1200))
if(*skey[a].value == BLU && ((myxml_dvd.size + len) < (BUFFER_SIZE_DVD - 1200)))
_concat(&myxml_dvd, templn);
#endif
}
Expand Down Expand Up @@ -1530,7 +1539,7 @@ static bool scan_mygames_xml(u64 conn_s_p)
if(scanning_roms)
{
skip_rom_path:
roms_count[roms_index] = key, count_roms += key;
roms_count[roms_index] = key, count_roms += key; *cur_roms_path = key = 0;
roms_index++;
}
else
Expand All @@ -1544,7 +1553,7 @@ static bool scan_mygames_xml(u64 conn_s_p)
if(!roms_path[roms_index])
goto skip_rom_path; // skip roms path if not listed in roms_paths.txt

strcpy(cur_roms_path, roms_path[roms_index]); to_lower(cur_roms_path);
sprintf(cur_roms_path, "%s", roms_path[roms_index]); to_lower(cur_roms_path);
goto scan_roms; // loop scanning_roms
}
scanning_roms = false;
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ SYS_MODULE_STOP(wwwd_stop);
SYS_MODULE_EXIT(wwwd_stop);

#define WM_APPNAME "webMAN"
#define WM_VERSION "1.47.47 MOD"
#define WM_VERSION "1.47.47a MOD"
#define WM_APP_VERSION WM_APPNAME " " WM_VERSION
#define WEBMAN_MOD WM_APPNAME " MOD"

Expand Down

0 comments on commit 5a0a042

Please sign in to comment.