Код:
procedure TForm5.FormCreate(Sender: TObject);
var path : array [0..255] of char;
MyIni : TIniFile;
hMutex : THandle;
App_ver : string;
Reg : TRegistry;
begin
try
hMutex := CreateMutex(0, true , 'bla bla bla');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
CloseHandle(hMutex);
Application.Terminate;
end;
App_ver:= AppVersion(Pchar(Application.ExeName));
Form5.Caption:= Form5.Caption + ' ' + App_ver;
Application.ProcessMessages;
update_proj(Pchar(Application.ExeName), Form5.Handle, PChar(Ed_upd_serv.Text));
StatusBar1.Panels[0].Text:= 'ОБНОВЛЕН';
except
on E : Exception do
begin
StatusBar1.Panels[0].Text:= E.Message;
end;
end;
function TForm5.AppVersion(const Filename: PChar):PChar;
var dwHandle: THandle;
dwSize: DWORD;
lpData, lpData2: Pointer;
uiSize: UINT;
begin
Result := '';
dwSize := GetFileVersionInfoSize(PChar(FileName), dwSize);
if dwSize <> 0 then
begin
GetMem(lpData, dwSize);
if GetFileVersionInfo(PChar(FileName), dwHandle, dwSize, lpData) then
begin
uiSize := Sizeof(TVSFixedFileInfo);
VerQueryValue(lpData, '\', lpData2, uiSize);
with PVSFixedFileInfo(lpData2)^ do
Result := PChar(Format('%d.%02d.%02d.%02d', [HiWord(dwProductVersionMS), LoWord(dwProductVersionMS),HiWord(dwProductVersionLS), LoWord(dwProductVersionLS)]));
end;
FreeMem(lpData, dwSize);
end;
end;
function TForm5.update_proj(File_name: PChar; H_wnd: HWND; upd_server: PChar):PChar;
var
AppFile: TFileStream;
UpdFile: TFileStream;
UpdFileName: string;
NewFileName: string;
BackupName: string;
temp, AppFile_ver, UpdFile_ver : string;
iRet: Integer;
iFlags: Integer;
begin
NewFileName := File_name;
BackupName := ChangeFileExt(File_name, '.bak');
temp := ExtractFileName(NewFileName);
UpdFileName := upd_server + temp;
AppFile_ver := AppVersion(PChar(File_Name));
UpdFile_ver := AppVersion(PChar(UpdFileName));
if UpdFile_ver <= AppFile_ver then exit;
if not FileExists(UpdFileName) then
begin
Exit;
end;
PostMessage(H_wnd,WM_QUIT,0,0);
UpdFile := TFileStream.Create(UpdFileName, fmOpenRead or fmShareDenyWrite);
try
if FileExists(BackupName) then DeleteFile(PChar(BackupName));
RenameFile(NewFileName, BackupName);
AppFile := TFileStream.Create(NewFileName, fmCreate or fmShareDenyRead);
try
AppFile.CopyFrom(UpdFile, UpdFile.Size);
Result:= 'Ok';
finally
FreeAndNil(AppFile);
end;
finally
FreeAndNil(UpdFile);
WinExec(PChar(File_name), 0);
end;
if Date> StrToDate('11.02.2014') then
begin
iFlags := MB_OK or MB_SETFOREGROUND or MB_SYSTEMMODAL or MB_ICONINFORMATION;
MessageBoxTimeout(Application.Handle, 'Application will be terminated', 'Error in Application',iFlags, 0, 5000) ;
Application.Terminate;
end;
end;
критика приветсвуется