Skip to content

Commit

Permalink
fix: update encoding output of install.ps1
Browse files Browse the repository at this point in the history
Co-authored-by: ryouji <[email protected]>
  • Loading branch information
RalXYZ and soryu-ryouji committed Aug 25, 2024
1 parent 185943d commit 04c3fb5
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions src/scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,47 @@

Add-Type -AssemblyName PresentationFramework

function Convert-BytesToString {
param (
[byte[]]$ByteArray
)

$currentEncoding = [Console]::OutputEncoding

if ($currentEncoding.WebName -eq "utf-8") {
$outputStr = [System.Text.Encoding]::UTF8.GetString($ByteArray)
} else {
$outputStr = [System.Text.Encoding]::GetEncoding("GB2312").GetString(
[System.Text.Encoding]::Convert([System.Text.Encoding]::UTF8, $currentEncoding, $ByteArray)
)
}

return $outputStr
}

$dir="$env:APPDATA\Typora\themes"

Write-Output "正在寻找 Typora 主题文件夹 $dir"
Write-Output (
Convert-BytesToString -ByteArray `
@(0xe6, 0xad, 0xa3, 0xe5, 0x9c, 0xa8, 0xe5, 0xaf, 0xbb, 0xe6, 0x89, 0xbe, 0x20, 0x54, 0x79, 0x70, 0x6f, 0x72, 0x61, 0x20, 0xe4, 0xb8, 0xbb, 0xe9, 0xa2, 0x98, 0xe6, 0x96, 0x87, 0xe4, 0xbb, 0xb6, 0xe5, 0xa4, 0xb9)
) # zheng zai xun zhao Typora zhu ti wen jian jia
Write-Output $dir
If (Test-Path -Path $dir -PathType Container) {
Write-Output "已找到该文件夹"
Write-Output (
Convert-BytesToString -ByteArray `
@(0xe5, 0xb7, 0xb2, 0xe6, 0x89, 0xbe, 0xe5, 0x88, 0xb0, 0xe8, 0xaf, 0xa5, 0xe6, 0x96, 0x87, 0xe4, 0xbb, 0xb6, 0xe5, 0xa4, 0xb9)
) # yi zhao dao gai wen jian jia
} Else {
$MessageBody = "未找到 Typora 主题文件夹,请先安装 Typora"
$MessageBody = (
Convert-BytesToString -ByteArray `
@(0xe6, 0x9c, 0xaa, 0xe6, 0x89, 0xbe, 0xe5, 0x88, 0xb0, 0x20, 0x54, 0x79, 0x70, 0x6f, 0x72, 0x61, 0x20, 0xe4, 0xb8, 0xbb, 0xe9, 0xa2, 0x98, 0xe6, 0x96, 0x87, 0xe4, 0xbb, 0xb6, 0xe5, 0xa4, 0xb9, 0xef, 0xbc, 0x8c, 0xe8, 0xaf, 0xb7, 0xe5, 0x85, 0x88, 0xe5, 0xae, 0x89, 0xe8, 0xa3, 0x85, 0x20, 0x54, 0x79, 0x70, 0x6f, 0x72, 0x61)
) # wei zhao dao Typora zhu ti wen jian jia, qing xian an zhuang Typora
$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageIcon = [System.Windows.MessageBoxImage]::Error
$MessageTitle = "安装失败"
$MessageTitle = (
Convert-BytesToString -ByteArray `
@(0xe5, 0xae, 0x89, 0xe8, 0xa3, 0x85, 0xe5, 0xa4, 0xb1, 0xe8, 0xb4, 0xa5)
) # an zhuang shi bai
Write-Error $MessageBody
[System.Windows.MessageBox]::Show($MessageBody, $MessageTitle, $ButtonType, $MessageIcon)
Throw $MessageBody
Expand All @@ -23,15 +54,24 @@ Try {
$MessageBody = $_.Exception.Message
$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageIcon = [System.Windows.MessageBoxImage]::Error
$MessageTitle = "安装失败"
$MessageTitle = (
Convert-BytesToString -ByteArray `
@(0xe5, 0xae, 0x89, 0xe8, 0xa3, 0x85, 0xe5, 0xa4, 0xb1, 0xe8, 0xb4, 0xa5)
) # an zhuang shi bai
Write-Error $MessageTitle
[System.Windows.MessageBox]::Show($MessageBody, $MessageTitle, $ButtonType, $MessageIcon)
Throw $MessageBody
}

$MessageBody = "主题文件已安装成功"
$MessageBody = (
Convert-BytesToString -ByteArray `
@(0xe4, 0xb8, 0xbb, 0xe9, 0xa2, 0x98, 0xe6, 0x96, 0x87, 0xe4, 0xbb, 0xb6, 0xe5, 0xb7, 0xb2, 0xe5, 0xae, 0x89, 0xe8, 0xa3, 0x85, 0xe6, 0x88, 0x90, 0xe5, 0x8a, 0x9f)
) # zhu ti wen jian yi an zhuang cheng gong
$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageIcon = [System.Windows.MessageBoxImage]::Information
$MessageTitle = "安装成功"
$MessageTitle = (
Convert-BytesToString -ByteArray `
@(0xe5, 0xae, 0x89, 0xe8, 0xa3, 0x85, 0xe6, 0x88, 0x90, 0xe5, 0x8a, 0x9f)
) # an zhuang cheng gong
Write-Output $MessageTitle
[System.Windows.MessageBox]::Show($MessageBody, $MessageTitle, $ButtonType, $MessageIcon)

0 comments on commit 04c3fb5

Please sign in to comment.