BSOne.SFC/Tocsg.Module/CDRomBlock/DCdBlkMain.pas

102 lines
2.6 KiB
Plaintext

unit DCdBlkMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Tocsg.Trace;
type
TDlgCdBlkMain = class(TForm)
btnFindBlock: TButton;
mmInfo: TMemo;
edDrive: TEdit;
btnGetType: TButton;
procedure btnFindBlockClick(Sender: TObject);
procedure btnGetTypeClick(Sender: TObject);
private
{ Private declarations }
Trace_: TTgTrace;
public
{ Public declarations }
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
end;
var
DlgCdBlkMain: TDlgCdBlkMain;
implementation
uses
Tocsg.Disk, Tocsg.Safe, Tocsg.Strings, Tocsg.Driver, Tocsg.Path;
{$R *.dfm}
Constructor TDlgCdBlkMain.Create(aOwner: TComponent);
begin
Inherited Create(aOwner);
DeleteFile(GetRunExePathDir + 'CDRomBlock.log');
Trace_ := TTgTrace.Create(GetRunExePathDir, 'CDRomBlock.log');
Trace_.Level := 99;
end;
Destructor TDlgCdBlkMain.Destroy;
begin
FreeAndNil(Trace_);
Inherited;
end;
procedure TDlgCdBlkMain.btnGetTypeClick(Sender: TObject);
begin
edDrive.Text := Trim(edDrive.Text);
if edDrive.Text = '' then
begin
MessageBox(Handle, PChar('드라이브를 입력해주십시오.'), PChar(Caption), MB_ICONWARNING or MB_OK);
exit;
end;
if not DirectoryExists(edDrive.Text) then
begin
MessageBox(Handle, PChar('존재하지 않는 드라이브 입니다.'), PChar(Caption), MB_ICONWARNING or MB_OK);
exit;
end;
ShowMessage(Format('DriveType=%d', [GetDriveType(PChar(edDrive.Text))]));
end;
procedure TDlgCdBlkMain.btnFindBlockClick(Sender: TObject);
var
DriveList: TStringList;
i: Integer;
sDrive,
sResult: String;
begin
Guard(DriveList, TStringList.Create);
SplitString(GetDrivesFromMask(GetLogicalDrives), ',', DriveList);
for i := 0 to DriveList.Count - 1 do
begin
sDrive := DriveList[i];
case GetDriveType(PChar(sDrive)) of
DRIVE_CDROM :
begin
mmInfo.Lines.Add('CDROM : ' + sDrive);
mmInfo.Lines.Add(Format('"%s" 차단 시도...', [sDrive]));
sResult := EjectDrive(sDrive, nil, false, true);
if sResult = FAIL_EJECT then
sResult := EjectDrive2(sDrive, nil, false, true);
if (sResult = FAIL_EJECT) or (GetDriveType(PChar(sDrive)) = DRIVE_CDROM) then
mmInfo.Lines.Add('차단을 실패했습니다...')
else
mmInfo.Lines.Add('차단 성공!! - ' + sResult);
exit;
end;
end;
end;
mmInfo.Lines.Add('CDROM을 발견하지 못했습니다.')
end;
end.