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 ...
随机推荐
- 六、【Docker笔记】Docker数据管理
前几节我们介绍了Docker的基本使用和三大核心概念,那么我们在使用Docker的过程中,Docker中必然产生了大量的数据,对于这些数据我们需要查看或者对这些数据进行一个备份,也有可能容器之间的数据 ...
- 将本地项目关联到git上面
1.github上面创建新项目 2.初始化项目-------------可忽略 首先加入git提交忽略的文件.gitignore文件 .idea 忽略以.idea文件logs/ 忽略logs文件夹* ...
- Redis操作,数据库操作
Redis操作,数据库操作 案例1:源码安装Redis缓存服务 案例2:常用Redis数据库操作指令 案例3:配置Redis主从服务器 1 案例1:源码安装Redis缓存服务 1.1 问题 本案例要求 ...
- Hadoop(十一):组合任务概述和格式
组合任务概述 一些复杂的任务很难由一个MR处理完成,所以一般需要将其拆分成为多个简单的MR子任务来执行. MapReduce框架中对于这类的问题提供了几种方式进行任务执行流程的控制,主要包括以下几种方 ...
- 工作中常用的Android系统ADB命令收集
工作中常用的Android系统ADB命令收集如下:先收藏以备以后查阅! adb --help //adb帮助 adb start-server //启动adb server adb kill-s ...
- 9.2ArrayList 集合 案例,学生管理系统
循环的使用 添加学生:while嵌套for,for设置变量,内嵌if更新变量.if语句判断变量值 修改学生:for循环内嵌if,获取循环中的某个值. package day9_ArrayList.AL ...
- Go语言 可变参数
最近与同事讨论时,提到Go语言的可变参数,之前没有总结过相关知识点,今天我们介绍一下Go语言的可变参数. 可变参数(Variable Parameters):参数数量可变的函数称之为可变参数函数,主要 ...
- web网页html基础
列表标签 ul:定义一个列表 li:定义列表中的条目 图片标签 Img:用来向网页中插入一张图片 Src:指定图片所在的路径 Width:指定图片宽度 (% px) Height:指定图片高度 (% ...
- numpy basic sheatsheet
NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库.NumPy 通常与 SciPy(Scien ...
- Q - QQpet exploratory park HDU - 1493 (概率DP)
题目大意: 一共有61个位置,标记为0~60.其中有10个重要位置,分别为:5, 12, 22, 29, 33, 38, 42, 46, 50 and 55. 有一个筛子,一共6个面,标有1~6.摇到 ...