Made necessary changes to facilitate metadata reading from arbitrary file sources, like archives
parent
1c37cefae6
commit
810d58b4fe
|
@ -16,6 +16,8 @@
|
|||
|
||||
#import "Plugin.h"
|
||||
|
||||
extern DUMBFILE_SYSTEM dfs;
|
||||
|
||||
@interface DumbDecoder : NSObject <CogDecoder> {
|
||||
DUH *duh;
|
||||
DUH_SIGRENDERER *dsr;
|
||||
|
|
|
@ -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<CogSource>)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");
|
||||
|
|
|
@ -25,15 +25,28 @@
|
|||
|
||||
+ (NSDictionary *)metadataForURL:(NSURL *)url
|
||||
{
|
||||
if (![url isFileURL])
|
||||
return nil;
|
||||
|
||||
dumb_register_stdfiles();
|
||||
id audioSourceClass = NSClassFromString(@"AudioSource");
|
||||
id<CogSource> 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");
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#import "Plugin.h"
|
||||
|
||||
extern gme_err_t readCallback( void* data, void* out, long count );
|
||||
|
||||
@interface GameDecoder : NSObject <CogDecoder> {
|
||||
Music_Emu* emu;
|
||||
id<CogSource> source;
|
||||
|
|
|
@ -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!");
|
||||
|
|
|
@ -26,8 +26,14 @@
|
|||
|
||||
+ (NSDictionary *)metadataForURL:(NSURL *)url
|
||||
{
|
||||
if (![url isFileURL])
|
||||
return nil;
|
||||
id audioSourceClass = NSClassFromString(@"AudioSource");
|
||||
id<CogSource> 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;
|
||||
|
|
Loading…
Reference in New Issue