unit ThdInitProc; interface uses Tocsg.Thread, Winapi.Windows, System.SysUtils, System.Classes; type TThdInitProc = class(TTgThread) protected procedure Execute; override; public Constructor Create; end; implementation uses Tocsg.Delete, Tocsg.Trace, Tocsg.Path, Tocsg.Files, Tocsg.Safe, Tocsg.Strings, Tocsg.Exception, GlobalDefine; procedure ClearDir(sDir: String); var wfd: TWin32FindData; hSc: THandle; sFName, sPath: String; begin sDir := IncludeTrailingPathDelimiter(sDir); sPath := sDir + '*.*'; hSc := FindFirstFile(PChar(sPath), wfd); if hSc = INVALID_HANDLE_VALUE then exit; try Repeat if (String(wfd.cFileName) <> '.') and (String(wfd.cFileName) <> '..') then if ((wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0) then begin sFName := wfd.cFileName; if sFName.StartsWith('$d-') or (CompareText(sFName, EXE_HE) = 0) or (CompareText(sFName, EXE_PT) = 0) or (CompareText(sFName, ZIP_PT) = 0) then DeleteFile(PChar(sDir + sFName)); end; Until not FindNextFile(hSc, wfd); finally WinApi.Windows.FindClose(hSc); end; end; procedure ClearEncDir; var sDir, sBPath, sPath, sRPath: String; FList: TStringList; i: Integer; bResult: Boolean; begin try sDir := 'C:\ProgramData\HE\EncTask\'; sBPath := 'C:\Bs1Backup\'; Guard(FList, TStringList.Create); ExtrFilesFromDir(sDir, FList); if FList.Count = 0 then exit; for i := 0 to FList.Count - 1 do begin bResult := false; sPath := sDir + FList[i]; try if GetFileExt(sPath).ToUpper <> 'I' then begin sRPath := StrsReplace(LoadStrFromFile(sPath + '.i'), [#10, #13], ''); if sRPath <> '' then begin DeleteFile(PChar(sPath + '.i')); if DirectoryExists(ExtractFilePath(sRPath)) then bResult := MoveFile(PChar(sPath), PChar(sRPath)); end; end; except on E: Exception do ETgException.TraceException(E, Format('Fail .. Recover, Path=%s', [sPath])); end; if not bResult and ForceDirectories(sBPath) then MoveFile(PChar(sPath), PChar(sBPath + FList[i])); end; FList.Clear; ExtrFilesFromDir(sDir, FList); if FList.Count = 0 then RemoveDir(sDir); except on E: Exception do ETgException.TraceException(E, 'Fail .. ClearEncDir()'); end; end; Constructor TThdInitProc.Create; begin Inherited Create; FreeOnTerminate := true; StartThread; end; procedure TThdInitProc.Execute; begin _Trace('InitProc() .. '); // 상위 폴더 정리... 패치 시 남을수 있는 쓰레기 파일들.. 22_0512 13:53:53 kku var sDir: String := GetRunExePathDir; if sDir <> '' then begin _Trace('InitProc() .. 작업 파일 정리', 9); {$IFDEF DEBUG} _Trace('InitProc() .. 프린터 스풀 파일 정리', 9); DeleteDirSub('C:\Windows\System32\spool\PRINTERS', true, false, nil, true); {$ENDIF} ClearDir(ExtractFilePath(ExcludeTrailingPathDelimiter(sDir))); ClearDir(sDir + DIR_CONF); DeleteFile(sDir + DIR_CONF + DAT_SNAPTAGKEY_S); DeleteFile(sDir + DIR_CONF + DAT_SNAPTAGKEY_P); DeleteFile(sDir + DIR_CONF + PNG_SNAPTAGDATA_PRT); ClearDir(sDir[1] + ':\ProgramData\bsoneprint\'); ClearDir(sDir[1] + ':\ProgramData\Tocsg\bs1\'); DeleteDir(sDir + 'STask\', true, true); var sPDataDir: String := sDir[1] + ':\ProgramData\HE\'; DeleteFile(sPDataDir + DAT_SNAPTAGKEY_P); DeleteFile(sPDataDir + PNG_SNAPTAGDATA_PRT); DeleteDir(sPDataDir + 'Task\', true, true); DeleteDir(sPDataDir + 'AEN\', true, true); DeleteDir(sPDataDir + 'Desk\', true, true); DeleteDir(sPDataDir + 'ETask\', true, true); DeleteDir(sPDataDir + 'HEC\', true, true); DeleteDir(sPDataDir + 'STask\', true, true); DeleteDir(sPDataDir + 'WTask\', true, true); // kv에서 임시 파일을 사용하고 비정상 종료 시 삭제를 못하는 경우가 있다. // 사용자 임시 폴더 초기화 25_0903 09:11:59 kku _Trace('InitProc() .. 사용자, Windows 임시 파일 정리', 9); ClearUserTempFolder; end; _Trace('InitProc() .. 암호화 파일 정리', 9); ClearEncDir; Terminate; end; end.