From 120b19f8e6a41e7a3a7ef2a99ca39c8a8d4fd75f Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Mon, 23 Feb 2026 02:35:24 +0800 Subject: [PATCH] Cocoa compat --- a/libhb/platform/macosx/config.m +++ b/libhb/platform/macosx/config.m @@ -13,47 +13,93 @@ { NSString *presetFile = @"HandBrake/UserPresets.json"; - NSURL *presetsUrl1 = [url1 URLByAppendingPathComponent:presetFile isDirectory:NO]; - NSURL *presetsUrl2 = [url2 URLByAppendingPathComponent:presetFile isDirectory:NO]; + NSURL *presetsUrl1 = [[url1 URLByAppendingPathComponent:@"HandBrake"] + URLByAppendingPathComponent:@"UserPresets.json"]; + NSURL *presetsUrl2 = [[url2 URLByAppendingPathComponent:@"HandBrake"] + URLByAppendingPathComponent:@"UserPresets.json"]; NSDate *date1 = nil; - [presetsUrl1 getResourceValue:&date1 forKey:NSURLAttributeModificationDateKey error:nil]; + NSError *error1 = nil; + + NSString *path1 = [presetsUrl1 path]; + if (path1 != nil) + { + NSDictionary *attrs1 = [[NSFileManager defaultManager] attributesOfItemAtPath:path1 error:&error1]; + if (attrs1 != nil) + { + date1 = [attrs1 objectForKey:NSFileModificationDate]; + } + } NSDate *date2 = nil; - [presetsUrl2 getResourceValue:&date2 forKey:NSURLAttributeModificationDateKey error:nil]; + NSError *error2 = nil; + NSString *path2 = [presetsUrl2 path]; + if (path2 != nil) + { + NSDictionary *attrs2 = [[NSFileManager defaultManager] attributesOfItemAtPath:path2 error:&error2]; + if (attrs2 != nil) + { + date2 = [attrs2 objectForKey:NSFileModificationDate]; + } + } - return presetsUrl2 && (date1 == nil || [date2 compare:date1] == NSOrderedDescending) ? url2 : url1; + if (presetsUrl2 != nil && (date1 == nil || [date2 compare:date1] == NSOrderedDescending)) + { + return url2; + } + return url1; } static NSURL * macOS_get_application_support_url() { - NSFileManager *fileManager = NSFileManager.defaultManager; - NSArray *applicationSupportUrls = [fileManager URLsForDirectory:NSApplicationSupportDirectory - inDomains:NSUserDomainMask]; - - NSURL *appSupportURL = applicationSupportUrls.firstObject; - - NSArray *libraryUrls = [fileManager URLsForDirectory:NSLibraryDirectory - inDomains:NSUserDomainMask]; - NSString *sandboxPath = @"Containers/fr.handbrake.HandBrake/Data/Library/Application Support"; - NSURL *sandboxAppSupportURL = [libraryUrls.firstObject URLByAppendingPathComponent:sandboxPath isDirectory:YES]; + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSArray *applicationSupportUrls = [fileManager URLsForDirectory:NSApplicationSupportDirectory + inDomains:NSUserDomainMask]; + + NSURL *appSupportURL = [applicationSupportUrls objectAtIndex:0]; + + NSArray *libraryUrls = [fileManager URLsForDirectory:NSLibraryDirectory + inDomains:NSUserDomainMask]; + + NSURL *libraryURL = [libraryUrls objectAtIndex:0]; + NSURL *sandboxAppSupportURL = [[[[[libraryURL + URLByAppendingPathComponent:@"Containers"] + URLByAppendingPathComponent:@"fr.handbrake.HandBrake"] + URLByAppendingPathComponent:@"Data"] + URLByAppendingPathComponent:@"Library"] + URLByAppendingPathComponent:@"Application Support"]; return macOS_last_modified_url(appSupportURL, sandboxAppSupportURL); } int macOS_get_user_config_directory(char path[512]) { - @autoreleasepool + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + NSURL *url = macOS_get_application_support_url(); + if (url == nil) { - NSURL *url = macOS_get_application_support_url(); + [pool release]; + return -1; + } - if (url == nil) - { - return -1; - } + NSString *urlPath = [url path]; + if (urlPath == nil) + { + [pool release]; + return -1; + } - strncpy(path, url.fileSystemRepresentation, 511); - path[511] = 0; - return 0; + const char *cPath = [urlPath UTF8String]; + if (cPath == NULL) + { + [pool release]; + return -1; } + + strncpy(path, cPath, 511); + path[511] = 0; + + [pool release]; + return 0; }