Created
April 1, 2010 01:59
Revisions
-
gonzoua created this gist
Apr 1, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ // newer iTunes seems to prefer "iTunes Media" over "iTunes Music" #define ITUNES_MUSIC @"/Music/iTunes/iTunes Music" #define ITUNES_MEDIA @"/Music/iTunes/iTunes Media" -(NSString*) _getiTunesMediaFolder { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults addSuiteNamed:@"com.apple.iTunes"]; NSDictionary *keys = [defaults dictionaryRepresentation]; NSString *key; NSData *aliasData = nil; NSString *mediaFolder = nil; for (key in keys) { if ([key hasPrefix:@"alis:"] && [key hasSuffix:@"Music Folder Location"]) { aliasData = [defaults dataForKey:key]; break; } } // try to get dir from alias if (aliasData) { mediaFolder = [[BDAlias aliasWithData:aliasData] fullPath]; if (mediaFolder) NSLog(@"iTunes Media Folder location: %@", [mediaFolder stringByAbbreviatingWithTildeInPath]); return mediaFolder; } // check standard locations BOOL isDir; NSString *homeDir = NSHomeDirectory(); if ([[NSFileManager defaultManager] fileExistsAtPath:[homeDir stringByAppendingString:ITUNES_MEDIA] isDirectory:&isDir]) { if (isDir) return [[homeDir stringByAppendingString:ITUNES_MEDIA] autorelease]; } if ([[NSFileManager defaultManager] fileExistsAtPath:[homeDir stringByAppendingString:ITUNES_MUSIC] isDirectory:&isDir]) { if (isDir) return [[homeDir stringByAppendingString:ITUNES_MEDIA] autorelease]; } // whatever. homedir is good enough return homeDir; }