Skip to content

Commit

Permalink
fixup streams
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Jun 25, 2024
1 parent f41d521 commit 5d38387
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 48 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/CI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ $error.clear()
$repoPath = "$PSScriptRoot/../.."
try{
mkdir $repoPath/build -ErrorAction Ignore | Out-Null
Import-Module $repoPath -Force | Out-Host
Import-Module $repoPath -Force | Write-Host
Set-ps12exeContextMenu 1
& $repoPath/ps12exe.ps1 $repoPath/ps12exe.ps1 $repoPath/build/ps12exe.exe -verbose | Out-Host
& $repoPath/build/ps12exe.exe $repoPath/ps12exe.ps1 -verbose -noConsole -title 'lol' | Out-Host
& $repoPath/build/ps12exe.exe $repoPath/ps12exe.ps1 $repoPath/build/ps12exe2.exe -verbose | Out-Host
"'Hello World!'" | ps12exe -outputFile $repoPath/build/hello.exe -verbose | Out-Host
& $repoPath/build/ps12exe2.exe -Content '$PSEXEpath;$PSScriptRoot' -outputFile $repoPath/build/pathtest.exe | Out-Host
& $repoPath/ps12exe.ps1 $repoPath/ps12exe.ps1 $repoPath/build/ps12exe.exe -verbose | Write-Host
& $repoPath/build/ps12exe.exe $repoPath/ps12exe.ps1 -verbose -noConsole -title 'lol' | Write-Host

Check failure on line 9 in .github/workflows/CI.ps1

View workflow job for this annotation

GitHub Actions / test

The term 'D:\a\ps12exe\ps12exe\.github\workflows/../../build/ps12exe.exe' is not recognized as a name of a cmdlet, function, script file, or executable program.
& $repoPath/build/ps12exe.exe $repoPath/ps12exe.ps1 $repoPath/build/ps12exe2.exe -verbose | Write-Host
"'Hello World!'" | ps12exe -outputFile $repoPath/build/hello.exe -verbose | Write-Host
& $repoPath/build/ps12exe2.exe -Content '$PSEXEpath;$PSScriptRoot' -outputFile $repoPath/build/pathtest.exe | Write-Host
$pathresult=. $repoPath/build/pathtest.exe
$pathresultshouldbe=@("$repoPath/build/pathtest.exe","$repoPath/build")
# 在路径层面比较 $pathresult 和 $pathresultshouldbe
Expand All @@ -23,7 +23,7 @@ try{
Write-Error "$path1 -ne $path2"
}
}
& $repoPath/build/hello.exe | Out-Host
& $repoPath/build/hello.exe | Write-Host
Set-ps12exeContextMenu 0
Remove-Item $repoPath/build -Recurse -Force
}catch{}
Expand Down
38 changes: 15 additions & 23 deletions ps12exe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,17 @@ Param(
$Verbose = $PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent
function RollUp {
param ($num = 1, [switch]$InVerbose)
$CousorPos = $Host.UI.RawUI.CursorPosition
try {
if (-not $Verbose -or $InVerbose) {
if ($nested) { throw }
$CousorPos.Y = $CousorPos.Y - $num
$Host.UI.RawUI.CursorPosition = $CousorPos
if (-not $Verbose -or $InVerbose) {
if ($Host.UI.SupportsVirtualTerminal) {
Write-Host $([char]27 + '[' + $num + 'A') -NoNewline
}
elseif (-not $nested) {
$CousorPos = $Host.UI.RawUI.CursorPosition
try {
$CousorPos.Y = $CousorPos.Y - $num
$Host.UI.RawUI.CursorPosition = $CousorPos
} catch { $Error.RemoveAt(0) }
}
}
catch {
Write-Host $([char]27 + '[' + $num + 'A') -NoNewline
}
}
function Show-Help {
Expand All @@ -207,11 +208,11 @@ function Show-Help {
. $PSScriptRoot\src\HelpShower.ps1 -HelpData $MyHelp
}
if ($help) {
Show-Help | Out-Host
Show-Help | Write-Host
return
}
if (-not ($inputFile -or $Content)) {
Show-Help | Out-Host
Show-Help | Write-Host
Write-Host
Write-Error "Input not specified!"
return
Expand Down Expand Up @@ -385,6 +386,7 @@ else {
}
}
#_if PSScript #在PSEXE中主机永远是winpwsh,可省略该部分
. $PSScriptRoot/src/PSObjectToString.ps1
function UsingWinPowershell($Boundparameters) {
# starting Windows Powershell
$Params = ([hashtable]$Boundparameters).Clone()
Expand All @@ -408,21 +410,11 @@ function UsingWinPowershell($Boundparameters) {
if ($iconFile) {
$Params['iconFile'] = $iconFile
}
$CallParam = foreach ($Param in $Params.GetEnumerator()) {
if ($Param.Value -is [Switch]) {
"-$($Param.Key):`$$([bool]$Param.Value)"
}
elseif ($Param.Value -is [string] -and $Param.Value) {
"-$($Param.Key):'$(($Param.Value).Replace("'", "''"))'"
}
else {
"-$($Param.Key):$($Param.Value)"
}
}
$CallParam = Get-ArgsString $Params

Write-Verbose "Starting WinPowershell ps12exe with parameters: $CallParam"

powershell -noprofile -Command "&'$PSScriptRoot\ps12exe.ps1' $CallParam -nested" | Out-Host
powershell -noprofile -Command "&'$PSScriptRoot\ps12exe.ps1' $CallParam -nested" | Write-Host
return
}
if (!$nested -and ($PSVersionTable.PSEdition -eq "Core") -and $UseWindowsPowerShell -and (Get-Command powershell -ErrorAction Ignore)) {
Expand Down
8 changes: 4 additions & 4 deletions src/AstAnalyze.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<#
function ShowAst($Ast) {
function Mapper($Ast) {
$Ast.GetType().Name | Out-Host
$Ast | Out-Host
$Ast.GetType().Name | Write-Host
$Ast | Write-Host
return $false
}
$Ast.Find($function:Mapper, $true)
Expand All @@ -17,8 +17,8 @@ AI prompt: 用你所知的最刁钻的方式和最花哨的技术写一段powers
我需要测试一段评估程序是不是常量程序的程序
#>
function AstAnalyze($Ast) {
$script:ConstCommands = @('Write-Host', 'echo', 'Write-Output', 'Write-Debug', 'Write-Information', 'ConvertFrom-Json', 'ConvertTo-Json', 'Out-Host')
$script:ConstVariables = @('?', '^', '$', 'Error', 'false', 'IsCoreCLR', 'IsLinux', 'IsMacOS', 'IsWindows', 'null', 'true', 'PSEXEScript', 'Out-Host')
$script:ConstCommands = @('Write-Host', 'echo', 'Write-Output', 'Write-Debug', 'Write-Information', 'ConvertFrom-Json', 'ConvertTo-Json', 'Write-Host')
$script:ConstVariables = @('?', '^', '$', 'Error', 'false', 'IsCoreCLR', 'IsLinux', 'IsMacOS', 'IsWindows', 'null', 'true', 'PSEXEScript', 'Write-Host')
$script:ConstTypes = @('Boolean', 'Char', 'DateTime', 'Decimal', 'Double', 'Int16', 'Int32', 'Int64', 'Int8', 'Int', 'Single', 'String', 'UInt16', 'UInt32', 'UInt64', 'UInt8', 'Void', 'Regex', 'System.Text.RegularExpressions.RegexOptions', 'HashTable', 'OrderedDictionary', 'PSObject', 'PSVariable', 'PSNoteProperty', 'PSMemberInfo', 'PSCustomObject', 'Math', 'Array', 'ref', 'Guid')
$script:EffectVariables = @('ConfirmPreference', 'DebugPreference', 'EnabledExperimentalFeatures', 'ErrorActionPreference', 'ErrorView', 'ExecutionContext', 'FormatEnumerationLimit', 'HOME', 'Host', 'InformationPreference', 'input', 'MaximumHistoryCount', 'MyInvocation', 'NestedPromptLevel', 'OutputEncoding', 'PID', 'PROFILE', 'ProgressPreference', 'PSBoundParameters', 'PSCommandPath', 'PSCulture', 'PSDefaultParameterValues', 'PSEdition', 'PSEmailServer', 'PSGetAPI', 'PSHOME', 'PSNativeCommandArgumentPassing', 'PSNativeCommandUseErrorActionPreference', 'PSScriptRoot', 'PSSessionApplicationName', 'PSSessionConfigurationName', 'PSSessionOption', 'PSStyle', 'PSUICulture', 'PSVersionTable', 'PWD', 'ShellId', 'StackTrace', 'VerbosePreference', 'WarningPreference', 'WhatIfPreference')
$script:AnalyzeResult = @{
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/ContextMenuAdder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $LocalizeData = . $PSScriptRoot\..\LocaleLoader.ps1 -Localize $Localize

if ($help) {
$MyHelp = $LocalizeData.SetContextMenuHelpData
. $PSScriptRoot\..\HelpShower.ps1 -HelpData $MyHelp | Out-Host
. $PSScriptRoot\..\HelpShower.ps1 -HelpData $MyHelp | Write-Host
return
}

Expand Down
11 changes: 0 additions & 11 deletions src/GUI/Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ function Set-UIData {
$Script:refs.LongPathSupportCheckBox.Checked = $UIData.longPaths
}

. $PSScriptRoot/../PSObjectToString.ps1

function Get-ps12exeArgsString {
param(
[hashtable]$Params
)
$result = 'ps12exe'
$Params.GetEnumerator() | ForEach-Object { $result += " -$($_.Key):$(PSObjectToString $_.Value -OneLine)" }
$result
}

function Get-ps12exeArgs {
$UIData = Get-UIData
$result = $UIData.Clone()
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ param(
if ($help) {
$LocalizeData = . $PSScriptRoot\..\LocaleLoader.ps1 -Localize $Localize
$MyHelp = $LocalizeData.GUIHelpData
. $PSScriptRoot\..\HelpShower.ps1 -HelpData $MyHelp | Out-Host
. $PSScriptRoot\..\HelpShower.ps1 -HelpData $MyHelp | Write-Host
return
}

Expand Down
3 changes: 3 additions & 0 deletions src/PSObjectToString.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ function PSObjectToString($obj, [Switch]$OneLine = $false) {
elseif ($obj -is [bool]) { "`$$obj" }
else { "$obj" }
}
function Get-ArgsString([hashtable]$Params) {
$Params.GetEnumerator() | ForEach-Object { "-$($_.Key):$(PSObjectToString $_.Value -OneLine)" }
}
2 changes: 1 addition & 1 deletion src/WebServer/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $LocalizeData = . $PSScriptRoot\..\LocaleLoader.ps1 -Localize $Localize

if ($help) {
$MyHelp = $LocalizeData.WebServerHelpData
. $PSScriptRoot\..\HelpShower.ps1 -HelpData $MyHelp | Out-Host
. $PSScriptRoot\..\HelpShower.ps1 -HelpData $MyHelp | Write-Host
return
}

Expand Down

0 comments on commit 5d38387

Please sign in to comment.