317 lines
8.4 KiB
Plaintext
317 lines
8.4 KiB
Plaintext
unit DHeHelperMain;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, DefineHelper, Tocsg.Trace;
|
|
|
|
type
|
|
TDlgHeHelperMain = class(TForm)
|
|
tMtx: TTimer;
|
|
procedure tMtxTimer(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
hRcvWnd_: HWND;
|
|
sOwnerMtx_: String;
|
|
Trace_: TTgTrace;
|
|
procedure ProcessRole(nRole: Integer);
|
|
procedure ProcessNetFileScan;
|
|
public
|
|
{ Public declarations }
|
|
Constructor Create(aOwner: TComponent); override;
|
|
Destructor Destroy; override;
|
|
|
|
procedure process_WM_REQUEST_HLEPER(var msg: TMessage); Message WM_REQUEST_HLEPER;
|
|
end;
|
|
|
|
var
|
|
DlgHeHelperMain: TDlgHeHelperMain;
|
|
|
|
implementation
|
|
|
|
uses
|
|
ProcessParam, Tocsg.Win32, Tocsg.WinInfo, Winapi.PsAPI, Tocsg.Exception,
|
|
Tocsg.Network, Tocsg.Safe, Tocsg.Strings, Tocsg.Path, System.DateUtils,
|
|
Tocsg.DateTime, Tocsg.Files, superobject;
|
|
|
|
{$R *.dfm}
|
|
|
|
Constructor TDlgHeHelperMain.Create(aOwner: TComponent);
|
|
begin
|
|
Inherited Create(aOwner);
|
|
hRcvWnd_ := gParam.RcvWnd;
|
|
sOwnerMtx_ := gParam.OwnerMtx;
|
|
|
|
{$IFDEF DEBUG}
|
|
var sLogPath: String := 'C:\ProgramData\HE\' + CutFileExt(ExtractFileName(GetRunExePath)) + '.log';
|
|
DeleteFile(sLogPath);
|
|
Trace_ := TTgTrace.Create(ExtractFilePath(sLogPath), ExtractFileName(sLogPath));
|
|
Trace_.T('Create()');
|
|
{$ELSE}
|
|
Trace_ := nil;
|
|
{$ENDIF}
|
|
|
|
ChangeWindowMessageFilter(WM_REQUEST_HLEPER, MSGFLT_ADD);
|
|
|
|
if (hRcvWnd_ = 0) or (sOwnerMtx_ = '') then
|
|
TerminateProcess(GetCurrentProcess, 98);
|
|
|
|
tMtx.Enabled := true;
|
|
|
|
PostMessage(hRcvWnd_, WM_INIT_HLEPER, gParam.Role, Handle);
|
|
ProcessRole(gParam.Role);
|
|
end;
|
|
|
|
Destructor TDlgHeHelperMain.Destroy;
|
|
begin
|
|
if Trace_ <> nil then
|
|
begin
|
|
Trace_.T('Destroy()');
|
|
FreeAndNil(Trace_);
|
|
end;
|
|
Inherited;
|
|
end;
|
|
|
|
procedure TDlgHeHelperMain.tMtxTimer(Sender: TObject);
|
|
begin
|
|
if not MutexExists(sOwnerMtx_) then
|
|
TerminateProcess(GetCurrentProcess, 99);
|
|
end;
|
|
|
|
procedure TDlgHeHelperMain.ProcessRole(nRole: Integer);
|
|
begin
|
|
try
|
|
case nRole of
|
|
HLP_ROLE_WINDOWS_UPDATE_SCAN :
|
|
begin
|
|
PostMessage(hRcvWnd_, WM_RESPONSE_HLEPER, nRole, GetWinUpdateAbleList);
|
|
|
|
var ProcMemCnts: TProcessMemoryCounters;
|
|
if GetProcessMemoryInfo(GetCurrentProcess, @ProcMemCnts, SizeOf(ProcMemCnts)) then
|
|
begin
|
|
if ProcMemCnts.WorkingSetSize > 52428800 then // 50MB 이상이면 종료
|
|
TerminateProcess(GetCurrentProcess, 90);
|
|
end;
|
|
end;
|
|
|
|
HPCMD_REQ_NETDIR_SCAN : ProcessNetFileScan;
|
|
|
|
else TerminateProcess(GetCurrentProcess, 100);
|
|
end;
|
|
except
|
|
on E: Exception do
|
|
ETgException.TraceException(Self, E, 'Fail .. ProcessRole()');
|
|
end;
|
|
end;
|
|
|
|
function SendData(h: HWND; dwCmd: DWORD; const sData: String): LONGLONG;
|
|
var
|
|
CopyData: TCopyDataStruct;
|
|
begin
|
|
CopyData.dwData := dwCmd;
|
|
|
|
CopyData.cbData := (Length(sData) + 1) * 2;
|
|
CopyData.lpData := PChar(sData);
|
|
|
|
Result := SendMessage(h, WM_COPYDATA, 0, NativeInt(@CopyData));
|
|
end;
|
|
|
|
procedure TDlgHeHelperMain.ProcessNetFileScan;
|
|
var
|
|
llLimitSize, llTotalTgFile,
|
|
llTotalDir, llTotalFile,
|
|
llNotiDir, llNotiFile: LONGLONG;
|
|
ScanExtList,
|
|
IgrWordPaths: TStringList;
|
|
NI: TNetScanInfo;
|
|
dwTick, dwProgTick: DWORD;
|
|
|
|
procedure SendProgress(bForce: Boolean = false);
|
|
var
|
|
O: ISuperObject;
|
|
begin
|
|
dwTick := GetTickCount;
|
|
if bForce or ( (dwTick - dwProgTick) >= 2000 ) then
|
|
begin
|
|
dwProgTick := dwTick;
|
|
|
|
O := SO;
|
|
O.I['TKR'] := NI.llTasker;
|
|
O.I['InD'] := llTotalDir - llNotiDir;
|
|
O.I['InF'] := llTotalFile - llNotiFile;
|
|
|
|
SendData(hRcvWnd_, HPCMD_REP_NETDIR_PROGRESS, O.AsString);
|
|
|
|
llNotiDir := llTotalDir;
|
|
llNotiFile := llTotalFile;
|
|
end;
|
|
end;
|
|
|
|
procedure SendPath(sPath: String);
|
|
var
|
|
O: ISuperObject;
|
|
begin
|
|
O := SO;
|
|
O.I['TKR'] := NI.llTasker;
|
|
O.S['Path'] := sPath;
|
|
|
|
SendData(hRcvWnd_, HPCMD_REP_NETDIR_SCANPATH, O.AsString);
|
|
end;
|
|
|
|
procedure ExtractFiles(sDir: String);
|
|
var
|
|
wfd: TWin32FindData;
|
|
hSc: THandle;
|
|
sExt,
|
|
sPath: String;
|
|
dtCreate,
|
|
dtModify: TDateTime;
|
|
llSize: LONGLONG;
|
|
begin
|
|
try
|
|
if not DirectoryExists(sDir) then
|
|
exit;
|
|
|
|
sDir := IncludeTrailingPathDelimiter(sDir);
|
|
|
|
if IgrWordPaths.Count > 0 then
|
|
begin
|
|
var i: Integer;
|
|
sPath := UpperCase(sDir);
|
|
for i := 0 to IgrWordPaths.Count - 1 do
|
|
begin
|
|
if Pos(IgrWordPaths[i], sPath) > 0 then
|
|
exit;
|
|
end;
|
|
end;
|
|
|
|
sPath := sDir + '*.*';
|
|
hSc := FindFirstFile(PChar(sPath), wfd);
|
|
if hSc = INVALID_HANDLE_VALUE then
|
|
exit;
|
|
|
|
try
|
|
Repeat
|
|
SendProgress;
|
|
|
|
if (String(wfd.cFileName) <> '.') and (String(wfd.cFileName) <> '..') then
|
|
begin
|
|
sPath := sDir + wfd.cFileName;
|
|
if ((wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <> 0) then
|
|
begin
|
|
Inc(llTotalDir);
|
|
|
|
// \application data\ 등 junction 속성 경로가 있으면 무시해야함..
|
|
// 시스템 권한으로 돌리면 해당 경로로 정크된 경로까지 따라 들어감 24_0226 14:32:14 kku
|
|
if (wfd.dwFileAttributes and FILE_ATTRIBUTE_REPARSE_POINT) = 0 then
|
|
ExtractFiles(sPath);
|
|
end else begin
|
|
Inc(llTotalFile);
|
|
|
|
sExt := GetFileExt(sPath).ToLower;
|
|
if (sExt <> '$KV') and (ScanExtList.IndexOf(sExt) <> -1) then
|
|
begin
|
|
if NI.FileScanOpt.bPartScan and (NI.FileScanOpt.dtRecent <> 0) then
|
|
begin
|
|
dtCreate := ConvFileTimeToDateTime_Local(wfd.ftCreationTime);
|
|
dtModify := ConvFileTimeToDateTime_Local(wfd.ftLastWriteTime);
|
|
|
|
if (CompareDateTime(NI.FileScanOpt.dtRecent, dtCreate) <> -1) and
|
|
(CompareDateTime(NI.FileScanOpt.dtRecent, dtModify) <> -1) then
|
|
continue;
|
|
end;
|
|
|
|
llSize := GetFileSizeHiLow(wfd.nFileSizeHigh, wfd.nFileSizeLow);
|
|
if llSize = 0 then
|
|
continue;
|
|
|
|
if (llLimitSize > 0) and (llSize >= llLimitSize) then
|
|
continue;
|
|
|
|
// 소캠 파일 거르기 23_1031 12:30:45 kku
|
|
// if bIgrScDrm_ then
|
|
// begin
|
|
// if CheckSign(sPath, @SIGN_SOFTCAMP_DRM[0], 14) then
|
|
// begin
|
|
//// Inc(CttSchProg_.llEncFileCnt);
|
|
// continue;
|
|
// end;
|
|
// end;
|
|
|
|
// if bIgrAipDrm_ then
|
|
// begin
|
|
// if Pos('대외비', GetAipLabel(sPath)) > 0 then
|
|
// continue;
|
|
// end;
|
|
|
|
// 예외 거르기 23_1227 12:58:55 kku
|
|
// if (MgCampExcept_ <> nil) and MgCampExcept_.IsExceptFile(sPath) then
|
|
// continue;
|
|
|
|
SendPath(sPath);
|
|
// Inc(llTotalTgFile_);
|
|
end;
|
|
end;
|
|
end;
|
|
Until not FindNextFile(hSc, wfd);
|
|
finally
|
|
WinApi.Windows.FindClose(hSc);
|
|
end;
|
|
except
|
|
// ..
|
|
end;
|
|
end;
|
|
|
|
var
|
|
sTgDir: String;
|
|
begin
|
|
try
|
|
NI := gParam.NetSI;
|
|
if NI.sTgNetDir = '' then
|
|
exit;
|
|
|
|
if not NI.sTgNetDir.StartsWith('\\') then
|
|
begin
|
|
var sDrv: String := Format('%s:\', [NI.sTgNetDir[1]]);
|
|
sTgDir := NetDriveToRemoteAddr(sDrv);
|
|
if sTgDir = '' then
|
|
exit;
|
|
sTgDir := IncludeTrailingPathDelimiter(sTgDir);
|
|
|
|
sTgDir := StringReplace(NI.sTgNetDir, sDrv, sTgDir, [rfReplaceAll, rfIgnoreCase]);
|
|
sTgDir := IncludeTrailingPathDelimiter(sTgDir);
|
|
end else
|
|
sTgDir := IncludeTrailingPathDelimiter(NI.sTgNetDir);
|
|
|
|
if not DirectoryExists(sTgDir) then
|
|
exit;
|
|
|
|
llLimitSize := LONGLONG(NI.FileScanOpt.nLimitSizeMB) * 1048576;
|
|
Guard(ScanExtList, TStringList.Create);
|
|
ScanExtList.CaseSensitive := false;
|
|
SplitString(NI.FileScanOpt.sScanExt, '|', ScanExtList);
|
|
Guard(IgrWordPaths, TStringList.Create);
|
|
SplitString(UpperCase(NI.FileScanOpt.sIgrWordPath), '|', IgrWordPaths);
|
|
|
|
llTotalDir := 0;
|
|
llTotalFile := 0;
|
|
llTotalTgFile := 0;
|
|
llNotiDir := 0;
|
|
llNotiFile := 0;
|
|
dwProgTick := 0;
|
|
|
|
ExtractFiles(sTgDir);
|
|
SendProgress(true);
|
|
finally
|
|
TerminateProcess(GetCurrentProcess, 100);
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgHeHelperMain.process_WM_REQUEST_HLEPER(var msg: TMessage);
|
|
begin
|
|
ProcessRole(msg.WParam);
|
|
end;
|
|
|
|
end.
|