Skip to content

Instantly share code, notes, and snippets.

@hoang-himself
Last active August 19, 2023 17:12
Show Gist options
  • Save hoang-himself/185642cedf1103c65e0e7c662fba3112 to your computer and use it in GitHub Desktop.
Save hoang-himself/185642cedf1103c65e0e7c662fba3112 to your computer and use it in GitHub Desktop.
Local runcoms

Local runcoms

These modules are meant to be used with my dotfiles. They live in $Profile\profile.d or ~/.config/zsh/.zshrc.d of their respective shell.

function Update-TF2Mod {
[CmdletBinding(SupportsShouldProcess)]
param(
[string]$Path = 'D:\SteamLibrary\steamapps\common\Team Fortress 2\tf'
)
$ErrorActionPreference = 'Stop'
if ($PSCmdlet.ShouldProcess('Create temporary directory')) {
mktmp
}
if ($PSCmdlet.ShouldProcess('Generate jobs to download mods')) {
$scriptBlockList = @()
$scriptBlockList += {
$version = (Invoke-RestMethod -Uri 'https://api.github.com/repos/Vexcenot/-Middle-Mann/releases/latest').tag_name
Invoke-WebRequest -Uri "https://github.com/Vexcenot/-Middle-Mann/releases/latest/download/middle-mann-${version}.rar" `
-OutFile 'middle-mann.rar'
&"$env:ProgramFiles\7-zip\7z.exe" x 'middle-mann.rar'
Get-ChildItem -Path '!middle-mann-*' | Copy-Item -Destination '_TF2\custom\middle-mann' -Recurse -Force
if ($PSCmdlet.ShouldProcess('Remove old middle-mann folder')) {
Remove-Item -Path "$using:Path\custom\middle-mann" -Recurse -Force
}
}
}
if ($PSCmdlet.ShouldProcess('Execute jobs to download mods')) {
$scriptBlockList | ForEach-Object { Start-Job -ScriptBlock $_ }
while (Get-Job -State 'Running') {
Start-Sleep -Seconds 1
}
}
if ($PSCmdlet.ShouldProcess("Copy mods from temporary directory to $Path")) {
Copy-Item -Path '_TF2\*' -Destination "$Path" -Recurse -Force
}
if ($PSCmdlet.ShouldProcess('Remove temporary directory')) {
rmtmp
}
}
function Update-WoTMod {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '')]
[CmdletBinding(SupportsShouldProcess)]
param(
[string]$Path = 'D:\Games\World_of_Tanks_ASIA',
[string]$Version = (Select-Xml -Path "$Path\version.xml" -XPath '/version.xml/version' `
| ForEach-Object { $_.Node }).InnerXml.Split(' ')[1].Substring(2)
)
$ErrorActionPreference = 'Stop'
if ($PSCmdlet.ShouldProcess('Create temporary directory')) {
mktmp
}
if ($PSCmdlet.ShouldProcess('Generate jobs to download mods')) {
$scriptBlockList = @()
$scriptBlockList += {
Start-Process -FilePath 'https://wotinspector.com/baactivate'
Start-Process -FilePath 'https://wgmods.net/46/'
}
$scriptBlockList += {
Invoke-WebRequest -Uri 'https://down.wotspeak.org/zj_mod/TargetDirection.rar' `
-OutFile 'TargetDirection.rar'
&"$env:ProgramFiles\7-zip\7z.exe" x '-oTargetDirection' 'TargetDirection.rar'
Copy-Item -Path 'TargetDirection' -Exclude @('*.url', '*.txt') `
-Destination "_WoT\res_mods\$using:Version" -Recurse -Force
}
$scriptBlockList += {
Invoke-WebRequest -Uri 'https://down.wotspeak.org/mods_no_work/525-mod_atac.zip' `
-OutFile 'ATAC.zip'
Expand-Archive -Path 'ATAC.zip' -DestinationPath 'ATAC'
$variant = Get-ChildItem -Path 'ATAC' | Select-String -Pattern '150'
Copy-Item -Path "$variant\*" -Exclude @('*.url', '*.txt') `
-Destination "_WoT\res_mods\$using:Version" -Recurse -Force
}
# 'lesta' for normal, 'wg' for EU/NA/ASIA
@(
'WotspeakDestructionsBeholder',
'WotspeakRedBall'
) | ForEach-Object {
$scriptBlockList += [scriptblock]::Create(@"
Invoke-WebRequest -Uri "https://down.wotspeak.org/wotspeakmods/wg/$_.zip" ``
-OutFile "$_.zip"
Expand-Archive -Path "$_.zip" -DestinationPath "$_"
Copy-Item -Path "$_\mods" -Exclude @('*.url', '*.txt') ``
-Destination '_WoT' -Recurse -Force
"@)
}
}
if ($PSCmdlet.ShouldProcess('Execute jobs to download mods')) {
$scriptBlockList | ForEach-Object { Start-Job -ScriptBlock $_ }
while (Get-Job -State 'Running') {
Start-Sleep -Seconds 1
}
}
if ($PSCmdlet.ShouldProcess("Copy mods from temporary directory to $Path")) {
Copy-Item -Path '_WoT\*' -Destination "$Path" -Recurse -Force
}
if ($PSCmdlet.ShouldProcess('Remove temporary directory')) {
rmtmp
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment