program UpDate;

uses
  Forms,
  messages,
  sysutils,
  shellapi,
  windows;

{$R *.res}
var
  SO: SHFILEOPSTRUCT;
  h: THandle;

function SlashSep(const Path, S: string): string;
begin
  if AnsiLastChar(Path)^ <> '\' then
    Result := Path + '\' + S
  else
    Result := Path + S;
end;

begin
  Application.Initialize;
  h := FindWindow('TfrmAnyQ', nil);
  while h>0 do
  begin
    PostMessage(h, WM_Close, 0, 0);
    sleep(500);
    h := FindWindow('TfrmAnyQ', nil);
  end;
  sleep(500);
  FillChar(So, Sizeof(So), #0);
  SO.Wnd := Application.Handle;
  SO.wFunc := FO_MOVE;
  SO.pFrom := PChar(SlashSep(ExtractFilePath(Application.ExeName), 'tmp\*'));
  SO.pTo := PChar(ExtractFilePath(Application.ExeName));
  SO.fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
  SHFileOperation(SO);
  WinExec(PChar(SlashSep(ExtractFilePath(Application.ExeName), 'AnyQ.exe')), SW_NORMAL);
//  Application.Run;
end.
