http support for cdi & gdi, updated based gdipsr
- Fix coreio fsize - Fix coreio fopen to seek to 0 - Fix coreio/http to smart-escape urls - For urls that include \ or % in the filenames, you have to pass them escaped - Update gdi parser to use (mostly) streamstream. That code is horrible and should be rewritten - coreio core is hacky and horrible at places as well - Update imgreader to use coreio - Update cdi parser + driver to use coreio
This commit is contained in:
parent
d055dbd7cb
commit
3ca3b1220d
|
@ -2,6 +2,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "deps/coreio/coreio.h"
|
||||||
#include "cdipsr.h"
|
#include "cdipsr.h"
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
|
@ -11,6 +12,10 @@ unsigned long temp_value;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define FILE core_file
|
||||||
|
#define fread(buff,sz,cnt,fc) core_fread(fc,buff,sz*cnt)
|
||||||
|
#define fseek core_fseek
|
||||||
|
#define ftell core_ftell
|
||||||
|
|
||||||
unsigned long ask_type(FILE *fsource, long header_position)
|
unsigned long ask_type(FILE *fsource, long header_position)
|
||||||
{
|
{
|
||||||
|
@ -110,8 +115,7 @@ void CDI_get_tracks (FILE *fsource, image_s *image)
|
||||||
|
|
||||||
void CDI_init (FILE *fsource, image_s *image, char *fsourcename)
|
void CDI_init (FILE *fsource, image_s *image, char *fsourcename)
|
||||||
{
|
{
|
||||||
fseek(fsource, 0L, SEEK_END);
|
image->length = core_fsize(fsource);
|
||||||
image->length = ftell(fsource);
|
|
||||||
|
|
||||||
if (image->length < 8) printf( "Image file is too short");
|
if (image->length < 8) printf( "Image file is too short");
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef __CDI_H__
|
#ifndef __CDI_H__
|
||||||
#define __CDI_H__
|
#define __CDI_H__
|
||||||
|
|
||||||
|
#include "deps/coreio/coreio.h"
|
||||||
|
|
||||||
/* Basic structures */
|
/* Basic structures */
|
||||||
|
|
||||||
|
@ -38,12 +38,11 @@ typedef struct track_s
|
||||||
#define CDI_V3 0x80000005
|
#define CDI_V3 0x80000005
|
||||||
#define CDI_V35 0x80000006
|
#define CDI_V35 0x80000006
|
||||||
|
|
||||||
unsigned long ask_type(FILE *fsource, long header_position);
|
unsigned long ask_type(core_file *fsource, long header_position);
|
||||||
void CDI_init (FILE *fsource, image_s *image, char *fsourcename);
|
void CDI_init(core_file *fsource, image_s *image, char *fsourcename);
|
||||||
void CDI_get_sessions (FILE *fsource, image_s *image);
|
void CDI_get_sessions(core_file *fsource, image_s *image);
|
||||||
void CDI_get_tracks (FILE *fsource, image_s *image);
|
void CDI_get_tracks(core_file *fsource, image_s *image);
|
||||||
void CDI_read_track (FILE *fsource, image_s *image, track_s *track);
|
void CDI_read_track(core_file *fsource, image_s *image, track_s *track);
|
||||||
void CDI_skip_next_session (FILE *fsource, image_s *image);
|
void CDI_skip_next_session(core_file *fsource, image_s *image);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
|
|
||||||
|
@ -22,6 +26,27 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
string url_encode(const string &value) {
|
||||||
|
ostringstream escaped;
|
||||||
|
escaped.fill('0');
|
||||||
|
escaped << hex;
|
||||||
|
|
||||||
|
for (string::const_iterator i = value.begin(), n = value.end(); i != n; ++i) {
|
||||||
|
string::value_type c = (*i);
|
||||||
|
|
||||||
|
// Keep alphanumeric and other accepted characters intact
|
||||||
|
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~' || c == '/' || c =='%' ) {
|
||||||
|
escaped << c;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Any other characters are percent-encoded
|
||||||
|
escaped << '%' << setw(2) << int((unsigned char)c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return escaped.str();
|
||||||
|
}
|
||||||
|
|
||||||
size_t HTTP_GET(string host, int port,string path, size_t offs, size_t len, void* pdata){
|
size_t HTTP_GET(string host, int port,string path, size_t offs, size_t len, void* pdata){
|
||||||
string request;
|
string request;
|
||||||
string response;
|
string response;
|
||||||
|
@ -97,7 +122,7 @@ size_t HTTP_GET(string host, int port,string path, size_t offs, size_t len, void
|
||||||
*/
|
*/
|
||||||
size_t content_length = 0;
|
size_t content_length = 0;
|
||||||
|
|
||||||
size_t rv = content_length;
|
size_t rv = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
|
@ -128,10 +153,10 @@ size_t HTTP_GET(string host, int port,string path, size_t offs, size_t len, void
|
||||||
_data:
|
_data:
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
|
rv = content_length;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
verify(len == content_length);
|
verify(len == content_length); //crash is a bit too harsh here perhaps?
|
||||||
u8* ptr = (u8*)pdata;
|
u8* ptr = (u8*)pdata;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -141,6 +166,8 @@ _data:
|
||||||
ptr += rcv;
|
ptr += rcv;
|
||||||
}
|
}
|
||||||
while (len >0);
|
while (len >0);
|
||||||
|
|
||||||
|
rv = content_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
_cleanup:
|
_cleanup:
|
||||||
|
@ -180,7 +207,7 @@ core_file* core_fopen(const char* filename)
|
||||||
rv->host = p.substr(7,p.npos);
|
rv->host = p.substr(7,p.npos);
|
||||||
rv->host = rv->host.substr(0, rv->host.find_first_of("/"));
|
rv->host = rv->host.substr(0, rv->host.find_first_of("/"));
|
||||||
|
|
||||||
rv->path = p.substr(p.find("/", 7), p.npos);
|
rv->path = url_encode(p.substr(p.find("/", 7), p.npos));
|
||||||
|
|
||||||
rv->port = 80;
|
rv->port = 80;
|
||||||
size_t pos = rv->host.find_first_of(":");
|
size_t pos = rv->host.find_first_of(":");
|
||||||
|
@ -198,6 +225,7 @@ core_file* core_fopen(const char* filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_fseek((core_file*)rv, 0, SEEK_SET);
|
||||||
return (core_file*)rv;
|
return (core_file*)rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,6 +245,10 @@ size_t core_fseek(core_file* fc, size_t offs, size_t origin) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t core_ftell(core_file* fc) {
|
||||||
|
CORE_FILE* f = (CORE_FILE*)fc;
|
||||||
|
return f->seek_ptr;
|
||||||
|
}
|
||||||
int core_fread(core_file* fc, void* buff, size_t len)
|
int core_fread(core_file* fc, void* buff, size_t len)
|
||||||
{
|
{
|
||||||
CORE_FILE* f = (CORE_FILE*)fc;
|
CORE_FILE* f = (CORE_FILE*)fc;
|
||||||
|
|
|
@ -10,3 +10,4 @@ size_t core_fseek(core_file* fc, size_t offs, size_t origin);
|
||||||
int core_fread(core_file* fc, void* buff, size_t len);
|
int core_fread(core_file* fc, void* buff, size_t len);
|
||||||
int core_fclose(core_file* fc);
|
int core_fclose(core_file* fc);
|
||||||
size_t core_fsize(core_file* fc);
|
size_t core_fsize(core_file* fc);
|
||||||
|
size_t core_ftell(core_file* fc);
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
Disc* cdi_parse(const wchar* file)
|
Disc* cdi_parse(const wchar* file)
|
||||||
{
|
{
|
||||||
FILE* fsource=fopen(file,"rb");
|
core_file* fsource=core_fopen(file);
|
||||||
|
|
||||||
if (!fsource)
|
if (!fsource)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -34,7 +34,7 @@ Disc* cdi_parse(const wchar* file)
|
||||||
|
|
||||||
CDI_get_tracks (fsource, &image);
|
CDI_get_tracks (fsource, &image);
|
||||||
|
|
||||||
image.header_position = ftell(fsource);
|
image.header_position = core_ftell(fsource);
|
||||||
|
|
||||||
printf("\nSession %d has %d track(s)\n",image.global_current_session,image.tracks);
|
printf("\nSession %d has %d track(s)\n",image.global_current_session,image.tracks);
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ Disc* cdi_parse(const wchar* file)
|
||||||
|
|
||||||
CDI_read_track (fsource, &image, &track);
|
CDI_read_track (fsource, &image, &track);
|
||||||
|
|
||||||
image.header_position = ftell(fsource);
|
image.header_position = core_ftell(fsource);
|
||||||
|
|
||||||
// Show info
|
// Show info
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ Disc* cdi_parse(const wchar* file)
|
||||||
t.CTRL=track.mode==0?0:4;
|
t.CTRL=track.mode==0?0:4;
|
||||||
t.StartFAD=track.start_lba+track.pregap_length;
|
t.StartFAD=track.start_lba+track.pregap_length;
|
||||||
t.EndFAD=t.StartFAD+track.length-1;
|
t.EndFAD=t.StartFAD+track.length-1;
|
||||||
t.file = new RawTrackFile(fopen(file,"rb"),track.position + track.pregap_length * track.sector_size,t.StartFAD,track.sector_size);
|
t.file = new RawTrackFile(core_fopen(file),track.position + track.pregap_length * track.sector_size,t.StartFAD,track.sector_size);
|
||||||
|
|
||||||
rv->tracks.push_back(t);
|
rv->tracks.push_back(t);
|
||||||
|
|
||||||
|
@ -115,21 +115,21 @@ Disc* cdi_parse(const wchar* file)
|
||||||
if (track.total_length < track.length + track.pregap_length)
|
if (track.total_length < track.length + track.pregap_length)
|
||||||
{
|
{
|
||||||
printf("\nThis track seems truncated. Skipping...\n");
|
printf("\nThis track seems truncated. Skipping...\n");
|
||||||
fseek(fsource, track.position, SEEK_SET);
|
core_fseek(fsource, track.position, SEEK_SET);
|
||||||
fseek(fsource, track.total_length, SEEK_CUR);
|
core_fseek(fsource, track.total_length, SEEK_CUR);
|
||||||
track.position = ftell(fsource);
|
track.position = core_ftell(fsource);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
printf("Track position: %d\n",track.position + track.pregap_length * track.sector_size);
|
printf("Track position: %d\n",track.position + track.pregap_length * track.sector_size);
|
||||||
fseek(fsource, track.position, SEEK_SET);
|
core_fseek(fsource, track.position, SEEK_SET);
|
||||||
// fseek(fsource, track->pregap_length * track->sector_size, SEEK_CUR);
|
// fseek(fsource, track->pregap_length * track->sector_size, SEEK_CUR);
|
||||||
// fseek(fsource, track->length * track->sector_size, SEEK_CUR);
|
// fseek(fsource, track->length * track->sector_size, SEEK_CUR);
|
||||||
fseek(fsource, track.total_length * track.sector_size, SEEK_CUR);
|
core_fseek(fsource, track.total_length * track.sector_size, SEEK_CUR);
|
||||||
|
|
||||||
//savetrack(fsource, &image, &track, &opts, &flags);
|
//savetrack(fsource, &image, &track, &opts, &flags);
|
||||||
track.position = ftell(fsource);
|
track.position = core_ftell(fsource);
|
||||||
|
|
||||||
rv->EndFAD=track.start_lba +track.total_length;
|
rv->EndFAD=track.start_lba +track.total_length;
|
||||||
// Generate cuesheet entries
|
// Generate cuesheet entries
|
||||||
|
@ -140,7 +140,7 @@ Disc* cdi_parse(const wchar* file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(fsource, image.header_position, SEEK_SET);
|
core_fseek(fsource, image.header_position, SEEK_SET);
|
||||||
|
|
||||||
|
|
||||||
// Close loops
|
// Close loops
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#include "deps/coreio/coreio.h"
|
||||||
|
|
||||||
extern u32 NullDriveDiscType;
|
extern u32 NullDriveDiscType;
|
||||||
struct TocTrackInfo
|
struct TocTrackInfo
|
||||||
{
|
{
|
||||||
|
@ -261,12 +263,12 @@ Disc* OpenDisc(const wchar* fn);
|
||||||
|
|
||||||
struct RawTrackFile : TrackFile
|
struct RawTrackFile : TrackFile
|
||||||
{
|
{
|
||||||
FILE* file;
|
core_file* file;
|
||||||
s32 offset;
|
s32 offset;
|
||||||
u32 fmt;
|
u32 fmt;
|
||||||
bool cleanup;
|
bool cleanup;
|
||||||
|
|
||||||
RawTrackFile(FILE* file,u32 file_offs,u32 first_fad,u32 secfmt)
|
RawTrackFile(core_file* file,u32 file_offs,u32 first_fad,u32 secfmt)
|
||||||
{
|
{
|
||||||
verify(file!=0);
|
verify(file!=0);
|
||||||
this->file=file;
|
this->file=file;
|
||||||
|
@ -289,13 +291,13 @@ struct RawTrackFile : TrackFile
|
||||||
verify(false);
|
verify(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek(file,offset+FAD*fmt,SEEK_SET);
|
core_fseek(file,offset+FAD*fmt,SEEK_SET);
|
||||||
fread(dst,1,fmt,file);
|
core_fread(file, dst, fmt);
|
||||||
}
|
}
|
||||||
virtual ~RawTrackFile()
|
virtual ~RawTrackFile()
|
||||||
{
|
{
|
||||||
if (cleanup && file)
|
if (cleanup && file)
|
||||||
fclose(file);
|
core_fclose(file);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
Disc* load_gdi(const char* file)
|
Disc* load_gdi(const char* file)
|
||||||
{
|
{
|
||||||
|
@ -8,13 +9,28 @@ Disc* load_gdi(const char* file)
|
||||||
|
|
||||||
//memset(&gdi_toc,0xFFFFFFFF,sizeof(gdi_toc));
|
//memset(&gdi_toc,0xFFFFFFFF,sizeof(gdi_toc));
|
||||||
//memset(&gdi_ses,0xFFFFFFFF,sizeof(gdi_ses));
|
//memset(&gdi_ses,0xFFFFFFFF,sizeof(gdi_ses));
|
||||||
FILE* t=fopen(file,"rb");
|
core_file* t=core_fopen(file);
|
||||||
if (!t)
|
if (!t)
|
||||||
return 0;
|
return 0;
|
||||||
fscanf(t,"%d\r\n",&iso_tc);
|
|
||||||
|
size_t gdi_len = core_fsize(t);
|
||||||
|
|
||||||
|
char gdi_data[8193] = { 0 };
|
||||||
|
|
||||||
|
if (gdi_len >= sizeof(gdi_data))
|
||||||
|
{
|
||||||
|
core_fclose(t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
core_fread(t, gdi_data, gdi_len);
|
||||||
|
core_fclose(t);
|
||||||
|
|
||||||
|
istringstream gdi(gdi_data);
|
||||||
|
|
||||||
|
gdi >> iso_tc;
|
||||||
printf("\nGDI : %d tracks\n",iso_tc);
|
printf("\nGDI : %d tracks\n",iso_tc);
|
||||||
|
|
||||||
char temp[512];
|
|
||||||
char path[512];
|
char path[512];
|
||||||
strcpy(path,file);
|
strcpy(path,file);
|
||||||
size_t len=strlen(file);
|
size_t len=strlen(file);
|
||||||
|
@ -30,30 +46,38 @@ Disc* load_gdi(const char* file)
|
||||||
s32 OFFSET=0;
|
s32 OFFSET=0;
|
||||||
for (u32 i=0;i<iso_tc;i++)
|
for (u32 i=0;i<iso_tc;i++)
|
||||||
{
|
{
|
||||||
|
string track_filename;
|
||||||
|
|
||||||
//TRACK FADS CTRL SSIZE file OFFSET
|
//TRACK FADS CTRL SSIZE file OFFSET
|
||||||
fscanf(t,"%d %d %d %d",&TRACK,&FADS,&CTRL,&SSIZE);
|
gdi >> TRACK;
|
||||||
//%s %d\r\n,temp,&OFFSET);
|
gdi >> FADS;
|
||||||
//disc->tracks.push_back(
|
gdi >> CTRL;
|
||||||
while(isspace(fgetc(t))) ;
|
gdi >> SSIZE;
|
||||||
fseek(t,-1,SEEK_CUR);
|
|
||||||
if (fgetc(t)=='"')
|
char last;
|
||||||
|
|
||||||
|
do {
|
||||||
|
gdi >> last;
|
||||||
|
} while (isspace(last));
|
||||||
|
|
||||||
|
if (last == '"')
|
||||||
{
|
{
|
||||||
char c;
|
for(;;) {
|
||||||
int i=0;
|
gdi >> last;
|
||||||
while((c=fgetc(t))!='"')
|
if (last == '"')
|
||||||
temp[i++]=c;
|
break;
|
||||||
temp[i]=0;
|
track_filename += last;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fseek(t,-1,SEEK_CUR);
|
gdi >> track_filename;
|
||||||
fscanf(t,"%s",temp);
|
track_filename = last + track_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
fscanf(t,"%d\r\n",&OFFSET);
|
gdi >> OFFSET;
|
||||||
printf("file[%d] \"%s\": FAD:%d, CTRL:%d, SSIZE:%d, OFFSET:%d\n",TRACK,temp,FADS,CTRL,SSIZE,OFFSET);
|
|
||||||
|
|
||||||
|
|
||||||
|
printf("file[%d] \"%s\": FAD:%d, CTRL:%d, SSIZE:%d, OFFSET:%d\n", TRACK, track_filename.c_str(), FADS, CTRL, SSIZE, OFFSET);
|
||||||
|
|
||||||
Track t;
|
Track t;
|
||||||
t.ADDR=0;
|
t.ADDR=0;
|
||||||
|
@ -63,8 +87,8 @@ Disc* load_gdi(const char* file)
|
||||||
|
|
||||||
if (SSIZE!=0)
|
if (SSIZE!=0)
|
||||||
{
|
{
|
||||||
strcpy(pathptr,temp);
|
strcpy(pathptr, track_filename.c_str());
|
||||||
t.file = new RawTrackFile(fopen(path,"rb"),OFFSET,t.StartFAD,SSIZE);
|
t.file = new RawTrackFile(core_fopen(path),OFFSET,t.StartFAD,SSIZE);
|
||||||
}
|
}
|
||||||
disc->tracks.push_back(t);
|
disc->tracks.push_back(t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue