unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin, ExtCtrls, Buttons, RzPanel;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel3: TPanel;
    Label1: TLabel;
    RadioGroup1: TRadioGroup;
    Edit1: TEdit;
    SpinEdit1: TSpinEdit;
    GroupBox1: TGroupBox;
    Memo1: TMemo;
    breg: TSpeedButton;
    Label2: TLabel;
    euserid: TEdit;
    Label3: TLabel;
    eregid: TEdit;
    RzToolbar1: TRzToolbar;
    SpeedButton3: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton1: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    SpeedButton13: TSpeedButton;
    SpeedButton14: TSpeedButton;
    SpeedButton15: TSpeedButton;
    SpeedButton16: TSpeedButton;
    SpeedButton17: TSpeedButton;
    SpeedButton18: TSpeedButton;
    SpeedButton19: TSpeedButton;
    SpeedButton20: TSpeedButton;
    SpeedButton21: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
    procedure SpeedButton8Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure bregClick(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure SpeedButton10Click(Sender: TObject);
    procedure SpeedButton11Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);
    procedure SpeedButton14Click(Sender: TObject);
    procedure SpeedButton15Click(Sender: TObject);
    procedure SpeedButton16Click(Sender: TObject);
    procedure SpeedButton17Click(Sender: TObject);
    procedure SpeedButton18Click(Sender: TObject);
    procedure SpeedButton19Click(Sender: TObject);
    procedure SpeedButton20Click(Sender: TObject);
    procedure SpeedButton21Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
{$DEFINE usedll} //使用源码还是动态库开关
implementation
uses{$IFDEF usedll}JyDiskInfoDll{$ELSE}JyDiskInfo{$ENDIF};
{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
var s: ansistring;
begin
  s := edit1.text;
  if RadioGroup1.itemindex = 0 then
  begin
    memo1.text := '物理磁盘序号' + spinedit1.text + ',磁盘类型:' + GetDiskTypeStr(GetDiskType(spinedit1.value));
  end
  else
  begin
    memo1.text := '盘符' + edit1.text + ',磁盘类型:' + GetDiskTypeStr(GetDiskType(s[1]));
  end;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
var st: TStringList;
  i: Integer;
begin
  st := TStringList.Create;
  try
    memo1.text := '当前物理设备数:' + inttostr(GetPhysicalDriveCount(st));
    memo1.Lines.Add('设备序号');
    for i := 1 to st.Count do
      memo1.Lines.Add(st.strings[i - 1]);
  finally
    st.Free;
  end;
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
  if RunAsAdmin then
    memo1.text := '当前用户具有admin权限'
  else
    memo1.text := '当前用户无admin权限';
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
var s: ansistring;
begin
  s := edit1.Text;
  memo1.text := '盘符' + edit1.Text + ',对应物理磁盘序号' + inttostr(GetDiskIndex(s[1]));
end;

procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
  memo1.text := '物理磁盘序号' + spinedit1.Text + ',对应盘符' + GetDiskDrive(spinedit1.value);
end;

procedure TForm1.SpeedButton6Click(Sender: TObject);
begin
  memo1.text := '当前所有盘符' + GetDriverList;
end;

procedure TForm1.SpeedButton7Click(Sender: TObject);
begin
  memo1.text := '物理磁盘序号' + spinedit1.Text + ',分区数' + inttostr(GetPhysicalDrivePartitionCount(spinedit1.value));
end;

procedure TForm1.SpeedButton8Click(Sender: TObject);
var tm: Cardinal;
  s: ansistring;
begin
  s := edit1.text;
  tm := GetTickCount;
  if RadioGroup1.ItemIndex = 0 then
    memo1.text := '物理磁盘序号' + spinedit1.Text + ',序列号' + GetDiskSerialNumber(spinedit1.value)
  else
    memo1.text := '盘符' + edit1.Text + ',序列号' + GetDiskSerialNumber(s[1]);
  Memo1.Lines.Add('用时' + inttostr(GetTickCount - tm) + '毫秒')
end;

procedure TForm1.FormShow(Sender: TObject);
begin
{$IFDEF usedll}
  breg.visible := True;
  InitJyDiskDll();
{$ELSE}
  breg.visible := false;
{$ENDIF}
  label2.Visible := breg.visible;
  label3.Visible := breg.visible;
  euserid.Visible := breg.visible;
  eregid.Visible := breg.visible;
{$IFDEF CPUX64}
  caption := caption + ' win64位';
{$ELSE}
  caption := caption + ' win32位';
{$ENDIF}
  if RunAsAdmin then
    caption := caption + ' 管理员权限'
  else
    caption := caption + ' 非管理员权限';
end;

procedure TForm1.bregClick(Sender: TObject);
begin
{$IFDEF usedll}
  Init();
  doreg(euserid.Text, eregid.Text);
  if IsRegisted then
    memo1.text := '控件已注册'
  else
    memo1.text := '控件未注册';
{$ENDIF}
end;

procedure TForm1.SpeedButton9Click(Sender: TObject);
var i: Integer;
  s: ansistring;
begin
  s := Edit1.text;
  i := getDiskPartitionIndex(s[1]);
  memo1.text := '盘符' + edit1.Text + ',所在物理分区序号' + IntToStr(i);
  if i = 0 then
    if RunAsAdmin = false then
      memo1.text := memo1.text + ',获取需要管理员权限';
end;

procedure TForm1.SpeedButton10Click(Sender: TObject);
var VolumeName, VolumeSerialNumber, PartitionType: ansistring;
  TotalSpace, TotalFreeSpace: int64;
  s: ansistring;
begin
  s := edit1.text;
  if GetHardDiskPartitionInfo(s[1], VolumeName, VolumeSerialNumber, PartitionType, TotalSpace, TotalFreeSpace) = false then
    memo1.text := '获取盘符' + edit1.Text + '信息失败'
  else
  begin
    memo1.text := '获取盘符' + edit1.Text + '信息成功';
    Memo1.Lines.Add('卷名称' + VolumeName);
    Memo1.Lines.Add('序列号' + VolumeSerialNumber);
    Memo1.Lines.Add('分区类型' + PartitionType);
    Memo1.Lines.Add('总容量' + inttostr(TotalSpace));
    Memo1.Lines.Add('空闲容量' + inttostr(TotalFreeSpace));
  end;
end;

function Array2String(a: array of ansichar; exit0: boolean = true): ansistring;
var i: integer;
begin
  result := '';
  for i := 0 to high(a) do
  begin
    if a[i] = #0 then
      if exit0 then
        exit;
    result := result + a[i];
  end;
end;

procedure TForm1.SpeedButton11Click(Sender: TObject);
var i: Integer;
  s: string;
  adiskinfo: JyHDiskInfo;
  e: ansistring;
begin
  e := Edit1.text;
  if RadioGroup1.ItemIndex = 0 then
    i := SpinEdit1.Value
  else
    i := GetDiskIndex(e[1]);
  Memo1.Lines.Clear;
  if RadioGroup1.ItemIndex = 0 then
    memo1.text := '物理磁盘序号' + spinedit1.text
  else
    memo1.text := '盘符' + e[1];
  if getdiskinfo(i, adiskinfo) = false then
  begin
    memo1.text := memo1.text + ',获取磁盘smart信息失败';
    if RunAsAdmin = False then
      memo1.text := memo1.text + ',需要管理员权限';
    Exit;
  end;
  memo1.text := memo1.text + ',获取磁盘smart信息成功';
  memo1.lines.add('磁盘序列号:' + adiskinfo.SerialNumber);
  memo1.lines.add('固件版本:' + adiskinfo.FirmwareRev);
  memo1.lines.add('磁盘名称:' + adiskinfo.ModelNumber);
  memo1.lines.add('接口:' + adiskinfo.Interface_);
  s := '';
  if ADiskInfo.MaxTransferMode <> '' then
    s := '|' + Array2String(adiskinfo.MaxTransferMode);
  memo1.lines.add('传输模式:' + adiskinfo.CurrentTransferMode + s);
  memo1.lines.add('标准:' + adiskinfo.MajorVersion + '|' + adiskinfo.MinorVersion);
  s := '';
  if ADiskInfo.IsSmartSupported then
    s := JyStringLink(s, 'Smart', ',');
  if ADiskInfo.IsApmSupported then
    s := JyStringLink(s, 'APM', ',');
  if ADiskInfo.IsAamSupported then
    s := JyStringLink(s, 'AAM', ',');
   {if ADiskInfo.IsLba48Supported then
     s:=JyStringLink(s,'48bit LBA',',');}
  if ADiskInfo.IsNcqSupported then
    s := JyStringLink(s, 'NCQ', ',');
  if ADiskInfo.IsTrimSupported then
    s := JyStringLink(s, 'TRIM', ',');
  if ADiskInfo.IsDeviceSleepSupported then
    s := JyStringLink(s, 'DevSleep', ',');
   {if ADiskInfo.IsNvCacheSupported then
     s:=JyStringLink(s,'NV Cache',',');
   if ADiskInfo.IsSsd then
     s:=JyStringLink(s,'SSD',','); }
  memo1.lines.add('支持功能:' + s);
  memo1.lines.add('缓存大小:' + inttostr(round(ADiskInfo.BufferSize * 512 / (1024))) + 'kb');
  memo1.lines.add('扇区大小:' + inttostr(ADiskInfo.BytesPerSector));
  memo1.lines.add('转速:' + inttostr(ADiskInfo.RotationRate));

  memo1.lines.add('主机写入量总计:' + inttostr(Round(ADiskInfo.HostWrites * 512 / (1024 * 1024 * 1024))) + 'GB');
  memo1.lines.add('通电次数:' + inttostr(ADiskInfo.PowerOnCount));
  s := '通电时间:' + inttostr(ADiskInfo.PowerOnTime);
  //if ADiskInfo.DetectedTimeUnitType=
  memo1.lines.add(s + '小时');
  memo1.lines.add('温度:' + inttostr(ADiskInfo.Temperature));
  memo1.lines.add('磁盘容量:' + inttostr(round(ADiskInfo.disksize / (1000 * 1000 * 1000))) + 'GB');
  memo1.lines.add('smart项目数:' + inttostr(ADiskInfo.SmartCount));
  for i := 1 to ADiskInfo.SmartCount do
  begin // ADiskInfo.DataValue
    s := IntToStr(ADiskInfo.itemid[i - 1]) + '(' + inttohex(ADiskInfo.itemid[i - 1], 2) + ')' + ',' + GetSmartItemAttribName(ADiskInfo.itemid[i - 1]) + ',' + inttostr(ADiskInfo.CurrentValue[i - 1]) +
      ',' + inttostr(ADiskInfo.WorstValue[i - 1]) + ',' + inttostr(ADiskInfo.ThresholdValue[i - 1]) +
      ',' + inttohex(ADiskInfo.DataValue[i - 1], 12) + ',' + getStateStr(ADiskInfo.State[i - 1]);
    Memo1.Lines.Add(s);
  end;
end;

procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
  memo1.text := '字符串:' + euserid.text;
  Memo1.Lines.Add(getmd5string(euserid.text));
end;

procedure TForm1.SpeedButton13Click(Sender: TObject);
begin
  memo1.text := 'cpuid:' + getcpuid;
end;

procedure TForm1.SpeedButton14Click(Sender: TObject);
begin
  memo1.text := '显卡Id:' + GetDisplayDeviceID;
end;

procedure TForm1.SpeedButton15Click(Sender: TObject);
begin
  memo1.text := 'BiosId:' + GetBiosID;
end;

procedure TForm1.SpeedButton16Click(Sender: TObject);
begin
  memo1.text := 'ip:' + Getip;
end;

procedure TForm1.SpeedButton17Click(Sender: TObject);
begin
  memo1.text := 'macaddress:' + GetMacaddr;
end;

procedure TForm1.SpeedButton18Click(Sender: TObject);
begin
{$IFDEF usedll}
  if IsWin64 then
    memo1.text := 'dll是64位的'
  else
    memo1.text := 'dll是32位的';
{$ENDIF}
end;

procedure TForm1.SpeedButton19Click(Sender: TObject);
var s, v: ansistring;
begin
  memo1.Text := '得usb设备pid';
  v := '';
  if RadioGroup1.ItemIndex = 0 then
  begin
    memo1.Lines.Add('磁盘物理序号' + spinedit1.Text);
    v := getUsbPNPDeviceID(spinedit1.value);
    memo1.Lines.Add('pid:' + v);
  end
  else
  begin
    memo1.Lines.Add('盘符' + edit1.Text);
    s := edit1.Text;
    v := getUsbPNPDeviceID(s[1]);
    memo1.Lines.Add('pid:' + v);
  end;
  {if RunAsAdmin = False then
    if v = '' then
    begin
      memo1.Lines.Add('不是移动设备或者可能需要管理员权限');
      exit;
    end;}
end;

procedure TForm1.SpeedButton20Click(Sender: TObject);
var s: ansistring;
  v:Int64;
begin
  memo1.Text := '得盘大小';
  v := 0;
  if RadioGroup1.ItemIndex = 0 then
  begin
    memo1.Lines.Add('磁盘物理序号' + spinedit1.Text);
    v := GetDiskSize(spinedit1.value);
  end
  else
  begin
    memo1.Lines.Add('盘符' + edit1.Text);
    s := edit1.Text;
    v := GetDiskSize(s[1]);
  end;
  memo1.Lines.Add('字节:' + IntToStr(v)+','+FloatToStr(v/1024)+'K'+','+FloatToStr(v/(1024*1024))+'M'+','+FloatToStr(v/(1024*1024*1024))+'G');
end;

procedure TForm1.SpeedButton21Click(Sender: TObject);
var s: ansistring;
  v:ansistring;
begin
  memo1.Text := '得盘名称';
  v := '';
  if RadioGroup1.ItemIndex = 0 then
  begin
    memo1.Lines.Add('磁盘物理序号' + spinedit1.Text);
    v := GetDiskName(spinedit1.value);
  end
  else
  begin
    memo1.Lines.Add('盘符' + edit1.Text);
    s := edit1.Text;
    v := GetDiskName(s[1]);
  end;
  memo1.Lines.Add('名称:' + v);

end;

end.

