Skip to content
Browse files

pierre noticed we were releasing but not retainig myBrowser in iMBAbs…

…tractParser
  • Loading branch information...
1 parent fa08531 commit 55954b1f8a986a1b31d0b7979ee23a7f1db87d6a @danwood danwood committed Feb 16, 2007
Showing with 50 additions and 2 deletions.
  1. +45 −0 NSFileManager+iMedia.m
  2. +5 −2 iMBAbstractParser.m
View
45 NSFileManager+iMedia.m
@@ -81,12 +81,57 @@ - (BOOL)isPathHidden:(NSString *)path
}
+
+/* Alternate to rolling our own cache -- use Cocoa's. Robert Blum has the beginnings of this but I need to
+figure out the details.
+
+From: r.blum@gmx.net
+Subject: [Dan Wood] Cocoa caching
+Date: January 29, 2007 7:23:35 PM PST (CA)
+
+No need to put it on your blog - I'm writing an article of my own ;) (Feel free to put yours up, too, though)
+
+Apologies for the untidiness of the code - I banged this out between shower and breakfast....
+
+NSURLCache* cache = [NSURLCache sharedURLCache]; // Get the standard URL cache. Haven't played with custom ones
+
+NSURL* existingURL = [ [NSURL alloc] initWithString:@"myapp://pictures/cachedresponse"];
+NSURLResponse* response = [[NSURLResponse alloc] initWithURL: existingURL MIMEType:@"binary" expectedContentLength:-1 textEncodingName:nil];
+NSData* responseData = [NSData dataWithBytes:"1234" length:5]; // That's the data you want to cache. It's probably not too hard to turn NSImage into NSData
+
+
+NSCachedURLResponse* cachedResponse = [ [NSCachedURLResponse alloc] initWithResponse: response data: responseData];
+NSURLRequest* request = [NSURLRequest requestWithURL: existingURL];
+[cache storeCachedResponse: cachedResponse forRequest: request];
+
+NSCachedURLResponse* lookupResponse = [cache cachedResponseForRequest: request];
+NSData * newData = [lookupResponse data];
+
+lookupResponse = [cache cachedResponseForRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"myapp://pictures/noresponse"]]];
+if( lookupResponse != nil )
+MY_ASSERT( "This shouldn't happen - we don't have data for the request" );
+
+
+Hope that helps clear things up a bit.... mail me if you've got questions.
+
+- Robert
+
+*/
+
+
+
+
+
// Returns a path for caching a file at the given key (such as a file name or other unique descriptor)
// This is not like the NSURLRequest method, which seems to make a 72-bit (9-byte) hash
// and then possibly deal with collisions. They go like this: ~/Library/Caches/ nibble / nibble / Uint32-Uint32
// We will instead just do an SHA1 to get a pretty darn unique hash, then use the first two nibbles like they do,
// and then the rest, in hex.
+
+
+
+
#include <openssl/sha.h>
#define SHA1_CTX SHA_CTX
View
7 iMBAbstractParser.m
@@ -87,9 +87,12 @@ - (iMBLibraryNode *)parseDatabase
return nil;
}
-- (void)setBrowser:(id <iMediaBrowser>)browser
+
+- (void)setBrowser:(id <iMediaBrowser>)aBrowser
{
- myBrowser = browser;
+ [aBrowser retain];
+ [myBrowser release];
+ myBrowser = aBrowser;
}
- (NSString *)databasePath

0 comments on commit 55954b1

Please sign in to comment.
Something went wrong with that request. Please try again.