Last active
September 7, 2023 02:04
-
-
Save LiuQixuan/2b829d4ebe0039efa1ed7135895c0731 to your computer and use it in GitHub Desktop.
[GenshinImpact][YuanShen][原神]deleteOldFiles
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
$deleteFilesPath = ".\deletefiles.txt" | |
$GamePath = "E:\Games\Genshin Impact\Genshin Impact game" | |
$github = "https://gist.github.com/LiuQixuan/2b829d4ebe0039efa1ed7135895c0731" | |
function Protect-Exit([string]$keyValue='.',[string]$addtext=''){ | |
if($addtext -ne ''){ | |
$addtext = "`t" + $addtext | |
} | |
$keyText = '' | |
if($keyValue -eq '.'){ | |
$keyText = "任意键" | |
}else{ | |
$keyText = $keyValue | |
} | |
$isContinue = Read-Host "按$keyText`退出$addtext" | |
if($isContinue -match "[$keyValue]" ){ | |
exit | |
} | |
} | |
Class Logger{ | |
$time = "" | |
$logPath = "" | |
Logger(){ | |
$this.time = Get-Date -UFormat "%Y_%m_%d_%H_%M" | |
$this.logPath = Join-Path -Path $PSScriptRoot -ChildPath "deletefiles.Debug.$($this.time).log" | |
} | |
Logger([string]$Path){ | |
$this.time = Get-Date -UFormat "%Y_%m_%d_%H_%M" | |
$this.logPath = Join-Path -Path (Get-ItemProperty -Path $Path).Root -ChildPath "deletefiles.$($this.time).log" | |
} | |
[void]refreshTime(){ | |
$this.time = Get-Date -UFormat "%Y_%m_%d_%H_%M_%S" | |
} | |
[void]print([string]$Message,[string]$type){ | |
Write-Host -Object "[$($this.time)]-[$($type.ToUpper())]-$Message" | |
} | |
[void]print([string]$Message){ | |
$this.print($Message,'Error') | |
} | |
[void]log([string]$Message,[string]$type){ | |
Write-Host -Object "[$($this.time)]-[$($type.ToUpper())]-$Message">>$($this.logPath) | |
} | |
[void]log([string]$Message){ | |
$this.log($Message,'Error') | |
} | |
[void]write([string]$Message,[string]$type){ | |
"[$($this.time)]-[$($type.ToUpper())]-$Message">>$($this.logPath) | |
} | |
[void]write([string]$Message){ | |
$this.write($Message,'Error') | |
} | |
} | |
[Logger]$logger = [Logger]::new() | |
if(Test-Path -Path $deleteFilesPath){ | |
$logger.print('[Action]:检测到升级包中的deletefiles.txt文件,准备删除旧文件','info') | |
$delList = Get-Content $deleteFilesPath | |
foreach($item in $delList){ | |
if(Test-Path -Path (Join-Path -Path $GamePath -ChildPath $item)){ | |
Remove-Item -Path (Join-Path -Path $GamePath -ChildPath $item) | |
}else{ | |
$logger.write("[FileNotFound]:$item") | |
} | |
} | |
Write-Host "旧文件删除完成,现在可以关闭窗口.`n如有错误请把$($logger.logPath)`的内容发到项目留言中寻求帮助.`n项目地址:$github" | |
}else{ | |
$logger.log("[FileNotFound:deletefiles.txt]:deletefiles.txt 未找到,确认$deleteFilesPath 路径正确") | |
} | |
Protect-Exit -keyValue '.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
此脚本用于删除无用的历史文件,适用于使用脚本跨版本升级,虽然进入游戏下载完残缺文件后也能正常游戏,但由于未正确删除之前版本的无用文件导致游戏占用空间过大.
各版本游戏升级包中的deletefiles.txt文件将从即日起开始收集,发布地址日后更新.
使用方法:
Genshin Impact game
结尾)