mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 19:50:48 +00:00
NSImage fixes - return nil on failed init rather than raising exception.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3984 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2b273903c4
commit
085cb484ad
2 changed files with 52 additions and 28 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Thu Mar 25 20:34:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
|
* Source/NSImage.m: Incorporated fixes suggested by dave@turbocat.de
|
||||||
|
|
||||||
Thu Mar 25 20:34:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
Thu Mar 25 20:34:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
Mostly fixes to cope with case where tracking rectangles are
|
Mostly fixes to cope with case where tracking rectangles are
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
|
#include <Foundation/NSFileManager.h>
|
||||||
#include <Foundation/NSArray.h>
|
#include <Foundation/NSArray.h>
|
||||||
#include <Foundation/NSValue.h>
|
#include <Foundation/NSValue.h>
|
||||||
#include <Foundation/NSDictionary.h>
|
#include <Foundation/NSDictionary.h>
|
||||||
|
@ -268,43 +269,56 @@ static NSDictionary* nsmapping = nil;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- init
|
- (id) init
|
||||||
{
|
{
|
||||||
[self initWithSize: NSMakeSize(0, 0)];
|
self = [self initWithSize: NSMakeSize(0, 0)];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- initByReferencingFile: (NSString *)fileName
|
- (id) initByReferencingFile: (NSString *)fileName
|
||||||
|
{
|
||||||
|
id o = self;
|
||||||
|
|
||||||
|
if ((self = [self init]) == o)
|
||||||
{
|
{
|
||||||
[self init];
|
|
||||||
_flags.dataRetained = NO;
|
_flags.dataRetained = NO;
|
||||||
// FIXME: Should this be an exception? What else should happen?
|
|
||||||
if (![self useFromFile:fileName])
|
if (![self useFromFile:fileName])
|
||||||
[NSException raise: NSGenericException
|
{
|
||||||
format: @"Cannot find image representation for image %s",
|
[self release];
|
||||||
[fileName cString]];
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithContentsOfFile: (NSString *)fileName
|
- (id) initWithContentsOfFile: (NSString *)fileName
|
||||||
|
{
|
||||||
|
id o = self;
|
||||||
|
|
||||||
|
if ((self = [self init]) == o)
|
||||||
{
|
{
|
||||||
[self init];
|
|
||||||
_flags.dataRetained = YES;
|
_flags.dataRetained = YES;
|
||||||
// FIXME: Should this be an exception? What else should happen ?
|
|
||||||
if (![self useFromFile:fileName])
|
if (![self useFromFile:fileName])
|
||||||
[NSException raise: NSGenericException
|
{
|
||||||
format: @"Cannot find image representation for image %s",
|
[self release];
|
||||||
[fileName cString]];
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- initWithData: (NSData *)data;
|
- (id) initWithData: (NSData *)data;
|
||||||
|
{
|
||||||
|
id o = self;
|
||||||
|
|
||||||
|
if ((self = [self init]) == o)
|
||||||
{
|
{
|
||||||
[self init];
|
|
||||||
// FIXME: Should this be an exception? What else should happen ?
|
|
||||||
if (![self loadFromData: data])
|
if (![self loadFromData: data])
|
||||||
[NSException raise: NSGenericException
|
{
|
||||||
format: @"Cannot find image representation for data"];
|
[self release];
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,6 +694,12 @@ static NSDictionary* nsmapping = nil;
|
||||||
NSArray *array;
|
NSArray *array;
|
||||||
NSString *ext;
|
NSString *ext;
|
||||||
rep_data_t repd;
|
rep_data_t repd;
|
||||||
|
NSFileManager *manager = [NSFileManager defaultManager];
|
||||||
|
|
||||||
|
if ([manager fileExistsAtPath: fileName] == NO)
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
ext = [fileName pathExtension];
|
ext = [fileName pathExtension];
|
||||||
if (!ext)
|
if (!ext)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue