unit DAmhMain; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; type TDlgAmhMain = class(TForm) pnTop: TPanel; Label1: TLabel; Label2: TLabel; edAipPath: TEdit; edTargetDir: TEdit; mmLog: TMemo; btnEnc: TButton; btnDec: TButton; btnEncCnt: TButton; btnExtrLabel: TButton; btnSetLabel: TButton; btnLabelChk: TButton; procedure btnEncClick(Sender: TObject); procedure btnDecClick(Sender: TObject); procedure btnEncCntClick(Sender: TObject); procedure btnExtrLabelClick(Sender: TObject); procedure btnSetLabelClick(Sender: TObject); procedure btnLabelChkClick(Sender: TObject); private { Private declarations } function FindAipMdWnd: HWND; function SendData(h: HWND; dwCmd: DWORD; const sData: String): LONGLONG; public { Public declarations } end; var DlgAmhMain: TDlgAmhMain; implementation uses Tocsg.Files, Tocsg.Safe, Tocsg.Path, Tocsg.Shell, Tocsg.Process, Tocsg.DateTime, Tocsg.WndUtil, superobject, Tocsg.Registry; {$R *.dfm} procedure TDlgAmhMain.btnEncClick(Sender: TObject); var FileList: TStringList; i, nCnt, n: Integer; sTaskDir, sMdPath, sSrcPath, sDestPath: String; dtBegin: TDateTime; O: ISuperObject; begin edAipPath.Text := Trim(edAipPath.Text); edTargetDir.Text := Trim(edTargetDir.Text); if edAipPath.Text = '' then begin MessageBox(Handle, PChar('AIP ¸ðµâ °æ·Î¸¦ ÀÔ·ÂÇØ ÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); edAipPath.SetFocus; exit; end; sMdPath := edAipPath.Text; if not FileExists(sMdPath) then begin MessageBox(Handle, PChar('AIP ¸ðµâÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); edAipPath.SetFocus; exit; end; if edTargetDir.Text = '' then begin MessageBox(Handle, PChar('´ë»ó Æú´õ¸¦ ÀÔ·ÂÇØ ÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); edTargetDir.SetFocus; exit; end; sTaskDir := GetRunExePathDir + 'Task\'; if not ForceDirectories(sTaskDir) then begin MessageBox(Handle, PChar('ÀÛ¾÷ Æú´õ¸¦ »ý¼ºÇÏ´Â Áß ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; Guard(FileList, TStringList.Create); ExtrFilesPathFromDir(edTargetDir.Text, FileList); var h: HWND := FindAipMdWnd; dtBegin := Now; nCnt := 0; for i := 0 to FileList.Count - 1 do begin sSrcPath := FileList[i]; if not FileExists(sSrcPath) then continue; sDestPath := sTaskDir + ExtractFileName(sSrcPath); O := SO; O.S['src'] := sSrcPath; O.S['dst'] := sDestPath; if h <> 0 then begin n := SendData(h, 1, O.AsString); if (n = 10) and FileExists(sDestPath) then begin DeleteFile(sSrcPath); MoveFile_wait(sDestPath, sSrcPath); Inc(nCnt); end; end; // ExecuteAppWaitUntilTerminate(sMdPath, Format('-e "%s" "%s"', [sSrcPath, sDestPath]), SW_HIDE, 30000); // if FileExists(sDestPath) then // begin // DeleteFile(sSrcPath); // MoveFile_wait(sDestPath, sSrcPath); // Inc(nCnt); // end; end; ShowMessage(Format('¼º°ø : %d, ¼Ò¿ä½Ã°£ : %s', [nCnt, ConvSecBetweenToProgTime(dtBegin, Now)])); end; procedure TDlgAmhMain.btnEncCntClick(Sender: TObject); var FileList: TStringList; i, nCnt, n: Integer; sTaskDir, sMdPath, sSrcPath, sDestPath: String; dtBegin: TDateTime; O: ISuperObject; begin edAipPath.Text := Trim(edAipPath.Text); edTargetDir.Text := Trim(edTargetDir.Text); if edAipPath.Text = '' then begin MessageBox(Handle, PChar('AIP ¸ðµâ °æ·Î¸¦ ÀÔ·ÂÇØ ÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); edAipPath.SetFocus; exit; end; sMdPath := edAipPath.Text; if not FileExists(sMdPath) then begin MessageBox(Handle, PChar('AIP ¸ðµâÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); edAipPath.SetFocus; exit; end; if edTargetDir.Text = '' then begin MessageBox(Handle, PChar('´ë»ó Æú´õ¸¦ ÀÔ·ÂÇØ ÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); edTargetDir.SetFocus; exit; end; sTaskDir := GetRunExePathDir + 'Task\'; if not ForceDirectories(sTaskDir) then begin MessageBox(Handle, PChar('ÀÛ¾÷ Æú´õ¸¦ »ý¼ºÇÏ´Â Áß ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; Guard(FileList, TStringList.Create); ExtrFilesPathFromDir(edTargetDir.Text, FileList); var h: HWND := FindAipMdWnd; dtBegin := Now; nCnt := 0; for i := 0 to FileList.Count - 1 do begin sSrcPath := FileList[i]; if not FileExists(sSrcPath) then continue; sDestPath := sTaskDir + ExtractFileName(sSrcPath); O := SO; O.S['src'] := sSrcPath; O.S['dst'] := sDestPath; if h <> 0 then begin n := SendData(h, 3, O.AsString); if n = 10 then Inc(nCnt); end; // ExecuteAppWaitUntilTerminate(sMdPath, Format('"%s" "%s"', [sSrcPath, sDestPath]), SW_HIDE, 30000); // if FileExists(sDestPath) then // begin // DeleteFile(sSrcPath); // MoveFile_wait(sDestPath, sSrcPath); // Inc(nCnt); // end; end; ShowMessage(Format('¼º°ø : %d, ¼Ò¿ä½Ã°£ : %s', [nCnt, ConvSecBetweenToProgTime(dtBegin, Now)])); end; procedure TDlgAmhMain.btnExtrLabelClick(Sender: TObject); var dtBegin: TDateTime; O: ISuperObject; sPath, sTaskDir: String; n: Integer; begin sTaskDir := GetRunExePathDir + 'Task\'; if not ForceDirectories(sTaskDir) then begin MessageBox(Handle, PChar('ÀÛ¾÷ Æú´õ¸¦ »ý¼ºÇÏ´Â Áß ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; var h: HWND := FindAipMdWnd; dtBegin := Now; if h <> 0 then begin O := SO; sPath := sTaskDir + 'LabelList.txt'; O.S['src'] := sPath; O.S['dst'] := sPath + '.tmp'; n := SendData(h, 0, O.AsString); if (n = 10) and FileExists(sPath) then begin mmLog.Lines.LoadFromFile(sPath, TEncoding.UTF8); DeleteFile(sPath); end; end; ShowMessage(Format('¼Ò¿ä½Ã°£ : %s', [ConvSecBetweenToProgTime(dtBegin, Now)])); end; procedure TDlgAmhMain.btnLabelChkClick(Sender: TObject); const REG_TEST = 'SOFTWARE\eCrmHomeEdition'; var dtBegin: TDateTime; O: ISuperObject; sTaskDir: String; n: Integer; begin // sTaskDir := GetRunExePathDir + 'Task\'; // if not ForceDirectories(sTaskDir) then // begin // MessageBox(Handle, PChar('ÀÛ¾÷ Æú´õ¸¦ »ý¼ºÇÏ´Â Áß ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); // exit; // end; // SetRegValueString(HKEY_LOCAL_MACHINE, REG_TEST, 'TEST', 'TEST', true); // mmLog.Lines.Add(GetRegValueAsString(HKEY_LOCAL_MACHINE, 'SOFTWARE\eCrmHomeEdition', 'TEST', true)); // exit; edTargetDir.Text := Trim(edTargetDir.Text); var h: HWND := FindWindow(nil, 'BSOne-AIP-T140713'); dtBegin := Now; if h <> 0 then begin O := SO; O.S['src'] := edTargetDir.Text; O.S['dst'] := edTargetDir.Text + '.tmp'; O.S['ssid'] := GetRegRecentUserSid; n := SendData(h, 4, O.AsString); if n = 10 then begin mmLog.Lines.Add(GetRegValueAsString(HKEY_CURRENT_USER, 'SOFTWARE\eCrmHomeEdition', 'ALabel')); // DelRegValue(HKEY_CURRENT_USER, 'SOFTWARE\eCrmHomeEdition', 'ALabel'); end else mmLog.Lines.Add('½ÇÆÐ'); end else mmLog.Lines.Add('½ÇÆÐ2'); ShowMessage(Format('¼Ò¿ä½Ã°£ : %s', [ConvSecBetweenToProgTime(dtBegin, Now)])); end; procedure TDlgAmhMain.btnSetLabelClick(Sender: TObject); var FileList: TStringList; i, nCnt, n: Integer; sTaskDir, sMdPath, sSrcPath, sDestPath: String; dtBegin: TDateTime; O: ISuperObject; begin edAipPath.Text := Trim(edAipPath.Text); edTargetDir.Text := Trim(edTargetDir.Text); if edAipPath.Text = '' then begin MessageBox(Handle, PChar('AIP ¸ðµâ °æ·Î¸¦ ÀÔ·ÂÇØ ÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); edAipPath.SetFocus; exit; end; sMdPath := edAipPath.Text; if not FileExists(sMdPath) then begin MessageBox(Handle, PChar('AIP ¸ðµâÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); edAipPath.SetFocus; exit; end; if edTargetDir.Text = '' then begin MessageBox(Handle, PChar('´ë»ó Æú´õ¸¦ ÀÔ·ÂÇØ ÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); edTargetDir.SetFocus; exit; end; sTaskDir := GetRunExePathDir + 'Task\'; if not ForceDirectories(sTaskDir) then begin MessageBox(Handle, PChar('ÀÛ¾÷ Æú´õ¸¦ »ý¼ºÇÏ´Â Áß ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; Guard(FileList, TStringList.Create); ExtrFilesPathFromDir(edTargetDir.Text, FileList); var h: HWND := FindAipMdWnd; dtBegin := Now; nCnt := 0; for i := 0 to FileList.Count - 1 do begin sSrcPath := FileList[i]; if not FileExists(sSrcPath) then continue; sDestPath := sTaskDir + ExtractFileName(sSrcPath); O := SO; O.S['src'] := sSrcPath; O.S['dst'] := sDestPath; O.S['lid'] := '9877e059-3e04-4eba-ad87-888eb0c7e9ba'; if h <> 0 then begin n := SendData(h, 5, O.AsString); if (n = 10) and FileExists(sDestPath) then begin DeleteFile(sSrcPath); MoveFile_wait(sDestPath, sSrcPath); Inc(nCnt); end; end; // ExecuteAppWaitUntilTerminate(sMdPath, Format('"%s" "%s"', [sSrcPath, sDestPath]), SW_HIDE, 30000); // if FileExists(sDestPath) then // begin // DeleteFile(sSrcPath); // MoveFile_wait(sDestPath, sSrcPath); // Inc(nCnt); // end; end; ShowMessage(Format('¼º°ø : %d, ¼Ò¿ä½Ã°£ : %s', [nCnt, ConvSecBetweenToProgTime(dtBegin, Now)])); end; function TDlgAmhMain.FindAipMdWnd: HWND; var nTO: Integer; sPName: String; begin nTO := 0; Result := FindWindow(nil, 'BSOne-AIP-T140713'); if Result = 0 then begin sPName := ExtractFileName(edAipPath.Text); while Result = 0 do begin if nTO > 300 then exit; if GetProcessPidByName(sPName) = 0 then begin if not FileExists(edAipPath.Text) then exit; ExecutePath_hide(edAipPath.Text, '-r'); Sleep(500); end; Result := FindWindow(nil, 'BSOne-AIP-T140713'); Sleep(200); end; if Result = 0 then TerminateProcessByName(sPName); end; end; function TDlgAmhMain.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 TDlgAmhMain.btnDecClick(Sender: TObject); var FileList: TStringList; i, nCnt, n: Integer; sTaskDir, sMdPath, sSrcPath, sDestPath: String; dtBegin: TDateTime; O: ISuperObject; begin edAipPath.Text := Trim(edAipPath.Text); edTargetDir.Text := Trim(edTargetDir.Text); if edAipPath.Text = '' then begin MessageBox(Handle, PChar('AIP ¸ðµâ °æ·Î¸¦ ÀÔ·ÂÇØ ÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); edAipPath.SetFocus; exit; end; sMdPath := edAipPath.Text; if not FileExists(sMdPath) then begin MessageBox(Handle, PChar('AIP ¸ðµâÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); edAipPath.SetFocus; exit; end; if edTargetDir.Text = '' then begin MessageBox(Handle, PChar('´ë»ó Æú´õ¸¦ ÀÔ·ÂÇØ ÁֽʽÿÀ.'), PChar(Caption), MB_ICONWARNING or MB_OK); edTargetDir.SetFocus; exit; end; sTaskDir := GetRunExePathDir + 'Task\'; if not ForceDirectories(sTaskDir) then begin MessageBox(Handle, PChar('ÀÛ¾÷ Æú´õ¸¦ »ý¼ºÇÏ´Â Áß ¿À·ù°¡ ¹ß»ýÇß½À´Ï´Ù.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; Guard(FileList, TStringList.Create); ExtrFilesPathFromDir(edTargetDir.Text, FileList); var h: HWND := FindAipMdWnd; dtBegin := Now; nCnt := 0; for i := 0 to FileList.Count - 1 do begin sSrcPath := FileList[i]; if not FileExists(sSrcPath) then continue; sDestPath := sTaskDir + ExtractFileName(sSrcPath); O := SO; O.S['src'] := sSrcPath; O.S['dst'] := sDestPath; if h <> 0 then begin n := SendData(h, 2, O.AsString); if (n = 10) and FileExists(sDestPath) then begin DeleteFile(sSrcPath); MoveFile_wait(sDestPath, sSrcPath); Inc(nCnt); end; end; // ExecuteAppWaitUntilTerminate(sMdPath, Format('"%s" "%s"', [sSrcPath, sDestPath]), SW_HIDE, 30000); // if FileExists(sDestPath) then // begin // DeleteFile(sSrcPath); // MoveFile_wait(sDestPath, sSrcPath); // Inc(nCnt); // end; end; ShowMessage(Format('¼º°ø : %d, ¼Ò¿ä½Ã°£ : %s', [nCnt, ConvSecBetweenToProgTime(dtBegin, Now)])); end; end.