1045 lines
27 KiB
Plaintext
1045 lines
27 KiB
Plaintext
unit DDecryptDrm;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VirtualTrees, Vcl.ExtCtrls, Vcl.StdCtrls,
|
|
Vcl.Menus, System.Generics.Collections, superobject;
|
|
|
|
const
|
|
WM_CLICK_DECRYPT = WM_USER + 8548;
|
|
|
|
type
|
|
PDrmEnt = ^TDrmEnt;
|
|
TDrmEnt = record
|
|
sDir,
|
|
sExt,
|
|
sFName: String;
|
|
bDrm: Boolean;
|
|
nImgIdx: Integer;
|
|
end;
|
|
|
|
TDlgDecryptDrm = class(TForm)
|
|
pnTop: TPanel;
|
|
pnClient: TPanel;
|
|
vtList: TVirtualStringTree;
|
|
btnDecrypt: TButton;
|
|
Label1: TLabel;
|
|
popFun: TPopupMenu;
|
|
miDelFile: TMenuItem;
|
|
miDelNoDrm: TMenuItem;
|
|
N1: TMenuItem;
|
|
miClear: TMenuItem;
|
|
btnAddFile: TButton;
|
|
btnAddDir: TButton;
|
|
OpenDialog: TOpenDialog;
|
|
FileOpenDialog: TFileOpenDialog;
|
|
N2: TMenuItem;
|
|
N3: TMenuItem;
|
|
procedure vtListGetNodeDataSize(Sender: TBaseVirtualTree;
|
|
var NodeDataSize: Integer);
|
|
procedure vtListGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
|
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle;
|
|
var HintText: string);
|
|
procedure vtListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
|
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
|
|
procedure vtListPaintText(Sender: TBaseVirtualTree;
|
|
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
|
|
TextType: TVSTTextType);
|
|
procedure vtListGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
|
Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean;
|
|
var ImageIndex: TImageIndex);
|
|
procedure vtListAfterPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas);
|
|
procedure vtListFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
|
procedure miDelFileClick(Sender: TObject);
|
|
procedure miDelNoDrmClick(Sender: TObject);
|
|
procedure btnDecryptClick(Sender: TObject);
|
|
procedure vtListContextPopup(Sender: TObject; MousePos: TPoint;
|
|
var Handled: Boolean);
|
|
procedure miClearClick(Sender: TObject);
|
|
procedure btnAddFileClick(Sender: TObject);
|
|
procedure btnAddDirClick(Sender: TObject);
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
procedure N3Click(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
FileImageList_: TImageList;
|
|
vtListOldWndProc_: TWndMethod;
|
|
CheckFList_: TStringList;
|
|
sExceptReason_: String;
|
|
DcNDrvIps_: TDictionary<String,String>;
|
|
sUName_, sDept_, sEmpNo_, sPoName_: String;
|
|
bApproval_: Boolean;
|
|
procedure vtListWndProc(var msg: TMessage);
|
|
function CountEncFile: Integer;
|
|
function CheckNetPath(sPath: String): String;
|
|
function SendExceptReason_TMAP: Boolean;
|
|
procedure AddFile(sPath: String);
|
|
function ReqDecFilesToJson: ISuperObject;
|
|
public
|
|
{ Public declarations }
|
|
Constructor Create(aOwner: TComponent); override;
|
|
procedure CreateParams(var Params: TCreateParams); override; // 작업표시줄에 표시
|
|
Destructor Destroy; override;
|
|
|
|
procedure AddFiles(aList: TStringList);
|
|
procedure DoDecFiles(var nSuccess, nFail, nNorCnt: Integer);
|
|
procedure SetReadOnly;
|
|
|
|
procedure process_WM_COPYDATA(var msg: TMessage); Message WM_COPYDATA;
|
|
procedure process_WM_CLICK_DECRYPT(var msg: TMessage); Message WM_CLICK_DECRYPT;
|
|
end;
|
|
|
|
var
|
|
DlgDecryptDrm: TDlgDecryptDrm;
|
|
|
|
implementation
|
|
|
|
uses
|
|
{$IFDEF _HE_}
|
|
ManagerService, ManagerModel,
|
|
{$ENDIF}
|
|
{$IFDEF _HE_HLP_}
|
|
ProcessParam,
|
|
{$ENDIF}
|
|
Tocsg.Convert, Tocsg.Shell, Winapi.ShellAPI, Tocsg.Path, Tocsg.DRM.Encrypt,
|
|
Tocsg.Encrypt, GlobalDefine, Condition, Tocsg.Files, Tocsg.Strings,
|
|
Tocsg.VTUtil, DefineHelper, Define, Tocsg.Exception, Tocsg.Process,
|
|
Tocsg.User32, Tocsg.Network, Tocsg.Trace, Tocsg.Hash;
|
|
|
|
resourcestring
|
|
RS_MsgAddFile = '먼저 파일을 추가해 주십시오.';
|
|
RS_NoTgFile = '복호화 할 파일이 없습니다.';
|
|
RS_MsgFileDecReason = '파일 복호화 사유를 입력해주세요.';
|
|
RS_ErrorExcept = '예외 신청중 오류가 발생했습니다.';
|
|
RS_FileDec = '파일 복호화';
|
|
RS_Q_DrmDec = 'DRM 적용을 해제 하시겠습니까?';
|
|
RS_Q_ReqDec = 'DRM 해제를 요청하시겠습니까?';
|
|
RS_LimitReqDec = 'DRM 해제 요청은 최대 10까지 가능합니다.';
|
|
RS_MsgError = '작업을 준비하는 중 오류가 발생했습니다.';
|
|
RS_CompleteWork1 = '작업을 완료했습니다.';
|
|
RS_CompleteWork2 = '(성공 : %d, 실패 : %d, 무시 : %d)';
|
|
RS_Q_Clear = '목록을 초기화 하시겠습니까?';
|
|
RS_SelExceptFile = '제외 할 파일을 선택해 주십시오.';
|
|
RS_Q_ExceptFile = '선택한 파일들을 제외 하시겠습니까?';
|
|
RS_NoExceptFile = '제외 할 파일이 없습니다.';
|
|
RS_DrmFileDragDrop = 'DRM 파일을 드래그/드롭 해주십시오.';
|
|
RS_Ok = '확인';
|
|
RS_ReqDec = '해제 요청';
|
|
RS_NoApprovalInfo = '결재자 정보를 가져올 수 없습니다.';
|
|
|
|
{$R *.dfm}
|
|
|
|
Constructor TDlgDecryptDrm.Create(aOwner: TComponent);
|
|
var
|
|
hSysIcons: THandle;
|
|
begin
|
|
Inherited Create(aOwner);
|
|
|
|
{$IFDEF _HE_}
|
|
sUName_ := gMgSvc.UName;
|
|
sDept_ := gMgSvc.DeptName;
|
|
if sDept_ = '' then
|
|
sDept_ := gMgSvc.ModePolicy.DeptName;
|
|
sEmpNo_ := gMgSvc.EmpNo;
|
|
sPoName_ := gMgSvc.ModePolicy.PolicyName;
|
|
{$ENDIF}
|
|
|
|
{$IFDEF _HE_HLP_}
|
|
sUName_ := gParam.DrmI.sUName;
|
|
sDept_ := gParam.DrmI.sDept;
|
|
sEmpNo_ := gParam.DrmI.sEmpNo;
|
|
sPoName_ := gParam.DrmI.sPoName;
|
|
bApproval_ := gParam.DrmI.bApproval;
|
|
{$ELSE}
|
|
bApproval_ := IsApproveSupport and gMgSvc.ModePolicy.DrmApproval;
|
|
{$ENDIF}
|
|
|
|
if bApproval_ then
|
|
btnDecrypt.Caption := RS_ReqDec;
|
|
|
|
sExceptReason_ := '';
|
|
FileImageList_ := TImageList.Create(Self);
|
|
FileImageList_.ShareImages := true;
|
|
FileImageList_.BlendColor := clHighlight;
|
|
hSysIcons := GetShellImageHandle;
|
|
if hSysIcons <> 0 then
|
|
begin
|
|
FileImageList_.Handle := hSysIcons;
|
|
vtList.Images := FileImageList_;
|
|
end;
|
|
|
|
CheckFList_ := TStringList.Create;
|
|
CheckFList_.CaseSensitive := false;
|
|
|
|
vtListOldWndProc_ := vtList.WindowProc;
|
|
vtList.WindowProc := vtListWndProc;
|
|
DragAcceptFiles(vtList.Handle, true);
|
|
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
|
|
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
|
|
ChangeWindowMessageFilterEx(vtList.Handle, WM_DROPFILES, MSGFLT_ALLOW, nil);
|
|
ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ADD);
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.CreateParams(var Params: TCreateParams);
|
|
begin
|
|
Inherited CreateParams(Params);
|
|
{$IFDEF _HE_}
|
|
Params.ExStyle := WS_EX_APPWINDOW;
|
|
{$ENDIF}
|
|
end;
|
|
|
|
Destructor TDlgDecryptDrm.Destroy;
|
|
begin
|
|
FreeAndNil(CheckFList_);
|
|
Inherited;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.FormClose(Sender: TObject; var Action: TCloseAction);
|
|
begin
|
|
Action := TCloseAction.caFree;
|
|
end;
|
|
|
|
function TDlgDecryptDrm.CountEncFile: Integer;
|
|
var
|
|
pData: PDrmEnt;
|
|
pNode: PVirtualNode;
|
|
begin
|
|
Result := 0;
|
|
vtList.BeginUpdate;
|
|
try
|
|
pNode := vtList.GetFirst;
|
|
while pNode <> nil do
|
|
begin
|
|
pData := vtList.GetNodeData(pNode);
|
|
if pData.bDrm then
|
|
Inc(Result);
|
|
pNode := vtList.GetNext(pNode);
|
|
end;
|
|
finally
|
|
vtList.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
function TDlgDecryptDrm.CheckNetPath(sPath: String): String;
|
|
var
|
|
sDrive, sExe, sIpAddr: String;
|
|
dwExecuteTick, dwWaitResult: DWORD;
|
|
begin
|
|
Result := sPath;
|
|
try
|
|
sDrive := IncludeTrailingPathDelimiter(ExtractFileDrive(sPath));
|
|
if not DirectoryExists(sDrive) then
|
|
begin
|
|
sIpAddr := '';
|
|
if not DcNDrvIps_.ContainsKey(sDrive) then
|
|
begin
|
|
sIpAddr := NetDriveToRemoteAddr(sDrive);
|
|
DcNDrvIps_.Add(sDrive, sIpAddr);
|
|
end else
|
|
sIpAddr := DcNDrvIps_[sDrive];
|
|
|
|
if sIpAddr = '' then
|
|
exit;
|
|
|
|
// TTgTrace.T('TDlgEncryptDrm.AddFile() .. 7, IP=%s', [sIpAddr]);
|
|
|
|
sIpAddr := IncludeTrailingPathDelimiter(sIpAddr);
|
|
Result := StringReplace(sPath, sDrive, sIpAddr, [rfReplaceAll, rfIgnoreCase]);
|
|
|
|
// TTgTrace.T('TDlgEncryptDrm.AddFile() .. 8, Path=%s', [Result]);
|
|
end;
|
|
except
|
|
on E: Exception do
|
|
ETgException.TraceException(Self, E, 'Fail .. CheckNetPath()');
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.AddFile(sPath: String);
|
|
var
|
|
pData: PDrmEnt;
|
|
begin
|
|
try
|
|
if CheckFList_.IndexOf(sPath) <> -1 then
|
|
exit;
|
|
|
|
CheckFList_.Add(sPath);
|
|
|
|
pData := VT_AddChildData(vtList);
|
|
pData.sDir := ExtractFilePath(sPath);
|
|
pData.sFName := ExtractFileName(sPath);
|
|
pData.sExt := GetFileExt(pData.sFName).ToUpper;
|
|
pData.nImgIdx := -1;
|
|
try
|
|
pData.bDrm := TTgEncrypt.CheckSign(sPath, SIG_DRM);
|
|
except
|
|
pData.bDrm := false;
|
|
end;
|
|
except
|
|
on E: Exception do
|
|
ETgException.TraceException(Self, E, 'Fail .. AddFile()');
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.AddFiles(aList: TStringList);
|
|
var
|
|
sPath: String;
|
|
i: Integer;
|
|
begin
|
|
vtList.BeginUpdate;
|
|
try
|
|
for i := 0 to aList.Count - 1 do
|
|
begin
|
|
sPath := aList[i];
|
|
|
|
if not FileExists(sPath) then
|
|
continue;
|
|
|
|
AddFile(sPath);
|
|
end;
|
|
finally
|
|
vtList.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
function TDlgDecryptDrm.SendExceptReason_TMAP: Boolean;
|
|
var
|
|
pData: PDrmEnt;
|
|
pNode: PVirtualNode;
|
|
O, OA: ISuperObject;
|
|
dtCreate, dtModify, dtAccess: TDateTime;
|
|
sPath: String;
|
|
begin
|
|
Result := false;
|
|
ASSERT(sExceptReason_ <> '');
|
|
try
|
|
OA := TSuperObject.Create(stArray);
|
|
vtList.BeginUpdate;
|
|
try
|
|
pNode := vtList.GetFirst;
|
|
while pNode <> nil do
|
|
begin
|
|
pData := vtList.GetNodeData(pNode);
|
|
sPath := pData.sDir + pData.sFName;
|
|
if pData.bDrm and FileExists(sPath) then
|
|
begin
|
|
O := SO;
|
|
O.S['DOCNAME'] := pData.sFName;
|
|
O.S['DOCPATH'] := pData.sDir;
|
|
O.S['DOCSIZE'] := IntToStr(GetFileSize_path(sPath));
|
|
if GetFileDateTime_Local(sPath, dtCreate, dtModify, dtAccess) then
|
|
O.S['DOCDATE'] := FormatDateTime('yyyy-mm-dd hh:nn:ss', dtModify)
|
|
else
|
|
O.S['DOCDATE'] := '2000-12-31 12:00:00';
|
|
OA.AsArray.Add(O);
|
|
end;
|
|
pNode := vtList.GetNext(pNode);
|
|
end;
|
|
|
|
if OA.AsArray.Length > 0 then
|
|
begin
|
|
{$IFDEF _HE_}
|
|
var ExptInfo: TReqDevExceptInfo;
|
|
ZeroMemory(@ExptInfo, SizeOf(ExptInfo));
|
|
ExptInfo.ReqDevType := rdtDrm;
|
|
ExptInfo.sDevName := OA.AsString;
|
|
gMgSvc.SendRequest('', ExptInfo, sExceptReason_, '', '', 0, 'Request DRM Decrypt.');
|
|
sExceptReason_ := '';
|
|
{$ENDIF}
|
|
Result := true;
|
|
end;
|
|
finally
|
|
vtList.EndUpdate;
|
|
end;
|
|
except
|
|
on E: Exception do
|
|
ETgException.TraceException(Self, E, 'Fail .. SendExceptReason_TMAP()');
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.btnAddDirClick(Sender: TObject);
|
|
|
|
procedure ExtrctFilesFromDir(sDir: String);
|
|
var
|
|
wfd: TWin32FindData;
|
|
hSc: THandle;
|
|
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
|
|
ExtrctFilesFromDir(sDir + wfd.cFileName);
|
|
end else begin
|
|
AddFile(sDir + wfd.cFileName);
|
|
end;
|
|
Until not FindNextFile(hSc, wfd);
|
|
finally
|
|
WinApi.Windows.FindClose(hSc);
|
|
end;
|
|
end;
|
|
|
|
begin
|
|
{$IFDEF _HE_}
|
|
if FileOpenDialog.FileName = '' then
|
|
FileOpenDialog.DefaultFolder := Format('C:\Users\%s\Desktop', [gMgSvc.UserName]);
|
|
{$ENDIF}
|
|
|
|
if FileOpenDialog.Execute then
|
|
begin
|
|
ExtrctFilesFromDir(FileOpenDialog.FileName);
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.btnAddFileClick(Sender: TObject);
|
|
var
|
|
i: Integer;
|
|
begin
|
|
{$IFDEF _HE_}
|
|
if (OpenDialog.Files.Count = 0) or (OpenDialog.FileName = '') then
|
|
OpenDialog.InitialDir := Format('C:\Users\%s\Desktop', [gMgSvc.UserName]);
|
|
{$ENDIF}
|
|
|
|
if OpenDialog.Execute(Handle) then
|
|
begin
|
|
vtList.BeginUpdate;
|
|
try
|
|
for i := 0 to OpenDialog.Files.Count - 1 do
|
|
AddFile(OpenDialog.Files[i]);
|
|
finally
|
|
vtList.EndUpdate;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TDlgDecryptDrm.ReqDecFilesToJson: ISuperObject;
|
|
var
|
|
pData: PDrmEnt;
|
|
pNode: PVirtualNode;
|
|
sPath: String;
|
|
dtCreate, dtModify, dtAccess: TDateTime;
|
|
O: ISuperObject;
|
|
begin
|
|
Result := TSuperObject.Create(stArray);
|
|
vtList.BeginUpdate;
|
|
try
|
|
pNode := vtList.GetFirst;
|
|
while pNode <> nil do
|
|
begin
|
|
pData := vtList.GetNodeData(pNode);
|
|
if pData.bDrm then
|
|
begin
|
|
sPath := pData.sDir + pData.sFName;
|
|
if FileExists(sPath) then
|
|
begin
|
|
if not GetFileDateTime_Local(sPath, dtCreate, dtModify, dtAccess) then
|
|
begin
|
|
dtCreate := 0;
|
|
dtModify := 0;
|
|
dtAccess := 0;
|
|
end;
|
|
|
|
O := SO;
|
|
O.S['filePath'] := sPath;
|
|
O.S['createDt'] := FormatDateTime('yyyy-mm-dd hh:nn:ss', dtCreate);
|
|
O.S['modifyDt'] := FormatDateTime('yyyy-mm-dd hh:nn:ss', dtModify);
|
|
O.S['hash'] := GetFileToSha1Str(sPath);
|
|
Result.AsArray.Add(O);
|
|
end;
|
|
end;
|
|
pNode := vtList.GetNext(pNode);
|
|
end;
|
|
finally
|
|
vtList.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.SetReadOnly;
|
|
begin
|
|
btnDecrypt.Enabled := false;
|
|
btnAddFile.Enabled := false;
|
|
btnAddDir.Enabled := false;
|
|
|
|
miDelNoDrm.Visible := false;
|
|
miDelNoDrm.Enabled := false;
|
|
miDelFile.Visible := false;
|
|
miDelFile.Enabled := false;
|
|
miClear.Visible := false;
|
|
miClear.Enabled := false;
|
|
|
|
DragAcceptFiles(vtList.Handle, false);
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.DoDecFiles(var nSuccess, nFail, nNorCnt: Integer);
|
|
var
|
|
pNode: PVirtualNode;
|
|
pData: PDrmEnt;
|
|
dec: TTgDrmDec;
|
|
bDecResult: Boolean;
|
|
sTaskDir,
|
|
sPath, sDecPath: String;
|
|
begin
|
|
sTaskDir := 'C:\ProgramData\HE\Taskd\';
|
|
DeleteDir(sTaskDir);
|
|
|
|
if not ForceDirectories(sTaskDir) then
|
|
begin
|
|
MessageBox(Handle, PChar(RS_MsgError), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
exit;
|
|
end;
|
|
|
|
{$IFDEF _HE_HLP_}
|
|
var OA: ISuperObject := TSuperObject.Create(stArray);
|
|
{$ENDIF}
|
|
|
|
vtList.BeginUpdate;
|
|
try
|
|
nSuccess := 0;
|
|
nFail := 0;
|
|
nNorCnt := 0;
|
|
|
|
pNode := vtList.GetFirst;
|
|
while pNode <> nil do
|
|
begin
|
|
pData := vtList.GetNodeData(pNode);
|
|
pNode := vtList.GetNext(pNode);
|
|
|
|
if pData.bDrm then
|
|
begin
|
|
try
|
|
bDecResult := true;
|
|
sPath := pData.sDir + pData.sFName;
|
|
|
|
sDecPath := GetSameFileNameInc(sTaskDir + '$Tmpd' + ExtractFileName(sPath));
|
|
if not MoveFile_wait(sPath, sDecPath, 3) then
|
|
begin
|
|
Inc(nFail);
|
|
continue;
|
|
end;
|
|
|
|
dec := TTgDrmDec.Create(sDecPath);
|
|
try
|
|
if not dec.CheckSig(SIG_DRM) then
|
|
begin
|
|
bDecResult := false;
|
|
Inc(nNorCnt);
|
|
end;
|
|
|
|
if bDecResult and not dec.ExtrHead(PASS_DRM_HEAD) then
|
|
begin
|
|
bDecResult := false;
|
|
Inc(nFail);
|
|
end;
|
|
|
|
if bDecResult and (dec.Head.dwCustomerCode <> CUSTOMER_TYPE) then
|
|
begin
|
|
bDecResult := false;
|
|
Inc(nFail);
|
|
end;
|
|
|
|
// todo : 권한 체크
|
|
if bDecResult then
|
|
begin
|
|
{$IFDEF _HE_}
|
|
gMgSvc.AddEncIgr(sPath);
|
|
{$ENDIF}
|
|
bDecResult := dec.DecryptToFile(GetMK, sPath);
|
|
if not bDecResult then
|
|
Inc(nFail);
|
|
end;
|
|
finally
|
|
FreeAndNil(dec);
|
|
end;
|
|
|
|
if bDecResult then
|
|
begin
|
|
// gMgSvc.AddAfterEnc(sPath);
|
|
if DeleteFile(sDecPath) then
|
|
begin
|
|
// MoveFile_wait(sDecPath, sPath, 3);
|
|
Inc(nSuccess);
|
|
pData.bDrm := false;
|
|
{$IFDEF _HE_}
|
|
if gMgSvc.IsNewApi then
|
|
begin
|
|
var LogInfo: TLogInfo;
|
|
ZeroMemory(@LogInfo, SizeOf(LogInfo));
|
|
LogInfo.sCode := PREVENT_DRM_DECRYPT;
|
|
LogInfo.sPath := sPath;
|
|
LogInfo.sSummary := ExtractFileName(sPath);
|
|
gMgSvc.SendEventLogEx(@LogInfo, false);
|
|
end else
|
|
gMgSvc.SendEventLog(URI_USER_ACTION, PREVENT_DRM_DECRYPT, sPath);
|
|
{$ENDIF}
|
|
|
|
{$IFDEF _HE_HLP_}
|
|
OA.AsArray.Add(sPath);
|
|
{$ENDIF}
|
|
|
|
// end else begin
|
|
// DeleteFile(sDecPath);
|
|
// Inc(nFail);
|
|
end;
|
|
end else begin
|
|
// 원상복구
|
|
MoveFile_wait(sDecPath, sPath, 3);
|
|
end;
|
|
except
|
|
Inc(nFail);
|
|
end;
|
|
end else
|
|
Inc(nNorCnt);
|
|
end;
|
|
{$IFDEF _HE_HLP_}
|
|
if OA.AsArray.Length > 0 then
|
|
begin
|
|
var O: ISuperObject := SO;
|
|
O.B['IsDec'] := true;
|
|
O.O['List'] := OA;
|
|
|
|
gParam.SendData(HPCMD_OPEN_ENCRYPT, O.AsJSon);
|
|
end;
|
|
{$ENDIF}
|
|
finally
|
|
DeleteDir(sTaskDir);
|
|
vtList.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.btnDecryptClick(Sender: TObject);
|
|
var
|
|
nSuccess, nFail, nNorCnt: Integer;
|
|
O: ISuperObject;
|
|
begin
|
|
if vtList.RootNodeCount = 0 then
|
|
begin
|
|
MessageBox(Handle, PChar(RS_MsgAddFile), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
exit;
|
|
end;
|
|
|
|
nSuccess := CountEncFile;
|
|
if nSuccess = 0 then
|
|
begin
|
|
MessageBox(Handle, PChar(RS_NoTgFile), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
exit;
|
|
end;
|
|
|
|
if bApproval_ then
|
|
begin
|
|
if (sExceptReason_ = '') and
|
|
(MessageBox(Handle, PChar(RS_Q_ReqDec),
|
|
PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO) then exit;
|
|
|
|
if nSuccess > 10 then
|
|
begin
|
|
MessageBox(Handle, PChar(RS_LimitReqDec), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
exit;
|
|
end;
|
|
|
|
{$IFDEF _HE_HLP_}
|
|
gParam.SendData(HPCMD_REQ_DECRYPT, ReqDecFilesToJson.AsJSon);
|
|
{$ELSE}
|
|
var sUrl: String := gMgSvc.SendApproval(3, ReqDecFilesToJson);
|
|
if sUrl = '' then
|
|
begin
|
|
TTgTrace.T('Fail .. SendApproval(1)');
|
|
MessageBox(Handle, PChar(RS_NoApprovalInfo), PChar(APP_TITLE), MB_ICONWARNING or MB_OK);
|
|
end else begin
|
|
var sHlpExe: String := GetRunExePathDir + DIR_CONF + EXE_HLP;
|
|
if FileExists(sHlpExe) then
|
|
begin
|
|
O := SO;
|
|
O.I['RcvWnd'] := Handle;
|
|
O.I['Cmd'] := HPCMD_EXECUTE_FILE;
|
|
O.S['Path'] := gMgSvc.DestIPort + sUrl;
|
|
SaveJsonObjToFile(O, GetRunExePathDir + DIR_CONF + DAT_PARAM);
|
|
{$IFDEF DEBUG}
|
|
ExecutePath(sHlpExe);
|
|
{$ELSE}
|
|
ExecuteAppAsUser('explorer.exe', sHlpExe, '', SW_SHOWNORMAL);
|
|
{$ENDIF}
|
|
end else
|
|
ExecutePath(gMgSvc.DestIPort + sUrl);
|
|
end;
|
|
{$ENDIF}
|
|
|
|
Close;
|
|
exit;
|
|
end;
|
|
|
|
if (sExceptReason_ = '') and
|
|
(MessageBox(Handle, PChar(RS_Q_DrmDec),
|
|
PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO) then exit;
|
|
|
|
if CUSTOMER_TYPE = CUSTOMER_TMAP then
|
|
begin
|
|
if sExceptReason_ = '' then
|
|
begin
|
|
var sExe: String := GetRunExePathDir + DIR_CONF + EXE_HLP;
|
|
if FileExists(sExe) then
|
|
begin
|
|
O := SO;
|
|
O.I['RcvWnd'] := Handle;
|
|
O.I['Cmd'] := HPCMD_INPUT_EXCEPT_REASON;
|
|
O.S['WinCap'] := APP_TITLE;
|
|
O.S['Title'] := RS_FileDec;
|
|
O.S['Desc'] := RS_MsgFileDecReason;
|
|
O.S['BtnOk'] := RS_Ok;
|
|
SaveJsonObjToFile(O, GetRunExePathDir + DIR_CONF + DAT_PARAM);
|
|
{$IFDEF DEBUG}
|
|
ExecutePath(sExe);
|
|
{$ELSE}
|
|
ExecuteAppAsUser('explorer.exe', sExe, '', SW_SHOWNORMAL);
|
|
{$ENDIF}
|
|
btnDecrypt.Enabled := false;
|
|
end;
|
|
|
|
exit;
|
|
end else
|
|
if not SendExceptReason_TMAP then
|
|
begin
|
|
MessageBox(Handle, PChar(RS_ErrorExcept), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
exit;
|
|
end;
|
|
end;
|
|
|
|
DoDecFiles(nSuccess, nFail, nNorCnt);
|
|
|
|
MessageBox(Handle, PChar(Format(RS_CompleteWork1+#13+#10+RS_CompleteWork2,
|
|
[nSuccess, nFail, nNorCnt])), PChar(Caption), MB_ICONINFORMATION or MB_OK);
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.miClearClick(Sender: TObject);
|
|
begin
|
|
if MessageBox(Handle, PChar(RS_Q_Clear),
|
|
PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then exit;
|
|
|
|
CheckFList_.Clear;
|
|
VT_Clear(vtList);
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.miDelFileClick(Sender: TObject);
|
|
var
|
|
pNode: PVirtualNode;
|
|
pData: PDrmEnt;
|
|
nIdx: Integer;
|
|
begin
|
|
pNode := vtList.GetFirstSelected;
|
|
if pNode = nil then
|
|
begin
|
|
MessageBox(Handle, PChar(RS_SelExceptFile), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
exit;
|
|
end;
|
|
|
|
if MessageBox(Handle, PChar(RS_Q_ExceptFile),
|
|
PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then exit;
|
|
|
|
vtList.BeginUpdate;
|
|
try
|
|
while pNode <> nil do
|
|
begin
|
|
pData := vtList.GetNodeData(pNode);
|
|
nIdx := CheckFList_.IndexOf(pData.sDir + pData.sFName);
|
|
if nIdx <> -1 then
|
|
CheckFList_.Delete(nIdx);
|
|
pNode := vtList.GetNextSelected(pNode);
|
|
end;
|
|
|
|
vtList.DeleteSelectedNodes;
|
|
finally
|
|
vtList.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.miDelNoDrmClick(Sender: TObject);
|
|
var
|
|
pNode,
|
|
pDNode: PVirtualNode;
|
|
pData: PDrmEnt;
|
|
nIdx: Integer;
|
|
begin
|
|
pNode := vtList.GetFirst;
|
|
if pNode = nil then
|
|
begin
|
|
MessageBox(Handle, PChar(RS_NoExceptFile), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
exit;
|
|
end;
|
|
|
|
vtList.BeginUpdate;
|
|
try
|
|
while pNode <> nil do
|
|
begin
|
|
pData := vtList.GetNodeData(pNode);
|
|
if not pData.bDrm then
|
|
begin
|
|
nIdx := CheckFList_.IndexOf(pData.sDir + pData.sFName);
|
|
if nIdx <> -1 then
|
|
CheckFList_.Delete(nIdx);
|
|
pDNode := pNode;
|
|
end else
|
|
pDNode := nil;
|
|
|
|
pNode := vtList.GetNext(pNode);
|
|
|
|
if pDNode <> nil then
|
|
vtList.DeleteNode(pDNode);
|
|
end;
|
|
finally
|
|
vtList.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.N3Click(Sender: TObject);
|
|
var
|
|
pNode: PVirtualNode;
|
|
pData: PDrmEnt;
|
|
O: ISuperObject;
|
|
sHlpExe: String;
|
|
begin
|
|
pNode := vtList.GetFirstSelected;
|
|
if pNode = nil then
|
|
exit;
|
|
|
|
pData := vtList.GetNodeData(pNode);
|
|
|
|
sHlpExe := GetRunExePathDir + DIR_CONF + EXE_HLP;
|
|
if FileExists(sHlpExe) then
|
|
begin
|
|
O := SO;
|
|
O.I['RcvWnd'] := Handle;
|
|
O.I['Cmd'] := HPCMD_OPEN_SELECT;
|
|
O.S['Path'] := pData.sDir + pData.sFName;
|
|
SaveJsonObjToFile(O, GetRunExePathDir + DIR_CONF + DAT_PARAM);
|
|
{$IFDEF DEBUG}
|
|
ExecutePath(sHlpExe);
|
|
{$ELSE}
|
|
ExecuteAppAsUser('explorer.exe', sHlpExe, '', SW_SHOWNORMAL);
|
|
{$ENDIF}
|
|
end else
|
|
ExplorerSelectedPath(pData.sDir + pData.sFName);
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.vtListWndProc(var msg: TMessage);
|
|
|
|
procedure ExtrctFilesFromDir(sDir: String);
|
|
var
|
|
wfd: TWin32FindData;
|
|
hSc: THandle;
|
|
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
|
|
ExtrctFilesFromDir(sDir + wfd.cFileName);
|
|
end else begin
|
|
AddFile(sDir + wfd.cFileName);
|
|
end;
|
|
Until not FindNextFile(hSc, wfd);
|
|
finally
|
|
WinApi.Windows.FindClose(hSc);
|
|
end;
|
|
end;
|
|
|
|
var
|
|
sPath: String;
|
|
nCnt: Integer;
|
|
i, nLen: Integer;
|
|
pNode: PVirtualNode;
|
|
pData: PDrmEnt;
|
|
begin
|
|
if msg.Msg = WM_DROPFILES then
|
|
begin
|
|
nCnt := DragQueryFile(msg.WParam, DWORD(-1), nil, MAX_PATH);
|
|
vtList.BeginUpdate;
|
|
try
|
|
for i := 0 to nCnt - 1 do
|
|
begin
|
|
nLen := DragQueryFile(msg.WParam, i, nil, 0) + 1;
|
|
SetLength(sPath, nLen);
|
|
DragQueryFile(msg.WParam, i, PChar(sPath), nLen);
|
|
sPath := DeleteNullTail(sPath);
|
|
if FileExists(sPath) then
|
|
AddFile(sPath)
|
|
else if DirectoryExists(sPath) then
|
|
ExtrctFilesFromDir(sPath);
|
|
end;
|
|
finally
|
|
vtList.EndUpdate;
|
|
end;
|
|
|
|
DragFinish(msg.WParam);
|
|
exit;
|
|
end;
|
|
vtListOldWndProc_(msg);
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.vtListAfterPaint(Sender: TBaseVirtualTree;
|
|
TargetCanvas: TCanvas);
|
|
var
|
|
nX, nY, nW, nH: Integer;
|
|
msg: String;
|
|
begin
|
|
if CUSTOMER_TYPE <> CUSTOMER_SERVE1 then // 서브원은 권한때문에 드래그드롭을 못함 24_0711 08:47:40 kku
|
|
begin
|
|
if TVirtualStringTree(Sender).RootNodeCount = 0 then
|
|
begin
|
|
TargetCanvas.Font.Color := clGray;
|
|
msg := RS_DrmFileDragDrop;
|
|
nW := TargetCanvas.TextWidth(msg);
|
|
nH := TargetCanvas.TextHeight(msg);
|
|
|
|
if Sender.Width > nW then
|
|
nX := (Sender.Width div 2) - (nW div 2)
|
|
else
|
|
nX := 0;
|
|
|
|
if Sender.Height > nH then
|
|
nY := (Sender.Height div 2) - (nH div 2) - 20
|
|
else
|
|
nY := 0;
|
|
|
|
TargetCanvas.TextOut(nX, nY, msg);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.vtListContextPopup(Sender: TObject; MousePos: TPoint;
|
|
var Handled: Boolean);
|
|
var
|
|
pNode: PVirtualNode;
|
|
begin
|
|
pNode := vtList.GetNodeAt(MousePos);
|
|
miDelFile.Visible := pNode <> nil;
|
|
miClear.Visible := vtList.RootNodeCount > 0;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.vtListFreeNode(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode);
|
|
var
|
|
pData: PDrmEnt;
|
|
begin
|
|
pData := Sender.GetNodeData(Node);
|
|
Finalize(pData^);
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.vtListGetHint(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode; Column: TColumnIndex;
|
|
var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: string);
|
|
begin
|
|
HintText := vtList.Text[Node, Column];
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.vtListGetImageIndex(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
|
|
var Ghosted: Boolean; var ImageIndex: TImageIndex);
|
|
var
|
|
pData: PDrmEnt;
|
|
begin
|
|
case Kind of
|
|
ikNormal,
|
|
ikSelected:
|
|
begin
|
|
if Column = 1 then
|
|
begin
|
|
pData := Sender.GetNodeData(Node);
|
|
if pData.nImgIdx = -1 then
|
|
pData.nImgIdx := GetShellImageIndex_path(pData.sDir + pData.sFName);
|
|
ImageIndex := pData.nImgIdx;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.vtListGetNodeDataSize(Sender: TBaseVirtualTree;
|
|
var NodeDataSize: Integer);
|
|
begin
|
|
NodeDataSize := SizeOf(TDrmEnt);
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.vtListGetText(Sender: TBaseVirtualTree;
|
|
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
|
|
var CellText: string);
|
|
var
|
|
pData: PDrmEnt;
|
|
begin
|
|
pData := Sender.GetNodeData(Node);
|
|
|
|
case Column of
|
|
0 : CellText := IntToStr(Node.Index + 1);
|
|
1 : CellText := pData.sFName;
|
|
2 : CellText := pData.sExt;
|
|
3 : CellText := BooleanToStr(pData.bDrm, 'O', 'X');
|
|
4 : CellText := pData.sDir;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.vtListPaintText(Sender: TBaseVirtualTree;
|
|
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
|
|
TextType: TVSTTextType);
|
|
var
|
|
pData: PDrmEnt;
|
|
begin
|
|
if not (vsSelected in Node.States) then
|
|
begin
|
|
pData := Sender.GetNodeData(Node);
|
|
if pData.bDrm then
|
|
TargetCanvas.Font.Color := clGreen;
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.process_WM_COPYDATA(var msg: TMessage);
|
|
var
|
|
dwData: DWORD;
|
|
pCpData: PCopyDataStruct;
|
|
O: ISuperObject;
|
|
sTemp: String;
|
|
begin
|
|
msg.Result := 0;
|
|
|
|
dwData := 0;
|
|
pCpData := PCopyDataStruct(msg.LParam);
|
|
try
|
|
dwData := pCpData.dwData;
|
|
case dwData of
|
|
HPCMD_INPUT_EXCEPT_REASON :
|
|
begin
|
|
btnDecrypt.Enabled := true;
|
|
sTemp := Copy(PChar(pCpData.lpData), 1, pCpData.cbData);
|
|
if sTemp = '' then
|
|
exit;
|
|
|
|
sExceptReason_ := sTemp;
|
|
PostMessage(Handle, WM_CLICK_DECRYPT, 0, 0);
|
|
end;
|
|
end;
|
|
except
|
|
on E: Exception do
|
|
ETgException.TraceException(Self, E, Format('Fail .. process_WM_COPYDATA(), dwData=%d', [dwData]));
|
|
end;
|
|
end;
|
|
|
|
procedure TDlgDecryptDrm.process_WM_CLICK_DECRYPT(var msg: TMessage);
|
|
begin
|
|
btnDecrypt.Click;
|
|
end;
|
|
|
|
end.
|