diff options
author | ritsuka <[email protected]> | 2015-02-20 12:23:27 +0000 |
---|---|---|
committer | ritsuka <[email protected]> | 2015-02-20 12:23:27 +0000 |
commit | 34c5f777ed3d5d15f9b805bfbda600c4ead7977c (patch) | |
tree | ccc88183f7624f58f3fc80fee8a1e3dad1f19d94 /macosx/HBAppDelegate.m | |
parent | 2fdcbaa06d9ab500077cb4831d1846642f9eca4b (diff) |
MacGui: remove logs older than a month in the EncodeLogs folder.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6933 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBAppDelegate.m')
-rw-r--r-- | macosx/HBAppDelegate.m | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/macosx/HBAppDelegate.m b/macosx/HBAppDelegate.m index 2d8259b22..42c18435a 100644 --- a/macosx/HBAppDelegate.m +++ b/macosx/HBAppDelegate.m @@ -54,7 +54,7 @@ [HBUtilities writeToActivityLog: "%s", versionStringFull.UTF8String]; // we init the HBPresetsManager - NSURL *presetsURL = [NSURL fileURLWithPath:[[HBUtilities appSupportPath] stringByAppendingPathComponent:@"UserPresets.plist"]]; + NSURL *presetsURL = [[HBUtilities appSupportURL] URLByAppendingPathComponent:@"UserPresets.plist"]; _presetsManager = [[HBPresetsManager alloc] initWithURL:presetsURL]; _queueController = [[HBQueueController alloc] init]; @@ -198,6 +198,11 @@ // Open queue window now if it was visible when HB was closed 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]; + }); } - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app @@ -285,6 +290,39 @@ return YES; } +#pragma mark - Clean ups + +/** + * Clears the EncodeLogs folder, removes the logs + * older than a month. + */ +- (void)cleanEncodeLogs +{ + NSURL *directoryUrl = [[HBUtilities appSupportURL] URLByAppendingPathComponent:@"EncodeLogs"]; + + 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]; + + for (NSURL *fileURL in contents) + { + NSDate *creationDate = nil; + [fileURL getResourceValue:&creationDate forKey:NSURLCreationDateKey error:NULL]; + if ([creationDate isLessThan:limit]) + { + [manager removeItemAtURL:fileURL error:NULL]; + } + } + + [manager release]; +} + #pragma mark - Menu actions - (IBAction)rip:(id)sender |