diff --git a/Plugins/Dumb/DumbDecoder.h b/Plugins/Dumb/DumbDecoder.h index 032b3b5ce..4d509fb0a 100755 --- a/Plugins/Dumb/DumbDecoder.h +++ b/Plugins/Dumb/DumbDecoder.h @@ -16,6 +16,8 @@ #import "Plugin.h" +extern DUMBFILE_SYSTEM dfs; + @interface DumbDecoder : NSObject { DUH *duh; DUH_SIGRENDERER *dsr; diff --git a/Plugins/Dumb/DumbDecoder.m b/Plugins/Dumb/DumbDecoder.m index 2579c9c0a..a841b32bc 100755 --- a/Plugins/Dumb/DumbDecoder.m +++ b/Plugins/Dumb/DumbDecoder.m @@ -12,9 +12,9 @@ int skipCallback(void *f, long n) { - DumbDecoder *decoder = (DumbDecoder *)f; + id source = (id)f; - if (![[decoder source] seek:n whence: SEEK_CUR]) + if (![source seek:n whence: SEEK_CUR]) { return 1; //Non-zero is error } @@ -24,11 +24,11 @@ int skipCallback(void *f, long n) int getCharCallback(void *f) { - DumbDecoder *decoder = (DumbDecoder *)f; + id source = (id)f; unsigned char c; - if ([[decoder source] read:&c amount:1] < 1) + if ([source read:&c amount:1] < 1) { return -1; } @@ -38,34 +38,34 @@ int getCharCallback(void *f) long readCallback(char *ptr, long n, void *f) { - DumbDecoder *decoder = (DumbDecoder *)f; + id source = (id)f; - return [[decoder source] read:ptr amount:n]; + return [source read:ptr amount:n]; } int seekCallback(void *f, long n) { - DumbDecoder *decoder = (DumbDecoder *)f; + id source = (id)f; - if (![[decoder source] seekable]) return -1; + if (![source seekable]) return -1; - if ([[decoder source] seek:n whence:SEEK_SET]) return 0; + if ([source seek:n whence:SEEK_SET]) return 0; else return -1; } long getsizeCallback(void *f) { - DumbDecoder *decoder = (DumbDecoder *)f; + id source = (id)f; - if (![[decoder source] seekable]) return 0; + if (![source seekable]) return 0; - long current_offset = [[decoder source] tell]; + long current_offset = [source tell]; - [[decoder source] seek:0 whence:SEEK_END]; + [source seek:0 whence:SEEK_END]; - long size = [[decoder source] tell]; + long size = [source tell]; - [[decoder source] seek:current_offset whence:SEEK_SET]; + [source seek:current_offset whence:SEEK_SET]; return size; } @@ -79,24 +79,25 @@ void oneTimeInit() } } +DUMBFILE_SYSTEM dfs = { + .open = NULL, + .skip = skipCallback, + .getc = getCharCallback, + .getnc = readCallback, + .close = NULL, + .seek = seekCallback, + .get_size = getsizeCallback +}; + - (BOOL)open:(id)s { [self setSource:s]; DUMBFILE *df; - DUMBFILE_SYSTEM dfs; - - dfs.open = NULL; - dfs.skip = skipCallback; - dfs.getc = getCharCallback; - dfs.getnc = readCallback; - dfs.close = NULL; - dfs.seek = seekCallback; - dfs.get_size = getsizeCallback; // dumb_register_stdfiles(); - df = dumbfile_open_ex(self, &dfs); + df = dumbfile_open_ex(s, &dfs); if (!df) { NSLog(@"EX Failed"); diff --git a/Plugins/Dumb/DumbMetadataReader.m b/Plugins/Dumb/DumbMetadataReader.m index 73121f089..73664e8cf 100644 --- a/Plugins/Dumb/DumbMetadataReader.m +++ b/Plugins/Dumb/DumbMetadataReader.m @@ -25,15 +25,28 @@ + (NSDictionary *)metadataForURL:(NSURL *)url { - if (![url isFileURL]) - return nil; - - dumb_register_stdfiles(); + id audioSourceClass = NSClassFromString(@"AudioSource"); + id source = [audioSourceClass audioSourceForURL:url]; + + if (![source open:url]) + return 0; + + if (![source seekable]) + return 0; + DUMBFILE * df = dumbfile_open_ex(source, &dfs); + if (!df) + { + NSLog(@"EX Failed"); + return NO; + } + DUH *duh; NSString *ext = [[[url path] pathExtension] lowercaseString]; - duh = dumb_load_any_quick([[url path] UTF8String], [ext isEqualToString:@"mod"] ? 0 : 1, 0); - + duh = dumb_read_any_quick(df, [ext isEqualToString:@"mod"] ? 0 : 1, 0); + + dumbfile_close(df); + if (!duh) { NSLog(@"Failed to create duh"); diff --git a/Plugins/GME/GameDecoder.h b/Plugins/GME/GameDecoder.h index af47375df..dea76428f 100755 --- a/Plugins/GME/GameDecoder.h +++ b/Plugins/GME/GameDecoder.h @@ -12,6 +12,8 @@ #import "Plugin.h" +extern gme_err_t readCallback( void* data, void* out, long count ); + @interface GameDecoder : NSObject { Music_Emu* emu; id source; diff --git a/Plugins/GME/GameDecoder.m b/Plugins/GME/GameDecoder.m index ca34414a3..5d7b59012 100755 --- a/Plugins/GME/GameDecoder.m +++ b/Plugins/GME/GameDecoder.m @@ -12,9 +12,9 @@ gme_err_t readCallback( void* data, void* out, long count ) { - GameDecoder *decoder = (GameDecoder *)data; + id source = (id)data; NSLog(@"Amount: %li", count); - int n = [[decoder source] read:out amount:count]; + int n = [source read:out amount:count]; NSLog(@"Read: %i", n); if (n <= 0) { @@ -58,7 +58,7 @@ gme_err_t readCallback( void* data, void* out, long count ) NSLog(@"Size: %li", size); - error = gme_load_custom(emu, readCallback, size, self); + error = gme_load_custom(emu, readCallback, size, s); if (error) { NSLog(@"ERROR Loding custom!"); diff --git a/Plugins/GME/GameMetadataReader.m b/Plugins/GME/GameMetadataReader.m index d86b6afb4..8320dfbe0 100644 --- a/Plugins/GME/GameMetadataReader.m +++ b/Plugins/GME/GameMetadataReader.m @@ -26,8 +26,14 @@ + (NSDictionary *)metadataForURL:(NSURL *)url { - if (![url isFileURL]) - return nil; + id audioSourceClass = NSClassFromString(@"AudioSource"); + id source = [audioSourceClass audioSourceForURL:url]; + + if (![source open:url]) + return 0; + + if (![source seekable]) + return 0; NSString *ext = [[[url path] pathExtension] lowercaseString]; @@ -46,14 +52,18 @@ return NO; } + [source seek:0 whence:SEEK_END]; + long size = [source tell]; + [source seek:0 whence:SEEK_SET]; + gme_err_t error; - error = gme_load_file(emu, [[url path] UTF8String]); - if (error) + error = gme_load_custom(emu, readCallback, size, source); + if (error) { NSLog(@"ERROR Loding file!"); return NO; } - + int track_num; if ([[url fragment] length] == 0) track_num = 0;