]> granicus.if.org Git - handbrake/commitdiff
CLI: use the presets from the sandbox container folder if they more recent.
authorDamiano Galassi <damiog@gmail.com>
Sun, 20 Oct 2019 10:30:58 +0000 (12:30 +0200)
committerDamiano Galassi <damiog@gmail.com>
Sun, 20 Oct 2019 10:30:58 +0000 (12:30 +0200)
libhb/platform/macosx/config.m
libhb/ports.c

index c30f34c4a5088122af27f0e8c837fce90a36ea6a..54c0df52e1b5e2c4f769c2c3d5c2b329bab90dda 100644 (file)
@@ -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;
     }
index 917da62b9807b65cfc7d5eb8fa3015760f28619f..cfdaf9ddc7d1dddfed711611698db7e9e936711c 100644 (file)
@@ -573,7 +573,7 @@ void hb_get_user_config_directory( char path[512] )
         return;
     }
 #elif defined( __APPLE__ )
-    if (osx_get_user_config_directory(path) == 0)
+    if (macOS_get_user_config_directory(path) == 0)
     {
         return;
     }