mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
UPD: refactoring File related from uMyDarwin to uDarwinFileUtil again
(cherry picked from commit 30b6ae5006)
This commit is contained in:
parent
49df0f028b
commit
f67ba5b23f
7 changed files with 72 additions and 73 deletions
|
|
@ -710,7 +710,7 @@ begin
|
|||
begin
|
||||
TypeProperty := TFileTypeProperty.Create;
|
||||
{$IF DEFINED(DARWIN)}
|
||||
TypeProperty.Value:= GetFileDescription(sFullPath);
|
||||
TypeProperty.Value:= TDarwinFileUtil.getDescription(sFullPath);
|
||||
{$ELSE}
|
||||
TypeProperty.Value:= GetFileMimeType(sFullPath);
|
||||
{$ENDIF}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ uses
|
|||
{$IF DEFINED(UNIX)}
|
||||
, DCFileAttributes
|
||||
{$IFDEF DARWIN}
|
||||
, MacOSAll
|
||||
, MacOSAll, uDarwinFileUtil
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
;
|
||||
|
|
@ -217,7 +217,7 @@ begin
|
|||
end;
|
||||
{$ELSEIF DEFINED(DARWIN)}
|
||||
begin
|
||||
LinkTarget:= ResolveAliasFile(FileName);
|
||||
LinkTarget:= TDarwinFileUtil.resolveAlias(FileName);
|
||||
if mbCompareFileNames(FileName, LinkTarget) then
|
||||
Result:= False
|
||||
else begin
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ interface
|
|||
uses
|
||||
Classes, SysUtils,
|
||||
uDebug, uLog,
|
||||
uFileProperty, uDisplayFile,
|
||||
MacOSAll, CocoaAll, Cocoa_Extra,
|
||||
uFileProperty,
|
||||
MacOSAll, CocoaAll, Cocoa_Extra, CocoaUtils,
|
||||
uDarwinUtil, uDarwinFinderModel;
|
||||
|
||||
type
|
||||
|
|
@ -30,9 +30,16 @@ type
|
|||
public
|
||||
class function mount( const serverAddress: String ): Boolean;
|
||||
class function unmountAndEject( const path: String ): Boolean;
|
||||
class function resolveAlias( const path: String ): String;
|
||||
public
|
||||
class function getSpecificProperty( const path: String ): TFileMacOSSpecificProperty;
|
||||
class function getDisplayName( const path: String ): String;
|
||||
class function getUniqueIcon( const path: String ): NSImage;
|
||||
class function getDescription( const path: String ): String;
|
||||
public
|
||||
class function getTempPath: String;
|
||||
class function getTerminalPath: String;
|
||||
class function getSpecifiedFolderPath( folder: NSSearchPathDirectory ): String;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
|
@ -229,6 +236,59 @@ begin
|
|||
Result:= NSWorkspace.sharedWorkspace.iconForFile( StringToNSString(path) );
|
||||
end;
|
||||
|
||||
class function TDarwinFileUtil.getTempPath: String;
|
||||
begin
|
||||
Result:= IncludeTrailingBackslash(NSTemporaryDirectory.UTF8String);
|
||||
end;
|
||||
|
||||
class function TDarwinFileUtil.getTerminalPath(): String;
|
||||
begin
|
||||
Result:= NSStringToString( NSWorkspace.sharedWorkspace.fullPathForApplication( NSStr('terminal') ) );
|
||||
end;
|
||||
|
||||
class function TDarwinFileUtil.getSpecifiedFolderPath(folder: NSSearchPathDirectory
|
||||
): String;
|
||||
var
|
||||
Path: NSArray;
|
||||
begin
|
||||
Path:= NSFileManager.defaultManager.URLsForDirectory_inDomains(folder, NSUserDomainMask);
|
||||
if Path.count > 0 then
|
||||
begin
|
||||
Result:= IncludeTrailingBackslash(NSURL(Path.objectAtIndex(0)).path.UTF8String) + ApplicationName;
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TDarwinFileUtil.getDescription(const path: String): String;
|
||||
var
|
||||
Error: NSError;
|
||||
WS: NSWorkspace;
|
||||
FileType: NSString;
|
||||
FileNameRef: CFStringRef;
|
||||
begin
|
||||
WS:= NSWorkspace.sharedWorkspace;
|
||||
FileNameRef:= StringToCFStringRef(path);
|
||||
if (FileNameRef = nil) then Exit(EmptyStr);
|
||||
FileType:= WS.typeOfFile_error(NSString(FileNameRef), @Error);
|
||||
if (FileType = nil) then
|
||||
Result:= Error.localizedDescription.UTF8String
|
||||
else begin
|
||||
Result:= WS.localizedDescriptionForType(FileType).UTF8String;
|
||||
end;
|
||||
CFRelease(FileNameRef);
|
||||
end;
|
||||
|
||||
class function TDarwinFileUtil.resolveAlias(const path: String): String;
|
||||
var
|
||||
ASource: NSURL;
|
||||
ATarget: NSURL;
|
||||
begin
|
||||
Result:= EmptyStr;
|
||||
ASource:= NSURL.fileURLWithPath(StringToNSString(path));
|
||||
ATarget:= NSURL.URLByResolvingAliasFileAtURL_options_error(ASource, NSURLBookmarkResolutionWithoutUI, nil);
|
||||
if Assigned(ATarget) then
|
||||
Result:= ATarget.fileSystemRepresentation;
|
||||
end;
|
||||
|
||||
procedure Initialize;
|
||||
begin
|
||||
TDarwinFileUtil.NetFS:= LoadLibrary('/System/Library/Frameworks/NetFS.framework/NetFS');
|
||||
|
|
|
|||
|
|
@ -46,18 +46,8 @@ const
|
|||
|
||||
procedure onMainMenuCreate( menu: NSMenu );
|
||||
|
||||
function getMacOSDefaultTerminal(): String;
|
||||
|
||||
procedure FixMacFormatSettings;
|
||||
|
||||
function NSGetTempPath: String;
|
||||
|
||||
function NSGetFolderPath(Folder: NSSearchPathDirectory): String;
|
||||
|
||||
function GetFileDescription(const FileName: String): String;
|
||||
|
||||
function ResolveAliasFile(const FileName: String): String;
|
||||
|
||||
procedure openSystemSecurityPreferences_PrivacyAllFiles;
|
||||
|
||||
procedure openNewInstance();
|
||||
|
|
@ -344,57 +334,6 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function NSGetTempPath: String;
|
||||
begin
|
||||
Result:= IncludeTrailingBackslash(NSTemporaryDirectory.UTF8String);
|
||||
end;
|
||||
|
||||
function getMacOSDefaultTerminal(): String;
|
||||
begin
|
||||
Result:= NSStringToString( NSWorkspace.sharedWorkspace.fullPathForApplication( NSStr('terminal') ) );
|
||||
end;
|
||||
|
||||
function NSGetFolderPath(Folder: NSSearchPathDirectory): String;
|
||||
var
|
||||
Path: NSArray;
|
||||
begin
|
||||
Path:= NSFileManager.defaultManager.URLsForDirectory_inDomains(Folder, NSUserDomainMask);
|
||||
if Path.count > 0 then
|
||||
begin
|
||||
Result:= IncludeTrailingBackslash(NSURL(Path.objectAtIndex(0)).path.UTF8String) + ApplicationName;
|
||||
end;
|
||||
end;
|
||||
|
||||
function GetFileDescription(const FileName: String): String;
|
||||
var
|
||||
Error: NSError;
|
||||
WS: NSWorkspace;
|
||||
FileType: NSString;
|
||||
FileNameRef: CFStringRef;
|
||||
begin
|
||||
WS:= NSWorkspace.sharedWorkspace;
|
||||
FileNameRef:= StringToCFStringRef(FileName);
|
||||
if (FileNameRef = nil) then Exit(EmptyStr);
|
||||
FileType:= WS.typeOfFile_error(NSString(FileNameRef), @Error);
|
||||
if (FileType = nil) then
|
||||
Result:= Error.localizedDescription.UTF8String
|
||||
else begin
|
||||
Result:= WS.localizedDescriptionForType(FileType).UTF8String;
|
||||
end;
|
||||
CFRelease(FileNameRef);
|
||||
end;
|
||||
|
||||
function ResolveAliasFile(const FileName: String): String;
|
||||
var
|
||||
ASource: NSURL;
|
||||
ATarget: NSURL;
|
||||
begin
|
||||
Result:= EmptyStr;
|
||||
ASource:= NSURL.fileURLWithPath(StringToNSString(FileName));
|
||||
ATarget:= NSURL(NSURL.URLByResolvingAliasFileAtURL_options_error(ASource, NSURLBookmarkResolutionWithoutUI, nil));
|
||||
if Assigned(ATarget) then Result:= ATarget.fileSystemRepresentation;
|
||||
end;
|
||||
|
||||
procedure openSystemSecurityPreferences_PrivacyAllFiles;
|
||||
const
|
||||
Privacy_AllFiles = 'x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles';
|
||||
|
|
|
|||
|
|
@ -32,13 +32,13 @@ implementation
|
|||
|
||||
{$IF DEFINED(DARWIN)}
|
||||
uses
|
||||
uOSUtils, uMyDarwin;
|
||||
uOSUtils, uMyDarwin, uDarwinFileUtil;
|
||||
|
||||
procedure Initialize;
|
||||
var
|
||||
Cmd: String;
|
||||
begin
|
||||
Cmd:= getMacOSDefaultTerminal;
|
||||
Cmd:= TDarwinFileUtil.getTerminalPath;
|
||||
if Length(Cmd) > 0 then
|
||||
begin
|
||||
RunTermCmd:= Cmd;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ implementation
|
|||
uses
|
||||
SimpleIPC, BaseUnix, uPollThread
|
||||
{$IF DEFINED(DARWIN)}
|
||||
, uMyDarwin
|
||||
, uMyDarwin, uDarwinFileUtil
|
||||
{$ELSE}
|
||||
, uXdg
|
||||
{$ENDIF}
|
||||
|
|
@ -68,7 +68,7 @@ Type
|
|||
function GetPipeFileName(const FileName: String; Global : Boolean): String;
|
||||
begin
|
||||
{$IF DEFINED(DARWIN)}
|
||||
Result:= NSGetTempPath + FileName;
|
||||
Result:= TDarwinFileUtil.getTempPath + FileName;
|
||||
{$ELSEIF DEFINED(HAIKU)}
|
||||
Result:= IncludeTrailingBackslash(GetTempDir) + FileName;
|
||||
{$ELSE}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ uses
|
|||
{$IF DEFINED(UNIX)}
|
||||
, BaseUnix, Unix, DCUnix
|
||||
{$IF DEFINED(DARWIN)}
|
||||
, CocoaAll, uMyDarwin
|
||||
, CocoaAll, uMyDarwin, uDarwinFileUtil
|
||||
{$ELSEIF DEFINED(HAIKU)}
|
||||
, DCHaiku
|
||||
{$ELSE}
|
||||
|
|
@ -152,7 +152,7 @@ begin
|
|||
end;
|
||||
{$ELSEIF DEFINED(DARWIN)}
|
||||
begin
|
||||
Result:= NSGetFolderPath(NSCachesDirectory);
|
||||
Result:= TDarwinFileUtil.getSpecifiedFolderPath(NSCachesDirectory);
|
||||
end;
|
||||
{$ELSEIF DEFINED(HAIKU)}
|
||||
begin
|
||||
|
|
@ -181,7 +181,7 @@ begin
|
|||
end;
|
||||
{$ELSEIF DEFINED(DARWIN)}
|
||||
begin
|
||||
Result:= NSGetFolderPath(NSApplicationSupportDirectory);
|
||||
Result:= TDarwinFileUtil.getSpecifiedFolderPath(NSApplicationSupportDirectory);
|
||||
end;
|
||||
{$ELSEIF DEFINED(HAIKU)}
|
||||
begin
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue