diff --git a/AppController.m b/AppController.m index 53190c8e..a0aebde3 100644 --- a/AppController.m +++ b/AppController.m @@ -134,26 +134,17 @@ - (instancetype)init { [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"ForceHLSBBCVideo"]; //Make sure Application Support folder exists - NSString *folder = @"~/Library/Application Support/Get iPlayer Automator/"; - folder = folder.stringByExpandingTildeInPath; - NSFileManager *fileManager = [NSFileManager defaultManager]; - if (![fileManager fileExistsAtPath:folder]) - { - [fileManager createDirectoryAtPath:folder withIntermediateDirectories:NO attributes:nil error:nil]; - } - [fileManager changeCurrentDirectoryPath:folder]; + NSString *appSupportDirectory = [[NSFileManager defaultManager] applicationSupportDirectory]; + [[NSFileManager defaultManager] changeCurrentDirectoryPath:appSupportDirectory]; //Install Plugins If Needed - NSString *pluginPath = [folder stringByAppendingPathComponent:@"plugins"]; - if (/*![fileManager fileExistsAtPath:pluginPath]*/TRUE) - { - [_logger addToLog:@"Installing/Updating Get_iPlayer Plugins..." :self]; - NSString *providedPath = [NSBundle mainBundle].bundlePath; - if ([fileManager fileExistsAtPath:pluginPath]) [fileManager removeItemAtPath:pluginPath error:NULL]; - providedPath = [providedPath stringByAppendingPathComponent:@"/Contents/Resources/plugins"]; - [fileManager copyItemAtPath:providedPath toPath:pluginPath error:nil]; - } - + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSString *pluginPath = [appSupportDirectory stringByAppendingPathComponent:@"plugins"]; + [_logger addToLog:@"Installing/Updating Get_iPlayer Plugins..." :self]; + NSString *providedPath = [NSBundle mainBundle].bundlePath; + if ([fileManager fileExistsAtPath:pluginPath]) [fileManager removeItemAtPath:pluginPath error:NULL]; + providedPath = [providedPath stringByAppendingPathComponent:@"/Contents/Resources/plugins"]; + [fileManager copyItemAtPath:providedPath toPath:pluginPath error:nil]; //Initialize Arguments _getiPlayerPath = [[NSString alloc] initWithString:[NSBundle mainBundle].bundlePath]; @@ -192,19 +183,14 @@ - (void)awakeFromNib //Read Queue & Series-Link from File NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *folder = @"~/Library/Application Support/Get iPlayer Automator/"; - folder = folder.stringByExpandingTildeInPath; - if ([fileManager fileExistsAtPath: folder] == NO) - { - [fileManager createDirectoryAtPath:folder withIntermediateDirectories:NO attributes:nil error:nil]; - } + NSString *appSupportFolder = [[NSFileManager defaultManager] applicationSupportDirectory]; // remove obsolete cache files - [fileManager removeItemAtPath:[folder stringByAppendingPathComponent:@"ch4.cache"] error:nil]; - [fileManager removeItemAtPath:[folder stringByAppendingPathComponent:@"podcast.cache"] error:nil]; + [fileManager removeItemAtPath:[appSupportFolder stringByAppendingPathComponent:@"ch4.cache"] error:nil]; + [fileManager removeItemAtPath:[appSupportFolder stringByAppendingPathComponent:@"podcast.cache"] error:nil]; NSString *filename = @"Queue.automatorqueue"; - NSString *filePath = [folder stringByAppendingPathComponent:filename]; + NSString *filePath = [appSupportFolder stringByAppendingPathComponent:filename]; NSDictionary * rootObject; @try @@ -229,7 +215,7 @@ - (void)awakeFromNib //Read Format Preferences filename = @"Formats.automatorqueue"; - filePath = [folder stringByAppendingPathComponent:filename]; + filePath = [appSupportFolder stringByAppendingPathComponent:filename]; @try { @@ -261,7 +247,7 @@ - (void)awakeFromNib } filename = @"ITVFormats.automator"; - filePath = [folder stringByAppendingPathComponent:filename]; + filePath = [appSupportFolder stringByAppendingPathComponent:filename]; @try { rootObject = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath]; [_itvFormatController addObjects:[rootObject valueForKey:@"itvFormats"]]; @@ -1656,16 +1642,9 @@ - (void)saveAppData } } - NSFileManager *fileManager = [NSFileManager defaultManager]; - - NSString *folder = @"~/Library/Application Support/Get iPlayer Automator/"; - folder = folder.stringByExpandingTildeInPath; - if ([fileManager fileExistsAtPath: folder] == NO) - { - [fileManager createDirectoryAtPath:folder withIntermediateDirectories:NO attributes:nil error:nil]; - } + NSString *appSupportFolder = [[NSFileManager defaultManager] applicationSupportDirectory]; NSString *filename = @"Queue.automatorqueue"; - NSString *filePath = [folder stringByAppendingPathComponent:filename]; + NSString *filePath = [appSupportFolder stringByAppendingPathComponent:filename]; NSMutableDictionary * rootObject; rootObject = [NSMutableDictionary dictionary]; @@ -1676,7 +1655,7 @@ - (void)saveAppData [NSKeyedArchiver archiveRootObject: rootObject toFile: filePath]; filename = @"Formats.automatorqueue"; - filePath = [folder stringByAppendingPathComponent:filename]; + filePath = [appSupportFolder stringByAppendingPathComponent:filename]; rootObject = [NSMutableDictionary dictionary]; @@ -1685,7 +1664,7 @@ - (void)saveAppData [NSKeyedArchiver archiveRootObject:rootObject toFile:filePath]; filename = @"ITVFormats.automator"; - filePath = [folder stringByAppendingPathComponent:filename]; + filePath = [appSupportFolder stringByAppendingPathComponent:filename]; rootObject = [NSMutableDictionary dictionary]; rootObject[@"itvFormats"] = _itvFormatController.arrangedObjects; [NSKeyedArchiver archiveRootObject:rootObject toFile:filePath]; diff --git a/BBCDownload.m b/BBCDownload.m index 91a790ff..9685fdd2 100644 --- a/BBCDownload.m +++ b/BBCDownload.m @@ -95,12 +95,7 @@ - (instancetype)initWithProgramme:(Programme *)tempShow tvFormats:(NSArray *)tvF //We don't want this to refresh now! NSString *cacheExpiryArg = @"-e604800000000"; - NSString *appSupportFolder = (@"~/Library/Application Support/Get iPlayer Automator/").stringByExpandingTildeInPath; - NSFileManager *fileManager = [NSFileManager defaultManager]; - if (![fileManager fileExistsAtPath: appSupportFolder]) - { - [fileManager createDirectoryAtPath:appSupportFolder withIntermediateDirectories:NO attributes:nil error:nil]; - } + NSString *appSupportFolder = [[NSFileManager defaultManager] applicationSupportDirectory]; _profileDirArg = [[NSString alloc] initWithFormat:@"--profile-dir=%@", appSupportFolder]; //Add Arguments that can't be NULL diff --git a/DownloadHistoryController.m b/DownloadHistoryController.m index b01d8adc..ad638814 100644 --- a/DownloadHistoryController.m +++ b/DownloadHistoryController.m @@ -9,6 +9,7 @@ #import "DownloadHistoryController.h" #import "DownloadHistoryEntry.h" #import "Programme.h" +#import "NSFileManager+DirectoryLocations.h" @implementation DownloadHistoryController @@ -25,8 +26,8 @@ - (void)readHistory:(id)sender if ([historyArrayController.arrangedObjects count] > 0) [historyArrayController removeObjectsAtArrangedObjectIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [historyArrayController.arrangedObjects count])]]; - NSString *historyFilePath = @"~/Library/Application Support/Get iPlayer Automator/download_history"; - NSFileHandle *historyFile = [NSFileHandle fileHandleForReadingAtPath:historyFilePath.stringByExpandingTildeInPath]; + NSString *historyFilePath = [[[NSFileManager defaultManager] applicationSupportDirectory] stringByAppendingPathComponent:@"download_history"]; + NSFileHandle *historyFile = [NSFileHandle fileHandleForReadingAtPath:historyFilePath]; NSData *historyFileData = [historyFile readDataToEndOfFile]; NSString *historyFileInfo = [[NSString alloc] initWithData:historyFileData encoding:NSUTF8StringEncoding]; @@ -87,8 +88,7 @@ - (IBAction)writeHistory:(id)sender { [historyString appendFormat:@"%@\n", [entry entryString]]; } - NSString *historyPath = @"~/Library/Application Support/Get iPlayer Automator/download_history"; - historyPath = historyPath.stringByExpandingTildeInPath; + NSString *historyPath = [[[NSFileManager defaultManager] applicationSupportDirectory] stringByAppendingPathComponent:@"download_history"]; NSData *historyData = [historyString dataUsingEncoding:NSUTF8StringEncoding]; NSFileManager *fileManager = [NSFileManager defaultManager]; if (![fileManager fileExistsAtPath:historyPath]) diff --git a/LogController.m b/LogController.m index 3a85de7c..a641fb5e 100644 --- a/LogController.m +++ b/LogController.m @@ -7,6 +7,7 @@ // #import "LogController.h" +#import "NSFileManager+DirectoryLocations.h" @implementation LogController @@ -19,8 +20,8 @@ - (instancetype)init NSString *initialLog = [NSString stringWithFormat:@"Get iPlayer Automator %@ Initialized.", version]; [self addToLog:initialLog :nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addToLogNotification:) name:@"AddToLog" object:nil]; - - NSString *filePath = (@"~/Library/Application Support/Get iPlayer Automator/log.txt").stringByExpandingTildeInPath; + NSString *filePath = [[[NSFileManager defaultManager] applicationSupportDirectory] stringByAppendingPathComponent:@"log.txt"]; + [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil]; diff --git a/Programme.m b/Programme.m index df0a34e6..957e0b1e 100644 --- a/Programme.m +++ b/Programme.m @@ -202,7 +202,7 @@ -(void)proxyRetrievalFinished:(id)sender proxyDict:(NSDictionary *)proxyDict _pipe = [[NSPipe alloc] init]; _metadataTask.launchPath = @"/usr/bin/perl"; - NSString *profileDirPath = [@"~/Library/Application Support/Get iPlayer Automator/" stringByExpandingTildeInPath]; + NSString *profileDirPath = [[NSFileManager defaultManager] applicationSupportDirectory]; NSString *profileArg = [NSString stringWithFormat:@"--profile-dir=%@", profileDirPath]; NSMutableArray *args = [NSMutableArray arrayWithArray:@[[[NSBundle mainBundle] pathForResource:@"get_iplayer" ofType:nil],