Browse Source

屏蔽错误信息输出

main v2022.6.16
dsx42 3 years ago
parent
commit
371cdd5c75
  1. 2
      UnattendTool.cmd
  2. 42
      UnattendTool.ps1
  3. 2
      build.cmd
  4. 77
      build.ps1
  5. 11
      product.json

2
UnattendTool.cmd

@ -1 +1 @@
PowerShell -ExecutionPolicy RemoteSigned -File .\UnattendTool.ps1 -Interactive PowerShell -NoProfile -ExecutionPolicy RemoteSigned -File "%~dp0UnattendTool.ps1" -Interactive

42
UnattendTool.ps1

@ -794,7 +794,7 @@ function ShowGetISOPath {
$ISOFiles = [ordered]@{} $ISOFiles = [ordered]@{}
$Index = 0; $Index = 0;
try { try {
Get-ChildItem -Path $Path -Include '*.iso' -Recurse -File | ForEach-Object { Get-ChildItem -Path $Path -Include '*.iso' -Recurse -File -ErrorAction SilentlyContinue | ForEach-Object {
$Index = $Index + 1 $Index = $Index + 1
$ISOFiles.Add([System.String]$Index, $_.FullName) $ISOFiles.Add([System.String]$Index, $_.FullName)
} }
@ -954,7 +954,37 @@ function UpdateVentoyConfig {
[System.IO.File]::WriteAllLines($VentoyConfigJsonPath, $JSONString, $Utf8NoBomEncoding) [System.IO.File]::WriteAllLines($VentoyConfigJsonPath, $JSONString, $Utf8NoBomEncoding)
} }
$VersionInfo = 'v2022.6.11' function GetVertion {
$ProductJsonPath = "$PSScriptRoot\product.json"
if (!(Test-Path -Path $ProductJsonPath -PathType Leaf)) {
Write-Warning -Message ("$ProductJsonPath 不存在")
[System.Environment]::Exit(0)
}
$ProductInfo = $null
try {
$ProductInfo = Get-Content -Path $ProductJsonPath | ConvertFrom-Json
}
catch {
Write-Warning -Message ("$ProductJsonPath 解析失败")
[System.Environment]::Exit(0)
}
if (!$ProductInfo -or $ProductInfo -isNot [PSCustomObject]) {
Write-Warning -Message ("$ProductJsonPath 解析失败")
[System.Environment]::Exit(0)
}
$Version = $ProductInfo.'version'
if (!$Version) {
Write-Warning -Message ("$ProductJsonPath 不存在 version 信息")
[System.Environment]::Exit(0)
}
return $Version
}
$VersionInfo = GetVertion
if ($Version) { if ($Version) {
return $VersionInfo return $VersionInfo
@ -964,7 +994,7 @@ Clear-Host
$PSDefaultParameterValues['*:Encoding'] = 'utf8' $PSDefaultParameterValues['*:Encoding'] = 'utf8'
$Host.UI.RawUI.WindowTitle = 'Windows 应答文件生成' $Host.UI.RawUI.WindowTitle = 'Windows 应答文件生成'
Set-Location -Path $PSScriptRoot Set-Location -Path $PSScriptRoot
Write-Host -Object "=====> Windows 系统自动安装应答文件生成 $VersionInfo <=====" Write-Host -Object "=====> Windows 系统自动安装应答文件生成 v$VersionInfo <====="
Write-Host -Object '' Write-Host -Object ''
$WipeDisk = $false $WipeDisk = $false
@ -1093,13 +1123,11 @@ else {
$VentoyConfigParentPath = Join-Path -Path $ParentPath -ChildPath 'ventoy' $VentoyConfigParentPath = Join-Path -Path $ParentPath -ChildPath 'ventoy'
if (!$(Test-Path -Path $VentoyConfigParentPath -PathType Container)) { if (!$(Test-Path -Path $VentoyConfigParentPath -PathType Container)) {
New-Item -Path $VentoyConfigParentPath -ItemType Directory -Force New-Item -Path $VentoyConfigParentPath -ItemType Directory -Force | Out-Null
Write-Host -Object ''
} }
$VentoyConfigScriptPath = Join-Path -Path $VentoyConfigParentPath -ChildPath 'script' $VentoyConfigScriptPath = Join-Path -Path $VentoyConfigParentPath -ChildPath 'script'
if (!$(Test-Path -Path $VentoyConfigScriptPath -PathType Container)) { if (!$(Test-Path -Path $VentoyConfigScriptPath -PathType Container)) {
New-Item -Path $VentoyConfigScriptPath -ItemType Directory -Force New-Item -Path $VentoyConfigScriptPath -ItemType Directory -Force | Out-Null
Write-Host -Object ''
} }
$ProductInfo = @{} $ProductInfo = @{}

2
build.cmd

@ -1 +1 @@
PowerShell -ExecutionPolicy RemoteSigned -File .\build.ps1 PowerShell -NoProfile -ExecutionPolicy RemoteSigned -File "%~dp0build.ps1"

77
build.ps1

@ -1,33 +1,72 @@
Set-Location -Path $PSScriptRoot Clear-Host
$Version = .\UnattendTool.ps1 -Version Set-Location -Path $PSScriptRoot
$Output = 'target'
$ProjectName = 'UnattendTool' $ProductJsonPath = "$PSScriptRoot\product.json"
if (!(Test-Path -Path $ProductJsonPath -PathType Leaf)) {
Write-Warning -Message ("$ProductJsonPath 不存在")
[System.Environment]::Exit(0)
}
$ProductInfo = $null
try {
$ProductInfo = Get-Content -Path $ProductJsonPath | ConvertFrom-Json
}
catch {
Write-Warning -Message ("$ProductJsonPath 解析失败")
[System.Environment]::Exit(0)
}
if (!$ProductInfo -or $ProductInfo -isNot [PSCustomObject]) {
Write-Warning -Message ("$ProductJsonPath 解析失败")
[System.Environment]::Exit(0)
}
$DestinationPath = ".\$Output\${ProjectName}_$Version.zip" $Version = $ProductInfo.'version'
if (!$Version) {
Write-Warning -Message ("$ProductJsonPath 不存在 version 信息")
[System.Environment]::Exit(0)
}
$ProjectName = $ProductInfo.'name'
if (!$ProjectName) {
Write-Warning -Message ("$ProductJsonPath 不存在 name 信息")
[System.Environment]::Exit(0)
}
$Files = $ProductInfo.'files'
if (!$Files -or $Files -isNot [System.Array] -or $Files.Count -le 0) {
Write-Warning -Message ("$ProductJsonPath 不存在 files 信息")
[System.Environment]::Exit(0)
}
$CopyFiles = @()
foreach ($File in $Files) {
$CopyFiles += "$PSScriptRoot\$File"
}
$Files = @( $Output = 'target'
'.\UnattendTool.cmd', $OutputPath = "$PSScriptRoot\$Output"
'.\UnattendTool.ps1', $OutputProjectPath = "$OutputPath\${ProjectName}"
'.\LICENSE', $OutputFileName = "${ProjectName}_v$Version"
'.\README.md' $ZipFilePath = "$OutputPath\$OutputFileName.zip"
) $Sha256FilePath = "$OutputPath\$OutputFileName.sha256"
if (Test-Path -Path ".\$Output" -PathType Container) { if (Test-Path -Path $OutputPath -PathType Container) {
Remove-Item -Path ".\$Output" -Recurse -Force Remove-Item -Path $OutputPath -Recurse -Force
} }
New-Item -Path ".\$Output\$ProjectName" -ItemType Directory -Force New-Item -Path $OutputProjectPath -ItemType Directory -Force | Out-Null
Copy-Item -Path $Files -Destination ".\$Output\$ProjectName" -Force -Recurse Copy-Item -Path $CopyFiles -Destination $OutputProjectPath -Force -Recurse
Compress-Archive -Path ".\$Output\$ProjectName" -DestinationPath $DestinationPath -Force Compress-Archive -Path $OutputProjectPath -DestinationPath $ZipFilePath -Force
$Hash = Get-FileHash -Path $DestinationPath -Algorithm SHA256 $Hash = Get-FileHash -Path $ZipFilePath -Algorithm SHA256
$Checksum = $Hash.Hash + " ${ProjectName}_$Version.zip" $Checksum = $Hash.Hash + " $OutputFileName.zip"
Add-Content -Path ".\$Output\${ProjectName}_$Version.sha256" -Value $Checksum Add-Content -Path $Sha256FilePath -Value $Checksum
Write-Host -Object '' Write-Host -Object ''
Write-Host -Object ('Path: ' + $Hash.Path) Write-Host -Object ('Path: ' + $Hash.Path)

11
product.json

@ -0,0 +1,11 @@
{
"name": "UnattendTool",
"version": "2022.6.16",
"files": [
"UnattendTool.cmd",
"UnattendTool.ps1",
"product.json",
"LICENSE",
"README.md"
]
}
Loading…
Cancel
Save