UPD: Creating hard links.

This commit is contained in:
cobines 2009-08-04 22:16:46 +00:00
commit d117cd0031
4 changed files with 111 additions and 82 deletions

View file

@ -3,68 +3,68 @@ object frmHardLink: TfrmHardLink
Height = 160
Top = 320
Width = 400
HorzScrollBar.Page = 399
HorzScrollBar.Range = 392
VertScrollBar.Page = 151
VertScrollBar.Range = 146
ActiveControl = edtDst
ActiveControl = edtLinkToCreate
BorderIcons = [biSystemMenu]
BorderStyle = bsDialog
Caption = 'Create hardlink'
ChildSizing.LeftRightSpacing = 8
ChildSizing.TopBottomSpacing = 8
ClientHeight = 152
ClientHeight = 160
ClientWidth = 400
Constraints.MaxHeight = 160
Constraints.MaxWidth = 400
KeyPreview = True
OnShow = FormShow
Position = poScreenCenter
object lblNew: TLabel
AnchorSideTop.Control = edtDst
LCLVersion = '0.9.27'
object lblExistingFile: TLabel
AnchorSideTop.Control = edtLinkToCreate
AnchorSideTop.Side = asrBottom
Left = 8
Height = 14
Top = 58
Width = 197
Height = 18
Top = 65
Width = 259
BorderSpacing.Top = 6
Caption = 'Existing destination (where will link point)'
FocusControl = edtExistingFile
ParentColor = False
end
object lblDst: TLabel
object lblLinkToCreate: TLabel
Left = 8
Height = 14
Height = 18
Top = 8
Width = 48
Width = 62
Caption = 'Link name'
FocusControl = edtLinkToCreate
ParentColor = False
end
object edtNew: TEdit
AnchorSideTop.Control = lblNew
object edtExistingFile: TEdit
AnchorSideTop.Control = lblExistingFile
AnchorSideTop.Side = asrBottom
Left = 8
Height = 24
Top = 78
Height = 27
Top = 89
Width = 384
BorderSpacing.Top = 6
TabOrder = 1
end
object edtDst: TEdit
AnchorSideTop.Control = lblDst
object edtLinkToCreate: TEdit
AnchorSideTop.Control = lblLinkToCreate
AnchorSideTop.Side = asrBottom
Left = 8
Height = 24
Top = 28
Height = 27
Top = 32
Width = 384
BorderSpacing.Top = 6
TabOrder = 3
TabOrder = 0
end
object btnOK: TBitBtn
AnchorSideTop.Control = edtNew
AnchorSideTop.Control = edtExistingFile
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = btnCancel
Left = 236
Left = 206
Height = 32
Top = 114
Top = 128
Width = 90
Anchors = [akTop, akRight]
BorderSpacing.Top = 12
@ -77,16 +77,16 @@ object frmHardLink: TfrmHardLink
NumGlyphs = 0
OnClick = btnOKClick
OnMouseDown = btnOKMouseDown
TabOrder = 0
TabOrder = 2
end
object btnCancel: TBitBtn
AnchorSideTop.Control = edtNew
AnchorSideTop.Control = edtExistingFile
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = edtNew
AnchorSideRight.Control = edtExistingFile
AnchorSideRight.Side = asrBottom
Left = 317
Left = 302
Height = 32
Top = 114
Top = 128
Width = 90
Anchors = [akTop, akRight]
BorderSpacing.Top = 12
@ -97,6 +97,6 @@ object frmHardLink: TfrmHardLink
ModalResult = 2
NumGlyphs = 0
OnMouseDown = btnCancelMouseDown
TabOrder = 2
TabOrder = 3
end
end

View file

@ -1,5 +1,5 @@
TFRMHARDLINK.CAPTION=Create hardlink
TFRMHARDLINK.LBLNEW.CAPTION=Existing destination (where will link point)
TFRMHARDLINK.LBLDST.CAPTION=Link name
TFRMHARDLINK.BTNOK.CAPTION=&OK
TFRMHARDLINK.BTNCANCEL.CAPTION=Cancel
TFRMHARDLINK.CAPTION=Create hardlink
TFRMHARDLINK.LBLEXISTINGFILE.CAPTION=Existing destination (where will link point)
TFRMHARDLINK.LBLLINKTOCREATE.CAPTION=Link name
TFRMHARDLINK.BTNOK.CAPTION=&OK
TFRMHARDLINK.BTNCANCEL.CAPTION=Cancel

View file

@ -12,10 +12,10 @@ type
{ TfrmHardLink }
TfrmHardLink = class(TForm)
lblNew: TLabel;
lblDst: TLabel;
edtNew: TEdit;
edtDst: TEdit;
lblExistingFile: TLabel;
lblLinkToCreate: TLabel;
edtExistingFile: TEdit;
edtLinkToCreate: TEdit;
btnOK: TBitBtn;
btnCancel: TBitBtn;
procedure btnCancelMouseDown(Sender: TObject; Button: TMouseButton;
@ -23,28 +23,31 @@ type
procedure btnOKClick(Sender: TObject);
procedure btnOKMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
FCurrentPath: String;
public
{ Public declarations }
constructor Create(TheOwner: TComponent;
CurrentPath: String); reintroduce;
end;
function ShowHardLinkForm(const sNew, sDst:String): Boolean;
function ShowHardLinkForm(const sExistingFile, sLinkToCreate, CurrentPath: String): Boolean;
implementation
uses
FileUtil, uLng, uGlobs, uLog, uShowMsg, uOSUtils;
FileUtil, uLng, uGlobs, uLog, uShowMsg, uOSUtils, uDCUtils;
function ShowHardLinkForm(const sNew, sDst:String): Boolean;
function ShowHardLinkForm(const sExistingFile, sLinkToCreate, CurrentPath: String): Boolean;
begin
with TfrmHardLink.Create(Application) do
with TfrmHardLink.Create(Application, CurrentPath) do
begin
try
edtDst.Text:=sDst;
edtNew.Text:=sNew;
edtLinkToCreate.Text := sLinkToCreate;
edtExistingFile.Text := sExistingFile;
Result:= (ShowModal = mrOK);
finally
Free;
@ -52,14 +55,28 @@ begin
end;
end;
constructor TfrmHardLink.Create(TheOwner: TComponent;
CurrentPath: String);
begin
inherited Create(TheOwner);
FCurrentPath := CurrentPath;
end;
procedure TfrmHardLink.btnOKClick(Sender: TObject);
var
sSrc,sDst:String;
begin
inherited;
sSrc:=edtNew.Text;
sDst:=edtDst.Text;
sSrc:=edtExistingFile.Text;
sDst:=edtLinkToCreate.Text;
if CompareFilenames(sSrc, sDst) = 0 then Exit;
if GetPathType(sSrc) <> ptAbsolute then
sSrc := FCurrentPath + sSrc;
if GetPathType(sDst) <> ptAbsolute then
sDst := FCurrentPath + sDst;
if CreateHardLink(sSrc, sDst) then
begin
// write log
@ -90,6 +107,11 @@ begin
btnOKClick(Sender);
end;
procedure TfrmHardLink.FormShow(Sender: TObject);
begin
edtLinkToCreate.SelectAll;
end;
initialization
{$I fhardlink.lrs}

View file

@ -1820,45 +1820,52 @@ end;
procedure TActs.cm_HardLink(param:string);
var
sFile1, sFile2:String;
Result: Boolean;
sExistingFile, sLinkToCreate: String;
SelectedFiles: TFiles;
begin
frmMain.ActiveFrame.ExecuteCommand('cm_HardLink', param);
{
with frmMain do
begin
inherited;
Result := False;
try
with ActiveFrame do
with frmMain do
begin
// Hard links work only for file system.
if not (ActiveFrame.FileSource is TFileSystemFileSource) then
begin
if SelectFileIfNoSelected(GetActiveItem) = False then Exit;
sFile2 := pnlFile.GetActiveItem^.sName;
sFile1 := ActiveDir + sFile2;
if param <> '' then
sFile2 := param + sFile2
else
sFile2 := NotActiveFrame.CurrentPath + sFile2;
msgWarning(rsMsgErrNotSupported);
Exit;
end;
Result:= ShowHardLinkForm(sFile1, sFile2);
SelectedFiles := ActiveFrame.SelectedFiles;
try
if SelectedFiles.Count > 1 then
msgWarning(rsMsgTooManyFilesSelected)
else if SelectedFiles.Count = 0 then
msgWarning(rsMsgNoFilesSelected)
else
begin
sExistingFile := SelectedFiles[0].Path + SelectedFiles[0].Name;
finally
if Result then
begin
frameLeft.RefreshPanel;
frameRight.RefreshPanel;
end
else
begin
with ActiveFrame do
UnSelectFileIfSelected(GetActiveItem);
if param <> '' then
sLinkToCreate := param
else
begin
if NotActiveFrame.FileSource is TFileSystemFileSource then
sLinkToCreate := NotActiveFrame.CurrentPath
else
sLinkToCreate := ActiveFrame.CurrentPath
end;
sLinkToCreate := sLinkToCreate + SelectedFiles[0].Name;
if ShowHardLinkForm(sExistingFile, sLinkToCreate, ActiveFrame.CurrentPath) then
begin
ActiveFrame.Reload;
if NotActiveFrame.FileSource is TFileSystemFileSource then
NotActiveFrame.Reload;
end;
end;
ActiveFrame.SetFocus;
finally
FreeAndNil(SelectedFiles);
end;
end;
end;
}
end;
procedure TActs.cm_ReverseOrder(param:string);