📄 main.pas
字号:
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, MiTeC_WinIOCTL, StdCtrls, ComCtrls, ExtCtrls, ImgList, MSI_Storage,
MSI_Disk, MSI_Common, MSI_DeviceMonitor;
type
Twnd_dv_Main = class(TForm)
Tree: TTreeView;
bRefresh: TButton;
bSave: TButton;
bClose: TButton;
sd: TSaveDialog;
Storage: TMiTeC_Storage;
Disk: TMiTeC_Disk;
List: TListView;
Panel1: TPanel;
Panel2: TPanel;
Splitter1: TSplitter;
ilStorage: TImageList;
DeviceMonitor: TMiTeC_DeviceMonitor;
cbxAuto: TCheckBox;
procedure DeviceMonitorVolumeConnect(Sender: TObject; Drive: Char;
Remote: Boolean);
procedure cmRefresh(Sender: TObject);
procedure bCloseClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure TreeDeletion(Sender: TObject; Node: TTreeNode);
procedure TreeCustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
State: TCustomDrawState; var DefaultDraw: Boolean);
procedure TreeChange(Sender: TObject; Node: TTreeNode);
procedure bSaveClick(Sender: TObject);
private
public
end;
var
wnd_dv_Main: Twnd_dv_Main;
implementation
uses MiTeC_StrUtils, MiTeC_Routines;
{$R *.dfm}
procedure Twnd_dv_Main.cmRefresh(Sender: TObject);
var
rd,c,i,j: Integer;
n,r: TTreeNode;
pi: PInteger;
s,d: string;
begin
d:='';
Tree.OnChange:=nil;
with Storage do
try
Screen.Cursor:=crHourGlass;
RefreshData;
Tree.Items.BeginUpdate;
try
Tree.Items.Clear;
c:=PhysicalCount;
for i:=0 to PhysicalCount-1 do
with Physical[i] do begin
New(pi);
pi^:=i;
if Size>0 then
r:=Tree.Items.AddChildObject(nil,Trim(Format('%s (%d MB)',[Model,Size shr 20])),pi)
else
r:=Tree.Items.AddChildObject(nil,Trim(Format('%s',[Model])),pi);
r.ImageIndex:=1;
case DeviceType of
FILE_DEVICE_CD_ROM,
FILE_DEVICE_DVD: r.ImageIndex:=2;
FILE_DEVICE_TAPE: r.ImageIndex:=3;
FILE_DEVICE_DISK: if Removable then
r.ImageIndex:=0;
end;
r.SelectedIndex:=r.ImageIndex;
for j:=0 to LogicalCount-1 do
with Logical[j] do
if PhysicalIndex=i then begin
d:=d+Copy(Drive,1,1);
New(pi);
pi^:=j;
if not(DeviceType in [FILE_DEVICE_CD_ROM,FILE_DEVICE_DVD, FILE_DEVICE_TAPE,FILE_DEVICE_UNKNOWN]) and (Length(Layout)>0) and (LayoutIndex>-1) then
n:=Tree.Items.AddChildObject(r,Format('%s: (%s %s - %d MB)',[
Drive,
GetPartitionType(Layout[LayoutIndex].Number,Layout[LayoutIndex].Typ),
GetPartitionSystem(Layout[LayoutIndex].Typ),
Layout[LayoutIndex].Length.QuadPart shr 20]),pi)
else
n:=Tree.Items.AddChildObject(r,Format('%s:',[Drive]),pi);
n.ImageIndex:=r.ImageIndex;
n.SelectedIndex:=n.ImageIndex;
end;
end;
new(pi);
pi^:=-1;
r:=Tree.Items.AddChildObject(nil,'Network drives',pi);
r.ImageIndex:=4;
r.SelectedIndex:=r.ImageIndex;
Disk.RefreshData;
s:=Disk.AvailableDisks;
with Disk do
for i:=1 to Length(s) do begin
Drive:=Format('%s:\',[Copy(s,i,1)]);
if MediaType=dtRemote then begin
d:=d+Copy(Drive,1,1);
new(pi);
pi^:=i;
n:=Tree.Items.AddChildObject(r,Format('%s (%s)',[Drive,UNCPath]),pi);
n.ImageIndex:=r.ImageIndex;
n.SelectedIndex:=n.ImageIndex;
end;
end;
if r.Count=0 then
Tree.Items.Delete(r);
new(pi);
pi^:=-2;
r:=Tree.Items.AddChildObject(nil,'Removable drives',pi);
r.ImageIndex:=0;
r.SelectedIndex:=r.ImageIndex;
with Disk do
for i:=1 to Length(s) do begin
Drive:=Format('%s:\',[Copy(s,i,1)]);
if (Pos(Copy(s,i,1),d)=0) and (MediaType=dtRemovable) then begin
d:=d+Copy(Drive,1,1);
new(pi);
pi^:=i;
n:=Tree.Items.AddChildObject(r,Format('%s',[Drive]),pi);
n.ImageIndex:=r.ImageIndex;
n.SelectedIndex:=n.ImageIndex;
Inc(rd);
end;
end;
if r.Count=0 then
Tree.Items.Delete(r);
new(pi);
pi^:=-2;
r:=Tree.Items.AddChildObject(nil,'Other drives',pi);
r.ImageIndex:=1;
r.SelectedIndex:=r.ImageIndex;
with Disk do
for i:=1 to Length(s) do begin
if Pos(Copy(s,i,1),d)=0 then begin
Drive:=Format('%s:\',[Copy(s,i,1)]);
new(pi);
pi^:=i;
n:=Tree.Items.AddChildObject(r,Format('%s',[Drive]),pi);
n.ImageIndex:=r.ImageIndex;
n.SelectedIndex:=n.ImageIndex;
end;
end;
if r.Count=0 then
Tree.Items.Delete(r);
Tree.FullExpand;
finally
Tree.Items.EndUpdate;
end;
finally
Screen.Cursor:=crDefault;
Caption:=Format('Storage Devices (%d physical, %d logical)',[PhysicalCount+rd, Length(s)]);
end;
Tree.OnChange:=TreeChange;
end;
procedure Twnd_dv_Main.DeviceMonitorVolumeConnect(Sender: TObject; Drive: Char;
Remote: Boolean);
begin
if cbxAuto.Checked then
cmRefresh(nil);
end;
procedure Twnd_dv_Main.bCloseClick(Sender: TObject);
begin
Close;
end;
procedure Twnd_dv_Main.FormCreate(Sender: TObject);
begin
cmRefresh(nil);
end;
procedure Twnd_dv_Main.TreeDeletion(Sender: TObject; Node: TTreeNode);
begin
if Assigned(Node.Data) then
Dispose(PInteger(Node.Data));
end;
procedure Twnd_dv_Main.TreeCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if Assigned(Node) then
if Node.Level=0 then
Sender.Canvas.Font.Style:=[fsBold];
end;
procedure Twnd_dv_Main.TreeChange(Sender: TObject; Node: TTreeNode);
var
s: string;
begin
List.Items.BeginUpdate;
List.Columns.BeginUpdate;
try
List.Items.Clear;
if Assigned(Node) and Assigned(Node.Data) then begin
if PInteger(Node.Data)^<0 then
Exit;
if Node.Level=0 then with Storage.Physical[PInteger(Node.Data)^] do begin
with List.Items.Add do begin
Caption:='Serial number';
SubItems.Add(SerialNumber);
end;
with List.Items.Add do begin
Caption:='Revision';
SubItems.Add(Revision);
end;
with List.Items.Add do begin
Caption:='Model';
SubItems.Add(Model);
end;
with List.Items.Add do begin
Caption:='Bus Type';
SubItems.Add(GetStorageBusTypeStr(BusType));
end;
s:='';
case DeviceType of
FILE_DEVICE_CD_ROM: s:='CD-ROM';
FILE_DEVICE_DVD: s:='DVD';
FILE_DEVICE_MASS_STORAGE: s:='Mass Storage';
FILE_DEVICE_TAPE: s:='Tape';
end;
if s<>'' then
with List.Items.Add do begin
Caption:='Device Type';
SubItems.Add(s);
end;
with List.Items.Add do begin
Caption:='Media Type';
SubItems.Add(GetDeviceMediaTypeStr(MediaType));
end;
if (DeviceType=FILE_DEVICE_CD_ROM) or (DeviceType=FILE_DEVICE_DVD) then begin
s:='';
if Read_CDRW then
s:=s+'CD-R,';
if Read_CDR then
s:=s+'CD-RW,';
if Read_DVDROM then
s:=s+'DVD-ROM,';
if Read_DVDR then
s:=s+'DVD-R,';
if Read_DVDRAM then
s:=s+'DVD-RAM,';
SetLength(s,Length(s)-1);
with List.Items.Add do begin
Caption:='Read Caps';
SubItems.Add(s);
end;
s:='';
if Write_CDRW then
s:=s+'CD-R,';
if Write_CDR then
s:=s+'CD-RW,';
if Write_DVDR then
s:=s+'DVD-R,';
if Write_DVDRAM then
s:=s+'DVD-RAM,';
SetLength(s,Length(s)-1);
with List.Items.Add do begin
Caption:='Write Caps';
SubItems.Add(s);
end;
end;
if HaId>=0 then
with List.Items.Add do begin
Caption:='SCSI adapter';
SubItems.Add(IntToStr(HaId));
end;
if PathId>=0 then
with List.Items.Add do begin
Caption:='Bus';
SubItems.Add(IntToStr(PathId));
end;
if Target>=0 then
with List.Items.Add do begin
Caption:='Target device';
SubItems.Add(IntToStr(Target));
end;
if Lun>=0 then
with List.Items.Add do begin
Caption:='Logical unit number';
SubItems.Add(IntToStr(Lun));
end;
//end;
if Temperature>0 then
with List.Items.Add do begin
Caption:='Temperature';
SubItems.Add(Format('%d癈',[Temperature]));
end;
if Size>0 then begin
with List.Items.Add do begin
Caption:='Capacity';
SubItems.Add(Format('%d MB',[Size shr 20]));
end;
with List.Items.Add do begin
Caption:='Cyls';
SubItems.Add(Format('%d',[Cylinders]));
end;
with List.Items.Add do begin
Caption:='Heads';
SubItems.Add(Format('%d',[Heads]));
end;
with List.Items.Add do begin
Caption:='Sectors per track';
SubItems.Add(Format('%d',[SectorsPerTrack]));
end;
with List.Items.Add do begin
Caption:='Bytes per sector';
SubItems.Add(Format('%d',[BytesPerSector]));
end;
end;
if ATAVersion<>0 then
with List.Items.Add do begin
Caption:='ATA version';
SubItems.Add(Format('%d',[ATAversion]));
end;
if ECCCode<>0 then
with List.Items.Add do begin
Caption:='ECC';
SubItems.Add(Format('%d',[ECCCode]));
end;
if CtlBufSize<>0 then
with List.Items.Add do begin
Caption:='Buffer size';
SubItems.Add(Format('%d KB',[CtlBufSize shr 10]));
end;
with List.Items.Add do begin
Caption:='S.M.A.R.T.';
if SMARTSupport then begin
if SMARTActive then
SubItems.Add('Supported and active')
else
SubItems.Add('Supported and NOT active');
end else
SubItems.Add('NOT supported');
end;
end else begin
if PInteger(Node.Parent.Data)^<0 then
Disk.Drive:=Copy(Disk.AvailableDisks,PInteger(Node.Data)^,1)+':'
else
Disk.Drive:=Storage.Logical[PInteger(Node.Data)^].Drive+':';
with List.Items.Add do begin
Caption:='Volume label';
SubItems.Add(Disk.VolumeLabel);
end;
with List.Items.Add do begin
Caption:='Serial number';
SubItems.Add(Disk.SerialNumber);
end;
with List.Items.Add do begin
Caption:='Capacity';
SubItems.Add(Format('%d MB',[Disk.Capacity shr 20]));
end;
with List.Items.Add do begin
Caption:='Free';
SubItems.Add(Format('%d MB',[Disk.FreeSpace shr 20]));
end;
with List.Items.Add do begin
Caption:='File system';
SubItems.Add(Disk.FileSystem);
end;
end;
end;
finally
List.Items.EndUpdate;
List.Columns.EndUpdate;
end;
end;
procedure Twnd_dv_Main.bSaveClick(Sender: TObject);
begin
if sd.Execute then
Storage.SaveToStorage(sd.FileName);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -