Home > Software design >  Can this powershell script be modified to run inside Inno Setup ISPP section? It writes version info
Can this powershell script be modified to run inside Inno Setup ISPP section? It writes version info

Time:12-01

Related question:

Trying to extract version info and save to INI file on Windows 11 with PowerShell

The accepted answer had this script:

$exe_info = Get-Item -Path '.\MeetSchedAssistSetup.exe'
$ini_path = '.\version_meetschedassist2.ini'
$ini = Get-IniContent -FilePath $ini_path

$ini['MeetSchedAssist Update']['LatestVersion'] = 
    '{0}.{1}{2}' -f $exe_info.VersionInfo.FileMajorPart, 
                    $exe_info.VersionInfo.FileMinorPart, $exe_info.VersionInfo.FileBuildPart
$ini['MeetSchedAssist Update']['LatestVersionString'] =
    '{0}.{1}.{2}' -f $exe_info.VersionInfo.FileMajorPart, 
                    $exe_info.VersionInfo.FileMinorPart, $exe_info.VersionInfo.FileBuildPart

Out-IniFile -FilePath $ini_path -InputObject $ini -Force

I am now wondering though if I can do things easier with Inno Setup? Afterall, I update this INI whenever I build a new version of the installer. I know we have accessed the version info before and used powershell:

#define AppVerText() \
   GetVersionComponents(SourceDir   '\Meeting Schedule Assistant.exe', \
       Local[0], Local[1], Local[2], Local[3]), \
   Str(Local[0])   "."   Str(Local[1])   "."   Str(Local[2])
     
#define GetSHA256OfFile(FileName) \
  Local[0] = AddBackslash(GetEnv("TEMP"))   "sha256.txt", \
  Local[1] = \
    "-ExecutionPolicy Unrestricted -Command """   \
    "Set-Content -Path '"   Local[0]   "' -NoNewline -Value "   \
    "(Get-FileHash('"   FileName   "')).Hash"   \
    """", \
  Exec("powershell.exe", Local[1], SourcePath, , SW_HIDE), \
  Local[2] = FileOpen(Local[0]), \
  Local[3] = FileRead(Local[2]), \
  FileClose(Local[2]), \
  DeleteFileNow(Local[0]), \
  LowerCase(Local[3])

Is it possible to somehow do the same thing as my original script? Take the version info from the exe (Meeting Schedule Assistant.exe) and update the INI file which is in same folder as the setup file? It would make sense to do the updating from here in Inno.

CodePudding user response:

Use WriteIni preprocessor function. Something like this (untested):

#expr WriteIni( \
    SourcePath   "\version_meetschedassist2.ini", "MeetSchedAssist Update", \
    "LatestVersion", AppVerText())

(and repeat for the other key)

  • Related