BSOne.SFC/Tocsg.Module/FileMon/DFileMonMain.pas

117 lines
2.6 KiB
Plaintext

unit DFileMonMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Tocsg.Files;
type
TDlgFileMonMain = class(TForm)
Panel1: TPanel;
mmLog: TMemo;
경로: TLabel;
edTgDir: TEdit;
btnMon: TButton;
procedure btnMonClick(Sender: TObject);
private
{ Private declarations }
DirWatch_: TTgDirWatchBase;
procedure Log(sLog: String);
procedure OnDirWatch(Sender: TObject; pEnt: PDirWatchEnt);
public
{ Public declarations }
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
end;
var
DlgFileMonMain: TDlgFileMonMain;
implementation
uses
Tocsg.Exception;
{$R *.dfm}
Constructor TDlgFileMonMain.Create(aOwner: TComponent);
begin
Inherited Create(aOwner);
DirWatch_ := TTgDirWatchBase.Create(true, true);
DirWatch_.Processor.OnProcessDirWatch := OnDirWatch;
end;
Destructor TDlgFileMonMain.Destroy;
begin
if DirWatch_ <> nil then
FreeAndNil(DirWatch_);
Inherited;
end;
procedure TDlgFileMonMain.Log(sLog: String);
begin
mmLog.Lines.Add(Format('[%s] %s', [DateTimeToStr(Now), sLog]));
end;
procedure TDlgFileMonMain.OnDirWatch(Sender: TObject; pEnt: PDirWatchEnt);
var
sEvent: String;
begin
try
case pEnt.dwAction of
1 : sEvent := '생성됨'; // Create
2 : sEvent := '삭제됨'; // Delete
3 : sEvent := '수정됨'; // Modify
4 : sEvent := '이름변경'; // Rename
5 : sEvent := '새이름'; // New Name
else sEvent := 'Unknown ' + IntToStr(pEnt.dwAction);
end;
Log(sEvent + ' : ' + pEnt.sPath);
except
on E: Exception do
ETgException.TraceException(Self, E, 'Fail .. OnDirWatch()');
end;
end;
procedure TDlgFileMonMain.btnMonClick(Sender: TObject);
begin
if btnMon.Tag = 1 then
begin
if MessageBox(Handle, PChar('감시를 중지하시겠습니까?'), PChar(Caption),
MB_ICONQUESTION or MB_YESNO) = IDNO then exit;
DirWatch_.StopWatch;
btnMon.Caption := '감시 시작';
edTgDir.Enabled := true;
Log('감시 중지');
btnMon.Tag := 0;
exit;
end;
mmLog.Clear;
edTgDir.Text := Trim(edTgDir.Text);
if not DirectoryExists(edTgDir.Text) then
begin
MessageBox(Handle, PChar('존재하지 않는 경로입니다.'), PChar(Caption), MB_ICONWARNING or MB_OK);
edTgDir.SetFocus;
exit;
end;
DirWatch_.AddDirWatch(edTgDir.Text);
DirWatch_.StartWatch;
btnMon.Tag := 1;
edTgDir.Enabled := false;
btnMon.Caption := '감시 중지';
Log('감시 시작');
end;
end.