summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--macosx/HBAppDelegate.m40
-rw-r--r--macosx/HBUtilities.h4
-rw-r--r--macosx/HBUtilities.m14
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;