forked from doublecmd/doublecmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffileproperties.pas
940 lines (835 loc) · 28 KB
/
ffileproperties.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
{
Double Commander
-------------------------------------------------------------------
File Properties Dialog
Copyright (C) 2003-2004 Radek Cervinka ([email protected])
Copyright (C) 2003 Martin Matusu <[email protected]>
Copyright (C) 2006-2023 Alexander Koblov ([email protected])
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, see <http://www.gnu.org/licenses/>.
}
unit fFileProperties;
{$mode objfpc}{$H+}
interface
uses
LResources, SysUtils, Classes, Graphics, Forms, StdCtrls, Buttons, ComCtrls,
Dialogs, Controls, ExtCtrls, Grids, ButtonPanel, DividerBevel, KASCDEdit,
DCBasicTypes, uFile, uFileProperty, uFileSource, uFileSourceOperation,
uFileSourceCalcStatisticsOperation, uFileSourceSetFilePropertyOperation,
DCOSUtils;
type
{ TfrmFileProperties }
TfrmFileProperties = class(TForm)
ButtonPanel: TButtonPanel;
cbExecGroup: TCheckBox;
cbExecOther: TCheckBox;
cbExecOwner: TCheckBox;
cbReadGroup: TCheckBox;
cbReadOther: TCheckBox;
cbReadOwner: TCheckBox;
cbSgid: TCheckBox;
cbSticky: TCheckBox;
cbSuid: TCheckBox;
cbWriteGroup: TCheckBox;
cbWriteOther: TCheckBox;
cbWriteOwner: TCheckBox;
cbxGroups: TComboBox;
cbxUsers: TComboBox;
chkExecutable: TCheckBox;
chkRecursive: TCheckBox;
DividerBevel1: TDividerBevel;
DividerBevel2: TDividerBevel;
DividerBevel3: TDividerBevel;
DividerBevel4: TDividerBevel;
edtOctal: TEdit;
lblExecutable: TLabel;
lblFileName: TLabel;
imgFileIcon: TImage;
lblFolder: TKASCDEdit;
lblFolderStr: TLabel;
lblGroupStr: TLabel;
lblLastAccess: TKASCDEdit;
lblLastAccessStr: TLabel;
lblLastModif: TKASCDEdit;
lblLastModifStr: TLabel;
lblLastStChange: TKASCDEdit;
lblLastStChangeStr: TLabel;
lblCreated: TKASCDEdit;
lblCreatedStr: TLabel;
lblOctal: TLabel;
lblAttrBitsStr: TLabel;
lblAttrText: TLabel;
lblExec: TLabel;
lblFileStr: TLabel;
lblFile: TLabel;
lblAttrGroupStr: TLabel;
lblAttrOtherStr: TLabel;
lblAttrOwnerStr: TLabel;
lblOwnerStr: TLabel;
lblRead: TLabel;
lblSize: TKASCDEdit;
lblSizeOnDisk: TKASCDEdit;
lblContains: TKASCDEdit;
lblSizeStr: TLabel;
lblSizeOnDiskStr: TLabel;
lblContainsStr: TLabel;
lblSymlink: TKASCDEdit;
lblAttrTextStr: TLabel;
lblSymlinkStr: TLabel;
lblMediaType: TKASCDEdit;
lblMediaTypeStr: TLabel;
lblType: TKASCDEdit;
lblTypeStr: TLabel;
lblLinks: TKASCDEdit;
lblLinksStr: TLabel;
lblWrite: TLabel;
pnlOwner: TPanel;
pnlCaption: TPanel;
pnlData: TPanel;
pnlIcon: TPanel;
pcPageControl: TPageControl;
sgPlugins: TStringGrid;
tsPlugins: TTabSheet;
tmUpdateFolderSize: TTimer;
tsProperties: TTabSheet;
tsAttributes: TTabSheet;
procedure cbChangeModeClick(Sender: TObject);
procedure chkExecutableChange(Sender: TObject);
procedure edtOctalKeyPress(Sender: TObject; var Key: char);
procedure edtOctalKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure OKButtonClick(Sender: TObject);
procedure tmUpdateFolderSizeTimer(Sender: TObject);
procedure FileSourceOperationStateChangedNotify(Operation: TFileSourceOperation;
State: TFileSourceOperationState);
private
bPerm: Boolean;
FFileSource: IFileSource;
FFiles: TFiles;
FPropertyFormatter: IFilePropertyFormatter;
FFileSourceCalcStatisticsOperation: TFileSourceCalcStatisticsOperation;
FChangeTriggersEnabled: Boolean;
FFileAttr: TFileAttributeData;
FFileType,
OriginalAttr: TFileAttrs;
OriginalUser, OriginalGroup: String;
FOperation: TFileSourceSetFilePropertyOperation;
procedure ShowType(Attrs: TFileAttrs);
procedure ShowExecutable;
procedure ShowPermissions(Mode: TFileAttrs);
function GetModeFromForm(out ExcludeAttrs: TFileAttrs): TFileAttrs;
function FormatSize(ASize: Int64): String;
procedure ShowMany;
procedure ShowFile(iIndex:Integer);
procedure StartCalcFolderSize;
procedure StopCalcFolderSize;
procedure ShowPlugin(iIndex:Integer);
procedure UpdateAllowGrayed(AllowGrayed: Boolean);
function FormatUnixAttributesEx(iAttr: TFileAttrs): String;
public
constructor Create(AOwner: TComponent; aFileSource: IFileSource; theFiles: TFiles); reintroduce;
destructor Destroy; override;
end;
procedure ShowFileProperties(aFileSource: IFileSource; const aFiles: TFiles);
implementation
{$R *.lfm}
uses
LCLType, LazUTF8, uLng, BaseUnix, uUsersGroups, uDCUtils,
uDefaultFilePropertyFormatter, uMyUnix, DCFileAttributes, uGlobs, uWdxModule,
uFileSourceOperationTypes, uFileSystemFileSource, uOperationsManager, WdxPlugin,
uFileSourceOperationOptions, uKeyboard, DCStrUtils, uPixMapManager,
uFileSourceProperty, DCDateTimeUtils, uTypes;
procedure ShowFileProperties(aFileSource: IFileSource; const aFiles: TFiles);
begin
if aFiles.Count > 0 then
begin
with TfrmFileProperties.Create(Application, aFileSource, aFiles) do
try
ShowModal;
finally
Free;
end;
end;
end;
constructor TfrmFileProperties.Create(AOwner: TComponent; aFileSource: IFileSource; theFiles: TFiles);
var
ASize: Integer;
AFiles: TFiles;
HasAttr: Boolean;
ActiveFile: TFile;
aFileProperties: TFileProperties;
begin
FFiles := theFiles.Clone;
FFileSource:= aFileSource;
FChangeTriggersEnabled := True;
FPropertyFormatter := MaxDetailsFilePropertyFormatter;
ActiveFile:= FFiles[0];
HasAttr:= (fspDirectAccess in aFileSource.Properties) and
(mbFileGetAttr(ActiveFile.FullPath, FFileAttr));
if HasAttr then
begin
{$IFDEF UNIX}
if not (fpOwner in ActiveFile.SupportedProperties) then
begin
ActiveFile.Properties[fpOwner]:= TFileOwnerProperty.Create;
end;
ActiveFile.OwnerProperty.Group:= FFileAttr.FindData.st_gid;
ActiveFile.OwnerProperty.Owner:= FFileAttr.FindData.st_uid;
{$ENDIF}
if fpModificationTime in ActiveFile.SupportedProperties then
ActiveFile.ModificationTime:= FileTimeToDateTime(DCBasicTypes.TFileTime(FFileAttr.LastWriteTime));
if fpChangeTime in ActiveFile.SupportedProperties then
ActiveFile.ChangeTime:= FileTimeToDateTime(DCBasicTypes.TFileTime(FFileAttr.PlatformTime));
if fpLastAccessTime in ActiveFile.SupportedProperties then
ActiveFile.LastAccessTime:= FileTimeToDateTime(DCBasicTypes.TFileTime(FFileAttr.LastAccessTime));
end;
if (fsoSetFileProperty in aFileSource.GetOperationsTypes) then
begin
AFiles:= FFiles.Clone;
FillByte(aFileProperties, SizeOf(aFileProperties), 0);
if fpAttributes in ActiveFile.SupportedProperties then
aFileProperties[fpAttributes]:= ActiveFile.Properties[fpAttributes].Clone;
if fpOwner in ActiveFile.SupportedProperties then
aFileProperties[fpOwner]:= ActiveFile.Properties[fpOwner].Clone;
FOperation:= aFileSource.CreateSetFilePropertyOperation(AFiles,
aFileProperties) as TFileSourceSetFilePropertyOperation;
end;
inherited Create(AOwner);
tsProperties.AutoSize:= True;
tsAttributes.AutoSize:= True;
// Enable only supported file properties
if Assigned(FOperation) then
begin
if fpAttributes in FOperation.SupportedProperties then
begin
UpdateAllowGrayed((FFiles.Count > 1) or FFiles[0].IsDirectory);
end;
end;
ASize:= gIconsSize * Round( Application.MainForm.GetCanvasScaleFactor );
if ASize > 48 then ASize:= 48;
imgFileIcon.Width:= ASize;
imgFileIcon.Height:= ASize;
pnlOwner.Enabled:= Assigned(FOperation) and (fpOwner in FOperation.SupportedProperties);
tsAttributes.Enabled:= Assigned(FOperation) and (fpAttributes in FOperation.SupportedProperties);
end;
destructor TfrmFileProperties.Destroy;
begin
FFiles.Free;
StopCalcFolderSize;
FreeAndNil( FOperation );
inherited Destroy;
FPropertyFormatter := nil; // free interface
end;
function TfrmFileProperties.GetModeFromForm(out ExcludeAttrs: TFileAttrs): TFileAttrs;
begin
Result:= 0;
ExcludeAttrs:= 0;
case cbReadOwner.State of
cbChecked: Result:= (Result or S_IRUSR);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IRUSR;
end;
case cbWriteOwner.State of
cbChecked: Result:= (Result or S_IWUSR);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IWUSR;
end;
case cbExecOwner.State of
cbChecked: Result:= (Result or S_IXUSR);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IXUSR;
end;
case cbReadGroup.State of
cbChecked: Result:= (Result or S_IRGRP);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IRGRP;
end;
case cbWriteGroup.State of
cbChecked: Result:= (Result or S_IWGRP);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IWGRP;
end;
case cbExecGroup.State of
cbChecked: Result:= (Result or S_IXGRP);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IXGRP;
end;
case cbReadOther.State of
cbChecked: Result:= (Result or S_IROTH);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IROTH;
end;
case cbWriteOther.State of
cbChecked: Result:= (Result or S_IWOTH);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IWOTH;
end;
case cbExecOther.State of
cbChecked: Result:= (Result or S_IXOTH);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_IXOTH;
end;
case cbSuid.State of
cbChecked: Result:= (Result or S_ISUID);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_ISUID;
end;
case cbSgid.State of
cbChecked: Result:= (Result or S_ISGID);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_ISGID;
end;
case cbSticky.State of
cbChecked: Result:= (Result or S_ISVTX);
cbUnchecked: ExcludeAttrs:= ExcludeAttrs or S_ISVTX;
end;
end;
function TfrmFileProperties.FormatSize(ASize: Int64): String;
begin
if (ASize < 0) then
Result:= '???'
else if gFileSizeFormat in [fsfByte, fsfPersonalizedByte] then
Result:= cnvFormatFileSize(ASize)
else begin
Result:= Format('%s (%s)', [cnvFormatFileSize(ASize), IntToStrTS(ASize)]);
end;
end;
procedure TfrmFileProperties.ShowMany;
var
ASize: Int64;
AFile: TFile;
Index: Integer;
ABitmap: TBitmap;
UserID: Cardinal;
Files, Directories: Integer;
begin
ASize := 0;
Files := 0;
Directories := 0;
ABitmap := PixMapManager.GetThemeIcon('edit-copy', gIconsSize);
if Assigned(ABitmap) then
begin
imgFileIcon.Picture.Bitmap := ABitmap;
ABitmap.Free;
end;
for Index:= 0 to FFiles.Count - 1 do
begin
AFile:= FFiles[Index];
if AFile.IsDirectory then
Inc(Directories)
else begin
Inc(Files);
Inc(ASize, AFile.Size);
end;
end;
chkRecursive.Visible:= (Directories > 0);
DividerBevel4.Visible:= chkRecursive.Visible;
if (Directories = 0) then
begin
lblSize.Caption := FormatSize(ASize);
end
else if (fsoCalcStatistics in FFileSource.GetOperationsTypes) then
begin
StartCalcFolderSize // Start calculate folder size operation
end;
// Chown
if Assigned(FOperation.NewProperties[fpOwner]) then
begin
OriginalUser := '*';
OriginalGroup := '*';
// Get current user ID
UserID := fpGetUID;
// Only owner or root can change owner
bPerm := (UserID = FFileAttr.FindData.st_uid) or (UserID = 0);
// Owner combo box
cbxUsers.Text := OriginalUser;
// Only root can change owner
cbxUsers.Enabled := (UserID = 0);
if cbxUsers.Enabled then
begin
GetUsers(cbxUsers.Items);
cbxUsers.Sorted:= False;
cbxUsers.Items.Insert(0, '*');
end;
// Group combo box
cbxGroups.Text := OriginalGroup;
cbxGroups.Enabled := bPerm;
if bPerm then
begin
GetUsrGroups(UserID, cbxGroups.Items);
cbxGroups.Sorted:= False;
cbxGroups.Items.Insert(0, '*');
end;
end;
lblFile.Caption := Format(rsPropsContains, [Files, Directories]);
lblFileName.Caption := lblFile.Caption;
lblContains.Visible:= (Directories > 0);
lblContainsStr.Visible:= (Directories > 0);
lblMediaType.Visible:= False;
lblMediaTypeStr.Visible:= False;
lblSizeOnDisk.Visible:= False;
lblSizeOnDiskStr.Visible:= False;
lblSymlink.Visible:= False;
lblSymlinkStr.Visible:= False;
lblLinks.Visible:= False;
lblLinksStr.Visible:= False;
lblLastAccess.Visible:= False;
lblLastAccessStr.Visible:= False;
lblLastModif.Visible:= False;
lblLastModifStr.Visible:= False;
lblLastStChange.Visible:= False;
lblLastStChangeStr.Visible:= False;
lblCreated.Visible := False;
lblCreatedStr.Visible := False;
lblFolder.Caption:= FFiles.Path;
lblExecutable.Visible:= False;
chkExecutable.Visible:= False;
FFileType:= FFiles[0].Attributes and S_IFMT;
for Index:= 1 to FFiles.Count - 1 do
begin
if (FFileType <> (FFiles[Index].Attributes and S_IFMT)) then
begin
lblType.Caption:= rsPropsMultipleTypes;
Exit;
end;
end;
ShowType(FFileType);
end;
procedure TfrmFileProperties.cbChangeModeClick(Sender: TObject);
var
AMode, ExcludeAttrs: TFileAttrs;
CheckBox: TCheckBox absolute Sender;
begin
if fsCreating in FormState then exit;
if FChangeTriggersEnabled then
begin
FChangeTriggersEnabled := False;
if CheckBox.State = cbGrayed then
begin
edtOctal.Text:= EmptyStr;
lblAttrText.Caption:= EmptyStr;
end
else begin
AMode:= GetModeFromForm(ExcludeAttrs);
edtOctal.Text:= DecToOct(AMode);
lblAttrText.Caption:= FormatUnixAttributesEx(AMode);
end;
FChangeTriggersEnabled := True;
end;
end;
procedure TfrmFileProperties.chkExecutableChange(Sender: TObject);
begin
if chkExecutable.Tag = 0 then
begin
chkExecutable.Tag:= 1;
case chkExecutable.State of
cbChecked,
cbUnchecked:
begin
cbExecOwner.Checked:= chkExecutable.Checked;
cbExecGroup.Checked:= chkExecutable.Checked;
cbExecOther.Checked:= chkExecutable.Checked;
end;
cbGrayed:
begin
cbExecOwner.Checked:= ((OriginalAttr and S_IXUSR) = S_IXUSR);
cbExecGroup.Checked:= ((OriginalAttr and S_IXGRP) = S_IXGRP);
cbExecOther.Checked:= ((OriginalAttr and S_IXOTH) = S_IXOTH);
end;
end;
chkExecutable.Tag:= 0;
end;
end;
procedure TfrmFileProperties.edtOctalKeyPress(Sender: TObject; var Key: char);
begin
if not ((Key in ['0'..'7']) or (Key = Chr(VK_BACK)) or (Key = Chr(VK_DELETE))) then
Key:= #0;
end;
procedure TfrmFileProperties.edtOctalKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
AMode: TFileAttrs;
begin
if FChangeTriggersEnabled then
begin
FChangeTriggersEnabled := False;
AMode:= OctToDec(edtOctal.Text);
lblAttrText.Caption := FormatUnixAttributesEx(AMode);
ShowPermissions(AMode);
FChangeTriggersEnabled := True;
end;
end;
procedure TfrmFileProperties.ShowPermissions(Mode: TFileAttrs);
begin
cbReadOwner.Checked:= ((Mode AND S_IRUSR) = S_IRUSR);
cbWriteOwner.Checked:= ((Mode AND S_IWUSR) = S_IWUSR);
cbExecOwner.Checked:= ((Mode AND S_IXUSR) = S_IXUSR);
cbReadGroup.Checked:= ((Mode AND S_IRGRP) = S_IRGRP);
cbWriteGroup.Checked:= ((Mode AND S_IWGRP) = S_IWGRP);
cbExecGroup.Checked:= ((Mode AND S_IXGRP) = S_IXGRP);
cbReadOther.Checked:= ((Mode AND S_IROTH) = S_IROTH);
cbWriteOther.Checked:= ((Mode AND S_IWOTH) = S_IWOTH);
cbExecOther.Checked:= ((Mode AND S_IXOTH) = S_IXOTH);
cbSuid.Checked:= ((Mode AND S_ISUID) = S_ISUID);
cbSgid.Checked:= ((Mode AND S_ISGID) = S_ISGID);
cbSticky.Checked:= ((Mode AND S_ISVTX) = S_ISVTX);
ShowExecutable;
end;
procedure TfrmFileProperties.ShowFile(iIndex:Integer);
var
Idx: PtrInt;
ASize: Int64;
UserID: Cardinal;
hasSize: Boolean;
ABitmap: TBitmap;
Attrs: TFileAttrs;
AMimeType: String;
isFileSystem: Boolean;
begin
isFileSystem := FFileSource.IsClass(TFileSystemFileSource);
Idx := PixMapManager.GetIconByFile(FFiles[iIndex], isFileSystem, True, sim_all_and_exe, True);
if Idx < 0 then Idx:= PixMapManager.GetDefaultIcon(FFiles[iIndex]);
ABitmap:= PixMapManager.GetBitmap(Idx);
imgFileIcon.Picture.Bitmap := ABitmap;
ABitmap.Free;
with FFiles[iIndex] do
begin
lblFileName.Caption:= Name;
lblFile.Caption:= Name;
lblFolder.Caption:= Path;
if not (fpCreationTime in SupportedProperties) then
begin
if fpCreationTime in FFileSource.RetrievableFileProperties then
begin
FFileSource.RetrieveProperties(FFiles[iIndex], [fpCreationTime], []);
end;
end;
// Size
hasSize := (fpSize in SupportedProperties) and (not IsLinkToDirectory);
if hasSize then
begin
if IsDirectory and (fsoCalcStatistics in FFileSource.GetOperationsTypes) then
StartCalcFolderSize // Start calculate folder size operation
else
lblSize.Caption := FormatSize(Size);
end;
lblSize.Visible := hasSize;
lblSizeStr.Visible := hasSize;
lblContains.Visible:= IsDirectory;
lblContainsStr.Visible:= IsDirectory;
// Size on disk
hasSize:= (fpAttributes in SupportedProperties) and (FPS_ISREG(Attributes)) and
(FFileAttr.FindData.st_ino <> 0);
if hasSize then
begin
ASize:= FFileAttr.FindData.st_blocks * 512;
lblSizeOnDisk.Caption:= FormatSize(ASize);
end;
lblSizeOnDisk.Visible:= hasSize;
lblSizeOnDiskStr.Visible:= hasSize;
// Links
lblLinks.Visible:= isFileSystem and (FPS_ISREG(Attributes)) and (FFileAttr.FindData.st_nlink > 1);
if lblLinks.Visible then lblLinks.Caption:= IntToStrTS(FFileAttr.FindData.st_nlink);
lblLinksStr.Visible:= lblLinks.Visible;
// Times
lblLastAccess.Visible := fpLastAccessTime in SupportedProperties;
lblLastAccessStr.Visible := fpLastAccessTime in SupportedProperties;
if fpLastAccessTime in SupportedProperties then
lblLastAccess.Caption := Properties[fpLastAccessTime].Format(FPropertyFormatter)
else
lblLastAccess.Caption := '';
lblLastStChange.Visible := fpChangeTime in SupportedProperties;
lblLastStChangeStr.Visible := fpChangeTime in SupportedProperties;
if fpChangeTime in SupportedProperties then
lblLastStChange.Caption := Properties[fpChangeTime].Format(FPropertyFormatter)
else
lblLastStChange.Caption := '';
lblLastModif.Visible := fpModificationTime in SupportedProperties;
lblLastModifStr.Visible := fpModificationTime in SupportedProperties;
if fpModificationTime in SupportedProperties then
lblLastModif.Caption := Properties[fpModificationTime].Format(FPropertyFormatter)
else
lblLastModif.Caption := '';
lblCreated.Visible := fpCreationTime in SupportedProperties;
lblCreatedStr.Visible := fpCreationTime in SupportedProperties;
if fpCreationTime in SupportedProperties then
lblCreated.Caption := Properties[fpCreationTime].Format(FPropertyFormatter)
else
lblCreated.Caption := '';
// Chown
if fpOwner in SupportedProperties then
begin
OriginalUser := UIDToStr(OwnerProperty.Owner);
OriginalGroup := GIDToStr(OwnerProperty.Group);
// Get current user ID
UserID := fpGetUID;
// Only owner or root can change owner
bPerm := (UserID = OwnerProperty.Owner) or (UserID = 0);
// Owner combo box
cbxUsers.Text := OriginalUser;
// Only root can change owner
cbxUsers.Enabled := (UserID = 0);
if cbxUsers.Enabled then GetUsers(cbxUsers.Items);
// Group combo box
cbxGroups.Text := OriginalGroup;
cbxGroups.Enabled := bPerm;
if bPerm then GetUsrGroups(UserID, cbxGroups.Items);
end;
// MIME type
hasSize:= isFileSystem;
if hasSize then
begin
AMimeType:= GetFileMimeType(FullPath);
hasSize:= Length(AMimeType) > 0;
lblMediaType.Caption:= AMimeType;
end;
lblMediaType.Visible:= hasSize;
lblMediaTypeStr.Visible:= hasSize;
// Attributes
if fpAttributes in SupportedProperties then
begin
Attrs := AttributesProperty.Value;
FFileType:= Attrs and S_IFMT;
OriginalAttr := Attrs and $0FFF;
ShowPermissions(Attrs);
lblExecutable.Visible:= FPS_ISREG(Attrs);
chkExecutable.Visible:= lblExecutable.Visible;
lblAttrText.Caption := Properties[fpAttributes].Format(DefaultFilePropertyFormatter);
ShowType(Attrs);
chkRecursive.Visible := IsDirectory;
DividerBevel4.Visible:= chkRecursive.Visible;
lblSymlink.Visible := FPS_ISLNK(Attrs);
lblSymlinkStr.Visible := lblSymlink.Visible;
if lblSymlink.Visible then
begin
if isFileSystem then
lblSymlink.Caption := ReadSymLink(FullPath)
else if (Assigned(LinkProperty) and LinkProperty.IsValid) then
lblSymlink.Caption := LinkProperty.LinkTo
else begin
lblSymlink.Visible := False;
lblSymlinkStr.Visible := False;
end;
end;
end
else
begin
chkRecursive.Visible:= False;
DividerBevel4.Visible:= False;
edtOctal.Text:= rsMsgErrNotSupported;
lblAttrText.Caption:= rsMsgErrNotSupported;
lblType.Caption:= rsPropsUnknownType;
lblSymlink.Caption:= '';
end;
end;
tsPlugins.Visible:= isFileSystem;
if isFileSystem then ShowPlugin(iIndex);
end;
procedure TfrmFileProperties.FormCreate(Sender: TObject);
begin
InitPropStorage(Self);
if (FFiles.Count = 1) then
ShowFile(0)
else begin
ShowMany;
end;
end;
procedure TfrmFileProperties.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_TAB:
begin
if Shift * KeyModifiersShortcut = [ssCtrl] then
begin
pcPageControl.SelectNextPage(True);
Key := 0;
end
else if Shift * KeyModifiersShortcut = [ssCtrl, ssShift] then
begin
pcPageControl.SelectNextPage(False);
Key := 0;
end;
end;
end;
end;
procedure TfrmFileProperties.OKButtonClick(Sender: TObject);
var
theNewProperties: TFileProperties;
begin
if Assigned(FOperation) then
begin
with FOperation do
begin
theNewProperties:= NewProperties;
if fpAttributes in SupportedProperties then
begin
if theNewProperties[fpAttributes] is TUnixFileAttributesProperty then
IncludeAttributes:= GetModeFromForm(ExcludeAttributes);
// Nothing changed, clear new property
if (IncludeAttributes = 0) and (ExcludeAttributes = 0) then
begin
theNewProperties[fpAttributes].Free;
theNewProperties[fpAttributes]:= nil;
end;
end;
if fpOwner in SupportedProperties then
begin
if (OriginalUser <> cbxUsers.Text) or (OriginalGroup <> cbxGroups.Text) then
begin
TFileOwnerProperty(theNewProperties[fpOwner]).Owner:= StrToUID(cbxUsers.Text);
TFileOwnerProperty(theNewProperties[fpOwner]).Group:= StrToGID(cbxGroups.Text);
end
// Nothing changed, clear new property
else begin
theNewProperties[fpOwner].Free;
theNewProperties[fpOwner]:= nil;
end;
end;
NewProperties:= theNewProperties;
Recursive:= chkRecursive.Checked;
end;
OperationsManager.AddOperation(FOperation);
FOperation:= nil;
end;
end;
procedure TfrmFileProperties.tmUpdateFolderSizeTimer(Sender: TObject);
begin
if Assigned(FFileSourceCalcStatisticsOperation) then
with FFileSourceCalcStatisticsOperation.RetrieveStatistics do
begin
lblSize.Caption := FormatSize(Size);
lblContains.Caption := Format(rsPropsContains, [Files, Directories]);
end;
end;
procedure TfrmFileProperties.FileSourceOperationStateChangedNotify(
Operation: TFileSourceOperation; State: TFileSourceOperationState);
begin
if Assigned(FFileSourceCalcStatisticsOperation) and (State = fsosStopped) then
begin
tmUpdateFolderSize.Enabled:= False;
tmUpdateFolderSizeTimer(tmUpdateFolderSize);
FFileSourceCalcStatisticsOperation := nil;
end;
end;
procedure TfrmFileProperties.ShowType(Attrs: TFileAttrs);
begin
if FPS_ISDIR(Attrs) then
lblType.Caption:= rsPropsFolder
{$IFDEF UNIX}
else if FPS_ISREG(Attrs) then
lblType.Caption:= rsPropsFile
else if FPS_ISCHR(Attrs) then
lblType.Caption:= rsPropsSpChrDev
else if FPS_ISBLK(Attrs) then
lblType.Caption:= rsPropsSpBlkDev
else if FPS_ISFIFO(Attrs) then
lblType.Caption:= rsPropsNmdPipe
else if FPS_ISLNK(Attrs) then
lblType.Caption:= rsPropsSymLink
else if FPS_ISSOCK(Attrs) then
lblType.Caption:= rsPropsSocket
{$ENDIF}
else
lblType.Caption:= rsPropsUnknownType;
end;
procedure TfrmFileProperties.ShowExecutable;
begin
if chkExecutable.Tag = 0 then
begin
if cbExecOwner.Checked and cbExecGroup.Checked and cbExecOther.Checked then
chkExecutable.State:= cbChecked
else if not (cbExecOwner.Checked or cbExecGroup.Checked or cbExecOther.Checked) then
chkExecutable.State:= cbUnchecked
else begin
chkExecutable.AllowGrayed:= True;
chkExecutable.State:= cbGrayed;
end;
end;
end;
procedure TfrmFileProperties.StartCalcFolderSize;
var
aFiles: TFiles;
begin
aFiles:= FFiles.Clone;
try
FFileSourceCalcStatisticsOperation:= FFileSource.CreateCalcStatisticsOperation(aFiles) as TFileSourceCalcStatisticsOperation;
if Assigned(FFileSourceCalcStatisticsOperation) then
begin
FFileSourceCalcStatisticsOperation.SkipErrors:= True;
FFileSourceCalcStatisticsOperation.SymLinkOption:= fsooslDontFollow;
FFileSourceCalcStatisticsOperation.AddStateChangedListener([fsosStopped], @FileSourceOperationStateChangedNotify);
OperationsManager.AddOperation(FFileSourceCalcStatisticsOperation, False);
tmUpdateFolderSize.Enabled:= True;
end;
finally
aFiles.Free;
end;
end;
procedure TfrmFileProperties.StopCalcFolderSize;
begin
if Assigned(FFileSourceCalcStatisticsOperation) then
begin
tmUpdateFolderSize.Enabled:= False;
FFileSourceCalcStatisticsOperation.Stop;
end;
FFileSourceCalcStatisticsOperation:= nil;
end;
procedure TfrmFileProperties.ShowPlugin(iIndex: Integer);
var
I, J: Integer;
Value: String;
Index: Integer;
FileName: String;
WdxModule: TWdxModule;
begin
FileName:= FFiles[iIndex].FullPath;
Value:= LowerCase(FFiles[iIndex].Extension);
for Index:= 0 to gWdxPlugins.Count - 1 do
begin
WdxModule:= gWdxPlugins.GetWdxModule(Index);
if (Length(WdxModule.DetectStr) > 0) and WdxModule.FileParamVSDetectStr(FFiles[iIndex]) then
begin
if not gWdxPlugins.IsLoaded(Index) then
begin
if not gWdxPlugins.LoadModule(Index) then
Continue;
end;
J:= 0;
sgPlugins.RowCount:= WdxModule.FieldList.Count + 1;
for I:= 0 to WdxModule.FieldList.Count - 1 do
begin
if not (TWdxField(WdxModule.FieldList.Objects[I]).FType in [ft_fulltext, ft_fulltextw]) then
begin
Value:= WdxModule.CallContentGetValue(FileName, I, 0, CONTENT_DELAYIFSLOW);
if (Length(Value) > 0) then
begin
Inc(J);
sgPlugins.Cells[1, J]:= Value;
sgPlugins.Cells[0, J]:= TWdxField(WdxModule.FieldList.Objects[I]).LName;
end;
end;
end;
sgPlugins.RowCount:= J + 1;
tsPlugins.TabVisible:= J > 0;
if tsPlugins.TabVisible then Break;
end;
end;
end;
procedure TfrmFileProperties.UpdateAllowGrayed(AllowGrayed: Boolean);
var
Index: Integer;
begin
for Index:= 0 to tsAttributes.ControlCount - 1 do
begin
if tsAttributes.Controls[Index] is TCheckBox then
TCheckBox(tsAttributes.Controls[Index]).AllowGrayed:= AllowGrayed;
end;
end;
function TfrmFileProperties.FormatUnixAttributesEx(iAttr: TFileAttrs): String;
begin
if (FFiles.Count = 1) then
Result:= FormatUnixAttributes(FFileType or iAttr)
else begin
Result:= Copy(FormatUnixAttributes(iAttr), 2, MaxInt);
end;
end;
end.