internal Dictionary <string, GameInfo> GetInstalledGames() { var games = new Dictionary <string, GameInfo>(); using (var butler = new Butler()) { var caves = butler.GetCaves(); if (caves?.Any() != true) { return(games); } foreach (var cave in caves) { if (cave.game.classification != Models.GameClassification.game && cave.game.classification != Models.GameClassification.tool) { continue; } // TODO: We don't support multiple version of one game at moment if (games.ContainsKey(cave.game.id.ToString())) { continue; } var installDir = cave.installInfo.installFolder; if (!Directory.Exists(installDir)) { continue; } var game = new GameInfo() { Source = "itch.io", GameId = cave.game.id.ToString(), Name = cave.game.title, InstallDirectory = installDir, IsInstalled = true, CoverImage = cave.game.coverUrl, PlayAction = new GameAction { Type = GameActionType.URL, Path = ItchioGameController.DynamicLaunchActionStr, Arguments = cave.id, IsHandledByPlugin = true } }; if (TryGetGameActions(installDir, out var play, out var others)) { game.OtherActions = new List <GameAction>(others); } games.Add(game.GameId, game); } } return(games); }
public async void StartUninstallWatcher() { watcherToken = new CancellationTokenSource(); using (var butler = new Butler()) { while (true) { if (watcherToken.IsCancellationRequested) { return; } var installed = butler.GetCaves(); var cave = installed?.FirstOrDefault(a => a.game.id.ToString() == Game.GameId); if (cave == null) { OnUninstalled(this, new GameControllerEventArgs(this, 0)); return; } await Task.Delay(2000); } } }
public async void StartInstallWatcher() { watcherToken = new CancellationTokenSource(); using (var butler = new Butler()) { while (true) { if (watcherToken.IsCancellationRequested) { return; } var installed = butler.GetCaves(); var cave = installed?.FirstOrDefault(a => a.game.id.ToString() == Game.GameId); if (cave != null) { var installInfo = new GameInfo { InstallDirectory = cave.installInfo.installFolder, PlayAction = new GameAction() { Type = GameActionType.URL, Path = DynamicLaunchActionStr, Arguments = cave.id, IsHandledByPlugin = true } }; OnInstalled(this, new GameInstalledEventArgs(installInfo, this, 0)); return; } await Task.Delay(5000); } } }