2013-10-04 23:34:29 +00:00
|
|
|
//
|
|
|
|
// DumbContainer.m
|
|
|
|
// Dumb
|
|
|
|
//
|
|
|
|
// Created by Christopher Snowhill on 10/4/13.
|
|
|
|
// Copyright 2013 __NoWork, Inc__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <Dumb/dumb.h>
|
|
|
|
|
|
|
|
#import "DumbContainer.h"
|
|
|
|
#import "DumbDecoder.h"
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
@interface DumbCallbackData : NSObject {
|
|
|
|
@public
|
|
|
|
NSString *baseUrl;
|
|
|
|
@public
|
|
|
|
NSMutableArray *tracks;
|
2016-05-03 07:58:19 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DumbCallbackData
|
|
|
|
@end
|
|
|
|
|
2013-10-04 23:34:29 +00:00
|
|
|
@implementation DumbContainer
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)fileTypes {
|
|
|
|
return [DumbDecoder fileTypes];
|
2013-10-04 23:34:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)mimeTypes {
|
2013-10-04 23:34:29 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (float)priority {
|
|
|
|
return 1.0f;
|
2015-04-13 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
int scanCallback(void *data, int startOrder, long length) {
|
|
|
|
NSObject *_cbData = (__bridge NSObject *)(data);
|
|
|
|
DumbCallbackData *cbData = (id)_cbData;
|
|
|
|
|
|
|
|
[cbData->tracks addObject:[NSURL URLWithString:[cbData->baseUrl stringByAppendingFormat:@"#%i", startOrder]]];
|
|
|
|
|
|
|
|
return 0;
|
2013-10-04 23:34:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url {
|
|
|
|
if([url fragment]) {
|
|
|
|
// input url already has fragment defined - no need to expand further
|
|
|
|
return [NSMutableArray arrayWithObject:url];
|
|
|
|
}
|
|
|
|
|
|
|
|
id audioSourceClass = NSClassFromString(@"AudioSource");
|
|
|
|
id<CogSource> source = [audioSourceClass audioSourceForURL:url];
|
|
|
|
|
|
|
|
if(![source open:url])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(![source seekable])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
[source seek:0 whence:SEEK_END];
|
|
|
|
long size = [source tell];
|
|
|
|
[source seek:0 whence:SEEK_SET];
|
|
|
|
|
|
|
|
void *data = malloc(size);
|
|
|
|
[source read:data amount:size];
|
|
|
|
|
|
|
|
DUMBFILE *df = dumbfile_open_memory_and_free(data, size);
|
|
|
|
if(!df) {
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"Open failed for file: %@", [url absoluteString]);
|
2013-10-04 23:34:29 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
NSMutableArray *tracks = [NSMutableArray array];
|
|
|
|
|
2013-10-04 23:34:29 +00:00
|
|
|
int i;
|
2022-02-07 05:49:27 +00:00
|
|
|
int subsongs = dumb_get_psm_subsong_count(df);
|
|
|
|
if(subsongs) {
|
|
|
|
dumbfile_close(df);
|
|
|
|
|
|
|
|
for(i = 0; i < subsongs; ++i) {
|
|
|
|
[tracks addObject:[NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:@"#%i", i]]];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dumbfile_seek(df, 0, SEEK_SET);
|
|
|
|
|
|
|
|
DUH *duh;
|
|
|
|
NSString *ext = [[url pathExtension] lowercaseString];
|
|
|
|
duh = dumb_read_any_quick(df, [ext isEqualToString:@"mod"] ? 0 : 1, 0);
|
|
|
|
|
|
|
|
dumbfile_close(df);
|
|
|
|
|
|
|
|
if(duh) {
|
|
|
|
DumbCallbackData *data = [[DumbCallbackData alloc] init];
|
|
|
|
data->baseUrl = [url absoluteString];
|
|
|
|
data->tracks = tracks;
|
|
|
|
|
|
|
|
dumb_it_scan_for_playable_orders(duh_get_it_sigdata(duh), scanCallback, (__bridge void *)data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-04 23:34:29 +00:00
|
|
|
return tracks;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|