Skip to content

Commit

Permalink
feat(local-build): config file
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Sep 16, 2023
1 parent 2edfaf2 commit 04c3a96
Showing 1 changed file with 64 additions and 21 deletions.
85 changes: 64 additions & 21 deletions src/playbook/local-build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,70 @@
@echo off & powershell -nop Get-Content """%~f0""" -Raw ^| iex & exit /b
: end batch / begin PowerShell #>

# name of resulting apbx
$fileName = "Atlas Test"

# if the script should delete any playbook that already exists with the same name or not
# if not, it will make something like "Atlas Test (1).apbx"
$replaceOldPlaybook = $true

# add AME Wizard Live Log window
$liveLog = $true

# choose to get Atlas dependencies or not to speed up installation
$removeDependencies = $false
# choose not to modify certain aspects from playbook.conf
$removeRequirements = $false
$removeWinverRequirement = $true
# not recommended to disable as it will show malicious
$removeProductCode = $true

# ------ #
# script #
# ------ #
# Do not change anything here, this is simply for reference
$defaultConfig = @{
# Name of resulting APBX
fileName = "Atlas Test"

# If the script should delete any playbook that already exists with the same name or not
# If not, it will make something like "Atlas Test (1).apbx"
replaceOldPlaybook = $true

# Add AME Wizard Live Log window
liveLog = $true

# Choose to get Atlas dependencies or not to speed up installation
removeDependencies = $true

# Choose not to modify certain aspects from playbook.conf
removeRequirements = $false
removeWinverRequirement = $true

# Not recommended to disable as it will show malicious
removeProductCode = $true
}

$configPath = "$env:appdata\local-build\config.json"

# ------------- #
# config system #
# ------------- #

function CreateConfig($conf) {
New-Item -Type Directory -Force -Path $(Split-Path $configPath) -ErrorAction SilentlyContinue | Out-Null
$conf | ConvertTo-Json -Depth 100 | Out-File $configPath
}
if (!(Test-Path $configPath)) { CreateConfig $defaultConfig }

try {
$configNotHashtable = Get-Content $configPath | ConvertFrom-Json
# convert JSON config to hashtable
$config = @{}; foreach ($property in $configNotHashtable.PSObject.Properties) { $config[$property.Name] = $property.Value }
} catch {
Write-Host "Your configuration is corrupted." -ForegroundColor Yellow
choice /c:yn /n /m "Would you like to reset it? [Y/N]"
if ($LASTEXITCODE -eq 1) {
CreateConfig $defaultConfig
} else {exit 1}
}

# update config
$defaultConfig.Keys | ForEach-Object {
if ($config.Keys -notcontains $_) {
$config = $config + @{
$_ = $defaultConfig.$_
}; $updateConfig = $true
}
}
if ($updateConfig) {CreateConfig $config}

foreach ($a in $config.Keys) {
New-Variable -Name $a -Value $config.$a
}

# ----------- #
# main script #
# ----------- #

$apbxFileName = "$fileName.apbx"
$apbxPath = "$PWD\$fileName.apbx"
Expand Down

0 comments on commit 04c3a96

Please sign in to comment.