Skip to content

Instantly share code, notes, and snippets.

@artemsmikh
Last active June 5, 2022 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artemsmikh/9f949db3b7a89394299d8b3f71e11fd0 to your computer and use it in GitHub Desktop.
Save artemsmikh/9f949db3b7a89394299d8b3f71e11fd0 to your computer and use it in GitHub Desktop.
Move screenshots into a Steam game folder
# Modified version of @piotr-kowalski's script
# Now also makes thumbnails for screenshots
# https://gaming.stackexchange.com/a/238288/212957
#
# Note:
# This script finds last logged-in user and last played game so keep it in mind before running.
#
# Usage:
# 1) Save this as run.bat:
# @powershell -NoProfile -ExecutionPolicy Bypass -File main.ps1
# 2) Download this file
# 3) Put both files in one directory with screenshots you want to upload and launch run.bat.
Function Get-VDFContent ([string] $path)
{
$fileContent = Get-Content $path
$obj = @{}
$stack = New-Object System.Collections.Stack
$group = [regex] '^\s*"([^"]+)"\s*$'
$keyVal = [regex] '^\s*"([^"]+)"\s*"([^"]+)"\s*$'
$bracket = $False
ForEach ($line in $fileContent)
{
If ($bracket)
{
If ($line -Like "*{*")
{
$bracket = $False
}
}
ElseIf (($match = $group.Match($line)) -And $match.Success)
{
$obj.($match.Groups[1].Value) = @{}
$stack.Push($obj)
$obj = $obj.($match.Groups[1].Value)
$bracket = $True
}
ElseIf (($match = $keyVal.Match($line)) -And $match.Success)
{
$obj.($match.Groups[1].Value) = $match.Groups[2].Value
}
ElseIf ($line -Like "*}*")
{
$obj = $stack.Pop()
}
Else
{
Throw
}
}
Return $obj
}
Function Create-ScreenshotPath([string] $screenshots, [string] $date, [string] $i)
{
Return Join-Path $screenshots ($date + ($i.PadLeft(5, "0")) + ".jpg")
}
Function Save-Thumbnail([string] $imagePath, [string] $pathToSave)
{
$wia = New-Object -com wia.imagefile
$wia.LoadFile($imagePath)
$wip = New-Object -ComObject wia.imageprocess
$scale = $wip.FilterInfos.Item("Scale").FilterId
$wip.Filters.Add($scale)
$wip.Filters[1].Properties("MaximumWidth") = 200
$wip.Filters[1].Properties("MaximumHeight") = 150
#aspect ratio should be set as false if you want the pics in exact size
$wip.Filters[1].Properties("PreserveAspectRatio") = $true
$wip.Apply($wia)
$newimg = $wip.Apply($wia)
$newimg.SaveFile($pathToSave)
}
$steamPath = ""
If (Test-Path "HKCU:\Software\Valve\Steam")
{
$steamPath = (Get-ItemProperty "HKCU:\Software\Valve\Steam").SteamPath
}
If (-Not $steamPath)
{
$steamPath = Read-Host 'Enter Steam install folder path (example: "c:/program files (x86)/steam")'
}
$loginUsers = Join-Path $steamPath "config/loginusers.vdf"
$users = (Get-VDFContent $loginUsers).users
$lastUser = ($users.GetEnumerator() | Sort-Object { [int]$_.Value.Timestamp } -Descending)[0].Name
$lastUserShort = $lastUser - 0x110000100000000
$userPath = Join-Path $steamPath ("userdata/" + $lastUserShort)
$localConfig = Join-Path $userPath "/config/localconfig.vdf"
$apps = (Get-VDFContent $localConfig).UserLocalConfigStore.Software.Valve.Steam.apps
$lastPlayed = ($apps.GetEnumerator() | Sort-Object { [int]$_.Value.LastPlayed } -Descending)[0].Name
$screenshots = Join-Path $userPath ("760/remote/" + $lastPlayed + "/screenshots")
$thumbnails = Join-Path $screenshots "thumbnails"
New-Item -Force -ItemType directory -Path $thumbnails >$null
$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
$date = Get-Date -Format yyyy-MM-dd_
$i = 1
While (Test-Path (Create-ScreenshotPath $screenshots $date $i)) { $i++ }
$filesToMove = Get-ChildItem $scriptPath -Filter "*.jpg" | % { $_.FullName }
ForEach ($file in $filesToMove)
{
$thumbnailPath = (Create-ScreenshotPath $thumbnails $date $i)
(Save-Thumbnail $file $thumbnailPath)
Move-Item $file (Create-ScreenshotPath $screenshots $date $i)
$i++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment