diff options
author | ritsuka <[email protected]> | 2015-02-21 07:28:48 +0000 |
---|---|---|
committer | ritsuka <[email protected]> | 2015-02-21 07:28:48 +0000 |
commit | 53508d57a481fa1e67ac66541581f925dda7fd6e (patch) | |
tree | 0c12901fc8489ede0a4a24792225681e1d7cb40d /macosx/HBAppDelegate.m | |
parent | 34c5f777ed3d5d15f9b805bfbda600c4ead7977c (diff) |
MacGui: add a preference to toggle the log cleanup. Use NSURL directly where possible.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6934 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBAppDelegate.m')
-rw-r--r-- | macosx/HBAppDelegate.m | 95 |
1 files changed, 58 insertions, 37 deletions
diff --git a/macosx/HBAppDelegate.m b/macosx/HBAppDelegate.m index 42c18435a..1a78e0815 100644 --- a/macosx/HBAppDelegate.m +++ b/macosx/HBAppDelegate.m @@ -89,26 +89,6 @@ // Get the number of HandBrake instances currently running NSUInteger instances = [NSRunningApplication runningApplicationsWithBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]].count; - // If we are a single instance it is safe to clean up the previews if there are any - // left over. This is a bit of a kludge but will prevent a build up of old instance - // live preview cruft. No danger of removing an active preview directory since they - // are created later in HBPreviewController if they don't exist at the moment a live - // preview encode is initiated. - if (instances == 1) - { - NSString *previewDirectory = [[HBUtilities appSupportPath] stringByAppendingPathComponent:@"Previews"]; - NSError *error = nil; - NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:previewDirectory error:&error]; - for (NSString *file in files) - { - BOOL result = [[NSFileManager defaultManager] removeItemAtPath:[previewDirectory stringByAppendingPathComponent:file] error:&error]; - if (result == NO && error) - { - [HBUtilities writeToActivityLog: "Could not remove existing preview at : %s", file.UTF8String]; - } - } - } - [self showMainWindow:self]; // Now we re-check the queue array to see if there are @@ -199,9 +179,22 @@ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"QueueWindowIsOpen"]) [self showQueueWindow:nil]; - // Remove encodes logs older than a month dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ - [self cleanEncodeLogs]; + // Remove encodes logs older than a month + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HBClearOldLogs"]) + { + [self cleanEncodeLogs]; + } + + // If we are a single instance it is safe to clean up the previews if there are any + // left over. This is a bit of a kludge but will prevent a build up of old instance + // live preview cruft. No danger of removing an active preview directory since they + // are created later in HBPreviewController if they don't exist at the moment a live + // preview encode is initiated. + if (instances == 1) + { + [self cleanPreviews]; + } }); } @@ -300,27 +293,55 @@ { NSURL *directoryUrl = [[HBUtilities appSupportURL] URLByAppendingPathComponent:@"EncodeLogs"]; - NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:directoryUrl - includingPropertiesForKeys:nil - options:NSDirectoryEnumerationSkipsSubdirectoryDescendants | - NSDirectoryEnumerationSkipsHiddenFiles | - NSDirectoryEnumerationSkipsPackageDescendants - error:NULL]; + if (directoryUrl) + { + NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:directoryUrl + includingPropertiesForKeys:nil + options:NSDirectoryEnumerationSkipsSubdirectoryDescendants | + NSDirectoryEnumerationSkipsHiddenFiles | + NSDirectoryEnumerationSkipsPackageDescendants + error:NULL]; - NSDate *limit = [NSDate dateWithTimeIntervalSinceNow: -(60 * 60 * 24 * 30)]; - NSFileManager *manager = [[NSFileManager alloc] init]; + NSDate *limit = [NSDate dateWithTimeIntervalSinceNow: -(60 * 60 * 24 * 30)]; + NSFileManager *manager = [[NSFileManager alloc] init]; - for (NSURL *fileURL in contents) - { - NSDate *creationDate = nil; - [fileURL getResourceValue:&creationDate forKey:NSURLCreationDateKey error:NULL]; - if ([creationDate isLessThan:limit]) + for (NSURL *fileURL in contents) { - [manager removeItemAtURL:fileURL error:NULL]; + NSDate *creationDate = nil; + [fileURL getResourceValue:&creationDate forKey:NSURLCreationDateKey error:NULL]; + if ([creationDate isLessThan:limit]) + { + [manager removeItemAtURL:fileURL error:NULL]; + } } + [manager release]; } +} - [manager release]; +- (void)cleanPreviews +{ + NSURL *previewDirectory = [[HBUtilities appSupportURL] URLByAppendingPathComponent:@"Previews"]; + + if (previewDirectory) + { + NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:previewDirectory + includingPropertiesForKeys:nil + options:NSDirectoryEnumerationSkipsSubdirectoryDescendants | + NSDirectoryEnumerationSkipsPackageDescendants + error:NULL]; + + NSFileManager *manager = [[NSFileManager alloc] init]; + for (NSURL *url in contents) + { + NSError *error = nil; + BOOL result = [manager removeItemAtURL:url error:&error]; + if (result == NO && error) + { + [HBUtilities writeToActivityLog: "Could not remove existing preview at : %s", url.lastPathComponent.UTF8String]; + } + } + [manager release]; + } } #pragma mark - Menu actions |