浏览代码

ADD: getMacOSFileUniqueIcon() on macOS

rich2014 2 月之前
父节点
当前提交
c28ce65eef
共有 1 个文件被更改,包括 21 次插入0 次删除
  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 getMacOSDisplayNameFromPath(const path: String): String;
 
 
+function getMacOSFileUniqueIcon(const path: String ): NSImage;
+
 // Workarounds for FPC RTL Bug
 // Workarounds for FPC RTL Bug
 // copied from ptypes.inc and modified fstypename only
 // copied from ptypes.inc and modified fstypename only
 {$if defined(cpuarm) or defined(cpuaarch64) or defined(iphonesim)}
 {$if defined(cpuarm) or defined(cpuaarch64) or defined(iphonesim)}
@@ -935,6 +937,25 @@ begin
   Result:= displayName.UTF8String;
   Result:= displayName.UTF8String;
 end;
 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
 initialization
   Initialize;
   Initialize;