summaryrefslogtreecommitdiffstats
path: root/libhb/platform/macosx
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2019-10-20 12:30:58 +0200
committerDamiano Galassi <[email protected]>2019-10-20 12:30:58 +0200
commit2b0ae7e36e3b8281d1c7396fe4f1c11d8583b156 (patch)
treef85b08d8dcc9aa9b29d6d5ca1e05ec7e4c2e2451 /libhb/platform/macosx
parent9901594fa20c59984459b316740ea9b3ca49b824 (diff)
CLI: use the presets from the sandbox container folder if they more recent.
Diffstat (limited to 'libhb/platform/macosx')
-rw-r--r--libhb/platform/macosx/config.m43
1 files changed, 37 insertions, 6 deletions
diff --git a/libhb/platform/macosx/config.m b/libhb/platform/macosx/config.m
index c30f34c4a..54c0df52e 100644
--- a/libhb/platform/macosx/config.m
+++ b/libhb/platform/macosx/config.m
@@ -1,18 +1,49 @@
#import <Foundation/Foundation.h>
-int osx_get_user_config_directory(char path[512])
+static NSURL * macOS_last_modified_url(NSURL *url1, NSURL* url2)
+{
+ NSString *presetFile = @"HandBrake/UserPresets.json";
+
+ NSURL *presetsUrl1 = [url1 URLByAppendingPathComponent:presetFile isDirectory:NO];
+ NSURL *presetsUrl2 = [url2 URLByAppendingPathComponent:presetFile isDirectory:NO];
+
+ NSDate *date1 = nil;
+ [presetsUrl1 getResourceValue:&date1 forKey:NSURLAttributeModificationDateKey error:nil];
+
+ NSDate *date2 = nil;
+ [presetsUrl2 getResourceValue:&date2 forKey:NSURLAttributeModificationDateKey error:nil];
+
+ return presetsUrl2 && (date1 == nil || [date2 compare:date1] == NSOrderedDescending) ? url2 : url1;
+}
+
+static NSURL * macOS_get_application_support_url()
+{
+ NSFileManager *fileManager = NSFileManager.defaultManager;
+ NSArray<NSURL *> *applicationSupportUrls = [fileManager URLsForDirectory:NSApplicationSupportDirectory
+ inDomains:NSUserDomainMask];
+
+ NSURL *appSupportURL = applicationSupportUrls.firstObject;
+
+ NSArray<NSURL *> *libraryUrls = [fileManager URLsForDirectory:NSLibraryDirectory
+ inDomains:NSUserDomainMask];
+ NSString *sandboxPath = @"Containers/fr.handbrake.HandBrake/Data/Library/Application Support";
+ NSURL *sandboxAppSupportURL = [libraryUrls.firstObject URLByAppendingPathComponent:sandboxPath isDirectory:YES];
+
+ return macOS_last_modified_url(appSupportURL, sandboxAppSupportURL);
+}
+
+int macOS_get_user_config_directory(char path[512])
{
@autoreleasepool
{
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
- NSUserDomainMask, YES);
- NSString *dir = paths.firstObject;
- if (dir.UTF8String == nil)
+ NSURL *url = macOS_get_application_support_url();
+
+ if (url == nil)
{
return -1;
}
- strncpy(path, dir.UTF8String, 511);
+ strncpy(path, url.fileSystemRepresentation, 511);
path[511] = 0;
return 0;
}