From 2f6216675bdb84ecef79a8b604b4127829f262a8 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Mon, 29 Jan 2024 10:50:50 -0700 Subject: [PATCH] Move some category extensions to Swift extensions. --- Boxer.xcodeproj/project.pbxproj | 20 +++--- .../BXAppController+BXGamesFolder.m | 2 +- Boxer/BXDrive+BXDriveArchiving.m | 2 +- Boxer/BXImportSession.m | 2 + .../BXDocumentationBrowser.m | 2 +- .../ADBToolkit/NSURL+ADBAliasHelpers.h | 49 ------------- .../ADBToolkit/NSURL+ADBAliasHelpers.m | 69 ------------------- .../ADBToolkit/NSURL+ADBFilesystemHelpers.h | 3 - .../ADBToolkit/NSURL+ADBFilesystemHelpers.m | 13 ---- .../ADBToolkit/NSURL+ADBQuickLookHelpers.h | 40 ----------- .../ADBToolkit/NSURL+ADBQuickLookHelpers.m | 55 --------------- .../ADBToolkit/URL+ADBAliasHelpers.swift | 11 +++ .../ADBToolkit/URL+ADBFilesystemHelpers.swift | 13 +++- .../ADBToolkit/URL+ADBQuickLookHelpers.swift | 19 +++++ 14 files changed, 53 insertions(+), 247 deletions(-) delete mode 100644 Other Sources/ADBToolkit/NSURL+ADBAliasHelpers.h delete mode 100644 Other Sources/ADBToolkit/NSURL+ADBAliasHelpers.m delete mode 100644 Other Sources/ADBToolkit/NSURL+ADBQuickLookHelpers.h delete mode 100644 Other Sources/ADBToolkit/NSURL+ADBQuickLookHelpers.m diff --git a/Boxer.xcodeproj/project.pbxproj b/Boxer.xcodeproj/project.pbxproj index 09d7a50ad..273568a67 100644 --- a/Boxer.xcodeproj/project.pbxproj +++ b/Boxer.xcodeproj/project.pbxproj @@ -91,6 +91,10 @@ 55998D3025F6EDC400581095 /* ne2000.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 55998D2625F6EDC300581095 /* ne2000.cpp */; }; 55998D3525F6EF5F00581095 /* libpcap.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55998D3425F6EF3F00581095 /* libpcap.tbd */; }; 55998D3725F6EF7900581095 /* libpcap.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55998D3425F6EF3F00581095 /* libpcap.tbd */; }; + 55A76C5E2B678C0700DEF246 /* URL+ADBAliasHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55419B73255A7FFA00A779B2 /* URL+ADBAliasHelpers.swift */; }; + 55A76C5F2B678C0700DEF246 /* URL+ADBFilesystemHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 551B793625593573006C57CE /* URL+ADBFilesystemHelpers.swift */; }; + 55A76C602B678C0700DEF246 /* URL+ADBQuickLookHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55419B67255A2F1400A779B2 /* URL+ADBQuickLookHelpers.swift */; }; + 55A76C612B6794DB00DEF246 /* URL+ADBQuickLookHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55419B67255A2F1400A779B2 /* URL+ADBQuickLookHelpers.swift */; }; 55B22BA21A1BD9760007665E /* Bundler.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 55B22BA11A1BD9760007665E /* Bundler.xcassets */; }; 55BBA4E9235EE141007AE319 /* NSError+ADBErrorHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55BBA4E8235EE141007AE319 /* NSError+ADBErrorHelpers.swift */; }; 55BBA4EA235EE141007AE319 /* NSError+ADBErrorHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55BBA4E8235EE141007AE319 /* NSError+ADBErrorHelpers.swift */; }; @@ -203,7 +207,6 @@ 9F125C4016983A9D003B5B2B /* BXDocumentationPanelController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F125C3F16983A9D003B5B2B /* BXDocumentationPanelController.m */; }; 9F125C4116983F0C003B5B2B /* BXDocumentationBrowser.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F631D7B16947AE900AD06C4 /* BXDocumentationBrowser.m */; }; 9F12F97C144875F400FC9645 /* DummyCD.iso in Resources */ = {isa = PBXBuildFile; fileRef = 9F12F97B144875F400FC9645 /* DummyCD.iso */; }; - 9F13768A17020B2C00B9A359 /* NSURL+ADBAliasHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F13768917020B2C00B9A359 /* NSURL+ADBAliasHelpers.m */; }; 9F13F9D011F85E6F0069A02E /* NSFileManager+ADBTemporaryFiles.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F13F9CF11F85E6F0069A02E /* NSFileManager+ADBTemporaryFiles.m */; }; 9F160DE21236952600F8768E /* Sample Games in Resources */ = {isa = PBXBuildFile; fileRef = 9F160BD91236952400F8768E /* Sample Games */; }; 9F160E711236B2A600F8768E /* BXAppController+BXGamesFolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F160E701236B2A600F8768E /* BXAppController+BXGamesFolder.m */; }; @@ -714,7 +717,6 @@ 9F9DF415153B058200233968 /* BXKeyBuffer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9F9DF414153B058200233968 /* BXKeyBuffer.mm */; }; 9F9E27D611F8C173003EE8F3 /* BXDrivePanelController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F9E27D511F8C173003EE8F3 /* BXDrivePanelController.m */; }; 9FA0C9E313D24FF3000F6FCB /* DDHidUsage+ADBUsageExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FA0C9E213D24FF3000F6FCB /* DDHidUsage+ADBUsageExtensions.m */; }; - 9FA0D0CC1694D62100CEF2EA /* NSURL+ADBQuickLookHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FA0D0CB1694D62100CEF2EA /* NSURL+ADBQuickLookHelpers.m */; }; 9FA1CF6813E5B44000416D74 /* BXMOMORacingControllerProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FA1CF6713E5B43F00416D74 /* BXMOMORacingControllerProfile.m */; }; 9FA2C09215C8409000380261 /* BXDOSWindowBackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FA2C09115C8409000380261 /* BXDOSWindowBackgroundView.m */; }; 9FA5D68311EB6CCC0012DFA5 /* ADBLineEnumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 9FA5D68211EB6CCC0012DFA5 /* ADBLineEnumerator.m */; }; @@ -1304,8 +1306,6 @@ 9F125C3E16983A9D003B5B2B /* BXDocumentationPanelController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BXDocumentationPanelController.h; path = "Boxer/Documentation Panel/BXDocumentationPanelController.h"; sourceTree = SOURCE_ROOT; }; 9F125C3F16983A9D003B5B2B /* BXDocumentationPanelController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BXDocumentationPanelController.m; path = "Boxer/Documentation Panel/BXDocumentationPanelController.m"; sourceTree = SOURCE_ROOT; }; 9F12F97B144875F400FC9645 /* DummyCD.iso */ = {isa = PBXFileReference; lastKnownFileType = file; path = DummyCD.iso; sourceTree = ""; }; - 9F13768817020B2C00B9A359 /* NSURL+ADBAliasHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+ADBAliasHelpers.h"; sourceTree = ""; }; - 9F13768917020B2C00B9A359 /* NSURL+ADBAliasHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+ADBAliasHelpers.m"; sourceTree = ""; }; 9F13F9CE11F85E6F0069A02E /* NSFileManager+ADBTemporaryFiles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+ADBTemporaryFiles.h"; sourceTree = ""; }; 9F13F9CF11F85E6F0069A02E /* NSFileManager+ADBTemporaryFiles.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+ADBTemporaryFiles.m"; sourceTree = ""; }; 9F160BD91236952400F8768E /* Sample Games */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "Sample Games"; sourceTree = ""; }; @@ -1829,8 +1829,6 @@ 9F9E27D511F8C173003EE8F3 /* BXDrivePanelController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BXDrivePanelController.m; sourceTree = ""; }; 9FA0C9E113D24FF3000F6FCB /* DDHidUsage+ADBUsageExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DDHidUsage+ADBUsageExtensions.h"; sourceTree = ""; }; 9FA0C9E213D24FF3000F6FCB /* DDHidUsage+ADBUsageExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "DDHidUsage+ADBUsageExtensions.m"; sourceTree = ""; }; - 9FA0D0CA1694D62100CEF2EA /* NSURL+ADBQuickLookHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+ADBQuickLookHelpers.h"; sourceTree = ""; }; - 9FA0D0CB1694D62100CEF2EA /* NSURL+ADBQuickLookHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+ADBQuickLookHelpers.m"; sourceTree = ""; }; 9FA1CF6713E5B43F00416D74 /* BXMOMORacingControllerProfile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BXMOMORacingControllerProfile.m; sourceTree = ""; }; 9FA2C09015C8409000380261 /* BXDOSWindowBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BXDOSWindowBackgroundView.h; sourceTree = ""; }; 9FA2C09115C8409000380261 /* BXDOSWindowBackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BXDOSWindowBackgroundView.m; sourceTree = ""; }; @@ -3541,10 +3539,6 @@ 9FC8F50B10934F3400AD6307 /* NSString+ADBPaths.m */, 9FB60E8C15C5552F00CD0D63 /* NSURL+ADBFilesystemHelpers.h */, 9FB60E8D15C5552F00CD0D63 /* NSURL+ADBFilesystemHelpers.m */, - 9FA0D0CA1694D62100CEF2EA /* NSURL+ADBQuickLookHelpers.h */, - 9FA0D0CB1694D62100CEF2EA /* NSURL+ADBQuickLookHelpers.m */, - 9F13768817020B2C00B9A359 /* NSURL+ADBAliasHelpers.h */, - 9F13768917020B2C00B9A359 /* NSURL+ADBAliasHelpers.m */, 9F573C580F8E18B10089D8B7 /* NSWorkspace+ADBMountedVolumes.h */, 9F573C590F8E18B10089D8B7 /* NSWorkspace+ADBMountedVolumes.m */, 9F76D1B710CA9DFB00C3B081 /* NSWorkspace+ADBFileTypes.h */, @@ -4416,7 +4410,6 @@ 9F201E381657DB7F0086F1BB /* ADBUserNotificationDispatcher.m in Sources */, 9F4B1AFA165C122F001AE063 /* BXDriveItem.m in Sources */, 9FFE7104165E931600F99C3D /* BXJoystickItem.m in Sources */, - 9FA0D0CC1694D62100CEF2EA /* NSURL+ADBQuickLookHelpers.m in Sources */, 9F125C4016983A9D003B5B2B /* BXDocumentationPanelController.m in Sources */, 9F125C4116983F0C003B5B2B /* BXDocumentationBrowser.m in Sources */, 9F6463F716C67415008B65BF /* BXOutputBinding.m in Sources */, @@ -4424,10 +4417,10 @@ 9F35F3E916CFBB700093CF45 /* NSFileManager+ADBUniqueFilenames.m in Sources */, 9F80E7FF16DA3170001C3162 /* ADBFileHandle.m in Sources */, 9F693D5E16DD40DD00CCEA7C /* ADBEnumerationHelpers.m in Sources */, + 55A76C5F2B678C0700DEF246 /* URL+ADBFilesystemHelpers.swift in Sources */, 9F38B38B16DFB1960050AB15 /* ADBLocalFilesystem.m in Sources */, 9F1E8CDA16E16C0400F1C908 /* ADBScanOperation.m in Sources */, 9F1E8CDE16E16EB800F1C908 /* ADBMountableImage.m in Sources */, - 9F13768A17020B2C00B9A359 /* NSURL+ADBAliasHelpers.m in Sources */, 9F20ADD01702E87B007263C8 /* BXDrive+BXDriveArchiving.m in Sources */, 9F77217612B38C4400072AE8 /* callback.cpp in Sources */, 9F77217712B38C4400072AE8 /* core_dyn_x86.cpp in Sources */, @@ -4484,6 +4477,7 @@ 9F7721A212B38C4400072AE8 /* render_scalers.cpp in Sources */, 9F7721A612B38C4400072AE8 /* adlib.cpp in Sources */, 9F7721A712B38C4400072AE8 /* cmos.cpp in Sources */, + 55A76C602B678C0700DEF246 /* URL+ADBQuickLookHelpers.swift in Sources */, 9F7721A812B38C4400072AE8 /* dbopl.cpp in Sources */, 9F7721A912B38C4400072AE8 /* disney.cpp in Sources */, 55F0B78826ABFEE80077E58C /* Integrator6581.cpp in Sources */, @@ -4518,6 +4512,7 @@ 9F7721C412B38C4400072AE8 /* vga_attr.cpp in Sources */, 9F7721C512B38C4400072AE8 /* vga_crtc.cpp in Sources */, 9F7721C612B38C4400072AE8 /* vga_dac.cpp in Sources */, + 55A76C5E2B678C0700DEF246 /* URL+ADBAliasHelpers.swift in Sources */, 9F7721C712B38C4400072AE8 /* vga_draw.cpp in Sources */, 9F7721C812B38C4400072AE8 /* vga_gfx.cpp in Sources */, 9F7721C912B38C4400072AE8 /* vga_memory.cpp in Sources */, @@ -4865,6 +4860,7 @@ 9F458D9D15D83B8C00DF9102 /* BXLaunchPanelController.m in Sources */, 9F458D9E15D83B9000DF9102 /* BXDOSWindowBackgroundView.m in Sources */, 9F57684A15DA27A300B50500 /* BXHUDSpinningProgressIndicator.m in Sources */, + 55A76C612B6794DB00DEF246 /* URL+ADBQuickLookHelpers.swift in Sources */, 9FDFB46E15DBA38F004EA615 /* BXStandaloneAboutController.m in Sources */, 5514501B24BE81E00002CE28 /* SDL_sound.c in Sources */, 55574806208FA8040045E635 /* ymdeltat.cpp in Sources */, diff --git a/Boxer/Application Delegate/BXAppController+BXGamesFolder.m b/Boxer/Application Delegate/BXAppController+BXGamesFolder.m index ee166853c..c551e97f3 100644 --- a/Boxer/Application Delegate/BXAppController+BXGamesFolder.m +++ b/Boxer/Application Delegate/BXAppController+BXGamesFolder.m @@ -20,8 +20,8 @@ #import "BXShelfAppearanceOperation.h" #import "NSString+ADBPaths.h" #import "NSURL+ADBFilesystemHelpers.h" -#import "NSURL+ADBAliasHelpers.h" #import "ADBAppKitVersionHelpers.h" +#import "Boxer-Swift.h" #pragma mark - Constants diff --git a/Boxer/BXDrive+BXDriveArchiving.m b/Boxer/BXDrive+BXDriveArchiving.m index 83e9f48cc..66670ead3 100644 --- a/Boxer/BXDrive+BXDriveArchiving.m +++ b/Boxer/BXDrive+BXDriveArchiving.m @@ -7,8 +7,8 @@ #import "BXDrive+BXDriveArchiving.h" #import "BXDrivePrivate.h" -#import "NSURL+ADBAliasHelpers.h" #import "ADBFilesystem.h" +#import "Boxer-Swift.h" /// Used when decoding drive records from previous Boxer versions, diff --git a/Boxer/BXImportSession.m b/Boxer/BXImportSession.m index 94ddb5936..f7b97a917 100644 --- a/Boxer/BXImportSession.m +++ b/Boxer/BXImportSession.m @@ -59,6 +59,8 @@ #import "ADBUserNotificationDispatcher.h" +#import "Boxer-Swift.h" + #pragma mark - #pragma mark Private method declarations diff --git a/Boxer/Documentation Panel/BXDocumentationBrowser.m b/Boxer/Documentation Panel/BXDocumentationBrowser.m index 1e16d8356..9ef5d9126 100644 --- a/Boxer/Documentation Panel/BXDocumentationBrowser.m +++ b/Boxer/Documentation Panel/BXDocumentationBrowser.m @@ -8,12 +8,12 @@ #import "BXDocumentationBrowser.h" #import "BXSession.h" #import "BXGamebox.h" -#import "NSURL+ADBQuickLookHelpers.h" #import "BXBaseAppController.h" #import "NSView+ADBDrawingHelpers.h" #import "BXBaseAppController.h" #import "NSError+ADBErrorHelpers.h" #import "NSBezierPath+MCAdditions.h" +#import "Boxer-Swift.h" NS_ENUM(NSInteger) { BXDocumentationItemIcon = 1, diff --git a/Other Sources/ADBToolkit/NSURL+ADBAliasHelpers.h b/Other Sources/ADBToolkit/NSURL+ADBAliasHelpers.h deleted file mode 100644 index a1e2fa59f..000000000 --- a/Other Sources/ADBToolkit/NSURL+ADBAliasHelpers.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2013, Alun Bestor (alun.bestor@gmail.com) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#import - -NS_ASSUME_NONNULL_BEGIN - -/// The ADBAliasHelpers category extends NSURL with methods to simplify working with legacy -/// alias records from OS X 10.5 and below and converting them to modern 10.6 bookmarks. -@interface NSURL (ADBAliasHelpers) - -/// Returns 10.6 bookmark data converted from the specified Finder alias record. -/// Returns @c nil and populates @c outError if conversion failed. -+ (nullable NSData *) bookmarkDataFromAliasRecord: (NSData *)aliasRecord - error: (out NSError **)outError; - -/// Returns a URL resolved from the specified Finder alias record. -/// Directly equivalent to URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:. -+ (nullable NSURL*)URLByResolvingAliasRecord: (NSData *)aliasRecord - options: (NSURLBookmarkResolutionOptions)options - relativeToURL: (nullable NSURL *)relativeURL - bookmarkDataIsStale: (out BOOL * _Nullable)isStale - error: (out NSError **)outError; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Other Sources/ADBToolkit/NSURL+ADBAliasHelpers.m b/Other Sources/ADBToolkit/NSURL+ADBAliasHelpers.m deleted file mode 100644 index 14fb1f7a5..000000000 --- a/Other Sources/ADBToolkit/NSURL+ADBAliasHelpers.m +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2013, Alun Bestor (alun.bestor@gmail.com) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#import "NSURL+ADBAliasHelpers.h" - -@implementation NSURL (ADBAliasHelpers) - -+ (NSData *) bookmarkDataFromAliasRecord: (NSData *)aliasRecord - error: (out NSError **)outError -{ - CFDataRef bookmarkDataRef = CFURLCreateBookmarkDataFromAliasRecord(kCFAllocatorDefault, (__bridge CFDataRef)aliasRecord); - if (bookmarkDataRef) - { - return (NSData *)CFBridgingRelease(bookmarkDataRef); - } - else - { - if (outError) - { - *outError = [NSError errorWithDomain: NSCocoaErrorDomain - code: NSFileReadCorruptFileError - userInfo: nil]; - } - return nil; - } -} - -+ (id) URLByResolvingAliasRecord: (NSData *)aliasRecord - options: (NSURLBookmarkResolutionOptions)options - relativeToURL: (NSURL *)relativeURL - bookmarkDataIsStale: (out BOOL *)isStale - error: (out NSError **)outError -{ - NSData *bookmarkData = [self bookmarkDataFromAliasRecord: aliasRecord error: outError]; - if (bookmarkData) - { - return [NSURL URLByResolvingBookmarkData: bookmarkData - options: options - relativeToURL: relativeURL - bookmarkDataIsStale: isStale - error: outError]; - } - else return nil; -} - -@end diff --git a/Other Sources/ADBToolkit/NSURL+ADBFilesystemHelpers.h b/Other Sources/ADBToolkit/NSURL+ADBFilesystemHelpers.h index 469dfa288..7f20d375f 100644 --- a/Other Sources/ADBToolkit/NSURL+ADBFilesystemHelpers.h +++ b/Other Sources/ADBToolkit/NSURL+ADBFilesystemHelpers.h @@ -56,9 +56,6 @@ NS_ASSUME_NONNULL_BEGIN /// Returns an array containing this URL and every parent directory leading back to the root. @property (readonly, copy) NSArray *componentURLs; -/// An analogue for NSString stringsByAppendingPaths: -- (NSArray *) URLsByAppendingPaths: (NSArray *)paths; - @end diff --git a/Other Sources/ADBToolkit/NSURL+ADBFilesystemHelpers.m b/Other Sources/ADBToolkit/NSURL+ADBFilesystemHelpers.m index 9b382f05d..db62ab55f 100644 --- a/Other Sources/ADBToolkit/NSURL+ADBFilesystemHelpers.m +++ b/Other Sources/ADBToolkit/NSURL+ADBFilesystemHelpers.m @@ -127,19 +127,6 @@ - (NSArray *) componentURLs return [components copy]; } -- (NSArray *) URLsByAppendingPaths: (NSArray *)paths -{ - NSMutableArray *URLs = [NSMutableArray arrayWithCapacity: paths.count]; - - for (NSString *pathComponent in paths) - { - NSURL *URL = [self URLByAppendingPathComponent: pathComponent]; - [URLs addObject: URL]; - } - - return [URLs copy]; -} - @end @implementation NSURL (ADBResourceValues) diff --git a/Other Sources/ADBToolkit/NSURL+ADBQuickLookHelpers.h b/Other Sources/ADBToolkit/NSURL+ADBQuickLookHelpers.h deleted file mode 100644 index 0876d31ac..000000000 --- a/Other Sources/ADBToolkit/NSURL+ADBQuickLookHelpers.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2013, Alun Bestor (alun.bestor@gmail.com) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#import - -@interface NSURL (ADBQuickLookHelpers) - -/// Returns a QuickLook thumbnail for the file at this URL, or nil if no thumbnail could be generated. -/// pixelSize specifies the maximum pixel dimensions for the preview, without taking into account -/// any UI scaling factors. The returned image is guaranteed to be *at most* this size; -/// a smaller image may be returned. -/// If useIconStyle is true, the thumbnail will be generated with the shadow and page-curl effects -/// as seen in Finder. -/// USAGE NOTE: this method is synchronous and can take a while to complete, so should be performed on a background thread. -- (nullable NSImage *) quickLookThumbnailWithMaxSize: (NSSize)pixelSize iconStyle: (BOOL)useIconStyle; - -@end diff --git a/Other Sources/ADBToolkit/NSURL+ADBQuickLookHelpers.m b/Other Sources/ADBToolkit/NSURL+ADBQuickLookHelpers.m deleted file mode 100644 index a819e063b..000000000 --- a/Other Sources/ADBToolkit/NSURL+ADBQuickLookHelpers.m +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2013, Alun Bestor (alun.bestor@gmail.com) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#import "NSURL+ADBQuickLookHelpers.h" -#import - -@implementation NSURL (ADBQuickLookHelpers) - -- (NSImage *) quickLookThumbnailWithMaxSize: (NSSize)pixelSize iconStyle: (BOOL)useIconStyle -{ - NSDictionary *options = @{(NSString*)kQLThumbnailOptionIconModeKey: @(useIconStyle)}; - - CGImageRef cgThumbnail = QLThumbnailImageCreate(CFAllocatorGetDefault(), - (__bridge CFURLRef)self, - NSSizeToCGSize(pixelSize), - (__bridge CFDictionaryRef)(options)); - - if (cgThumbnail) - { - NSImage *image = [[NSImage alloc] initWithCGImage: cgThumbnail - size: NSZeroSize]; - - CGImageRelease(cgThumbnail); - - return image; - } - else - { - return nil; - } -} -@end diff --git a/Other Sources/ADBToolkit/URL+ADBAliasHelpers.swift b/Other Sources/ADBToolkit/URL+ADBAliasHelpers.swift index 35d8c3d69..71f321471 100644 --- a/Other Sources/ADBToolkit/URL+ADBAliasHelpers.swift +++ b/Other Sources/ADBToolkit/URL+ADBAliasHelpers.swift @@ -26,3 +26,14 @@ extension URL { try self.init(resolvingBookmarkData: bookmarkData, options: options, relativeTo: relativeURL, bookmarkDataIsStale: &isStale) } } + +extension NSURL { + /// Returns a URL resolved from the specified Finder alias record. + /// + /// Directly equivalent to `URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error:`. + @objc(URLByResolvingAliasRecord:options:relativeToURL:bookmarkDataIsStale:error:) + static func resolvingAliasRecord(_ aliasRecord: Data, options: URL.BookmarkResolutionOptions, relativeTo relativeURL: URL?, bookmarkDataIsStale isStale: UnsafeMutablePointer?) throws -> NSURL { + let bookData = try URL.bookmarkData(fromAliasRecord: aliasRecord) + return try self.init(resolvingBookmarkData: bookData, options: options, relativeTo: relativeURL, bookmarkDataIsStale: isStale) + } +} diff --git a/Other Sources/ADBToolkit/URL+ADBFilesystemHelpers.swift b/Other Sources/ADBToolkit/URL+ADBFilesystemHelpers.swift index 8d4707a36..c1d5c2e2f 100644 --- a/Other Sources/ADBToolkit/URL+ADBFilesystemHelpers.swift +++ b/Other Sources/ADBToolkit/URL+ADBFilesystemHelpers.swift @@ -127,6 +127,14 @@ extension URL { } } +extension NSURL { + /// An analogue for `-[NSString stringsByAppendingPaths:]`. + @objc(URLsByAppendingPaths:) + func urls(byAppendingPaths paths: [String]) -> [URL] { + return (self as URL).urls(byAppendingPaths: paths) + } +} + extension URL { /// Returns the value for the specified resource property. /// @@ -322,7 +330,7 @@ extension URL { /// extension that would be suitable for the specified UTI. func conforms(to comparisonUTI: UTType) -> Bool { let reportedUTI = contentType - if let reportedUTI = reportedUTI, + if let reportedUTI, reportedUTI.conforms(to: comparisonUTI) { return true } @@ -335,7 +343,7 @@ extension URL { let ext = pathExtension if ext.count != 0 { let utiForExt = UTType(filenameExtension: ext) - if let utiForExt = utiForExt, + if let utiForExt, utiForExt != reportedUTI, utiForExt.conforms(to: comparisonUTI) { return true @@ -344,7 +352,6 @@ extension URL { return false } - /// Given a set of `UTType`s, returns the first one to which this /// URL conforms, or `nil` if it doesn't match any of them. diff --git a/Other Sources/ADBToolkit/URL+ADBQuickLookHelpers.swift b/Other Sources/ADBToolkit/URL+ADBQuickLookHelpers.swift index 8de2cfa89..1efed9835 100644 --- a/Other Sources/ADBToolkit/URL+ADBQuickLookHelpers.swift +++ b/Other Sources/ADBToolkit/URL+ADBQuickLookHelpers.swift @@ -31,3 +31,22 @@ extension URL { return NSImage(cgImage: cgThumbnail, size: .zero) } } + +extension NSURL { + /// Returns a QuickLook thumbnail for the file at this URL, or `nil` if no thumbnail could be generated. + /// pixelSize specifies the maximum pixel dimensions for the preview, without taking into account + /// any UI scaling factors. The returned image is guaranteed to be *at most* this size; + /// a smaller image may be returned. + /// + /// If `useIconStyle` is true, the thumbnail will be generated with the shadow and page-curl effects + /// as seen in Finder. + /// + /// USAGE NOTE: this method is synchronous and can take a while to complete, so should be performed on a background thread. + @objc(quickLookThumbnailWithMaxSize:iconStyle:) + func quickLookThumbnail(maxSize pixelSize: NSSize, useIconStyle: Bool) -> NSImage? { + guard let image = (self as URL).quickLookThumbnail(maxSize: pixelSize, useIconStyle: useIconStyle) else { + return nil + } + return image + } +}