summaryrefslogtreecommitdiffstats
path: root/macosx/HBUtilities.m
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2017-01-20 18:52:22 +0100
committerDamiano Galassi <[email protected]>2017-01-20 18:52:22 +0100
commita3d00959f42f940e8d3c2b73fb92a951cbf94472 (patch)
tree7085331974860d7771a3f6adaf1694383a1f064a /macosx/HBUtilities.m
parent40ec4ebaa2958b2549125dd525b6fcb2bd595d69 (diff)
MacGui: initial sandbox support. Added two new scheme RELEASE-SANDBOX and DEBUG-SANDBOX to build HandBrake with sandbox enabled.
Diffstat (limited to 'macosx/HBUtilities.m')
-rw-r--r--macosx/HBUtilities.m52
1 files changed, 40 insertions, 12 deletions
diff --git a/macosx/HBUtilities.m b/macosx/HBUtilities.m
index bf0c8bfa8..a0db9927b 100644
--- a/macosx/HBUtilities.m
+++ b/macosx/HBUtilities.m
@@ -53,6 +53,41 @@
va_end(args);
}
++ (nullable NSURL *)URLFromBookmark:(NSData *)bookmark
+{
+ NSParameterAssert(bookmark);
+
+ NSError *error;
+ BOOL isStale;
+
+ NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
+
+ if (error)
+ {
+ NSString *error_message = [NSString stringWithFormat:@"Failed to resolved bookmark: %@", error];
+ [HBUtilities writeToActivityLog:"%s", error_message.UTF8String];
+ }
+
+ return isStale ? nil : url;
+}
+
++ (nullable NSData *)bookmarkFromURL:(NSURL *)url
+{
+ NSParameterAssert(url);
+
+ NSError *error;
+
+ NSData *bookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&error];
+
+ if (error)
+ {
+ NSString *error_message = [NSString stringWithFormat:@"Failed to create bookmark: %@", error];
+ [HBUtilities writeToActivityLog:"%s", error_message.UTF8String];
+ }
+
+ return bookmark;
+}
+
+ (NSString *)displayNameForURL:(NSURL *)URL
{
NSString *displayName = URL.lastPathComponent;
@@ -107,6 +142,7 @@
[HBUtilities writeToActivityLog:"not a known to package"];
}
}
+#ifndef __SANDBOX_ENABLED__
else
{
// path is not a package, so we call perform scan directly on our file
@@ -121,6 +157,7 @@
[HBUtilities writeToActivityLog:"trying to open a folder or file"];
}
}
+#endif
return mediaURL;
}
@@ -161,16 +198,8 @@
return extension;
}
-+ (NSURL *)destURLForJob:(HBJob *)job
++ (NSString *)defaultNameForJob:(HBJob *)job
{
- // Check to see if the last destination has been set,use if so, if not, use Desktop
- NSURL *destURL = [[NSUserDefaults standardUserDefaults] URLForKey:@"HBLastDestinationDirectory"];
- if (!destURL || ![[NSFileManager defaultManager] fileExistsAtPath:destURL.path])
- {
- destURL = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES) firstObject]
- isDirectory:YES];
- }
-
// Generate a new file name
NSString *fileName = job.title.name;
@@ -180,12 +209,11 @@
fileName = [self automaticNameForJob:job];
}
- destURL = [destURL URLByAppendingPathComponent:fileName];
// use the correct extension based on the container
NSString *ext = [self automaticExtForJob:job];
- destURL = [destURL URLByAppendingPathExtension:ext];
+ fileName = [fileName stringByAppendingPathExtension:ext];
- return destURL;
+ return fileName;
}
+ (NSString *)automaticNameForSource:(NSString *)sourceName