pascalscript - Parse key-value text file in Inno Setup for checking version number -
i'm creating inno setup installer/updater application. need find way check if new version available , if available should installed automatically on installed version.
the special case version number in file other data. file inno setup need read looks like:
#eclipse product file #fri aug 18 08:20:35 cest 2017 version=0.21.0 name=appname id=appid i found way update application using script read text file version number in it. inno setup: check new updates
but in case contains more data installer not need. can me build script can parse version number out of file?
the code have looks like:
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) begin log('loaded file'); linecount := getarraylength(lines); sectionline := 0 linecount - 1 log('file line ' + lines[sectionline]); if (pos('version=', lines[sectionline]) <> 0) begin log('version found'); s := removequotes(trim(lines[sectionline])); stringchangeex(s, '\\', '\', true); result := s; exit; end; end; end; but when running script check checking if version string on line not work.
your code correct. missing begin , end around code, want repeat in for loop. log line repeats; , if executed out-of-the-range linecount index.
it becomes obvious, if format code better:
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) begin log('loaded file'); linecount := getarraylength(lines); sectionline := 0 linecount - 1 begin { <--- missing } log('file line ' + lines[sectionline] ); if (pos('version=', lines[sectionline]) <> 0) begin log('version found'); s := removequotes(trim(lines[sectionline])); stringchangeex(s, '\\', '\', true); result := s; exit; end; end; { <--- missing } end; end;
Comments
Post a Comment