Last active
February 28, 2016 16:19
-
-
Save claudenobs/3e279972233ea934489a to your computer and use it in GitHub Desktop.
Moves all GoG shortcut folders into a GoG.com folder. Put all primary game start shortcuts into GoG folder.
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
# 1. Save this script by right-click on Raw button and choose "Save link as..." | |
# 2. Start > Run... & type : powershell | |
# 3. To Run script type : Start-Process powershell -Verb RunAs -ArgumentList "-ExecutionPolicy Unrestricted -NoExit -file `"$Home\Downloads\GogShortcutSanitizer.ps1`""; exit | |
# 4. Give permissioo in pop-up | |
param([switch]$debug = $false, [string]$defaultShortcutPath) | |
function createDirectory($dir) { | |
if (-not (Test-Path $dir)) { | |
mkdir $dir | |
Write-Host "Created directory: $dir" | |
} | |
} | |
# Escapes [ & ] so that the path can be used without -LiteralPath | |
function escapeSquareBrackets([string]$path) { | |
$path -replace '\[','``[' -replace '\]','``]' | |
} | |
if (-not $defaultShortcutPath) { $defaultShortcutPath = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs" } | |
$relocationTarget = "$startmenuRoot\GoG.com" | |
$gameLinkTarget = "$Home\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GoG" | |
$regexStrict = '(^| |\[|\()(Documents|Config\w*|Editor|(Game)?Server|Language|Manual|(Developer|Safe|Software|TnL)( Mode)?|Multiplayer|Readme|Selector|Setup|Settings|Test|Tools?|Uninstall|Website)(.lnk|.url|$| |\)|\])' | |
$directories = get-childitem $defaultShortcutPath -Filter "*[GoG.com]" -Directory | |
if ($debug) { | |
Write-Host "Starting in debug mode. No modifications will be made!" | |
} else { | |
createDirectory $relocationTarget | |
createDirectory $gameLinkTarget | |
} | |
$i = 0 | |
foreach ($dir in $directories) { | |
foreach ($link in get-childitem "$(escapeSquareBrackets $dir.FullName)\*") { | |
if ($link.Name -match $regexStrict) { | |
if ($debug) { Write-Host $link.Name -ForegroundColor "red" } | |
} else { | |
if ($debug) { Write-Host $link.Name -ForegroundColor "green" } | |
else { $link | Copy-Item -Destination $gameLinkTarget -Force } | |
$i++ | |
} | |
} | |
if (-not $debug) { $dir | Move-Item -Destination $relocationTarget -Force } | |
} | |
Write-Host "All done!" | |
Write-Host "$($directories.count) new GoG games processed." | |
Write-Host "$i new GoG game links processed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment