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的更多相关文章

  1. Check .NET Version with Inno Setup

    原文 http://www.kynosarges.org/DotNetVersion.html Inno Setup by Jordan Russell is a great installation ...

  2. inno setup介绍及官方网站地址

    使 用 笔 记 1.Inno Setup 是什么?Inno Setup 是一个免费的 Windows 安装程序制作软件.第一次发表是在 1997 年,Inno Setup 今天在功能设置和稳定性上的竞 ...

  3. [!!!!!]Inno Setup教程-常见问题解答

    [转]Inno Setup教程-常见问题解答 功能 * 翻译 Inno Setup 文字  * 它支持 MBCS (多字节字符集) 吗?  * 将来会支持 Windows Installer 吗?   ...

  4. Inno Setup的使用笔记

    Inno Setup的使用笔记 分类: Install Setup 2013-02-02 15:33 1002人阅读 评论(0) 收藏 举报 项目需要,前些天学习了Inno Setup这跨打包工具的使 ...

  5. 使用Inno Setup 打包.NET程序,并自动安装.Net Framework

    使用Inno Setup 打包.NET程序,并自动安装.Net Framework http://www.cnblogs.com/xiaogangqq123/archive/2012/03/19/24 ...

  6. inno setup 打包

    ; -- Example1.iss -- ; Demonstrates copying files and creating an icon. ; SEE THE DOCUMENTATION FOR ...

  7. Inno Setup安装时不能关闭指定进程

    脚本由 Inno Setup 脚本向导 生成!; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "XX管理系统"#defi ...

  8. INNO setup 制作安装包

    1.获取SQLserver安装路径vardbpath:string;rtn:boolean;rtn := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWA ...

  9. 注册flash.ocx inno setup (转)

    ; 脚本由 Inno Setup 脚本向导 生成! ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "xx模块" #de ...

随机推荐

  1. linux硬件资源问题排查:cpu负载、内存使用情况、磁盘空间、磁盘IO

    在使用过程中之前正常的功能,突然无法使用,性能变慢,通常都是资源消耗问题,资源消耗可以从以下几个方面去排查.对于已经安装硬件资源监控软件(zabbix)的环境,直接使用硬件资源监控软件(zabbix) ...

  2. js 中对于this 的理解的 经典案例

    function Foo(){ getName = function(){console.log(1);}; return this; }Foo.getName = function(){consol ...

  3. PTA数据结构与算法题目集(中文) 7-19

    PTA数据结构与算法题目集(中文)  7-19 7-19 求链式线性表的倒数第K项 (20 分)   给定一系列正整数,请设计一个尽可能高效的算法,查找倒数第K个位置上的数字. 输入格式: 输入首先给 ...

  4. maven聚合与继承笔记

    maven聚合 聚合的目的是为了快速构建项目,当我们有几个maven模块,想要一次性构建,而不是到每个模块下面去执行maven命令,这时候就需要使用maven聚合(或者称为多模块). 使用聚合的时候, ...

  5. Jmeter压力测试笔记(5)问题原因

    压测链路是jmeter=>slb=>nginx => php=>rds 报 Too Many Connections 的原因是前端同时保持了 16000 个连接,达到实例规格的 ...

  6. javascript入门 之 zTree(十二 托拽事件(二))

    1.逻辑可能有不完善的地方,如果发现,请指出. <!DOCTYPE html> <HTML> <HEAD> <TITLE> ZTREE DEMO - d ...

  7. 21 static 静态的使用及特点

    /* * static:他是一个关键字,用来修饰成员变量和成员方法 * static特点: * 被所有的对象所共享 * 可以直接使用类名来调用 * 静态所修饰的成员加载优先于对象,随着类的加载而加载 ...

  8. Python Requests-学习笔记(9)-错误与异常

    遇到网络问题(如:DNS查询失败.拒绝连接等)时,Requests会抛出一个ConnectionError 异常. 遇到罕见的无效HTTP响应时,Requests则会抛出一个 HTTPError 异常 ...

  9. scala_spark实践3

    Spark 读写HBase优化 读数据 可以采用RDD的方式读取HBase数据: val conf = HBaseConfiguration.create() conf.set(TableInputF ...

  10. 《深入理解 Java 虚拟机》笔记整理

    正文 一.Java 内存区域与内存溢出异常 1.运行时数据区域 程序计数器:当前线程所执行的字节码的行号指示器.线程私有. Java 虚拟机栈:Java 方法执行的内存模型.线程私有. 本地方法栈:N ...