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 | |
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
-rw-r--r-- | macosx/HBAppDelegate.m | 40 | ||||
-rw-r--r-- | macosx/HBUtilities.h | 4 | ||||
-rw-r--r-- | macosx/HBUtilities.m | 14 |
3 files changed, 57 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 diff --git a/macosx/HBUtilities.h b/macosx/HBUtilities.h index 2e073d17a..dac8e5085 100644 --- a/macosx/HBUtilities.h +++ b/macosx/HBUtilities.h @@ -19,6 +19,10 @@ + (NSString *)appSupportPath; /** + * Returns the url of the current <user>/Library/Application Support/HandBrake folder. + */ ++ (NSURL *)appSupportURL; +/** * Writes a message to standard error. * The message will show up in the output panel and in the activity log. * diff --git a/macosx/HBUtilities.m b/macosx/HBUtilities.m index c661b2a26..6a61e1ab1 100644 --- a/macosx/HBUtilities.m +++ b/macosx/HBUtilities.m @@ -30,6 +30,20 @@ return appSupportPath; } ++ (NSURL *)appSupportURL +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSURL *appSupportURL = [[[fileManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] + firstObject] URLByAppendingPathComponent:@"HandBrake"]; + + if (![fileManager fileExistsAtPath:appSupportURL.path]) + { + [fileManager createDirectoryAtPath:appSupportURL.path withIntermediateDirectories:YES attributes:nil error:NULL]; + } + + return appSupportURL; +} + + (void)writeToActivityLog:(const char *)format, ... { va_list args; |