mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-28 10:02:14 +00:00
UPD: Use pmount to mount/unmount drives if available (Linux).
This commit is contained in:
parent
e594184c57
commit
4eb350a67e
2 changed files with 70 additions and 18 deletions
|
|
@ -31,7 +31,7 @@ unit uMyUnix;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, BaseUnix;
|
||||
Classes, SysUtils, BaseUnix, uDrive;
|
||||
|
||||
const
|
||||
libc = 'c';
|
||||
|
|
@ -161,6 +161,7 @@ function fpCloseDir(__dirp: pDir): cInt; cdecl; external libc name 'closedir';
|
|||
function fpReadDir(__dirp: pDir): pDirent; inline;
|
||||
function fpCloseDir(__dirp: pDir): cInt; inline;
|
||||
{$ENDIF}
|
||||
function fpSystemStatus(Command: string): cint;
|
||||
|
||||
function LinuxToWinAttr(pFileName: PChar; const srInfo: BaseUnix.Stat): Longint;
|
||||
function GetDesktopEnvironment: Cardinal;
|
||||
|
|
@ -186,6 +187,10 @@ function GetFileMimeType(const FileName: UTF8String): UTF8String;
|
|||
}
|
||||
procedure FixDateTimeSeparators;
|
||||
|
||||
function MountDrive(const Drive: TDrive): Boolean;
|
||||
function UnmountDrive(const Drive: TDrive): Boolean;
|
||||
function EjectDrive(const Drive: TDrive): Boolean;
|
||||
|
||||
{$IF DEFINED(BSD) AND NOT DEFINED(DARWIN)}
|
||||
const
|
||||
MNT_WAIT = 1; // synchronously wait for I/O to complete
|
||||
|
|
@ -214,12 +219,12 @@ procedure endfsent(); cdecl; external libc name 'endfsent';
|
|||
implementation
|
||||
|
||||
uses
|
||||
URIParser, uClassesEx, uDCUtils
|
||||
URIParser, Unix, uClassesEx, uDCUtils
|
||||
{$IF (NOT DEFINED(FPC_USE_LIBC)) or (DEFINED(BSD) AND NOT DEFINED(DARWIN))}
|
||||
, SysCall
|
||||
{$ENDIF}
|
||||
{$IFDEF LINUX}
|
||||
, uMimeActions
|
||||
, uMimeActions, uUDisks
|
||||
{$ENDIF}
|
||||
;
|
||||
|
||||
|
|
@ -257,6 +262,26 @@ end;
|
|||
|
||||
{$ENDIF}
|
||||
|
||||
function fpSystemStatus(Command: string): cint;
|
||||
begin
|
||||
Result := fpSystem(Command);
|
||||
if wifexited(Result) then
|
||||
Result := wexitStatus(Result);
|
||||
end;
|
||||
|
||||
{$IFDEF LINUX}
|
||||
|
||||
var
|
||||
HavePMount: Boolean = False;
|
||||
|
||||
procedure CheckPMount;
|
||||
begin
|
||||
HavePMount := (fpSystemStatus('pmount --version') = 0) and
|
||||
(fpSystemStatus('pumount --version') = 0);
|
||||
end;
|
||||
|
||||
{$ENDIF LINUX}
|
||||
|
||||
function LinuxToWinAttr(pFileName: PChar; const srInfo: BaseUnix.Stat): Longint;
|
||||
begin
|
||||
Result:= faArchive;
|
||||
|
|
@ -428,5 +453,42 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function MountDrive(const Drive: TDrive): Boolean;
|
||||
begin
|
||||
Result := fpSystemStatus('mount ' + Drive.DeviceId) = 0;
|
||||
{$IFDEF LINUX}
|
||||
if not Result and HavePMount then
|
||||
Result := fpSystemStatus('pmount ' + Drive.DeviceId) = 0;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function UnmountDrive(const Drive: TDrive): Boolean;
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
Result := False;
|
||||
if uUDisks.Initialize then
|
||||
begin
|
||||
Result := uUDisks.Unmount(DeviceFileToUDisksObjectPath(Drive.DeviceId), nil);
|
||||
uUDisks.Finalize;
|
||||
end;
|
||||
if not Result and HavePMount then
|
||||
Result := fpSystemStatus('pumount ' + Drive.DeviceId) = 0;
|
||||
if not Result then
|
||||
{$ENDIF}
|
||||
Result := fpSystemStatus('umount ' + Drive.Path) = 0;
|
||||
end;
|
||||
|
||||
function EjectDrive(const Drive: TDrive): Boolean;
|
||||
begin
|
||||
Result := fpSystemStatus('eject ' + Drive.DeviceId) = 0;
|
||||
end;
|
||||
|
||||
{$IFDEF LINUX}
|
||||
|
||||
initialization
|
||||
CheckPMount;
|
||||
|
||||
{$ENDIF}
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
|
|
@ -58,13 +58,13 @@ type
|
|||
implementation
|
||||
|
||||
uses
|
||||
LCLProc, Dialogs, IniFiles, Graphics, Unix, uTypes, uFindEx, uDCUtils,
|
||||
LCLProc, Dialogs, IniFiles, Graphics, uTypes, uFindEx, uDCUtils,
|
||||
uOSUtils, uFileProcs, uShellExecute, uLng, uGlobs, uPixMapManager, uMyUnix,
|
||||
fMain, fFileProperties
|
||||
{$IF DEFINED(DARWIN)}
|
||||
, MacOSAll
|
||||
{$ELSEIF DEFINED(LINUX)}
|
||||
, uMimeActions, uUDisks
|
||||
, uMimeActions
|
||||
{$ENDIF}
|
||||
;
|
||||
|
||||
|
|
@ -213,27 +213,17 @@ end;
|
|||
|
||||
procedure TShellContextMenu.DriveMountSelect(Sender: TObject);
|
||||
begin
|
||||
fpSystem('mount ' + FDrive.DeviceId);
|
||||
MountDrive(FDrive);
|
||||
end;
|
||||
|
||||
procedure TShellContextMenu.DriveUnmountSelect(Sender: TObject);
|
||||
var
|
||||
Succeeded: Boolean = False;
|
||||
begin
|
||||
{$IFDEF LINUX}
|
||||
if uUDisks.Initialize then
|
||||
begin
|
||||
Succeeded := uUDisks.Unmount(DeviceFileToUDisksObjectPath(FDrive.DeviceId), nil);
|
||||
uUDisks.Finalize;
|
||||
end;
|
||||
{$ENDIF}
|
||||
if not Succeeded then
|
||||
fpSystem('umount ' + FDrive.Path);
|
||||
UnmountDrive(FDrive);
|
||||
end;
|
||||
|
||||
procedure TShellContextMenu.DriveEjectSelect(Sender: TObject);
|
||||
begin
|
||||
fpSystem('eject ' + FDrive.DeviceId);
|
||||
EjectDrive(FDrive);
|
||||
end;
|
||||
|
||||
procedure TShellContextMenu.OpenWithMenuItemSelect(Sender: TObject);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue