Skip to content

Instantly share code, notes, and snippets.

@bburky
Created May 15, 2020 22:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bburky/5eb29b368bafd6e6a64d141cf0bc2bb8 to your computer and use it in GitHub Desktop.
Save bburky/5eb29b368bafd6e6a64d141cf0bc2bb8 to your computer and use it in GitHub Desktop.
Calculate Sizes of All Installed Games (Playnite Extension)

Calculate Sizes of All Installed Games

This extension calculates the sizes of the InstallDirectory of all installed games.

Emulated games may not be correctly supported. If only GameImagePath is set and not InstallDirectory, no size will be listed. If multiple games are in the same InstallDirectory, the total size of the directory will be listed for both games.

This script uses some pretty simple logic for calculating file sizes (the sum of the file size of each file, recursively). The file size may not be correctly calculated for a number of reasons (weird filesystem things, junction points, NTFS compressed files, etc.) Therefore, the reported size does NOT reflect "Size on disk", it's closer to Windows's "Size" calculation.

The report is saved as a game-sizes.csv file in your Playnite profile's ExtensionData folder. The extension automatically launches the file (probably with Excel) after completion.

File sizes are listed in the number of bytes. If you'd like more human readable numbers set a custom number format on the "Size" column in Excel:

[<1000000]0.00," KB";[<1000000000]0.00,," MB";0.00,,," GB"

The installation directory of the game is a hyperlink =HYPERLINK("C:\...") to allow clicking on the path in Excel.

If you attempt to re-run the extension before closing the file in Excel, you will get an error stating that the file cannot be opened "because it is being used by another process." Close it first before re-running the extension.

Name: Calculate Sizes of All Installed Games
Author: Blake Burkhart
Version: 0.1
Module: size.ps1
Type: Script
Functions:
- Description: Calculate Sizes of All Installed Games
FunctionName: game-size
function game-size () {
$csv = Join-Path $PlayniteAPI.Paths.ExtensionsDataPath "game-sizes.csv"
$PlayniteAPI.Database.Games.Where({$_.IsInstalled}) | ForEach-Object {
$sizeError = $null
$size = $null
if ($_.InstallDirectory -And (Test-Path $_.InstallDirectory) ) {
try {
$size = (Get-ChildItem $_.InstallDirectory -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum
}
catch {
$sizeError = "Error reading size"
}
} else {
$sizeError = "Installation directory does not exist"
}
[PSCustomObject]@{
Name=$_.Name
Size=$size
Source=$_.Source
InstallDirectory="=HYPERLINK(`"$($_.InstallDirectory)`")"
Error=$sizeError
}
} | Export-CSV -NoTypeInformation $csv
Start-Process $csv
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment