# HuayuGIS 安装脚本(Windows x64) # # 用法(PowerShell 5.1 / 7 均可): # irm https://lanhc.com/lanhc/huayu-gis.ps1 | iex # # 可选参数。通过 irm | iex 执行时用环境变量传入,存盘后用开关传参: # $env:HUAYUGIS_BASE_URL = 'https://lanhc.com/lanhc' 下载根地址(默认官方) # $env:HUAYUGIS_INSTALL_DIR = 'C:\...' 自定义安装目录 # $env:HUAYUGIS_NO_LAUNCH = '1' 安装后不自动启动 # # 安装方式:下载 HuayuGIS 便携版 zip(含 rustgis.exe 与 rustgis-cli.exe), # 解压到 %LOCALAPPDATA%\Programs\HuayuGIS。全程不需要管理员权限,也不会提权。 # 可执行文件为未签名构建,Windows SmartScreen 可能提示,请选择“仍要运行”。 param( [string] $BaseUrl = $env:HUAYUGIS_BASE_URL, [string] $InstallDir = $env:HUAYUGIS_INSTALL_DIR, [switch] $NoLaunch ) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' if (-not $BaseUrl) { $BaseUrl = 'https://lanhc.com/lanhc' } $BaseUrl = $BaseUrl.TrimEnd('/') $DoNoLaunch = ($NoLaunch.IsPresent) -or ($env:HUAYUGIS_NO_LAUNCH -eq '1') $AppName = 'HuayuGIS' $Version = '0.5.27' $MachineArch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } $ArchName = if ($MachineArch -eq 'ARM64') { 'aarch64' } else { 'x86_64' } $ArchLabel = if ($ArchName -eq 'aarch64') { 'Windows ARM64' } else { 'Windows x64' } $Zip = "HuayuGIS-$Version-windows-$ArchName-portable.zip" $ShaFile = "HuayuGIS-0.5.27-windows-$ArchName.sha256" $Folder = "HuayuGIS-$Version-windows-$ArchName" if (-not $InstallDir) { $InstallDir = Join-Path $env:LOCALAPPDATA "Programs\$AppName" } if (-not $InstallDir) { Write-Error '无法确定安装目录,请通过 $env:HUAYUGIS_INSTALL_DIR 指定。' } function Write-Head($t) { Write-Host ''; Write-Host "== $t" -ForegroundColor Cyan } function Write-Step($t) { Write-Host " $t" } function Write-Ok($t) { Write-Host " [ok] $t" -ForegroundColor Green } function Write-Note($t) { Write-Host " [!] $t" -ForegroundColor Yellow } function Write-Bad($t) { Write-Host " [x] $t" -ForegroundColor Red } Write-Head "HuayuGIS 安装($ArchLabel,当前用户)" Write-Step "下载安装包 $BaseUrl/$Zip" $tmp = Join-Path $env:TEMP "huayugis-install-$([guid]::NewGuid().ToString('N'))" New-Item -ItemType Directory -Path $tmp | Out-Null try { $zipPath = Join-Path $tmp $Zip Invoke-WebRequest -Uri "$BaseUrl/$Zip" -OutFile $zipPath if (-not (Test-Path $zipPath) -or (Get-Item $zipPath).Length -lt 1000000) { Write-Bad "下载失败:$BaseUrl/$Zip" exit 1 } Write-Ok "已下载 $((Get-Item $zipPath).Length) 字节" try { $resp = Invoke-WebRequest -Uri "$BaseUrl/$ShaFile" -UseBasicParsing if ($resp.Content -is [byte[]]) { $shaText = [System.Text.Encoding]::UTF8.GetString($resp.Content) } else { $shaText = [string]$resp.Content } $expected = ($shaText -split '\s+')[0].ToLowerInvariant() $actual = (Get-FileHash $zipPath -Algorithm SHA256).Hash.ToLowerInvariant() if ($expected -and $expected -ne $actual) { Write-Bad "SHA256 校验失败:期望 $expected,实际 $actual" exit 1 } Write-Ok "SHA256 校验通过 ($actual)" } catch { Write-Note '未找到校验和文件,跳过 SHA256 校验。' } Write-Step "安装到 $InstallDir" $dest = Join-Path $InstallDir $Folder if (Test-Path $dest) { Remove-Item -LiteralPath $dest -Recurse -Force } New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null Expand-Archive -LiteralPath $zipPath -DestinationPath $InstallDir -Force $exe = Join-Path $dest 'rustgis.exe' $cli = Join-Path $dest 'rustgis-cli.exe' if (-not (Test-Path $exe)) { Write-Bad "解压后未找到 $exe" exit 1 } Write-Ok "已安装:$dest" $binDir = $dest $current = [Environment]::GetEnvironmentVariable('Path', 'User') if ($current -notlike "*$binDir*") { [Environment]::SetEnvironmentVariable('Path', "$current;$binDir", 'User') Write-Ok "已把 $binDir 加入用户 PATH(新终端生效)" } else { Write-Ok "PATH 已包含 $binDir" } function New-HuayuShortcut($ShortcutPath) { try { $shell = New-Object -ComObject WScript.Shell $lnk = $shell.CreateShortcut($ShortcutPath) $lnk.TargetPath = $exe $lnk.WorkingDirectory = $dest $lnk.IconLocation = $exe $lnk.Description = '华宇GIS:地图制图、空间分析与地理处理' $lnk.Save() return $true } catch { return $false } } $startMenu = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs' if ($startMenu -and (Test-Path $startMenu)) { $shortcut = Join-Path $startMenu "$AppName.lnk" if (New-HuayuShortcut $shortcut) { Write-Ok "开始菜单快捷方式:$shortcut" } else { Write-Note '开始菜单快捷方式创建失败(不影响使用)。' } } $desktopDir = [Environment]::GetFolderPath('Desktop') if ($desktopDir -and (Test-Path $desktopDir)) { $shortcut = Join-Path $desktopDir "$AppName.lnk" if (New-HuayuShortcut $shortcut) { Write-Ok "桌面快捷方式:$shortcut" } else { Write-Note '桌面快捷方式创建失败(不影响使用)。' } } Write-Ok "命令行工具:$cli(rustgis-cli)" if ($DoNoLaunch) { Write-Note '按参数跳过启动,稍后运行 rustgis 即可打开。' exit 0 } Write-Step '启动 HuayuGIS…' Start-Process -FilePath $exe -WorkingDirectory $dest Write-Ok 'HuayuGIS 已启动' } finally { Remove-Item -LiteralPath $tmp -Recurse -Force -ErrorAction SilentlyContinue }