From cff4d3baf685e7bee2743b00da6a57578a056141 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 30 May 2025 14:00:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B0=20=D0=B2=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=81=D1=82=D0=B0=D0=BB=D0=BB=D1=8F=D1=86=D0=B8?= =?UTF-8?q?=D0=BE=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20Windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.ps1 | 103 ++++++++++++++++++++++++++++++++++++++++++ windows.md | 7 +++ windows/snag.bat | 21 +++++++++ windows/snag.iss | 30 ++++++++++++ windows/snag.json.bak | 16 +++++++ 5 files changed, 177 insertions(+) create mode 100644 build.ps1 create mode 100644 windows.md create mode 100644 windows/snag.bat create mode 100644 windows/snag.iss create mode 100644 windows/snag.json.bak diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..80fc10d --- /dev/null +++ b/build.ps1 @@ -0,0 +1,103 @@ +# 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!" diff --git a/windows.md b/windows.md new file mode 100644 index 0000000..481d5ba --- /dev/null +++ b/windows.md @@ -0,0 +1,7 @@ +# Сборка из под Windows + +Для сборки на Windows необходим установленный [Inno Setup](https://jrsoftware.org/isdl.php). + +``` +.\build.ps1 +``` diff --git a/windows/snag.bat b/windows/snag.bat new file mode 100644 index 0000000..d7f710b --- /dev/null +++ b/windows/snag.bat @@ -0,0 +1,21 @@ +@echo off + +chcp 65001 > nul + +set "SCRIPT_DIR=%~dp0" +set "SNAG_PATH=%SCRIPT_DIR%" +set "PATH=%PATH%;%SNAG_PATH%" + +echo ----------------------------------------------- +echo Snag Application Launcher +echo ----------------------------------------------- +echo. +echo NOTE: Ensure the config file exists at: +echo "%USERPROFILE%\snag\snag.json" +echo. +echo To get started, type: snag --help +echo ----------------------------------------------- +echo. + +cd /d "%USERPROFILE%" +cmd /k diff --git a/windows/snag.iss b/windows/snag.iss new file mode 100644 index 0000000..bc4a667 --- /dev/null +++ b/windows/snag.iss @@ -0,0 +1,30 @@ +; Сценарий для Inno Setup +[Setup] +AppName=Snag +AppVersion=version +DefaultDirName={commonpf}\snag +DefaultGroupName=Snag +OutputDir=Output +OutputBaseFileName=SnagInstaller +Compression=lzma +SolidCompression=yes +LicenseFile=../LICENSE + +[Languages] +Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl" + +[Files] +Source: "../bin/snag.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "snag.bat"; DestDir: "{app}"; Flags: ignoreversion +Source: "snag.json.bak"; DestDir: "{app}"; Flags: ignoreversion +Source: "../LICENSE"; DestDir: "{app}"; Flags: ignoreversion + +[Icons] +Name: "{group}\Snag"; Filename: "{app}\snag.bat" +Name: "{group}\{cm:UninstallProgram,Snag}"; Filename: "{uninstallexe}" + +[Run] +Filename: "{app}\snag.bat"; Description: "{cm:LaunchProgram,Snag}"; Flags: nowait postinstall skipifsilent + +[CustomMessages] +russian.LaunchProgram=Запустить Snag diff --git a/windows/snag.json.bak b/windows/snag.json.bak new file mode 100644 index 0000000..4cf4d52 --- /dev/null +++ b/windows/snag.json.bak @@ -0,0 +1,16 @@ +{ + "git": "", + "project": "", + "email": "", + "author": "", + "presnag": [ + ], + "postsnag": [ + ], + "rules": { + "tracking": [ + ], + "ignore": [ + ] + } +}