mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-08 11:57:53 +08:00
92 lines
2.7 KiB
PowerShell
92 lines
2.7 KiB
PowerShell
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ģ<EFBFBD><C4A3>
|
|||
|
Import-Module -Name Microsoft.PowerShell.Archive
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>Ŀ¼·<C2BC><C2B7>
|
|||
|
$directoryPath = ".\dist\BetterGI"
|
|||
|
$outputJsonPath = "E:\HuiTask\BetterGIBuild\UploadGit\bettergi-installation-data\hash.json"
|
|||
|
$destinationDir = "E:\HuiTask\BetterGIBuild\UploadGit\bettergi-installation-data\installation"
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
$absoluteDirectoryPath = (Resolve-Path -Path $directoryPath).Path
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼
|
|||
|
$excludedDirectories = @(
|
|||
|
".\dist\BetterGI\Script",
|
|||
|
".\dist\BetterGI\User"
|
|||
|
)
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
$excludedDirectories = $excludedDirectories | ForEach-Object { (Resolve-Path -Path $_).Path }
|
|||
|
|
|||
|
# <20><>ʼ<EFBFBD><CABC>һ<EFBFBD><D2BB><EFBFBD>յĹ<D5B5>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ϣֵ
|
|||
|
$fileHashes = @{}
|
|||
|
|
|||
|
# <20><>ȡĿ¼<C4BF>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼
|
|||
|
$files = Get-ChildItem -Path $directoryPath -Recurse -File
|
|||
|
|
|||
|
foreach ($file in $files) {
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD> .zip <20><><EFBFBD>ļ<EFBFBD>
|
|||
|
if ($file.Extension -eq ".zip") {
|
|||
|
continue
|
|||
|
}
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC>
|
|||
|
$skipFile = $false
|
|||
|
foreach ($excludedDir in $excludedDirectories) {
|
|||
|
if ($file.FullName.StartsWith($excludedDir)) {
|
|||
|
$skipFile = $true
|
|||
|
break
|
|||
|
}
|
|||
|
}
|
|||
|
if ($skipFile) {
|
|||
|
Write-Host "Skipping file in excluded directory: $($file.FullName)"
|
|||
|
continue
|
|||
|
}
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>Ĺ<EFBFBD>ϣֵ
|
|||
|
$hash = Get-FileHash -Path $file.FullName -Algorithm SHA256
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣֵ<CFA3>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>
|
|||
|
if ($null -eq $hash) {
|
|||
|
Write-Host "Failed to compute hash for file: $($file.FullName)"
|
|||
|
continue
|
|||
|
}
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
$relativePath = $file.FullName.Replace($absoluteDirectoryPath, "").TrimStart("\\")
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ϣֵ<CFA3><D6B5><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD>
|
|||
|
$fileHashes[$relativePath] = $hash.Hash
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
$zipFilePath = "$($file.FullName).zip"
|
|||
|
|
|||
|
# ѹ<><D1B9><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>滻ͬ<E6BBBB><CDAC>ѹ<EFBFBD><D1B9><EFBFBD>ļ<EFBFBD>
|
|||
|
Compress-Archive -Path $file.FullName -DestinationPath $zipFilePath -Force
|
|||
|
}
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3>ת<EFBFBD><D7AA>Ϊ JSON <20><>ʽ
|
|||
|
$jsonContent = $fileHashes | ConvertTo-Json -Depth 10
|
|||
|
|
|||
|
# ʹ<><CAB9> UTF-8 <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4> JSON <20>ļ<EFBFBD>
|
|||
|
[System.IO.File]::WriteAllText($outputJsonPath, $jsonContent, [System.Text.Encoding]::UTF8)
|
|||
|
|
|||
|
|
|||
|
|
|||
|
# <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> .zip <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼
|
|||
|
$zipFiles = Get-ChildItem -Path $absoluteDirectoryPath -Recurse -Filter *.zip
|
|||
|
|
|||
|
foreach ($file in $zipFiles) {
|
|||
|
# <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>·<EFBFBD><C2B7>
|
|||
|
$relativePath = $file.FullName.Substring($absoluteDirectoryPath.Length)
|
|||
|
$destinationPath = Join-Path $destinationDir $relativePath
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>Ŀ¼
|
|||
|
$destinationDirPath = Split-Path $destinationPath
|
|||
|
if (-not (Test-Path $destinationDirPath)) {
|
|||
|
New-Item -ItemType Directory -Path $destinationDirPath -Force
|
|||
|
}
|
|||
|
|
|||
|
# <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|||
|
Copy-Item -Path $file.FullName -Destination $destinationPath -Force
|
|||
|
}
|
|||
|
|
|||
|
Remove-Item -Path $absoluteDirectoryPath -Recurse -Force
|