Exemple #1
0
        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);
        }
Exemple #2
0
        internal List <GameInfo> GetLibraryGames()
        {
            var games = new List <GameInfo>();

            using (var butler = new Butler())
            {
                var profiles = butler.GetProfiles();
                if (profiles?.Any() != true)
                {
                    throw new Exception("User is not authenticated.");
                }

                foreach (var profile in profiles)
                {
                    var keys = butler.GetOwnedKeys(profile.id);
                    if (!keys.HasItems())
                    {
                        continue;
                    }

                    foreach (var key in keys)
                    {
                        if (key.game == null)
                        {
                            continue;
                        }

                        if (key.game.classification != GameClassification.game &&
                            key.game.classification != GameClassification.tool)
                        {
                            continue;
                        }

                        if (games.Any(a => a.GameId == key.game.id.ToString()))
                        {
                            continue;
                        }

                        var game = new GameInfo()
                        {
                            Source     = "itch.io",
                            GameId     = key.game.id.ToString(),
                            Name       = key.game.title.RemoveTrademarks(),
                            CoverImage = key.game.coverUrl,
                            Platform   = "PC"
                        };

                        games.Add(game);
                    }
                }
            }

            return(games);
        }
Exemple #3
0
        internal List <Game> GetLibraryGames()
        {
            var games = new List <Game>();

            using (var butler = new Butler())
            {
                var profiles = butler.GetProfiles();
                if (profiles?.Any() != true)
                {
                    throw new Exception("User is not authenticated.");
                }

                foreach (var profile in profiles)
                {
                    var keys = butler.GetOwnedKeys(profile.id);
                    foreach (var key in keys)
                    {
                        if (key.game == null)
                        {
                            continue;
                        }

                        if (key.game.classification != GameClassification.game &&
                            key.game.classification != GameClassification.tool)
                        {
                            continue;
                        }

                        if (games.Any(a => a.GameId == key.game.id.ToString()))
                        {
                            continue;
                        }

                        var game = new Game()
                        {
                            PluginId   = Id,
                            GameId     = key.game.id.ToString(),
                            Name       = key.game.title,
                            CoverImage = key.game.coverUrl
                        };

                        games.Add(game);
                    }
                }
            }

            return(games);
        }
Exemple #4
0
        public override void Play()
        {
            CheckItchInstallStatus();
            ReleaseResources();
            if (Game.PlayAction.Path == DynamicLaunchActionStr ||
                Game.PlayAction.Type == GameActionType.File ||
                Game.PlayAction.Type == GameActionType.URL)
            {
                OnStarting(this, new GameControllerEventArgs(this, 0));

                if (Game.PlayAction.Path == DynamicLaunchActionStr)
                {
                    butler = new Butler();
                    butler.RequestReceived      += Butler_RequestReceived;
                    butler.NotificationReceived += Butler_NotificationReceived;
                    butler.LaunchAsync(Game.PlayAction.Arguments);
                }
                else
                {
                    if (!Directory.Exists(Game.InstallDirectory))
                    {
                        throw new DirectoryNotFoundException(api.Resources.GetString("LOCInstallDirNotFoundError"));
                    }

                    GameActionActivator.ActivateAction(api.ExpandGameVariables(Game, Game.PlayAction));
                    if (Directory.Exists(Game.InstallDirectory))
                    {
                        procMon                = new ProcessMonitor();
                        procMon.TreeStarted   += ProcMon_TreeStarted;
                        procMon.TreeDestroyed += Monitor_TreeDestroyed;
                        procMon.WatchDirectoryProcesses(Game.InstallDirectory, false);
                    }
                    else
                    {
                        OnStopped(this, new GameControllerEventArgs(this, 0));
                    }
                }
            }
            else
            {
                throw new Exception(api.Resources.GetString("LOCInvalidGameActionSettings"));
            }
        }
Exemple #5
0
        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);
                }
            }
        }
Exemple #6
0
        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);
                }
            }
        }
 public ItchioMetadataProvider(ItchioLibrary library)
 {
     butler       = new Butler();
     this.library = library;
 }
 public ItchioMetadataProvider()
 {
     butler = new Butler();
 }
 public ItchioMetadataProvider(IPlayniteAPI api)
 {
     butler   = new Butler();
     this.api = api;
 }