X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fcd%2Fcd_file.c;h=4e2446c479527008e224fc373874471595167675;hb=f8675e282e7aa72bc6ab0edbb1dada4395d1c44c;hp=f5d8744c314ea5d1c2a91a0a0dd962af412aaa98;hpb=1cfc5cc4ce06642b9bc45ca3b9d32793718e9455;p=picodrive.git diff --git a/pico/cd/cd_file.c b/pico/cd/cd_file.c index f5d8744..4e2446c 100644 --- a/pico/cd/cd_file.c +++ b/pico/cd/cd_file.c @@ -13,6 +13,16 @@ //#define cdprintf(f,...) printf(f "\n",##__VA_ARGS__) // tmp +static void to_upper(char *d, const char *s) +{ + for (; *s != 0; d++, s++) { + if ('a' <= *s && *s <= 'z') + *d = *s - 'a' + 'A'; + else + *d = *s; + } +} + static int audio_track_mp3(const char *fname, int index) { _scd_track *Tracks = Pico_mcd->TOC.Tracks; @@ -27,7 +37,7 @@ static int audio_track_mp3(const char *fname, int index) fs = ftell(tmp_file); // used to calculate length fseek(tmp_file, 0, SEEK_SET); -#if DONT_OPEN_MANY_FILES +#ifdef _PSP_FW_VERSION // some systems (like PSP) can't have many open files at a time, // so we work with their names instead. fclose(tmp_file); @@ -38,10 +48,10 @@ static int audio_track_mp3(const char *fname, int index) if (ret != 0 || Tracks[index].KBtps <= 0) { elprintf(EL_STATUS, "track %2i: mp3 bitrate %i", index+1, Tracks[index].KBtps); -#if !DONT_OPEN_MANY_FILES - fclose(tmp_file); -#else +#ifdef _PSP_FW_VERSION free(tmp_file); +#else + fclose(tmp_file); #endif return -1; } @@ -62,18 +72,16 @@ PICO_INTERNAL int Load_CD_Image(const char *cd_img_name, cd_img_type type) { int i, j, num_track, Cur_LBA, index, ret, iso_name_len, missed, cd_img_sectors; _scd_track *Tracks = Pico_mcd->TOC.Tracks; - char tmp_name[1024], tmp_ext[10]; + char tmp_name[1024], tmp_ext[10], tmp_ext_u[10]; cue_data_t *cue_data = NULL; pm_file *pmf; - static char *exts[] = { + static const char *exts[] = { "%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3", "%d.mp3", " %d.mp3", "-%d.mp3", "_%d.mp3", " - %d.mp3", -#if CASE_SENSITIVE_FS - "%02d.MP3", " %02d.MP3", "-%02d.MP3", "_%02d.MP3", " - %02d.MP3", -#endif }; - if (PicoCDLoadProgressCB != NULL) PicoCDLoadProgressCB(1); + if (PicoCDLoadProgressCB != NULL) + PicoCDLoadProgressCB(cd_img_name, 1); Unload_ISO(); @@ -118,7 +126,8 @@ PICO_INTERNAL int Load_CD_Image(const char *cd_img_name, cd_img_type type) i = 100 / cue_data->track_count+1; for (num_track = 2; num_track <= cue_data->track_count; num_track++) { - if (PicoCDLoadProgressCB != NULL) PicoCDLoadProgressCB(i * num_track); + if (PicoCDLoadProgressCB != NULL) + PicoCDLoadProgressCB(cd_img_name, i * num_track); index = num_track - 1; Cur_LBA += cue_data->tracks[num_track].pregap; if (cue_data->tracks[num_track].type == CT_MP3) { @@ -179,24 +188,38 @@ PICO_INTERNAL int Load_CD_Image(const char *cd_img_name, cd_img_type type) for (num_track = 2, i = 0, missed = 0; i < 100 && missed < 4; i++) { - if (PicoCDLoadProgressCB != NULL && i > 1) PicoCDLoadProgressCB(i + (100-i)*missed/4); + if (PicoCDLoadProgressCB != NULL && i > 1) + PicoCDLoadProgressCB(cd_img_name, i + (100-i)*missed/4); for (j = 0; j < sizeof(exts)/sizeof(char *); j++) { int ext_len; + char *p; + + index = num_track - 1; + sprintf(tmp_ext, exts[j], i); ext_len = strlen(tmp_ext); + to_upper(tmp_ext_u, tmp_ext); memcpy(tmp_name, cd_img_name, iso_name_len + 1); - tmp_name[iso_name_len - 4] = 0; - strcat(tmp_name, tmp_ext); + p = tmp_name + iso_name_len - 4; - index = num_track - 1; + strcpy(p, tmp_ext); ret = audio_track_mp3(tmp_name, index); + if (ret != 0) { + strcpy(p, tmp_ext_u); + ret = audio_track_mp3(tmp_name, index); + } + if (ret != 0 && i > 1 && iso_name_len > ext_len) { - tmp_name[iso_name_len - ext_len] = 0; - strcat(tmp_name, tmp_ext); + p = tmp_name + iso_name_len - ext_len; + strcpy(p, tmp_ext); ret = audio_track_mp3(tmp_name, index); + if (ret != 0) { + strcpy(p, tmp_ext_u); + ret = audio_track_mp3(tmp_name, index); + } } if (ret == 0) @@ -225,7 +248,8 @@ finish: elprintf(EL_STATUS, "End CD - %02d:%02d:%02d\n", Tracks[index].MSF.M, Tracks[index].MSF.S, Tracks[index].MSF.F); - if (PicoCDLoadProgressCB != NULL) PicoCDLoadProgressCB(100); + if (PicoCDLoadProgressCB != NULL) + PicoCDLoadProgressCB(cd_img_name, 100); return 0; } @@ -244,7 +268,7 @@ PICO_INTERNAL void Unload_ISO(void) if (Pico_mcd->TOC.Tracks[i].F != NULL) { if (Pico_mcd->TOC.Tracks[i].ftype == TYPE_MP3) -#if DONT_OPEN_MANY_FILES +#ifdef _PSP_FW_VERSION free(Pico_mcd->TOC.Tracks[i].F); #else fclose(Pico_mcd->TOC.Tracks[i].F);