Permalink
Browse files

Changed support for password protected archives. It seems to work now…

…. Untested and the dialog does not re-appear on failure.
  • Loading branch information...
1 parent a36c12f commit 4af13e07d9dc7145c5405df610fe8ace420180e6 Alexander Rauchfuss committed Apr 26, 2011
Showing with 52 additions and 51 deletions.
  1. +51 −49 Managed Objects/TSSTManagedGroup.m
  2. +1 −2 SimpleComicAppDelegate.m
@@ -244,18 +244,18 @@ - (id)instance
{
if (!instance)
{
- NSFileManager * manager = [NSFileManager defaultManager];
- if([manager fileExistsAtPath: [self valueForKey: @"path"]])
- {
- instance = [[XADArchive alloc] initWithFile: [self valueForKey: @"path"]];
- // Set the archive delegate so that password and encoding queries can have a modal pop up.
- [instance setDelegate: [NSApp delegate]];
+ NSFileManager * manager = [NSFileManager defaultManager];
+ if([manager fileExistsAtPath: [self valueForKey: @"path"]])
+ {
+ instance = [[XADArchive alloc] initWithFile: [self valueForKey: @"path"] delegate: self error:NULL];
+
+ // Set the archive delegate so that password and encoding queries can have a modal pop up.
- if([self valueForKey: @"password"])
- {
- [instance setPassword: [self valueForKey: @"password"]];
- }
- }
+ if([self valueForKey: @"password"])
+ {
+ [instance setPassword: [self valueForKey: @"password"]];
+ }
+ }
}
return instance;
@@ -315,25 +315,6 @@ - (NSManagedObject *)topLevelGroup
- (void)nestedArchiveContents
{
XADArchive * imageArchive = [self valueForKey: @"instance"];
-
- if([imageArchive isEncrypted])
- {
- NSString * password = nil;
- NSData * testData = nil;
- do
- {
- password = [[NSApp delegate] passwordForArchiveWithPath: [self valueForKey: @"path"]];
- [imageArchive setPassword: password];
- testData = [self dataForPageIndex: 1];
- } while(password && !testData);
-
- if(!testData)
- {
- return;
- }
-
- [self setValue: password forKey: @"password"];
- }
NSFileManager * fileManager = [NSFileManager defaultManager];
NSData * fileData;
@@ -369,26 +350,26 @@ - (void)nestedArchiveContents
}
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"];
-
- collision = 0;
- do {
- archivePath = [NSString stringWithFormat: @"%i-%@", collision, fileName];
- archivePath = [NSTemporaryDirectory() stringByAppendingPathComponent: archivePath];
- ++collision;
- } while ([fileManager fileExistsAtPath: archivePath]);
-
- [[NSFileManager defaultManager] createDirectoryAtPath: [archivePath stringByDeletingLastPathComponent]
- withIntermediateDirectories: YES
- attributes: nil
- error: NULL];
- [[NSFileManager defaultManager] createFileAtPath: archivePath contents: fileData attributes: nil];
+ 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: archivePath forKey: @"path"];
- [(TSSTManagedArchive *)nestedDescription nestedArchiveContents];
+ collision = 0;
+ do {
+ archivePath = [NSString stringWithFormat: @"%i-%@", collision, fileName];
+ archivePath = [NSTemporaryDirectory() stringByAppendingPathComponent: archivePath];
+ ++collision;
+ } while ([fileManager fileExistsAtPath: archivePath]);
+
+ [[NSFileManager defaultManager] createDirectoryAtPath: [archivePath stringByDeletingLastPathComponent]
+ withIntermediateDirectories: YES
+ attributes: nil
+ error: NULL];
+ [[NSFileManager defaultManager] createFileAtPath: archivePath contents: fileData attributes: nil];
+
+ [nestedDescription setValue: archivePath forKey: @"path"];
+ [(TSSTManagedArchive *)nestedDescription nestedArchiveContents];
}
else if([[TSSTPage textExtensions] containsObject: extension])
{
@@ -432,6 +413,27 @@ - (BOOL)quicklookCompatible
}
+/** Delegates **/
+
+/* Called when Simple Comic encounters a password protected
+ archive. Brings a password dialog forward. */
+-(void)archiveNeedsPassword:(XADArchive *)archive
+{
+ NSString * password = [self valueForKey: @"password"];
+
+ if(password)
+ {
+ [archive setPassword: password];
+ return;
+ }
+
+ password = [[NSApp delegate] passwordForArchiveWithPath: [self valueForKey: @"path"]];
+ [archive setPassword: password];
+
+ [self setValue: password forKey: @"password"];
+}
+
+
@end
View
@@ -827,8 +827,7 @@ - (void)updateEncodingMenuTestedAgainst:(NSData *)data
}
-/* Called when Simple Comic encounters a password protected
- archive. Brings a password dialog forward. */
+
- (NSString*)passwordForArchiveWithPath:(NSString*)filename
{
NSString* password = nil;

0 comments on commit 4af13e0

Please sign in to comment.