Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use new shared temporary folder method. Also, make use of threadSafe …

…file manager while I"m at it.
  • Loading branch information...
commit 6d6de572450a9235cc3a4f40e0f1eaab8ac17f68 1 parent 2b41862
Dan Wood authored September 17, 2010
8  IMBFireFoxParser.m
@@ -99,7 +99,7 @@ + (NSArray*) parserInstancesForMediaType:(NSString*)inMediaType
99 99
 	NSMutableArray* parserInstances = [NSMutableArray array];
100 100
 	
101 101
 	NSString *bookmarkPath = [self firefoxBookmarkPath];
102  
-	NSFileManager *fm = [NSFileManager defaultManager];	// File manager, not flying meat!
  102
+	NSFileManager *fm = [NSFileManager threadSafeManager];	// File manager, not flying meat!
103 103
 	if ([self isInstalled] && bookmarkPath && [fm fileExistsAtPath:bookmarkPath] && [fm isReadableFileAtPath:bookmarkPath])
104 104
 	{
105 105
 		IMBFireFoxParser* parser = [[[self class] alloc] initWithMediaType:inMediaType];
@@ -119,7 +119,7 @@ + (NSString *)firefoxBookmarkPath;
119 119
 	NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
120 120
 	NSString *path = [libraryPaths objectAtIndex:0];
121 121
 	
122  
-	NSFileManager *fm = [NSFileManager defaultManager];
  122
+	NSFileManager *fm = [NSFileManager threadSafeManager];
123 123
 	
124 124
 	NSString *firefoxPath = [path stringByAppendingPathComponent:@"Firefox"];
125 125
 	NSString *profilesPath = [firefoxPath stringByAppendingPathComponent:@"Profiles"];
@@ -148,14 +148,14 @@ + (NSString *)firefoxBookmarkPath;
148 148
 
149 149
 - (void) copyDatabase;		// try to copy the database and store in copy.
150 150
 {
151  
-	NSFileManager *fm = [NSFileManager defaultManager];
  151
+	NSFileManager *fm = [NSFileManager threadSafeManager];
152 152
 	NSString *newPath = nil;	// copy destination if we have to copy the file
153 153
 	
154 154
 	// null result set means we couldn't open it ... it's probably busy.
155 155
 	// The stupid workaround is to make a copy of the sqlite file, and check there!
156 156
 	// However just in case the source file has not changed, we'll check modification dates.
157 157
 	//
158  
-	newPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"places.sqlite"];
  158
+	newPath = [[[NSFileManager threadSafeManager] sharedTemporaryFolder:@"firefox"] stringByAppendingPathComponent:@"places.sqlite"];
159 159
 	if (![newPath isEqualToString:self.databasePathCurrent])	// if we are trying to open the copy, don't allow that.
160 160
 	{
161 161
 		BOOL needToCopyFile = YES;		// probably we will need to copy but let's check
5  IMBFlickrObject.m
@@ -83,8 +83,7 @@ - (NSURL*) previewItemURL
83 83
 	{
84 84
 		// The is our temp download folder...
85 85
 		
86  
-		NSString* folder = [NSTemporaryDirectory() stringByAppendingPathComponent:@"iMedia-QuickLook"];
87  
-		[[NSFileManager defaultManager] createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:nil error:nil];
  86
+		NSString* folder = [[NSFileManager threadSafeManager] sharedTemporaryFolder:@"quicklook"];
88 87
 
89 88
 		// Build a path for the download file...
90 89
 		
@@ -93,7 +92,7 @@ - (NSURL*) previewItemURL
93 92
 		
94 93
 		// If the file is already there, then use it...
95 94
 		
96  
-		if ([[NSFileManager defaultManager] fileExistsAtPath:path])
  95
+		if ([[NSFileManager threadSafeManager] fileExistsAtPath:path])
97 96
 		{
98 97
 			previewItemURL = [NSURL fileURLWithPath:path];
99 98
 		}
2  IMBFolderParser.m
@@ -112,7 +112,7 @@ - (IMBNode*) nodeWithOldNode:(const IMBNode*)inOldNode options:(IMBOptions)inOpt
112 112
 	// Check if the folder exists. If not then do not return a node...
113 113
 	
114 114
 	BOOL exists,directory;
115  
-	exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&directory];
  115
+	exists = [[NSFileManager threadSafeManager] fileExistsAtPath:path isDirectory:&directory];
116 116
 	
117 117
 	if (!exists || !directory) 
118 118
 	{
4  IMBGarageBandParser.m
@@ -257,7 +257,7 @@ - (IMBNode*) _unpopulatedRootNodes
257 257
 	
258 258
 	NSString* demoSongsPath = [IMBGarageBandParser demoSongsPath];
259 259
 
260  
-	if ([[NSFileManager defaultManager] fileExistsAtPath:demoSongsPath])
  260
+	if ([[NSFileManager threadSafeManager] fileExistsAtPath:demoSongsPath])
261 261
 	{
262 262
 		IMBNode* demo = [[[IMBNode alloc] init] autorelease];
263 263
 		demo.parentNode = root;
@@ -278,7 +278,7 @@ - (IMBNode*) _unpopulatedRootNodes
278 278
 	
279 279
 	NSString* userSongsPath = [IMBGarageBandParser userSongsPath];
280 280
 
281  
-	if ([[NSFileManager defaultManager] fileExistsAtPath:userSongsPath])
  281
+	if ([[NSFileManager threadSafeManager] fileExistsAtPath:userSongsPath])
282 282
 	{
283 283
 		IMBNode* user = [[[IMBNode alloc] init] autorelease];
284 284
 		user.parentNode = root;
2  IMBLightroom3Parser.m
@@ -513,7 +513,7 @@ + (NSString*)cloneDatabase:(NSString*)databasePath
513 513
 	NSString *pathExtension = [databasePath pathExtension];	
514 514
 	NSString *readOnlyDatabasePath = [[NSString stringWithFormat:@"%@-readOnly", basePath] stringByAppendingPathExtension:pathExtension];
515 515
 	
516  
-	NSFileManager *fileManager = [NSFileManager defaultManager];
  516
+	NSFileManager *fileManager = [NSFileManager threadSafeManager];
517 517
 	BOOL needToCopyFile = YES;		// probably we will need to copy but let's check
518 518
 	NSError* error;
519 519
 	
2  IMBLightroomParser.m
@@ -253,7 +253,7 @@ + (void) parseRecentLibrariesList:(NSString*)inRecentLibrariesList into:(NSMutab
253 253
 				path = [path substringWithRange:NSMakeRange(1, [path length] - 3)];
254 254
  
255 255
 				BOOL exists,changed;
256  
-				exists = [[NSFileManager defaultManager] fileExistsAtPath:&path wasChanged:&changed];
  256
+				exists = [[NSFileManager threadSafeManager] fileExistsAtPath:&path wasChanged:&changed];
257 257
 				if (exists) [inLibraryPaths addObject:path];
258 258
 				
259 259
                 path = @"";
2  IMBMovieFolderParser.m
@@ -152,7 +152,7 @@ - (NSDictionary*) metadataForFileAtPath:(NSString*)inPath
152 152
 	}
153 153
 	else
154 154
 	{
155  
-//		NSLog(@"Nil from MDItemCreate for %@ exists?%d", inPath, [[NSFileManager defaultManager] fileExistsAtPath:inPath]);
  155
+//		NSLog(@"Nil from MDItemCreate for %@ exists?%d", inPath, [[NSFileManager threadSafeManager] fileExistsAtPath:inPath]);
156 156
 	}
157 157
 	
158 158
 	return metadata;
4  IMBNodeViewController.m
@@ -695,7 +695,7 @@ - (NSDragOperation) outlineView:(NSOutlineView*)inOutlineView validateDrop:(id<N
695 695
 	
696 696
 	for (NSString* path in paths)
697 697
 	{
698  
-		exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&directory];
  698
+		exists = [[NSFileManager threadSafeManager] fileExistsAtPath:path isDirectory:&directory];
699 699
 		
700 700
 		if (exists && directory)
701 701
 		{
@@ -717,7 +717,7 @@ - (BOOL) outlineView:(NSOutlineView*)inOutlineView acceptDrop:(id<NSDraggingInfo
717 717
 	
718 718
 	for (NSString* path in paths)
719 719
 	{
720  
-		exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&directory];
  720
+		exists = [[NSFileManager threadSafeManager] fileExistsAtPath:path isDirectory:&directory];
721 721
 		
722 722
 		if (exists && directory)
723 723
 		{
8  IMBObjectPromise.m
@@ -366,7 +366,7 @@ - (void) _loadObject:(IMBObject*)inObject
366 366
 			// Now, copy this to the download folder path ... ?
367 367
 			NSString *fullPath = [self.downloadFolderPath stringByAppendingPathComponent:[[localURL path] lastPathComponent]];
368 368
 			NSError *err = nil;
369  
-			[[NSFileManager defaultManager] copyItemAtPath:[localURL path] toPath:fullPath error:&err];
  369
+			[[NSFileManager threadSafeManager] copyItemAtPath:[localURL path] toPath:fullPath error:&err];
370 370
 			if (err)
371 371
 			{
372 372
 				NSLog(@"%@", err);
@@ -545,7 +545,11 @@ - (void) loadObjects:(NSArray*)inObjects
545 545
 				op.delegateReference = object;
546 546
 				
547 547
 				NSString *downloadFolderPath = self.downloadFolderPath;
548  
-				if (!downloadFolderPath) downloadFolderPath = NSTemporaryDirectory();	// force downloading into temporary directory
  548
+				if (!downloadFolderPath)
  549
+				{
  550
+					downloadFolderPath = [[NSFileManager threadSafeManager] sharedTemporaryFolder:@"downloads"];
  551
+					// force downloading into temporary directory
  552
+				}
549 553
 				op.downloadFolderPath = downloadFolderPath;
550 554
 				
551 555
 				[self.downloadOperations addObject:op];
2  NSFileManager+iMedia.h
@@ -60,6 +60,8 @@
60 60
 - (NSString*)uniqueTemporaryFile:(NSString*)name withinDirectory:(NSString*)directoryPath;
61 61
 - (NSString*)uniqueTemporaryPathWithinDirectory:(NSString*)directoryPath;
62 62
 
  63
+- (NSString*)sharedTemporaryFolder:(NSString*)dirName;
  64
+
63 65
 - (NSString*) volumeNameAtPath:(NSString*)inPath;
64 66
 - (NSString*) relativePathToVolumeAtPath:(NSString*)inPath;
65 67
 - (BOOL) fileExistsAtPath:(NSString**)ioPath wasChanged:(BOOL*)outWasChanged;
16  NSFileManager+iMedia.m
@@ -106,7 +106,7 @@ - (BOOL)createDirectoryPath:(NSString *)path attributes:(NSDictionary *)attribut
106 106
 		[NSException raise:@"iMediaException" format:@"createDirectoryPath:attributes: path not absolute:%@", path];
107 107
 	}
108 108
 	
109  
-	return [[NSFileManager defaultManager] fileExistsAtPath:path];
  109
+	return [self fileExistsAtPath:path];
110 110
 }
111 111
 
112 112
 - (BOOL)isPathHidden:(NSString *)path
@@ -154,6 +154,20 @@ - (NSString *)pathResolved:(NSString *)path
154 154
 	return resolvedPath;
155 155
 }
156 156
 
  157
+// Return (creating if necessary) a path to the shared iMedia temporary directory.
  158
+// If you pass in a subfolder name, that will be created and appended.
  159
+
  160
+- (NSString*)sharedTemporaryFolder:(NSString*)dirName;
  161
+{
  162
+	NSString *directoryPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"iMedia"];
  163
+	if (dirName && ![dirName isEqualToString:@""])
  164
+	{
  165
+		directoryPath = [directoryPath stringByAppendingPathComponent:dirName];
  166
+	}
  167
+	[self createDirectoryAtPath:directoryPath withIntermediateDirectories:YES attributes:nil error:NULL];
  168
+    return directoryPath;
  169
+}
  170
+
157 171
 - (NSString*)uniqueTemporaryFile:(NSString*)name
158 172
 {
159 173
 	NSString *processName = [[NSProcessInfo processInfo] processName];

0 notes on commit 6d6de57

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