1/* 2 NSError_PPUtilities.m 3 4 Copyright 2013-2018 Josh Freeman 5 http://www.twilightedge.com 6 7 This file is part of PikoPixel for Mac OS X and GNUstep. 8 PikoPixel is a graphical application for drawing & editing pixel-art images. 9 10 PikoPixel is free software: you can redistribute it and/or modify it under 11 the terms of the GNU Affero General Public License as published by the 12 Free Software Foundation, either version 3 of the License, or (at your 13 option) any later version approved for PikoPixel by its copyright holder (or 14 an authorized proxy). 15 16 PikoPixel is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 18 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 19 details. 20 21 You should have received a copy of the GNU Affero General Public License 22 along with this program. If not, see <http://www.gnu.org/licenses/>. 23*/ 24 25#import "NSError_PPUtilities.h" 26 27#import "PPDefines.h" 28 29 30#define kErrorDescription_ImageFileVersionIsTooNew \ 31 @"\n\nThe file was created by a newer version of PikoPixel and cannot be read " \ 32 "by this version." 33 34#define kErrorDescription_ImageFileDimensionsAreTooLarge \ 35 [NSString stringWithFormat: \ 36 @"\n\nThe image is too large.\nMaximum size allowed is: %d x %d", \ 37 kMaxCanvasDimension, kMaxCanvasDimension] 38 39#define kErrorDescriptionFormatString_UnableToCreateDataOfType \ 40 @"\n\nUnable to create data in \"%@\" format." 41 42 43@implementation NSError (PPUtilities) 44 45+ (NSError *) ppError_ImageFileIsCorrupt 46{ 47 return [NSError errorWithDomain: NSCocoaErrorDomain 48 code: NSFileReadCorruptFileError 49 userInfo: nil]; 50} 51 52+ (NSError *) ppError_ImageFileVersionIsTooNew 53{ 54 NSDictionary *errorUserInfoDict = 55 [NSDictionary dictionaryWithObject: 56 kErrorDescription_ImageFileVersionIsTooNew 57 forKey: NSLocalizedFailureReasonErrorKey]; 58 59 return [NSError errorWithDomain: NSCocoaErrorDomain 60 code: NSFileReadUnknownError 61 userInfo: errorUserInfoDict]; 62} 63 64+ (NSError *) ppError_ImageFileDimensionsAreTooLarge 65{ 66 NSDictionary *errorUserInfoDict = 67 [NSDictionary dictionaryWithObject: 68 kErrorDescription_ImageFileDimensionsAreTooLarge 69 forKey: NSLocalizedFailureReasonErrorKey]; 70 71 return [NSError errorWithDomain: NSCocoaErrorDomain 72 code: NSFileReadUnknownError 73 userInfo: errorUserInfoDict]; 74} 75 76+ (NSError *) ppError_UnableToCreateDataOfType: (NSString *) typeName 77{ 78 NSString *errorDescription = 79 [NSString stringWithFormat: 80 kErrorDescriptionFormatString_UnableToCreateDataOfType, typeName]; 81 82 NSDictionary *errorUserInfoDict = 83 [NSDictionary dictionaryWithObject: errorDescription 84 forKey: NSLocalizedFailureReasonErrorKey]; 85 86 return [NSError errorWithDomain: NSCocoaErrorDomain 87 code: NSFileWriteUnknownError 88 userInfo: errorUserInfoDict]; 89} 90 91@end 92