mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-29 22:17:39 +00:00
Use [GSModelLoaderFactory modelLoaderForData:] to generically implement methods that unarchive a model purely from data since we cannot use the file extension to determine which loader to instantiate.
This commit is contained in:
parent
0d3c3d1b2a
commit
d9921efd8e
6 changed files with 138 additions and 16 deletions
|
@ -29,6 +29,7 @@
|
|||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSBundle.h>
|
||||
#import <Foundation/NSDebug.h>
|
||||
#import <Foundation/NSData.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
#import <Foundation/NSException.h>
|
||||
|
@ -80,6 +81,33 @@ Class gmodel_class(void)
|
|||
// register for the gmodel type.
|
||||
}
|
||||
|
||||
+ (BOOL) canReadData: (NSData *)theData
|
||||
{
|
||||
char *header = calloc(1024, sizeof(char));
|
||||
|
||||
if (header != NULL)
|
||||
{
|
||||
NSUInteger len = [theData length];
|
||||
NSRange r = NSMakeRange(len - 1024, len - 1);
|
||||
NSString *hdr = nil;
|
||||
|
||||
[theData getBytes: header
|
||||
range: r];
|
||||
hdr = [[NSString alloc] initWithBytes: header
|
||||
length: 1024
|
||||
encoding: NSUTF8StringEncoding];
|
||||
AUTORELEASE(hdr);
|
||||
if ([hdr containsString: @"GMModel"])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
free(header);
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSString *) type
|
||||
{
|
||||
return @"gmodel";
|
||||
|
@ -119,7 +147,7 @@ Class gmodel_class(void)
|
|||
if ([ext isEqualToString: @"gmodel"])
|
||||
{
|
||||
return [gmodel_class() loadIMFile: fileName
|
||||
owner: [context objectForKey: NSNibOwner]];
|
||||
owner: [context objectForKey: NSNibOwner]];
|
||||
}
|
||||
|
||||
return NO;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue