mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-28 10:02:14 +00:00
UPD: Some code optimization
This commit is contained in:
parent
0aa4bb1557
commit
589b4cbf68
3 changed files with 185 additions and 183 deletions
18
uOSUtils.pas
18
uOSUtils.pas
|
|
@ -848,24 +848,6 @@ begin
|
|||
end;
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF MSWINDOWS}
|
||||
function WinToDosTime (var Wtime: TFileTime; var DTime: LongInt): LongBool;
|
||||
var
|
||||
lft : TFileTime;
|
||||
begin
|
||||
Result:= FileTimeToLocalFileTime(WTime,lft) and
|
||||
FileTimeToDosDateTime(lft,Longrec(Dtime).Hi,LongRec(DTIME).lo);
|
||||
end;
|
||||
{$ELSE}
|
||||
function UnixToWinAge(UnixAge: time_t): LongInt;
|
||||
var
|
||||
Y,M,D,hh,mm,ss : word;
|
||||
begin
|
||||
EpochToLocal(UnixAge,y,m,d,hh,mm,ss);
|
||||
Result:= DateTimeToFileDate(EncodeDate(y,m,d) + EncodeTime(hh,mm,ss,0));
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function mbFileAge(const FileName: UTF8String): Longint;
|
||||
{$IFDEF MSWINDOWS}
|
||||
var
|
||||
|
|
|
|||
12
umyunix.pas
12
umyunix.pas
|
|
@ -27,7 +27,7 @@ unit uMyUnix;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
Classes, SysUtils, BaseUnix, UnixUtil;
|
||||
|
||||
const
|
||||
libc = 'c';
|
||||
|
|
@ -123,7 +123,17 @@ function getgrgid(gid: __gid_t): PGroupRecord; cdecl; external libc name 'getgrg
|
|||
}
|
||||
function getgrnam(name: PChar): PGroupRecord; cdecl; external libc name 'getgrnam';
|
||||
|
||||
function UnixToWinAge(UnixAge: time_t): LongInt;
|
||||
|
||||
implementation
|
||||
|
||||
function UnixToWinAge(UnixAge: time_t): LongInt;
|
||||
var
|
||||
Y,M,D,hh,mm,ss : word;
|
||||
begin
|
||||
EpochToLocal(UnixAge,y,m,d,hh,mm,ss);
|
||||
Result:= DateTimeToFileDate(EncodeDate(y,m,d) + EncodeTime(hh,mm,ss,0));
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
338
umywindows.pas
338
umywindows.pas
|
|
@ -1,164 +1,174 @@
|
|||
{
|
||||
Double Commander
|
||||
-------------------------------------------------------------------------
|
||||
This unit contains specific WINDOWS functions.
|
||||
|
||||
Copyright (C) 2006-2008 Koblov Alexander (Alexx2000@mail.ru)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
}
|
||||
|
||||
unit uMyWindows;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Windows;
|
||||
|
||||
{en
|
||||
Checks readiness of a drive
|
||||
@param(sDrv String specifying the root directory of a file system volume)
|
||||
@returns(The function returns @true if drive is ready, @false otherwise)
|
||||
}
|
||||
function mbDriveReady(const sDrv: UTF8String): Boolean;
|
||||
{en
|
||||
Get the label of a file system volume
|
||||
@param(sDrv String specifying the root directory of a file system volume)
|
||||
@param(bVolReal @true if it a real file system volume)
|
||||
@returns(The function returns volume label)
|
||||
}
|
||||
function mbGetVolumeLabel(const sDrv: UTF8String; const bVolReal: Boolean): UTF8String;
|
||||
{en
|
||||
Set the label of a file system volume
|
||||
@param(sRootPathName String specifying the root directory of a file system volume)
|
||||
@param(sVolumeName String specifying a new name for the volume)
|
||||
@returns(The function returns @true if successful, @false otherwise)
|
||||
}
|
||||
function mbSetVolumeLabel(sRootPathName, sVolumeName: UTF8String): Boolean;
|
||||
{en
|
||||
Wait for change disk label
|
||||
@param(sDrv String specifying the root directory of a file system volume)
|
||||
@param(sCurLabel Current volume label)
|
||||
}
|
||||
procedure mbWaitLabelChange(const sDrv: UTF8String; const sCurLabel: UTF8String);
|
||||
{en
|
||||
Close CD/DVD drive
|
||||
@param(sDrv String specifying the root directory of a drive)
|
||||
}
|
||||
procedure mbCloseCD(const sDrv: UTF8String);
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
LCLProc, ShellAPI, MMSystem;
|
||||
|
||||
function DisplayName(const wsDrv: WideString): WideString;
|
||||
var
|
||||
SFI: TSHFileInfoW;
|
||||
begin
|
||||
FillChar(SFI, SizeOf(SFI), 0);
|
||||
SHGetFileInfoW(PWChar(wsDrv), 0, SFI, SizeOf(SFI), SHGFI_DISPLAYNAME);
|
||||
Result:= SFI.szDisplayName;
|
||||
|
||||
if Pos('(', Result) <> 0 then
|
||||
SetLength(Result, Pos('(', Result) - 2);
|
||||
end;
|
||||
|
||||
(* Drive ready *)
|
||||
|
||||
function mbDriveReady(const sDrv: UTF8String): Boolean;
|
||||
var
|
||||
NotUsed: DWORD;
|
||||
wsDrv: WideString;
|
||||
begin
|
||||
wsDrv:= UTF8Decode(sDrv);
|
||||
Result:= GetVolumeInformationW(PWChar(wsDrv), nil, 0, nil, NotUsed, NotUsed, nil, 0);
|
||||
end;
|
||||
|
||||
(* Disk label *)
|
||||
|
||||
function mbGetVolumeLabel(const sDrv: UTF8String; const bVolReal: Boolean): UTF8String;
|
||||
var
|
||||
WinVer: Byte;
|
||||
DriveType, NotUsed: DWORD;
|
||||
Buf: array [0..MAX_PATH - 1] of WideChar;
|
||||
wsDrv,
|
||||
wsResult: WideString;
|
||||
begin
|
||||
Result:= '';
|
||||
wsDrv:= UTF8Decode(sDrv);
|
||||
WinVer:= LOBYTE(LOWORD(GetVersion));
|
||||
DriveType:= GetDriveTypeW(PWChar(wsDrv));
|
||||
|
||||
if (WinVer <= 4) and (DriveType <> DRIVE_REMOVABLE) or bVolReal then
|
||||
begin // Win9x, Me, NT <= 4.0
|
||||
Buf[0]:= #0;
|
||||
GetVolumeInformationW(PWChar(wsDrv), Buf, DWORD(SizeOf(Buf)), nil,
|
||||
NotUsed, NotUsed, nil, 0);
|
||||
wsResult:= Buf;
|
||||
|
||||
if bVolReal and (WinVer >= 5) and (Result <> '') and
|
||||
(DriveType <> DRIVE_REMOVABLE) then // Win2k, XP and higher
|
||||
wsResult:= DisplayName(wsDrv)
|
||||
else if (Result = '') and (not bVolReal) then
|
||||
wsResult:= '<none>';
|
||||
end
|
||||
else
|
||||
wsResult:= DisplayName(wsDrv);
|
||||
Result:= UTF8Encode(wsResult);
|
||||
end;
|
||||
|
||||
(* Wait for change disk label *)
|
||||
|
||||
function mbSetVolumeLabel(sRootPathName, sVolumeName: UTF8String): Boolean;
|
||||
var
|
||||
wsRootPathName,
|
||||
wsVolumeName: WideString;
|
||||
begin
|
||||
wsRootPathName:= UTF8Decode(sRootPathName);
|
||||
wsVolumeName:= UTF8Decode(sVolumeName);
|
||||
Result:= SetVolumeLabelW(PWChar(wsRootPathName), PWChar(wsVolumeName));
|
||||
end;
|
||||
|
||||
procedure mbWaitLabelChange(const sDrv: UTF8String; const sCurLabel: UTF8String);
|
||||
var
|
||||
st1, st2: UTF8String;
|
||||
begin
|
||||
if mbGetVolumeLabel(sDrv, True) = '' then
|
||||
Exit;
|
||||
st1:= TrimLeft(sCurLabel);
|
||||
st2:= st1;
|
||||
while st1 = st2 do
|
||||
st2:= mbGetVolumeLabel(sDrv, FALSE);
|
||||
end;
|
||||
|
||||
(* Close CD/DVD *)
|
||||
|
||||
procedure mbCloseCD(const sDrv: UTF8String);
|
||||
var
|
||||
OpenParms: MCI_OPEN_PARMS;
|
||||
begin
|
||||
FillChar(OpenParms, SizeOf(OpenParms), 0);
|
||||
OpenParms.lpstrDeviceType:= 'CDAudio';
|
||||
OpenParms.lpstrElementName:= PChar(ExtractFileDrive(sDrv));
|
||||
mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Longint(@OpenParms));
|
||||
mciSendCommand(OpenParms.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
|
||||
mciSendCommand(OpenParms.wDeviceID, MCI_CLOSE, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Longint(@OpenParms));
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
{
|
||||
Double Commander
|
||||
-------------------------------------------------------------------------
|
||||
This unit contains specific WINDOWS functions.
|
||||
|
||||
Copyright (C) 2006-2008 Koblov Alexander (Alexx2000@mail.ru)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
}
|
||||
|
||||
unit uMyWindows;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Windows;
|
||||
|
||||
{en
|
||||
Checks readiness of a drive
|
||||
@param(sDrv String specifying the root directory of a file system volume)
|
||||
@returns(The function returns @true if drive is ready, @false otherwise)
|
||||
}
|
||||
function mbDriveReady(const sDrv: UTF8String): Boolean;
|
||||
{en
|
||||
Get the label of a file system volume
|
||||
@param(sDrv String specifying the root directory of a file system volume)
|
||||
@param(bVolReal @true if it a real file system volume)
|
||||
@returns(The function returns volume label)
|
||||
}
|
||||
function mbGetVolumeLabel(const sDrv: UTF8String; const bVolReal: Boolean): UTF8String;
|
||||
{en
|
||||
Set the label of a file system volume
|
||||
@param(sRootPathName String specifying the root directory of a file system volume)
|
||||
@param(sVolumeName String specifying a new name for the volume)
|
||||
@returns(The function returns @true if successful, @false otherwise)
|
||||
}
|
||||
function mbSetVolumeLabel(sRootPathName, sVolumeName: UTF8String): Boolean;
|
||||
{en
|
||||
Wait for change disk label
|
||||
@param(sDrv String specifying the root directory of a file system volume)
|
||||
@param(sCurLabel Current volume label)
|
||||
}
|
||||
procedure mbWaitLabelChange(const sDrv: UTF8String; const sCurLabel: UTF8String);
|
||||
{en
|
||||
Close CD/DVD drive
|
||||
@param(sDrv String specifying the root directory of a drive)
|
||||
}
|
||||
procedure mbCloseCD(const sDrv: UTF8String);
|
||||
|
||||
function WinToDosTime (var Wtime: TFileTime; var DTime: LongInt): LongBool;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
LCLProc, ShellAPI, MMSystem;
|
||||
|
||||
function DisplayName(const wsDrv: WideString): WideString;
|
||||
var
|
||||
SFI: TSHFileInfoW;
|
||||
begin
|
||||
FillChar(SFI, SizeOf(SFI), 0);
|
||||
SHGetFileInfoW(PWChar(wsDrv), 0, SFI, SizeOf(SFI), SHGFI_DISPLAYNAME);
|
||||
Result:= SFI.szDisplayName;
|
||||
|
||||
if Pos('(', Result) <> 0 then
|
||||
SetLength(Result, Pos('(', Result) - 2);
|
||||
end;
|
||||
|
||||
(* Drive ready *)
|
||||
|
||||
function mbDriveReady(const sDrv: UTF8String): Boolean;
|
||||
var
|
||||
NotUsed: DWORD;
|
||||
wsDrv: WideString;
|
||||
begin
|
||||
wsDrv:= UTF8Decode(sDrv);
|
||||
Result:= GetVolumeInformationW(PWChar(wsDrv), nil, 0, nil, NotUsed, NotUsed, nil, 0);
|
||||
end;
|
||||
|
||||
(* Disk label *)
|
||||
|
||||
function mbGetVolumeLabel(const sDrv: UTF8String; const bVolReal: Boolean): UTF8String;
|
||||
var
|
||||
WinVer: Byte;
|
||||
DriveType, NotUsed: DWORD;
|
||||
Buf: array [0..MAX_PATH - 1] of WideChar;
|
||||
wsDrv,
|
||||
wsResult: WideString;
|
||||
begin
|
||||
Result:= '';
|
||||
wsDrv:= UTF8Decode(sDrv);
|
||||
WinVer:= LOBYTE(LOWORD(GetVersion));
|
||||
DriveType:= GetDriveTypeW(PWChar(wsDrv));
|
||||
|
||||
if (WinVer <= 4) and (DriveType <> DRIVE_REMOVABLE) or bVolReal then
|
||||
begin // Win9x, Me, NT <= 4.0
|
||||
Buf[0]:= #0;
|
||||
GetVolumeInformationW(PWChar(wsDrv), Buf, DWORD(SizeOf(Buf)), nil,
|
||||
NotUsed, NotUsed, nil, 0);
|
||||
wsResult:= Buf;
|
||||
|
||||
if bVolReal and (WinVer >= 5) and (Result <> '') and
|
||||
(DriveType <> DRIVE_REMOVABLE) then // Win2k, XP and higher
|
||||
wsResult:= DisplayName(wsDrv)
|
||||
else if (Result = '') and (not bVolReal) then
|
||||
wsResult:= '<none>';
|
||||
end
|
||||
else
|
||||
wsResult:= DisplayName(wsDrv);
|
||||
Result:= UTF8Encode(wsResult);
|
||||
end;
|
||||
|
||||
(* Wait for change disk label *)
|
||||
|
||||
function mbSetVolumeLabel(sRootPathName, sVolumeName: UTF8String): Boolean;
|
||||
var
|
||||
wsRootPathName,
|
||||
wsVolumeName: WideString;
|
||||
begin
|
||||
wsRootPathName:= UTF8Decode(sRootPathName);
|
||||
wsVolumeName:= UTF8Decode(sVolumeName);
|
||||
Result:= SetVolumeLabelW(PWChar(wsRootPathName), PWChar(wsVolumeName));
|
||||
end;
|
||||
|
||||
procedure mbWaitLabelChange(const sDrv: UTF8String; const sCurLabel: UTF8String);
|
||||
var
|
||||
st1, st2: UTF8String;
|
||||
begin
|
||||
if mbGetVolumeLabel(sDrv, True) = '' then
|
||||
Exit;
|
||||
st1:= TrimLeft(sCurLabel);
|
||||
st2:= st1;
|
||||
while st1 = st2 do
|
||||
st2:= mbGetVolumeLabel(sDrv, FALSE);
|
||||
end;
|
||||
|
||||
(* Close CD/DVD *)
|
||||
|
||||
procedure mbCloseCD(const sDrv: UTF8String);
|
||||
var
|
||||
OpenParms: MCI_OPEN_PARMS;
|
||||
begin
|
||||
FillChar(OpenParms, SizeOf(OpenParms), 0);
|
||||
OpenParms.lpstrDeviceType:= 'CDAudio';
|
||||
OpenParms.lpstrElementName:= PChar(ExtractFileDrive(sDrv));
|
||||
mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Longint(@OpenParms));
|
||||
mciSendCommand(OpenParms.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
|
||||
mciSendCommand(OpenParms.wDeviceID, MCI_CLOSE, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Longint(@OpenParms));
|
||||
end;
|
||||
|
||||
function WinToDosTime (var Wtime: TFileTime; var DTime: LongInt): LongBool;
|
||||
var
|
||||
lft : TFileTime;
|
||||
begin
|
||||
Result:= FileTimeToLocalFileTime(WTime,lft) and
|
||||
FileTimeToDosDateTime(lft,Longrec(Dtime).Hi,LongRec(DTIME).lo);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue