Baca versi aplikasi dari file teks di Inno Setup

Aug 18 2020

Saya memiliki file TypeScript yang berisi baris ini:

export const version = '0.0.1';

Dan saya ingin mengakses nilai versiondan mengimpornya ke AppVersiondalam Setupbagian (file iss)

[Setup]
AppVersion={....}

Bagaimana saya bisa melakukannya?

Jawaban

2 MartinPrikryl Aug 18 2020 at 19:51

Demikian pula dengan Inno Setup: How to update AppVersion [Setup] value from Config.xml file , Anda dapat menggunakan skrip PowerShell dari preprocessor untuk mengurai versi dari file menggunakan ekspresi reguler:

#define RetrieveVersion(str FileName) \
  Local[0] = AddBackslash(GetEnv("TEMP")) + "version.txt", \
  Local[1] = \
    "-ExecutionPolicy Bypass -Command """ + \
    "$contents = Get-Content '" + FileName + "';" + \ "$match = $contents | Select-String 'version\s*=\s*''(.*?)''';" + \ "$version = $match.Matches.Groups[1].Value;" + \ "Set-Content -Path '" + Local[0] + "' -Value $version;" + \
    """", \
  Exec("powershell.exe", Local[1], SourcePath, , SW_HIDE), \
  Local[2] = FileOpen(Local[0]), \
  Local[3] = FileRead(Local[2]), \
  FileClose(Local[2]), \
  DeleteFileNow(Local[0]), \
  Local[3]

[Setup]
AppVersion={#RetrieveVersion("C:\path\script.ts")}