在 Inno Setup 中解析键值文本文件以检查版本号
Parse key-value text file in Inno Setup for checking version number
我正在为我的应用程序创建 Inno Setup installer/updater。现在我需要找到一种方法来检查是否有新版本可用,如果可用,它应该自动安装在已经安装的版本上。
特殊情况是版本号与其他数据在一个文件中。
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;
但是当运行脚本检查版本字符串是否在线时不起作用。
您的代码几乎是正确的。您只缺少代码周围的 begin
和 end
,您希望在 for
循环中重复这些代码。所以只有 Log
行重复; if
为超出范围的 LineCount
索引执行。
很明显,如果您更好地格式化代码:
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 installer/updater。现在我需要找到一种方法来检查是否有新版本可用,如果可用,它应该自动安装在已经安装的版本上。
特殊情况是版本号与其他数据在一个文件中。 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;
但是当运行脚本检查版本字符串是否在线时不起作用。
您的代码几乎是正确的。您只缺少代码周围的 begin
和 end
,您希望在 for
循环中重复这些代码。所以只有 Log
行重复; if
为超出范围的 LineCount
索引执行。
很明显,如果您更好地格式化代码:
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;