{*******************************************************} { } { ThdWatchPrintSpool } { } { Copyright (C) 2023 kku } { } {*******************************************************} unit ThdWatchPrintSpool; interface uses Winapi.Windows, System.Classes, Tocsg.Files; type TThdWatchPrintSpool = class(TTgDirWatchBase) protected sRecentSP_: String; dtRecentSP_: TDateTime; procedure ProcessDirWatchEnt(Sender: TObject; pInfo: PDirWatchEnt); override; public Constructor Create(bSubDir, bSync: Boolean); procedure StartWork; procedure StopWork; procedure ClearRecent; property RecentSpoolFile: String read sRecentSP_; property RecentSpoolDate: TDateTime read dtRecentSP_; end; implementation uses Tocsg.Path, Tocsg.Exception, System.SysUtils; { TThdWatchPrintSpool } Constructor TThdWatchPrintSpool.Create(bSubDir, bSync: Boolean); begin Inherited Create(bSubDir, bSync); ClearRecent; end; procedure TThdWatchPrintSpool.ProcessDirWatchEnt(Sender: TObject; pInfo: PDirWatchEnt); begin try case pInfo.dwAction of 1, 3 : begin if (sRecentSP_ = '') and (GetFileExt(pInfo.sPath).ToUpper = 'SPL') then sRecentSP_ := pInfo.sPath; if sRecentSP_ = pInfo.sPath then dtRecentSP_ := Now; end; end; except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. TThdWatchPrintSpool()'); end; end; procedure TThdWatchPrintSpool.ClearRecent; begin sRecentSP_ := ''; dtRecentSP_ := 0; end; procedure TThdWatchPrintSpool.StartWork; begin AddDirWatch(GetSystemDir + 'spool\PRINTERS\'); Processor_.StartThread; end; procedure TThdWatchPrintSpool.StopWork; begin Processor_.Clear; Processor_.PauseThread; ClearDirWatch; end; end.