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. ThreadPoolExcutor 原理探究

    概论 线程池(英语:thread pool):一种线程使用模式.线程过多会带来调度开销,进而影响缓存局部性和整体性能.而线程池维护着多个线程,等待着监督管理者分配可并发执行的任务.这避免了在处理短时间 ...

  2. postman 参数传递

    pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test(& ...

  3. Java 给 PowerPoint 文档添加背景颜色和背景图片

    在制作Powerpoint文档时,背景是非常重要的,统一的背景能让Powerpoint 演示文稿看起来更加干净美观.本文将详细讲述如何在Java应用程序中使用免费的Free Spire.Present ...

  4. Python 类属性和方法

    import types class Dog(object): __slots__ = ("name", "color", "info") ...

  5. 详解java访问修饰符

    详解java访问修饰符 为了防止初学者看到因为专业的术语而感觉晦涩难懂,我接下来尽量用生动比喻的说法来解释!首先第一点,我们来讲讲什么叫修饰符!看看这个名称,想想他的意思.修饰符!修饰符!,就是用来修 ...

  6. 29.3 ArrayList、List、LinkedList(链表)优缺点

    ArrayList.List特点:查询快.增删慢 链表特点:查询慢,增删快 案例 package day29_collection集合体系; import java.util.ArrayList; i ...

  7. Struts2-学习笔记系列(10)-自定义类型转换

    注意name=user和对应action中的实例名称一致 这些代码是写在HTML文件中的 <s:form action="login"> <s:textfield ...

  8. spark sql createOrReplaceTempView registerTempTable

    createOrReplaceTempView2.x版本以上. registerTempTable1.5.x val data1 = dataSelect1(sqlContext, sparkMode ...

  9. 数据结构和算法(Golang实现)(15)常见数据结构-列表

    列表 一.列表 List 我们又经常听到列表 List数据结构,其实这只是更宏观的统称,表示存放数据的队列. 列表List:存放数据,数据按顺序排列,可以依次入队和出队,有序号关系,可以取出某序号的数 ...

  10. SpringBoot项目中容易出现的问题

    SpringBoot项目的配置文件 另外启动文件的位置一定要在其它类的顶层,SpringBoot所在的main函数的同级包或子包在生效 开始做这个的时候最容易把配置文件搞错,造成sql查询异常