Forráskód Böngészése

ADD: getMacOSFileUniqueIcon() on macOS

rich2014 2 hónapja
szülő
commit
c28ce65eef
1 módosított fájl, 21 hozzáadás és 0 törlés
  1. 21 0
      src/platform/unix/darwin/umydarwin.pas

+ 21 - 0
src/platform/unix/darwin/umydarwin.pas

@@ -72,6 +72,8 @@ procedure openNewInstance();
 
 function getMacOSDisplayNameFromPath(const path: String): String;
 
+function getMacOSFileUniqueIcon(const path: String ): NSImage;
+
 // Workarounds for FPC RTL Bug
 // copied from ptypes.inc and modified fstypename only
 {$if defined(cpuarm) or defined(cpuaarch64) or defined(iphonesim)}
@@ -935,6 +937,25 @@ begin
   Result:= displayName.UTF8String;
 end;
 
+function hasUniqueIcon( const path: String ): Boolean;
+var
+  pathRef: FSRef;
+  catalogInfo: FSCatalogInfo;
+  pFinderInfo: FileInfoPtr;
+begin
+  FSPathMakeRef( pchar(path), pathRef, nil );
+  FSGetCatalogInfo( pathRef, kFSCatInfoFinderInfo, @catalogInfo, nil, nil, nil );
+  pFinderInfo:= FileInfoPtr( @catalogInfo.finderInfo );
+  Result:= (pFinderInfo^.finderFlags and kHasCustomIcon) <> 0;
+end;
+
+function getMacOSFileUniqueIcon( const path: String ): NSImage;
+begin
+  Result:= nil;
+  if hasUniqueIcon(path) then
+    Result:= NSWorkspace.sharedWorkspace.iconForFile( StringToNSString(path) );
+end;
+
 initialization
   Initialize;