103 lines
3.8 KiB
PowerShell
103 lines
3.8 KiB
PowerShell
# PowerShell script to automate building and creating the installer
|
|
|
|
# Путь к файлу version_.d
|
|
$versionFile = "source/snag/version_.d"
|
|
|
|
# Путь к файлу snag.iss
|
|
$issFile = "windows/snag.iss"
|
|
|
|
# Извлечение snagVersion из version_.d
|
|
$content = Get-Content -Path $versionFile -Raw -Encoding UTF8
|
|
if ($content -match 'enum\s+snagVersion\s*=\s*"([^"]+)"') {
|
|
$snagVersion = $Matches[1]
|
|
Write-Host "Extracted version: $snagVersion"
|
|
} else {
|
|
Write-Host "Failed to find snagVersion in $versionFile."
|
|
exit 1
|
|
}
|
|
|
|
# Чтение snag.iss
|
|
$issContent = Get-Content -Path $issFile -Raw -Encoding UTF8
|
|
|
|
# Обновление AppVersion
|
|
$appVersionPattern = "AppVersion=$snagVersion"
|
|
if ($issContent -match [regex]::Escape($appVersionPattern)) {
|
|
Write-Host "AppVersion in $issFile is already set to $snagVersion. Skipping update."
|
|
} else {
|
|
$issContent = $issContent -replace 'AppVersion=version', "AppVersion=$snagVersion"
|
|
Write-Host "Updated AppVersion to $snagVersion in $issFile."
|
|
}
|
|
|
|
# Обновление OutputBaseFileName
|
|
$appName = "snag_"
|
|
$postfix = "_windows-installer"
|
|
$newOutputBaseFileName = "$appName$snagVersion$postfix"
|
|
$outputBasePattern = "OutputBaseFileName=$newOutputBaseFileName"
|
|
if ($issContent -match [regex]::Escape($outputBasePattern)) {
|
|
Write-Host "OutputBaseFileName in $issFile is already set to $newOutputBaseFileName. Skipping update."
|
|
} else {
|
|
$issContent = $issContent -replace 'OutputBaseFileName=SnagInstaller', "OutputBaseFileName=$newOutputBaseFileName"
|
|
Write-Host "Updated OutputBaseFileName to $newOutputBaseFileName in $issFile."
|
|
}
|
|
|
|
# Сохранение обновленного snag.iss
|
|
Set-Content -Path $issFile -Value $issContent -Encoding UTF8
|
|
Write-Host "File $issFile successfully updated."
|
|
|
|
# Путь к файлу app.d
|
|
$appDFile = "source/app.d"
|
|
|
|
# Исходная и целевая строки для замены
|
|
$originalString = 'string configFile = argumets.option("config", "snag.json");'
|
|
$newString = @'
|
|
import std.process : environment;
|
|
import std.path : buildPath;
|
|
string configFile = argumets.option("config", environment.get("USERPROFILE").buildPath("snag\\snag.json"));
|
|
'@
|
|
|
|
# Чтение содержимого файла и замена строки
|
|
$content = Get-Content -Path $appDFile -Raw -Encoding UTF8
|
|
if ($content -match [regex]::Escape($newString)) {
|
|
Write-Host "The string in $appDFile is already updated. Skipping replacement."
|
|
} elseif ($content -match [regex]::Escape($originalString)) {
|
|
$content = $content -replace [regex]::Escape($originalString), $newString
|
|
Set-Content -Path $appDFile -Value $content -Encoding UTF8
|
|
Write-Host "The string in $appDFile has been successfully replaced."
|
|
} else {
|
|
Write-Host "The original string in $appDFile was not found."
|
|
exit 1
|
|
}
|
|
|
|
# Выполнение команды dub build
|
|
Write-Host "Starting build with dub..."
|
|
dub build --build=release > dub_build.log 2>&1
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "Error during dub build. Check dub_build.log for details."
|
|
exit 1
|
|
}
|
|
|
|
# Переход в директорию windows
|
|
Write-Host "Changing to the windows/ directory..."
|
|
Set-Location -Path "windows"
|
|
if (-not $?) {
|
|
Write-Host "Failed to change to the windows/ directory."
|
|
exit 1
|
|
}
|
|
|
|
# Запуск компиляции Inno Setup
|
|
Write-Host "Starting Inno Setup compilation..."
|
|
& 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe' .\snag.iss > inno_setup.log 2>&1
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "Error during Inno Setup compilation. Check inno_setup.log for details."
|
|
exit 1
|
|
}
|
|
|
|
# Выход из директории windows
|
|
Write-Host "Changing back to the parent directory..."
|
|
Set-Location -Path ..
|
|
if (-not $?) {
|
|
Write-Host "Failed to change back to the parent directory."
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Build and installer compilation completed successfully!"
|