Last active
February 15, 2019 04:58
-
-
Save bburky/31b7d15baef9c1a79770dcff60869086 to your computer and use it in GitHub Desktop.
This file contains 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
Name: Steam Last Played | |
Author: Blake Burkhart | |
Version: 0.1.0 | |
Module: SteamLastPlayed.ps1 | |
Type: Script | |
Functions: | |
- Description: Update Last Played for all Steam Games | |
FunctionName: SteamLastPlayed |
This file contains 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
Function Convert-FromUnixDate ($UnixDate) { | |
[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($UnixDate)) | |
} | |
function global:SteamLastPlayed() | |
{ | |
$steamGuid = [Guid]"CB91DFC9-B977-43BF-8E70-55F46E410FAB" | |
$app = [PlayniteUI.App]::CurrentApp | |
$steamLibrary = $app.Extensions.LibraryPlugins[$steamGuid].Plugin | |
# HACK HACK HACK: We want to access the Steam plugin's settings to access the user id | |
$settings = $steamLibrary.GetType().GetProperty("LibrarySettings", [Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Instance).GetValue($steamLibrary) | |
# TODO: User should be able to select Id | |
$id = ($settings.SteamUsers | Select-Object -First 1).Id | |
$accountId = [SteamKit2.SteamID]::new($id).AccountID | |
$installationPath = [SteamLibrary.Steam]::InstallationPath | |
$vdfPath = [io.Path]::Combine($installationPath, "userdata", $accountId, "config", "localconfig.vdf") | |
$localconfig = [SteamKit2.KeyValue]::new() | |
$localconfig.ReadFileAsText($vdfPath) | |
$apps = $localconfig["Software"]["Valve"]["Steam"]["Apps"] | |
$PlayniteApi.Database.GetGames() | % { | |
if ($_.PluginId -eq $steamGuid ) { | |
$steamInfo = $apps[$_.GameId] | |
if ($steamInfo.Children) { | |
$lastPlayed = Convert-FromUnixDate $steamInfo["LastPlayed"].Value | |
# TODO: Should keep which ever date is newer | |
$_.LastActivity = $lastPlayed | |
$PlayniteApi.Database.UpdateGame($_) | |
} | |
} | |
} | |
$PlayniteApi.Dialogs.ShowMessage("Done"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment