Skip to content

Commit

Permalink
Further NSURL fixes
Browse files Browse the repository at this point in the history
Added more error checking.
  • Loading branch information
arauchfuss committed Aug 19, 2013
1 parent 5bc326d commit 96bd09c
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions Managed Objects/TSSTManagedGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ - (void)didTurnIntoFault

- (void)setPath:(NSString *)newPath
{
NSError * urlError = nil;
NSURL * fileURL = [[NSURL alloc] initFileURLWithPath: newPath];
NSData * bookmarkData = [fileURL bookmarkDataWithOptions: NSURLBookmarkCreationMinimalBookmark
includingResourceValuesForKeys: nil
relativeToURL: nil
error: nil];
error: &urlError];
if (bookmarkData == nil || urlError != nil) {
bookmarkData = nil;
[NSApp presentError: urlError];
}
[self setValue: bookmarkData forKey: @"pathData"];
[fileURL release];
}
Expand All @@ -72,20 +77,24 @@ - (void)setPath:(NSString *)newPath

- (NSString *)path
{
NSError * urlError = nil;
BOOL stale = NO;
NSURL * fileURL = [NSURL URLByResolvingBookmarkData: [self valueForKey: @"pathData"]
options: NSURLBookmarkResolutionWithoutUI
relativeToURL: nil
bookmarkDataIsStale: NO
error: nil];
bookmarkDataIsStale: &stale
error: &urlError];


NSString * hardPath = nil;
if (fileURL) {
hardPath = [fileURL path];

if (fileURL == nil || urlError != nil) {
fileURL = nil;
[[self managedObjectContext] deleteObject: self];
[NSApp presentError: urlError];
}
else {
NSLog(@"Could not find image group");
[[self managedObjectContext] deleteObject: self];
hardPath = [fileURL path];
}

return hardPath;
Expand Down Expand Up @@ -163,7 +172,7 @@ - (void)nestedFolderContents
{
nestedDescription = [NSEntityDescription insertNewObjectForEntityForName: @"Image" inManagedObjectContext: [self managedObjectContext]];
[nestedDescription setValue: fullPath forKey: @"imagePath"];
[nestedDescription setValue: [NSNumber numberWithBool: YES] forKey: @"text"];
[nestedDescription setValue: @YES forKey: @"text"];
}
if(nestedDescription)
{
Expand Down Expand Up @@ -198,7 +207,7 @@ + (NSArray *)archiveExtensions
static NSArray * extensions = nil;
if(!extensions)
{
extensions = [[NSArray arrayWithObjects: @"rar", @"cbr", @"zip", @"cbz", @"7z", @"cb7", @"lha", @"lzh", nil] retain];
extensions = [@[@"rar", @"cbr", @"zip", @"cbz", @"7z", @"cb7", @"lha", @"lzh"] retain];
}

return extensions;
Expand All @@ -211,7 +220,7 @@ + (NSArray *)quicklookExtensions

if(!extensions)
{
extensions = [[NSArray arrayWithObjects: @"cbr", @"cbz", nil] retain];
extensions = [@[@"cbr", @"cbz"] retain];
}

return extensions;
Expand Down Expand Up @@ -277,7 +286,7 @@ - (NSData *)dataForPageIndex:(NSInteger)index
else
{
NSString * name = [[self instance] nameOfEntry: index];
NSString * fileName = [NSString stringWithFormat:@"%i.%@", index, [name pathExtension]];
NSString * fileName = [NSString stringWithFormat:@"%li.%@", (long)index, [name pathExtension]];
fileName = [solidDirectory stringByAppendingPathComponent: fileName];
if(![[NSFileManager defaultManager] fileExistsAtPath: fileName])
{
Expand Down Expand Up @@ -347,14 +356,14 @@ - (void)nestedArchiveContents
{
nestedDescription = [NSEntityDescription insertNewObjectForEntityForName: @"Image" inManagedObjectContext: [self managedObjectContext]];
[nestedDescription setValue: fileName forKey: @"imagePath"];
[nestedDescription setValue: [NSNumber numberWithInt: counter] forKey: @"index"];
[nestedDescription setValue: @(counter) forKey: @"index"];
}
else if([[[NSUserDefaults standardUserDefaults] valueForKey: TSSTNestedArchives] boolValue] && [[TSSTManagedArchive archiveExtensions] containsObject: extension])
{
fileData = [imageArchive contentsOfEntry: counter];
nestedDescription = [NSEntityDescription insertNewObjectForEntityForName: @"Archive" inManagedObjectContext: [self managedObjectContext]];
[nestedDescription setValue: fileName forKey: @"name"];
[nestedDescription setValue: [NSNumber numberWithBool: YES] forKey: @"nested"];
[nestedDescription setValue: @YES forKey: @"nested"];

collision = 0;
do {
Expand All @@ -376,8 +385,8 @@ - (void)nestedArchiveContents
{
nestedDescription = [NSEntityDescription insertNewObjectForEntityForName: @"Image" inManagedObjectContext: [self managedObjectContext]];
[nestedDescription setValue: fileName forKey: @"imagePath"];
[nestedDescription setValue: [NSNumber numberWithInt: counter] forKey: @"index"];
[nestedDescription setValue: [NSNumber numberWithBool: YES] forKey: @"text"];
[nestedDescription setValue: @(counter) forKey: @"index"];
[nestedDescription setValue: @YES forKey: @"text"];
}
else if([extension isEqualToString: @"pdf"])
{
Expand All @@ -394,7 +403,7 @@ - (void)nestedArchiveContents
[fileData writeToFile: archivePath atomically: YES];

[nestedDescription setValue: archivePath forKey: @"path"];
[nestedDescription setValue: [NSNumber numberWithBool: YES] forKey: @"nested"];
[nestedDescription setValue: @YES forKey: @"nested"];
[(TSSTManagedPDF *)nestedDescription pdfContents];
}

Expand Down Expand Up @@ -493,7 +502,7 @@ - (void)pdfContents
{
imageDescription = [NSEntityDescription insertNewObjectForEntityForName: @"Image" inManagedObjectContext: [self managedObjectContext]];
[imageDescription setValue: [NSString stringWithFormat: @"%i", pageNumber + 1] forKey: @"imagePath"];
[imageDescription setValue: [NSNumber numberWithInt: pageNumber] forKey: @"index"];
[imageDescription setValue: @(pageNumber) forKey: @"index"];
[pageSet addObject: imageDescription];
}
[self setValue: pageSet forKey: @"images"];
Expand Down

0 comments on commit 96bd09c

Please sign in to comment.