unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ComCtrls, DriveTools, ExtCtrls, TeeProcs,
  TeEngine, Chart, Series;

type
  TForm1 = class(TForm)
    cmbClose: TBitBtn;
    driveSize: TChart;
    cboDrives: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    txtLabel: TEdit;
    GroupBox1: TGroupBox;
    txtFSName: TEdit;
    Label3: TLabel;
    chkCompressed: TCheckBox;
    chkCompression: TCheckBox;
    chkCaseSensitive: TCheckBox;
    Label4: TLabel;
    txtSN: TEdit;
    Label5: TLabel;
    txtMaxFileName: TEdit;
    Series1: TPieSeries;
    txtDriveType: TEdit;
    Label6: TLabel;
    Button1: TButton;
    procedure cmbCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cboDrivesSelect(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.cmbCloseClick(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  //Загрузка букв дисков
  if GetDriveLetters(cboDrives.Items) > 0 then
  begin
    //Выделим первый диск
    cboDrives.ItemIndex := 0;
    cboDrivesSelect(self);
  end
  else
    Button1.Enabled := False;
end;

procedure TForm1.cboDrivesSelect(Sender: TObject);
var info: DriveInfo;
    root: String;
    fullSize, freeSize: Int64;
begin
  root := cboDrives.Items[cboDrives.ItemIndex];
  //Загружаем информацию о выбранном диске
  GetDriveInformation(root, info);

  txtLabel.Text := info.DriveLabel;
  txtDriveType.Text := GetDriveTypeName(root);
  txtFSName.Text := info.FileSystemName;
  txtSN.Text := IntToHex(Int64(info.SerialNumber), 8);
  txtMaxFileName.Text := IntToStr(Integer(info.MaxFileNameLen));

  chkCaseSensitive.Checked := info.FileSystemOptions.CaseSensitive;
  chkCompression.Checked := info.FileSystemOptions.SupportCompression;
  chkCompressed.Checked := info.FileSystemOptions.IsCompressed;

  //Размер диска
  fullSize := GetDriveSize(root);
  if fullSize <> -1 then
    freeSize := GetDriveFreeSpace(root)
  else
  begin //Ошибка при обращении к диску
    fullSize := 0;
    freeSize := 0;
  end;
  //..формирование диаграммы
  driveSize.Series[0].Clear;
  driveSize.Series[0].Add( freeSize, 'Свободно');
  driveSize.Series[0].Add( fullSize - freeSize, 'Занято')
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //Изменение метки диска
  if not SetDriveLabel(cboDrives.Items[cboDrives.ItemIndex],
                       txtLabel.Text)
  then
    MessageBox(self.Handle, 'Не удалось поменять метку диска', 'Ошибка',
               MB_ICONEXCLAMATION)
  else
    //Перечитаем информацию о диске
    cboDrivesSelect(self);
end;

end.
