Search
lxdream.org :: lxdream/src/gdrom/gdrom.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.c
changeset 168:203a72138e16
prev167:71c0cc416a64
next237:6f1a429c9d12
author nkeynes
date Mon Jun 26 10:30:42 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Implement multi-format CD image support
Fix CDI support up to (more or less) work
file annotate diff log raw
1.1 --- a/src/gdrom/gdrom.c Mon Jun 19 11:00:42 2006 +0000
1.2 +++ b/src/gdrom/gdrom.c Mon Jun 26 10:30:42 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gdrom.c,v 1.8 2006-06-19 11:00:42 nkeynes Exp $
1.6 + * $Id: gdrom.c,v 1.9 2006-06-26 10:30:42 nkeynes Exp $
1.7 *
1.8 * GD-Rom access functions.
1.9 *
1.10 @@ -17,7 +17,7 @@
1.11 */
1.12
1.13 #include <stdio.h>
1.14 -
1.15 +#include <errno.h>
1.16 #include "gdrom/ide.h"
1.17 #include "gdrom/gdrom.h"
1.18 #include "gdrom/packet.h"
1.19 @@ -26,6 +26,7 @@
1.20 static void gdrom_image_destroy( gdrom_disc_t );
1.21 static gdrom_error_t gdrom_image_read_sectors( gdrom_disc_t, uint32_t, uint32_t, int, char *, uint32_t * );
1.22
1.23 +gdrom_image_class_t gdrom_image_classes[] = { &nrg_image_class, &cdi_image_class, NULL };
1.24
1.25 gdrom_disc_t gdrom_disc = NULL;
1.26
1.27 @@ -34,7 +35,45 @@
1.28
1.29 gdrom_disc_t gdrom_image_open( const gchar *filename )
1.30 {
1.31 - return nrg_image_open( filename );
1.32 + const gchar *ext = strrchr(filename, '.');
1.33 + gdrom_disc_t disc = NULL;
1.34 + FILE *f = fopen(filename, "ro");
1.35 + int i,j;
1.36 + gdrom_image_class_t extclz = NULL;
1.37 +
1.38 + if( f == NULL ) {
1.39 + ERROR("Unable to open file '%s': %s", filename, strerror(errno));
1.40 + return NULL;
1.41 + }
1.42 +
1.43 + /* try extensions */
1.44 + if( ext != NULL ) {
1.45 + ext++; /* Skip the '.' */
1.46 + for( i=0; gdrom_image_classes[i] != NULL; i++ ) {
1.47 + if( strcasecmp( gdrom_image_classes[i]->extension, ext ) == 0 ) {
1.48 + extclz = gdrom_image_classes[i];
1.49 + if( extclz->is_valid_file(f) ) {
1.50 + disc = extclz->open_image_file(filename, f);
1.51 + if( disc != NULL )
1.52 + return disc;
1.53 + }
1.54 + break;
1.55 + }
1.56 + }
1.57 + }
1.58 +
1.59 + /* Okay, fall back to magic */
1.60 + for( i=0; gdrom_image_classes[i] != NULL; i++ ) {
1.61 + if( gdrom_image_classes[i] != extclz &&
1.62 + gdrom_image_classes[i]->is_valid_file(f) ) {
1.63 + disc = gdrom_image_classes[i]->open_image_file(filename, f);
1.64 + if( disc != NULL )
1.65 + return disc;
1.66 + }
1.67 + }
1.68 +
1.69 + fclose(f);
1.70 + return NULL;
1.71 }
1.72
1.73
.