12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //
- // SKDocumentController.m
- // PDF Reader Pro
- //
- // Created by lizhe on 2024/2/23.
- //
- #import "SKDocumentController.h"
- #import "SKAlias.h"
- NSString *SKDocumentSetupAliasKey = @"_BDAlias";
- NSString *SKDocumentSetupFileNameKey = @"fileName";
- @implementation SKDocumentController
- - (id)openDocumentWithSetup:(NSDictionary *)setup error:(NSError **)outError {
- id document = nil;
- NSURL *fileURL = [[SKAlias aliasWithData:[setup objectForKey:SKDocumentSetupAliasKey]] fileURL];
- if (fileURL == nil && [setup objectForKey:SKDocumentSetupFileNameKey])
- fileURL = [NSURL fileURLWithPath:[setup objectForKey:SKDocumentSetupFileNameKey]];
- if (fileURL && [fileURL checkResourceIsReachableAndReturnError:NULL] && NO == [self isTrashedFileURL:fileURL]) {
- if ((document = [self openDocumentWithContentsOfURL:fileURL display:NO error:outError])) {
- // [document applySetup:setup];
- [document showWindows];
- }
- } else if (outError) {
- *outError = [NSError errorWithDomain:@"SKDocumentErrorDomain" code:2 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to load file", @"Error description"), NSLocalizedDescriptionKey, nil]];
- }
- return document;
- }
- - (BOOL)isTrashedFileURL:(NSURL *)url {
- NSCParameterAssert([url isFileURL]);
- FSRef fileRef;
- Boolean result = false;
- if (CFURLGetFSRef((CFURLRef)url, &fileRef)) {
- FSDetermineIfRefIsEnclosedByFolder(0, kTrashFolderType, &fileRef, &result);
- if (result == false)
- FSDetermineIfRefIsEnclosedByFolder(0, kSystemTrashFolderType, &fileRef, &result);
- }
- return result;
- }
- - (Class)documentClassForContentsOfURL:(NSURL *)inAbsoluteURL {
- return [self documentClassForType:[self typeForContentsOfURL:inAbsoluteURL error:NULL]];
- }
- @end
|