SE38 source code ?? 乱码

本文介绍了解决SE38在激活后中文显示变为问号的问题。通过调整字符集设置,选择简体中文或UTF-8选项,可以恢复正常显示。

SE38 中文在activate后变成问号。

菜单栏右侧有个customize Local layout--&gtcharacter set---&gtSimplified Chinese(或UTF-8)

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/167898/viewspace-1039915/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/167898/viewspace-1039915/

PS C:\Users\Administrator> # CurlTools.psm1 >> # ============== >> >> # 模块初始化块 >> $script:Config = $null >> $script:CurlPath = $null >> $script:ConfigDir = $null >> $script:ConfigPath = $null >> $script:ModuleInitialized = $false >> >> # 检测操作系统 >> function Get-Platform { >> if ($PSVersionTable.PSEdition -eq "Core") { >> if ($IsWindows) { "Windows" } >> elseif ($IsLinux) { "Linux" } >> elseif ($IsMacOS) { "macOS" } >> } else { >> if ($env:OS -like "Windows*") { "Windows" } >> elseif (Test-Path "/etc/os-release") { "Linux" } >> else { "macOS" } >> } >> } >> >> # 获取配置目录 >> function Get-ConfigDir { >> $platform = Get-Platform >> switch ($platform) { >> "Linux" { [System.IO.Path]::Combine($HOME, ".config", "curltools") } >> "macOS" { [System.IO.Path]::Combine($HOME, "Library", "Application Support", "CurlTools") } >> default { [System.IO.Path]::Combine($env:APPDATA, "CurlTools") } >> } >> } >> >> # 核心初始化函数 - 修复ConfigPath变量 >> function Initialize-Module { >> try { >> # 设置配置目录 >> $script:ConfigDir = Get-ConfigDir >> if (-not (Test-Path $script:ConfigDir)) { >> New-Item -ItemType Directory -Path $script:ConfigDir -Force | Out-Null >> } >> # 修复乱码变量 >> $script:ConfigPath = Join-Path $script:ConfigDir "config.json" >> >> # 加载或创建配置 >> if (Test-Path $script:ConfigPath) { >> $script:Config = Get-Content $script:ConfigPath | ConvertFrom-Json >> } >> >> if (-not $script:Config) { >> $script:Config = [PSCustomObject]@{ >> CurlPath = $null >> LastUpdate = (Get-Date).ToString("o") >> AutoUpdate = $true >> } >> } >> >> # 查找或安装curl >> if (-not $script:Config.CurlPath -or -not (Test-Path $script:Config.CurlPath)) { >> $script:Config.CurlPath = Find-CurlPath >> } >> >> # 保存配置 >> $script:Config | ConvertTo-Json | Set-Content $script:ConfigPath -Force >> $script:CurlPath = $script:Config.CurlPath >> $script:ModuleInitialized = $true >> >> return $true >> } catch { >> Write-Warning "模块初始化失败: $_" >> return $false >> } >> } >> >> # 查找curl路径 >> function Find-CurlPath { >> $platform = Get-Platform >> $exeName = if ($platform -eq "Windows") { "curl.exe" } else { "curl" } >> >> # 检查系统PATH >> $pathCurl = Get-Command $exeName -ErrorAction SilentlyContinue >> if ($pathCurl) { >> return $pathCurl.Source | Split-Path >> } >> >> # 平台特定路径 >> $searchPaths = switch ($platform) { >> "Windows" { >> @( >> "C:\Windows\System32", >> "C:\Program Files\curl\bin", >> "${env:ProgramFiles}\Git\usr\bin" >> ) >> } >> "Linux" { @("/usr/bin", "/usr/local/bin") } >> "macOS" { @("/usr/local/bin", "/opt/homebrew/bin") } >> } >> >> foreach ($path in $searchPaths) { >> $fullPath = Join-Path $path $exeName >> if (Test-Path $fullPath) { >> return $path >> } >> } >> >> # 终极方案:自动安装 >> return Install-Curl >> } >> >> # curl安装函数 >> function Install-Curl { >> $platform = Get-Platform >> try { >> if ($platform -eq "Windows") { >> $tempDir = [System.IO.Path]::GetTempPath() >> $curlZip = Join-Path $tempDir "curl.zip" >> >> # 使用固定版本URL避免404错误 >> $curlUrl = "https://curl.se/windows/dl-8.8.0_5/curl-8.8.0_5-win64-mingw.zip" >> >> # 使用安全下载函数 >> Invoke-SecureDownload -Url $curlUrl -OutputPath $curlZip >> >> Expand-Archive $curlZip -DestinationPath $tempDir -Force >> >> # 查找解压后的bin目录 >> $installDir = Join-Path $tempDir "curl-8.8.0_5-win64-mingw\bin" >> >> if (-not (Test-Path $installDir)) { >> throw "安装目录不存在: $installDir" >> } >> >> return $installDir >> } >> else { >> if ($platform -eq "Linux") { >> if (Get-Command apt -ErrorAction SilentlyContinue) { >> sudo apt update >> sudo apt install -y curl >> } elseif (Get-Command yum -ErrorAction SilentlyContinue) { >> sudo yum install -y curl >> } elseif (Get-Command dnf -极乐净土ErrorAction SilentlyContinue) { >> sudo dnf install -y curl >> } >> return "/usr/bin" >> } >> else { # macOS >> if (-not (Get-Command brew -ErrorAction SilentlyContinue)) { >> # 使用官方方式安装Homebrew >> /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" >> } >> brew install curl >> return "/usr/local/bin" >> } >> } >> } catch { >> throw "无法自动安装curl: $_" >> } >> } >> >> # ========== 公共函数 ========== >> function Get-CurlPath { >> Ensure-ModuleInitialized >> return $script:CurlPath >> } >> >> function Set-CurlPath { >> param( >> [Parameter(Mandatory=$true)] >> [ValidateScript({ >> # 修复乱码 >> if (-not (Test-Path $_)) { >> Write-Warning "路径不存在,将在设置后创建: $_" >> $true >> } else { >> $true >> } >> })] >> [string]$Path >> ) >> >> Ensure-ModuleInitialized >> >> # 确保路径存在 >> if (-not (Test-Path $Path)) { >> New-Item -ItemType Directory -Path $Path -Force | Out-Null >> } >> >> $script:CurlPath = $Path >> $script:Config.CurlPath = $Path >> $script:Config | ConvertTo-Json | Set-Content $script:ConfigPath -Force >> Write-Host "已设置curl路径: $Path" -ForegroundColor Green >> >> # 验证路径下是否有curl可执行文件 >> $exeName = if ((Get-Platform) -eq "Windows") { "curl.exe" } else { "curl" } >> $curlExe = Join-Path $Path $exeName >> if (-not (Test-Path $curlExe)) { >> try { >> Write-Warning "路径 $Path 下找不到 $exeName,尝试自动安装..." >> $script:Config.CurlPath = Install-Curl >> $script:CurlPath = $script:Config.CurlPath >> $script:Config | ConvertTo-Json | Set-Content $script:ConfigPath -Force >> Write-Host "已自动安装curl到: $script:CurlPath" -ForegroundColor Green >> >> # 再次验证安装结果 >> $curlExe = Join-Path $script:CurlPath $exeName >> if (-not (Test-Path $curlExe)) { >> throw "自动安装后仍未找到curl可执行文件" >> } >> } catch { >> throw "自动安装失败: $_" >> } >> } >> } >> >> function Get-CurlVersion { >> Ensure-ModuleInitialized >> $exe = if ((Get-Platform) -eq "Windows") { "curl.exe" } else { "curl" } >> $curlExe = Join-Path $script:CurlPath $exe >> >> # 检查可执行文件是否存在 >> if (-not (Test-Path $curlExe)) { >> throw "在路径 $script:CurlPath 下找不到 $exe,请使用Set-CurlPath设置正确的路径或重新初始化模块" >> } >> >> & $curlExe --version | Select-Object -First 1 >> } >> >> function Invoke-SecureDownload { >> param( >> [Parameter(Mandatory=$true)] >> [string]$Url, >> >> [Parameter(Mandatory=$true)] >> [string]$OutputPath, >> >> [string]$ExpectedHash, >> [string]$HashAlgorithm = "SHA256" >> ) >> >> # 添加重试机制 >> $maxRetries = 3 >> $retryCount = 0 >> $success = $false >> >> do { >> try { >> Write-Verbose "下载文件: $Url (尝试 #$($retryCount + 1))" >> $ProgressPreference = 'SilentlyContinue' >> >> # 创建输出目录(如果不存在) >> $outputDir = [System.IO.Path]::GetDirectoryName($OutputPath) >> if (-not [string]::IsNullOrWhiteSpace($outputDir) -and -not (Test-Path $outputDir)) { >> New-Item -ItemType Directory -Path $outputDir -Force | Out-Null >> } >> >> # 使用更可靠的下载方法 >> if ($PSVersionTable.PSEdition -eq "Core" -or $PSVersionTable.PSVersion.Major -ge 6) { >> # 使用新的Invoke-WebRequest >> $params = @{ >> Uri = $Url >> OutFile = $OutputPath >> SkipCertificateCheck = $true >> ErrorAction = 'Stop' >> } >> Invoke-WebRequest @params >> } else { >> # 兼容旧版PowerShell >> $webClient = New-Object System.Net.WebClient >> $webClient.DownloadFile($Url, $OutputPath) >> } >> >> # 验证文件是否成功下载 >> if (-not (Test-Path $OutputPath)) { >> throw "文件下载后未找到: $OutputPath" >> } >> >> # 验证哈希(如果提供) >> if (-not [string]::IsNullOrWhiteSpace($ExpectedHash)) { >> $actualHash = (Get-FileHash -Path $OutputPath -Algorithm $HashAlgorithm).Hash >> if ($actualHash -ne $ExpectedHash) { >> Remove-Item -Path $OutputPath -Force >> throw "文件哈希不匹配! 期望: $ExpectedHash, 实际: $actualHash" >> } >> } >> >> $success = $true >> return $OutputPath >> } >> catch { >> $retryCount++ >> if ($retryCount -ge $maxRetries) { >> # 清理部分下载的文件 >> if (Test-Path $OutputPath) { >> Remove-Item -Path $OutputPath -Force -ErrorAction SilentlyContinue >> } >> throw "下载失败: $($_.Exception.Message)" >> } >> >> # 随机延迟后重试 >> $retryDelay = Get-Random -Minimum 1 -Maximum 5 >> Write-Warning "下载失败,$retryDelay 秒后重试: $($_.Exception.Message)" >> Start-Sleep -Seconds $retryDelay >> } >> } while (-not $success) >> } >> >> # ========== 辅助函数 ========== >> function Ensure-ModuleInitialized { >> if (-not $script:ModuleInitialized) { >> if (-not (Initialize-Module)) { >> throw "模块未正确初始化" >> } >> } >> } >> >> # ========== 模块初始化 ========== >> # 尝试初始化但不强制 >> try { >> Initialize-Module | Out-Null >> Write-Verbose "CurlTools 模块初始化成功" >> } catch { >> Write-Warning "模块初始化错误: $_" >> } >> >> # ========== 函数导出 ========== >> # 导出公共函数 >> Export-ModuleMember -Function Get-CurlPath, Set-CurlPath, Get-CurlVersion, Invoke-SecureDownload >> Export-ModuleMember : 只能从模块内调用 Export-ModuleMember cmdlet。 所在位置 行:328 字符: 1 + Export-ModuleMember -Function Get-CurlPath, Set-CurlPath, Get-CurlVer ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (:) [Export-ModuleMember], InvalidOperationException + FullyQualifiedErrorId : Modules_CanOnlyExecuteExportModuleMemberInsideAModule,Microsoft.PowerShell.Commands.Expo rtModuleMemberCommand PS C:\Users\Administrator> # Install-CurlTools.ps1 >> >> # 创建模块目录 >> $moduleDir = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules\CurlTools" >> New-Item -ItemType Directory -Path $moduleDir -Force | Out-Null >> >> # 保存模块代码 - 使用here-string避免路径问题 >> $moduleCode = @' >> # 在此处粘贴上面修复后的完整模块代码 >> '@ >> >> Set-Content -Path "$moduleDir\CurlTools.psm1" -Value $moduleCode -Force >> >> # 创建模块清单 >> $manifest = @" >> @{ >> ModuleVersion = '2.0.0' >> RootModule = 'CurlTools.psm1' >> FunctionsToExport = @( >> 'Get-CurlPath', >> 'Set-CurlPath', >> 'Get-CurlVersion', >> 'Invoke-SecureDownload' >> ) >> CompatiblePSEditions = @('Desktop', 'Core') >> GUID = 'c0d1b1e1-1a2b-4c3d-8e4f-9a0b1c2d3e4f' >> Author = 'Your Name' >> Description = 'Powerful curl tools for PowerShell' >> } >> "@ >> >> Set-Content -Path "$moduleDir\CurlTools.psd1" -Value $manifest -Force >> >> # 重新加载模块 >> Remove-Module CurlTools -ErrorAction SilentlyContinue >> Import-Module $moduleDir -Force -Verbose >> >> # 测试模块 >> if (Get-Module CurlTools) { >> Write-Host "CurlTools 模块安装成功!" -ForegroundColor Green >> >> # 测试基本功能 >> try { >> $curlPath = Get-CurlPath >> Write-Host "Curl路径: $curlPath" >> >> # 测试设置新路径 >> $newPath = Join-Path $env:TEMP "CurlTestPath" >> Set-CurlPath -Path $newPath >> >> $curlPath = Get-CurlPath >> Write-Host "新Curl路径: $curlPath" >> >> $version = Get-CurlVersion >> Write-Host "Curl版本: $version" >> >> # 测试下载功能 >> $testUrl = "https://raw.githubusercontent.com/PowerShell/PowerShell/master/README.md" >> $outputPath = Join-Path $env:TEMP "PowerShell_README.md" >> Invoke-SecureDownload -Url $testUrl -OutputPath $outputPath >> Write-Host "测试下载成功: $outputPath" -ForegroundColor Green >> } catch { >> Write-Warning "基本功能测试失败: $_" >> } >> } else { >> Write-Error "模块安装失败,请检查。" >> } >> 详细信息: 正在从路径“C:\Users\Administrator\Documents\WindowsPowerShell\Modules\CurlTools\CurlTools.psd1”加载模块。 详细信息: 正在从路径“C:\Users\Administrator\Documents\WindowsPowerShell\Modules\CurlTools\CurlTools.psm1”加载模块。 CurlTools 模块安装成功! Curl路径: E:\ai_temp\CurlTestPath 已设置curl路径: E:\ai_temp\CurlTestPath 警告: 路径 E:\ai_temp\CurlTestPath 下找不到 curl.exe,尝试自动安装... 警告: 下载失败,4 秒后重试: 使用“2”个参数调用“DownloadFile”时发生异常:“远程服务器返回错误: (404) 未找到。” 警告: 下载失败,4 秒后重试: 使用“2”个参数调用“DownloadFile”时发生异常:“远程服务器返回错误: (404) 未找到。” 警告: 基本功能测试失败: 自动安装失败: 无法自动安装curl: 下载失败: 使用“2”个参数调用“DownloadFile”时发生异常:“远程服务器返回错误: (404) 未找到。” PS C:\Users\Administrator> # CurlTools.psm1 - 结构化加载 >> $moduleRoot = $PSScriptRoot >> >> # 导入私有函数 >> Get-ChildItem -Path "$moduleRoot/Private/*.ps1" | ForEach-Object { >> . $_.FullName >> } >> >> # 导入公共函数 >> $publicFunctions = Get-ChildItem -Path "$moduleRoot/Public/*.ps1" >> foreach ($file in $publicFunctions) { >> . $file.FullName >> } >> >> # 导出公共函数 >> Export-ModuleMember -Function ($publicFunctions.BaseName) >> >> # 初始化模块 >> Initialize-Module >> Get-ChildItem : 找不到路径“C:\Private”,因为该路径不存在。 所在位置 行:5 字符: 1 + Get-ChildItem -Path "$moduleRoot/Private/*.ps1" | ForEach-Object { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Private:String) [Get-ChildItem], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand Get-ChildItem : 找不到路径“C:\Public”,因为该路径不存在。 所在位置 行:10 字符: 20 + $publicFunctions = Get-ChildItem -Path "$moduleRoot/Public/*.ps1" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Public:String) [Get-ChildItem], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand Export-ModuleMember : 只能从模块内调用 Export-ModuleMember cmdlet。 所在位置 行:16 字符: 1 + Export-ModuleMember -Function ($publicFunctions.BaseName) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (:) [Export-ModuleMember], InvalidOperationException + FullyQualifiedErrorId : Modules_CanOnlyExecuteExportModuleMemberInsideAModule,Microsoft.PowerShell.Commands.Expo rtModuleMemberCommand True PS C:\Users\Administrator> # CurlTools.psm1 - 结构化加载 >> $moduleRoot = $PSScriptRoot >> >> # 导入私有函数 >> Get-ChildItem -Path "$moduleRoot/Private/*.ps1" | ForEach-Object { >> . $_.FullName >> } >> >> # 导入公共函数 >> $publicFunctions = Get-ChildItem -Path "$moduleRoot/Public/*.ps1" >> foreach ($file in $publicFunctions) { >> . $file.FullName >> } >> >> # 导出公共函数 >> Export-ModuleMember -Function ($publicFunctions.BaseName) >> >> # 初始化模块 >> Initialize-Module >> Get-ChildItem : 找不到路径“C:\Private”,因为该路径不存在。 所在位置 行:5 字符: 1 + Get-ChildItem -Path "$moduleRoot/Private/*.ps1" | ForEach-Object { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Private:String) [Get-ChildItem], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand Get-ChildItem : 找不到路径“C:\Public”,因为该路径不存在。 所在位置 行:10 字符: 20 + $publicFunctions = Get-ChildItem -Path "$moduleRoot/Public/*.ps1" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Public:String) [Get-ChildItem], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand Export-ModuleMember : 只能从模块内调用 Export-ModuleMember cmdlet。 所在位置 行:16 字符: 1 + Export-ModuleMember -Function ($publicFunctions.BaseName) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (:) [Export-ModuleMember], InvalidOperationException + FullyQualifiedErrorId : Modules_CanOnlyExecuteExportModuleMemberInsideAModule,Microsoft.PowerShell.Commands.Expo rtModuleMemberCommand True PS C:\Users\Administrator>
最新发布
08-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值