Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Add Uninstall and Remove option
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Apr 26, 2022
1 parent db7ec4b commit 5c02791
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/GameManagement/GameManagementPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,37 @@ public override IEnumerable<GameMenuItem> GetGameMenuItems(GetGameMenuItemsArgs
Action = UninstallGameMenuAction,
Description = "Uninstall"
};

yield return new GameMenuItem
{
Action = UninstallAndRemoveGameMenuAction,
Description = "Uninstall and Remove"
};
}

private void UninstallGameMenuAction(GameMenuItemActionArgs args)
{
UninstallGames(args);
}

private void UninstallAndRemoveGameMenuAction(GameMenuItemActionArgs args)
{
var games = UninstallGames(args);
foreach (var game in games)
{
_playniteAPI.Database.Games.Remove(game);
}
}

private List<Game> UninstallGames(GameMenuItemActionArgs args)
{
var games = args.Games;
if (games is null || !games.Any()) return;
if (games is null || !games.Any()) return new List<Game>();

_logger.LogInformation("Uninstalling {Count} games", games.Count.ToString());

var actuallyUninstalledGames = new List<Game>();

foreach (var game in games)
{
_logger.LogDebug("Uninstalling {Name}", game.Name);
Expand All @@ -65,17 +87,13 @@ private void UninstallGameMenuAction(GameMenuItemActionArgs args)
continue;
}

actuallyUninstalledGames.Add(game);
Directory.Delete(game.InstallDirectory, true);
_playniteAPI.Database.Games.Remove(game);

// the internal uninstallation thing by Playnite is unreliable and is intended to remove the files but not
// the game from Playnite itself
// _playniteAPI.UninstallGame(game.Id);

_storageInfo.RemoveStorageInfo(game);
}

_storageInfo.SaveToFile(StoragePath);
return actuallyUninstalledGames;
}

private readonly CancellationTokenSource _source = new();
Expand Down

0 comments on commit 5c02791

Please sign in to comment.