Last active
February 25, 2024 19:54
-
-
Save LiuQixuan/7ac31b8f14b565b8a638fea2f9f79fe2 to your computer and use it in GitHub Desktop.
使用软链接的方式由已经安装的(国际服/国服)游戏客户端创建一个国服/国际服客户端.(Use sybolic link copy existing game folder to another HoYoverse service client.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #先读我 | |
| #如果有官方启动器则只需要修改$GamePath,$CopyGamePath,$ConfigrationPath,$UpgradePackagePath,$isInternationVersion五项,其他不用动, 脚本启动后不要乱按键盘一定要仔细阅读每一条提示切勿无脑下一步, 否则可能导致升级失败需要重新下载安装整个游戏 | |
| #$GamePath 为 游戏完整路径(非启动器路径) | |
| #$CopyGamePath 为 游戏 转换目标目录 | |
| #$ConfigrationPath 为 游戏 转换配置文件 | |
| #$UpgradePackagePath 为 游戏 转换资源包 | |
| #$isInternationVersion 为 是否是国际服希望创建官服游戏目录,如果是官服希望创建国际服游戏目录就为$false | |
| param( | |
| $GamePath = "G:\Games\Genshin Impact\Genshin Impact game", | |
| $CopyGamePath = "G:\Games\Genshin Impact CN\Genshin Impact game", | |
| $ConfigrationPath = "G:\Setup\GenshinImpact\script\createCNCopy\config.json", | |
| $UpgradePackagePath = "H:\Other\4.4资源替换包.zip", | |
| $isInternationVersion = $true | |
| ) | |
| $gameName = $isInternationVersion ?"GenshinImpact_Data":"YuanShen_Data" | |
| $CopyGameName = !$isInternationVersion ?"GenshinImpact_Data":"YuanShen_Data" | |
| $github = "https://gist.github.com/LiuQixuan/7ac31b8f14b565b8a638fea2f9f79fe2" | |
| $host.ui.RawUI.WindowTitle = "Create a copy for GenshinImpact" | |
| Write-Host '确保配置文件、已安装游戏版本、资源配置包三者版本一致.' | |
| Write-Host "遇到错误前往项目地址反馈:$github" | |
| $currentVersion = '' | |
| # #前置脚本 | |
| # #判断游戏版本 | |
| $lines = Get-Content -Path(Join-Path -Path $GamePath -ChildPath 'config.ini') | |
| for($i = 0;$i -lt $lines.Length;$i++){ | |
| if($lines[$i] -match 'game_version=(?<currentVersion>\d.\d.\d)'){ | |
| $currentVersion = $Matches.currentVersion | |
| break | |
| } | |
| } | |
| Write-Host "当前游戏版本: $currentVersion." | |
| # 判断配置文件版本 | |
| $config = Get-Content -Path $ConfigrationPath -Raw | ConvertFrom-Json | |
| if($config.GameVersion -eq $currentVersion){ | |
| Write-Host "配置文件与游戏版本匹配" | |
| }else { | |
| Write-Host "配置文件与游戏版本不匹配,按任意键退出." | |
| Protect-Exit -keyValue '.' | |
| } | |
| $keyText = $isInternationVersion ? "YuanShen":"GenshinImpact" | |
| $breakFlag = 2 | |
| # 判断资源包版本 | |
| $zipHandle = [System.IO.Compression.ZipFile]::OpenRead($UpgradePackagePath) | |
| foreach($zipEntry in $zipHandle.Entries){ | |
| # Write-Host $zipEntry.FullName,$zipEntry.ExternalAttributes//debug | |
| if($zipEntry.FullName.EndsWith("ini")){ | |
| $destinationPath = Join-Path -Path $UpgradePackagePath -ChildPath '../deletefiles.ini' | |
| # Write-Host $destinationPath | |
| [System.IO.Compression.ZipFileExtensions]::ExtractToFile($zipEntry,$destinationPath,1) | |
| $breakFlag-- | |
| } | |
| if($zipEntry.FullName.Contains($keyText)){ | |
| $zipEntry.FullName -match '^(?<keyText>.*/.*/)'+$keyText | |
| Write-Host "Matchers>keyText" $Matches.keyText | |
| $keyText = $Matches.keyText | |
| $breakFlag-- | |
| } | |
| if(!$breakFlag){break} | |
| } | |
| (Get-Content $destinationPath -TotalCount 4)[-1] -match '(?<packageVersion>\d.\d.\d)' | |
| Remove-Item -Path $destinationPath | |
| if ($Matches.packageVersion -eq $currentVersion) { | |
| Write-Host "资源包版本与游戏版本匹配" | |
| }else { | |
| Write-Host "资源包版本与游戏版本不匹配,按任意键退出." | |
| Protect-Exit -keyValue '.' | |
| } | |
| function Get-DataPath([string]$Dir, [string]$Path) { | |
| return $Dir.startsWith('data', $true, $null)?($Dir.replace('data', $Path, $true, $null)):$Dir | |
| } | |
| function Resolve-Item([string]$Name,$Item) { | |
| $tmp = @() | |
| if ($name -match "\*\[(?<itemType>.{1}):(?<keyword>\w+)=(?<listName>\w+)\]") { | |
| # Write-Host "resolve-item-list" $config.excludeList.($Matches.listName) | |
| if($Matches.keyword -eq 'without'){ | |
| [array]$itemList = Get-ChildItem -Path (Join-Path $GamePath -ChildPath (Get-DataPath -Dir $Item.dir -Path $gameName)) | |
| switch ($Matches.itemType) { | |
| '.' { $tmp = $itemList} | |
| 'a' { $tmp = $itemList.Where({ $_.Attributes.ToString().Contains("Archive")})} | |
| 'd' { $tmp = $itemList.Where({ $_.Attributes.ToString().Contains("Directory")})} | |
| Default {} | |
| } | |
| # Write-Host "resolve-item: " $itemList.foreach({$_.name}) | |
| $tmp = $tmp.foreach({ $_.name }).Where({ $config.excludeList.($Matches.listName).indexOf($_) -eq -1 }) | |
| } | |
| }else{ | |
| $tmp = @($name) | |
| } | |
| return $tmp | |
| } | |
| function Copy-Task($Item) { | |
| Write-Host "OK"$task.dir | |
| foreach($rawPathName in $Item.items){ | |
| Write-Host (Resolve-Item -Name $rawPathName.name -Item $Item) | |
| foreach ( $pathName in Resolve-Item -Name $rawPathName.name -Item $Item) { | |
| $p1 = (Join-Path -Path $GamePath -ChildPath (Get-DataPath -Dir $Item.dir -Path $gameName) -AdditionalChildPath $pathName) | |
| $p2 = (Join-Path -Path $CopyGamePath -ChildPath (Get-DataPath -Dir $Item.dir -Path $CopyGameName) -AdditionalChildPath $pathName) | |
| if (!(Test-Path -Path (Split-Path -Parent -Path $p2))) { New-Item -ItemType Directory -Path (Split-Path -Parent -Path $p2) -Force } | |
| Copy-Item -Path $p1 -Destination $p2 -Recurse | |
| } | |
| if($rawPathName.replace){ | |
| Write-Host "开始修改"$rawPathName.name | |
| Out-File -FilePath $p2 -InputObject( $isInternationVersion ?(Get-Content -Path $p2).replace($rawPathName.replace[0], $rawPathName.replace[1]):(Get-Content -Path $p2).replace($rawPathName.replace[1], $rawPathName.replace[0])) | |
| } | |
| } | |
| } | |
| function New-Link($Item) { | |
| foreach($rawPathName in $Item.items){ | |
| foreach($pathName in (Resolve-Item -Name $rawPathName -Item $Item)){ | |
| Write-Host "new-link: "$pathName | |
| $p1 = (Join-Path -Path $GamePath -ChildPath (Get-DataPath -Dir $Item.dir -Path $gameName) -AdditionalChildPath $pathName) | |
| $p2 = (Join-Path -Path $CopyGamePath -ChildPath (Get-DataPath -Dir $Item.dir -Path $CopyGameName) -AdditionalChildPath $pathName) | |
| if (!(Test-Path -Path (Split-Path -Parent -Path $p2))) { New-Item -ItemType Directory -Path (Split-Path -Parent -Path $p2)} | |
| New-Item -ItemType SymbolicLink -Path $p2 -Target $p1 | |
| } | |
| } | |
| } | |
| #主脚本 | |
| foreach($task in $config.copyTasks){ | |
| Copy-Task -Item $task | |
| } | |
| Write-Host "复制完成" | |
| # #创建软连接 | |
| foreach($task in $config.softlinkTasks){ | |
| New-Link -Item $task | |
| } | |
| # New-Link -Item $config.softlinkTasks[3] | |
| Read-Host -Prompt "基本框架搭建完成,按任意键继续解压文件" | |
| #释放资源包 | |
| $indexOfZipEntry = 1 | |
| $totalOfZipEntry = $zipHandle.Entries.Count | |
| Clear-Host | |
| $progressGap = [Math]::Max($totalOfZipEntry/100,[Math]::Round(1/$totalOfZipEntry*100,2)) | |
| $progressStage = $progressGap | |
| foreach($zipEntry in $zipHandle.Entries){ | |
| # Write-Host $zipEntry.FullName,$zipEntry.ExternalAttributes//debug | |
| # write-host $indexOfZipEntry $progressStage $($indexOfZipEntry -ge $progressStage) | |
| if($indexOfZipEntry -ge $progressStage){ | |
| $rc = [Math]::Round($indexOfZipEntry/$totalOfZipEntry*100) | |
| # Write-Host "PercentComplete:"$rc,$progressStage | |
| Write-Progress -Activity "解压进度:" -Status "已解压$rc%" -PercentComplete $rc -CurrentOperation "正在解压:$($zipEntry.FullName)" | |
| $progressStage+=$progressGap | |
| } | |
| $indexOfZipEntry++ | |
| if(!($zipEntry.FullName.EndsWith("/")) -and $zipEntry.FullName.Contains($keyText)){ | |
| # Write-Host "fullname.endwith: OK." $zipEntry.FullName | |
| # Write-Host "fileName: " $zipEntry.FullName.Split($keyText).Count | |
| $extractPath = Join-Path $CopyGamePath -ChildPath $zipEntry.FullName.Split($keyText)[1] | |
| # Write-Host "fullname.Contains: OK." $extractPath | |
| try { | |
| [System.IO.Compression.ZipFileExtensions]::ExtractToFile($zipEntry,$extractPath,1) | |
| } | |
| catch [System.IO.DirectoryNotFoundException]{ | |
| if (!(Test-Path -Path (Split-Path -Parent -Path $extractPath))) { New-Item -ItemType Directory -Path (Split-Path -Parent -Path $extractPath)} | |
| [System.IO.Compression.ZipFileExtensions]::ExtractToFile($zipEntry,$extractPath,1) | |
| } | |
| } | |
| } | |
| Write-Progress -Activity "解压进度:" -Status "已解压100%" -PercentComplete 100 -CurrentOperation "解压完成" -Completed | |
| $zipHandle.Dispose() | |
| Read-Host -Prompt "升级完成,按任意键可以关闭窗口.`n如有错误请到项目留言中寻求帮助.`n项目地址:$github" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment