Inno setup: check for new updates
Since you've decided to use a common version string pattern, you'll need a function which will parse and compare a version string of your setup and the one downloaded from your site. And because there is no such function built-in in Inno Setup, you'll need to have your own one.
I've seen a few functions for comparing version strings, like e.g. the one used in this script
, but I've decided to write my own. It can detect an invalid version string, and treats the missing version chunks as to be 0, which causes comparison of version strings like follows to be equal:
1.2.
1.2.3.0.0.0
The following script might do what you want (the setup version is defined by the AppVersion
directive):
[Setup]
AppName=My Program
AppVersion=1.2.
DefaultDirName={pf}\My Program [Code]
const
SetupURL = 'http://dex.wotanksmods.com/setup.exe';
VersionURL = 'http://dex.wotanksmods.com/latestver.txt'; type
TIntegerArray = array of Integer;
TCompareResult = (
crLesser,
crEquals,
crGreater
); function Max(A, B: Integer): Integer;
begin
if A > B then Result := A else Result := B;
end; function CompareValue(A, B: Integer): TCompareResult;
begin
if A = B then
Result := crEquals
else
if A < B then
Result := crLesser
else
Result := crGreater;
end; function AddVersionChunk(const S: string; var A: TIntegerArray): Integer;
var
Chunk: Integer;
begin
Chunk := StrToIntDef(S, -);
if Chunk <> - then
begin
Result := GetArrayLength(A) + ;
SetArrayLength(A, Result);
A[Result - ] := Chunk;
end
else
RaiseException('Invalid format of version string');
end; function ParseVersionStr(const S: string; var A: TIntegerArray): Integer;
var
I: Integer;
Count: Integer;
Index: Integer;
begin
Count := ;
Index := ; for I := to Length(S) do
begin
case S[I] of
'.':
begin
AddVersionChunk(Copy(S, Index, Count), A);
Count := ;
Index := I + ;
end;
'', '', '', '', '', '', '', '', '', '':
begin
Count := Count + ;
end;
else
RaiseException('Invalid char in version string');
end;
end;
Result := AddVersionChunk(Copy(S, Index, Count), A);
end; function GetVersionValue(const A: TIntegerArray; Index,
Length: Integer): Integer;
begin
Result := ;
if (Index >= ) and (Index < Length) then
Result := A[Index];
end; function CompareVersionStr(const A, B: string): TCompareResult;
var
I: Integer;
VerLenA, VerLenB: Integer;
VerIntA, VerIntB: TIntegerArray;
begin
Result := crEquals; VerLenA := ParseVersionStr(A, VerIntA);
VerLenB := ParseVersionStr(B, VerIntB); for I := to Max(VerLenA, VerLenB) - do
begin
Result := CompareValue(GetVersionValue(VerIntA, I, VerLenA),
GetVersionValue(VerIntB, I, VerLenB));
if Result <> crEquals then
Exit;
end;
end; function DownloadFile(const URL: string; var Response: string): Boolean;
var
WinHttpRequest: Variant;
begin
Result := True;
try
WinHttpRequest := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpRequest.Open('GET', URL, False);
WinHttpRequest.Send;
Response := WinHttpRequest.ResponseText;
except
Result := False;
Response := GetExceptionMessage;
end;
end; function InitializeSetup: Boolean;
var
ErrorCode: Integer;
SetupVersion: string;
LatestVersion: string;
begin
Result := True; if DownloadFile(VersionURL, LatestVersion) then
begin
SetupVersion := '{#SetupSetting('AppVersion')}';
if CompareVersionStr(LatestVersion, SetupVersion) = crGreater then
begin
if MsgBox('There is a newer version of this setup available. Do ' +
'you want to visit the site ?', mbConfirmation, MB_YESNO) = IDYES then
begin
Result := not ShellExec('', SetupURL, '', '', SW_SHOW, ewNoWait,
ErrorCode);
end;
end;
end;
end;
Inno setup: check for new updates的更多相关文章
- Check .NET Version with Inno Setup
原文 http://www.kynosarges.org/DotNetVersion.html Inno Setup by Jordan Russell is a great installation ...
- inno setup介绍及官方网站地址
使 用 笔 记 1.Inno Setup 是什么?Inno Setup 是一个免费的 Windows 安装程序制作软件.第一次发表是在 1997 年,Inno Setup 今天在功能设置和稳定性上的竞 ...
- [!!!!!]Inno Setup教程-常见问题解答
[转]Inno Setup教程-常见问题解答 功能 * 翻译 Inno Setup 文字 * 它支持 MBCS (多字节字符集) 吗? * 将来会支持 Windows Installer 吗? ...
- Inno Setup的使用笔记
Inno Setup的使用笔记 分类: Install Setup 2013-02-02 15:33 1002人阅读 评论(0) 收藏 举报 项目需要,前些天学习了Inno Setup这跨打包工具的使 ...
- 使用Inno Setup 打包.NET程序,并自动安装.Net Framework
使用Inno Setup 打包.NET程序,并自动安装.Net Framework http://www.cnblogs.com/xiaogangqq123/archive/2012/03/19/24 ...
- inno setup 打包
; -- Example1.iss -- ; Demonstrates copying files and creating an icon. ; SEE THE DOCUMENTATION FOR ...
- Inno Setup安装时不能关闭指定进程
脚本由 Inno Setup 脚本向导 生成!; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "XX管理系统"#defi ...
- INNO setup 制作安装包
1.获取SQLserver安装路径vardbpath:string;rtn:boolean;rtn := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWA ...
- 注册flash.ocx inno setup (转)
; 脚本由 Inno Setup 脚本向导 生成! ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "xx模块" #de ...
随机推荐
- Django之auth用户认证
auth模块 from django.contrib import auth django.contrib.auth中提供了许多方法,这里主要介绍其中的三个: authenticate() 提供 ...
- A - Investment
A - Investment John never knew he had a grand-uncle, until he received the notary's letter. He learn ...
- 树形DP——动态规划与数据结构的结合,在树上做DP
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是算法与数据结构的第15篇,也是动态规划系列的第4篇. 之前的几篇文章当中一直在聊背包问题,不知道大家有没有觉得有些腻味了.虽然经典的文 ...
- pyhton 信号量Semaphore和BoundedSemaphore
Semaphore和BoundedSemaphore两个,用起来好像没啥区别 都是定义信号量 sem=threading.BoundedSemaphore(5) sem=threading.Semap ...
- MySQL 数据备份与同步
前段时间使用MySQL作为数据存储做了一个小项目.项目上线运行了几十天之后,数据已经越来越多,达到了100多M.用mysqldump每天备份全量数据然后传输到另外一台机器上这种方式进行数据备份,久而久 ...
- Vulnhub DC-5靶机渗透
信息搜集 老样子,先找到靶机IP和扫描靶机 nmap -sP 192.168.146.0/24 #找靶机ip nmap -sS -Pn -A 192.168.146.141 #扫描端口 这次开的是80 ...
- Linux服务器架设篇,DNS服务器(三),正反解区域的配置
一.大体架构 DNS服务器其实只有一个"真正"的配置文件,即 /etc/named.conf .其他的配置文件都是依据此配置展开的.每个域都需要两个配置文件,即正解文件和反解文件. ...
- PyJWT 详解
1.首先,我们需要先了解 JWT 的概念,所以我们先看pyjwt的官网 https://jwt.io/ 2.对于官方 JWT 有两篇博文写的不错分别如下: https://blog.csdn.net/ ...
- git log查看某文件的修改历史
1. git log filename 可以看到fileName相关的commit记录 2. git log -p filename可以显示每次提交的diff 3. 只看某次提交中的某个文件变化,可以 ...
- String 对象-->charAt() 方法
1.定义和用法 charAt() 方法获取指定下标的字符,下标从0开始 语法: string.charAt(index) 参数: index:指定的下标 举例:获取下标为2的字符 var str = ...