我正在为我的应用程序创建一个 Inno Setup 安装程序/更新程序。现在我需要找到一种方法来检查新版本是否可用,如果可用,则应自动安装在已安装的版本上。
特殊情况是版本号与其他数据位于一个文件中。 Inno Setup 需要读取的文件如下所示:
#Eclipse Product File
#Fri Aug 18 08:20:35 CEST 2017
version=0.21.0
name=appName
id=appId
我已经找到了一种使用脚本更新应用程序的方法,该脚本仅读取其中包含版本号的文本文件。 Inno setup: check for new updates
但就我而言,它包含安装程序不需要的更多数据。有人可以帮我构建一个可以从文件中解析版本号的脚本吗?
我已有的代码如下所示:
function GetInstallDir(const FileName, Section: string): string;
var
S: string;
DirLine: Integer;
LineCount: Integer;
SectionLine: Integer;
Lines: TArrayOfString;
begin
Result := '';
Log('start');
if LoadStringsFromFile(FileName, Lines) then
begin
Log('Loaded file');
LineCount := GetArrayLength(Lines);
for SectionLine := 0 to LineCount - 1 do
Log('File line ' + lines[SectionLine]);
if (pos('version=', Lines[SectionLine]) <> 0) then
begin
Log('version found');
S := RemoveQuotes(Trim(Lines[SectionLine]));
StringChangeEx(S, '\\', '\', True);
Result := S;
Exit;
end;
end;
end;
但是运行脚本时,检查版本字符串是否在线的检查不起作用。
最佳答案
您的代码几乎是正确的。您只缺少要在 for
循环中重复的代码周围的 begin
和 end
。因此只有 Log
行重复;并且针对超出范围的 LineCount
索引执行 if
。
如果你更好地格式化代码,就会变得很明显:
function GetInstallDir(const FileName, Section: string): string;
var
S: string;
DirLine: Integer;
LineCount: Integer;
SectionLine: Integer;
Lines: TArrayOfString;
begin
Result := '';
Log('start');
if LoadStringsFromFile(FileName, Lines) then
begin
Log('Loaded file');
LineCount := GetArrayLength(Lines);
for SectionLine := 0 to LineCount - 1 do
begin { <--- Missing }
Log('File line ' + lines[SectionLine] );
if (pos('version=', Lines[SectionLine]) <> 0) then
begin
Log('version found');
S := RemoveQuotes(Trim(Lines[SectionLine]));
StringChangeEx(S, '\\', '\', True);
Result := S;
Exit;
end;
end; { <--- Missing }
end;
end;
关于inno-setup - 在 Inno Setup 中解析键值文本文件以检查版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45790351/