1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| function GetLastVersion(): Boolean;
var
DirMaj, ExeMaj: string;
VersionLocale, VersionMaj: string;
TmpIniFile: TIniFile;
BatOp: TStringList;
DosStr: array of Char;
BatName: string;
begin
Result := False;
TmpIniFile:= TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
try
DirMaj := TmpIniFile.ReadString('PATH', 'MAJPATH', DEFAULT_MAJPATH);
ExeMaj := IncludeTrailingPathDelimiter(DirMaj)+ExtractFileName(Application.ExeName);
finally
TmpIniFile.Free();
end;
if GetFileVersion(Application.ExeName, VersionLocale) and
GetFileVersion(ExeMaj, VersionMaj) then
begin
Result := CompareVersion(VersionMaj, VersionLocale) > 0;
if Result then
begin
BatOp := TStringList.Create();
try
//BatOp.Add('@ECHO OFF');
BatOp.Add(':LoopRename');
BatOp.Add(Format('RENAME "%s" "%s"', [Application.ExeName, ExtractFileName(ChangeFileExt(Application.ExeName, '.'+VersionLocale))]));
BatOp.Add(Format('IF NOT EXIST "%s" GOTO LoopRename', [ChangeFileExt(Application.ExeName, '.'+VersionLocale)]));
BatOp.Add(':LoopDelete');
BatOp.Add(Format('DEL "%s"', [Application.ExeName]));
BatOp.Add(Format('IF EXIST "%s" GOTO LoopDelete', [Application.ExeName]));
BatOp.Add(':LoopCopy');
BatOp.Add(Format('COPY "%s" "%s"', [ExeMaj, Application.ExeName]));
BatOp.Add(Format('IF NOT EXIST "%s" GOTO LoopCopy', [Application.ExeName]));
BatOp.Add(Format('"%s"', [Application.ExeName]));
BatName := Format('%s\MAJArchive.bat', [ExtractFileDir(Application.ExeName)]);
BatOp.Add(Format('DEL "%s"', [BatName]));
SetLength(DosStr, Length(BatOp.Text)+1);
if CharToOem(PChar(BatOp.Text), @DosStr[0]) then
BatOp.Text := StrPas(@DosStr[0]);
BatOp.SaveToFile(BatName);
ShellExecute(0, 'open', PChar(BatName), nil, PChar(ExtractFileDir(Application.ExeName)), SW_HIDE);
finally
BatOp.Free();
end;
end;
end;
end; |
Partager