Skip to content

Commit

Permalink
Restore playtime resync after download complete
Browse files Browse the repository at this point in the history
It will work only during repairing.
  • Loading branch information
hawkeye116477 committed Oct 23, 2024
1 parent b4b3f0b commit 5ebc0d4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/LegendaryDownloadManager.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Windows.Input;
using Playnite.SDK.Plugins;
using System.Collections.Specialized;
using LegendaryLibraryNS.Services;

namespace LegendaryLibraryNS
{
Expand Down Expand Up @@ -543,6 +544,29 @@ public async Task Install(DownloadManagerData.Download taskData)
game.Version = installedGameInfo.Version;
game.InstallSize = (ulong?)installedGameInfo.Install_size;
game.IsInstalled = true;
var playtimeSyncEnabled = false;
if (downloadProperties.downloadAction == DownloadAction.Repair)
{
if (playniteAPI.ApplicationSettings.PlaytimeImportMode != PlaytimeImportMode.Never)
{
playtimeSyncEnabled = LegendaryLibrary.GetSettings().SyncPlaytime;
var gameSettings = LegendaryGameSettingsView.LoadGameSettings(game.GameId);
if (gameSettings?.AutoSyncPlaytime != null)
{
playtimeSyncEnabled = (bool)gameSettings.AutoSyncPlaytime;
}
}
if (playtimeSyncEnabled)
{
var accountApi = new EpicAccountClient(playniteAPI, LegendaryLauncher.TokensPath);
var playtimeItems = await accountApi.GetPlaytimeItems();
var playtimeItem = playtimeItems?.FirstOrDefault(x => x.artifactId == gameID);
if (playtimeItem != null)
{
game.Playtime = playtimeItem.totalTime;
}
}
}
// Some games need specific key in registry, otherwise they can't launch
try
{
Expand Down

0 comments on commit 5ebc0d4

Please sign in to comment.