Kumsen
Kumsen

Reputation: 85

Modify configuration file in compiled Inno Setup installer (custom configuration file for each downloaded executable)

I am working on a project which needs a unique method of operation which requires a windows installer exe (packaged using Inno Setup) to be updated with different configuration file containing a unique identification number for every downloads.

The project itself is a web based for which I am using PHP on Apache and on Linux.

The installer contains a Windows binary executable file and config.ini file. I just need to edit the config.ini file every time the file is to be made ready for download. The updates are simply incremented counter.

I am not finding a direction to approach as I am looking at editing a Inno Setup packaged file created in Windows to be edited in a Linux server.

Can anyone point me towards some ideas to achieve this please.

Thanks,
Sk

Upvotes: 3

Views: 2171

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202340

Below is an old answer that works only if you do not sing the installer. Nowadays you basically cannot distribute unsigned installers. Skip further below.

Just store the configuration file to the installer uncompressed to allow easy modification. Use nocompression flag. You also have to use dontverifychecksum flag, otherwise the installer will consider the modified file as corrupted, when installing.

[Files]
Source: "config.ini"; DestDir: "{app}"; Flags: nocompression dontverifychecksum

You also cannot modify file length. So you need to reserve enough space in the file for larger numbers, like:

[Section]
Counter=?????

To modify the installer with PHP, you can now do:

$counter = $_GET["counter"];
$filename = "mysetup.exe";
$contents = file_get_contents($filename);
$mask = "?????";
$prefix = "Counter=";
$replace = $prefix . $mask;
$p = strpos($contents, $replace);
if ($p !== false)
{
    $s = $prefix . str_pad($counter, strlen($mask), "0", STR_PAD_LEFT);
    $contents =
        substr($contents, 0, $p) . $s . substr($contents, $p + strlen($replace));

    // (or feed directly to the output stream)
    file_put_contents($filename, $contents);
}

If you sign the installer (these day it is basically necessary for downloadable installers), you have to sign it after modifying it.

Or see Embed user-specific data into an authenticode signed installer on download.


Another way is to include the custom data into the installer name.

Upvotes: 3

Related Questions