Пример #1
0
        public async void StartInstallWatcher()
        {
            watcherToken = new CancellationTokenSource();
            await Task.Run(async() =>
            {
                var stopWatch = Stopwatch.StartNew();
                var id        = Game.ToSteamGameID();

                while (true)
                {
                    if (watcherToken.IsCancellationRequested)
                    {
                        return;
                    }

                    var gameState = Steam.GetAppState(id);
                    if (gameState.Installed == true)
                    {
                        if (Game.PlayAction == null)
                        {
                            Game.PlayAction = SteamLibrary.CreatePlayTask(Game.ToSteamGameID());
                        }

                        stopWatch.Stop();
                        OnInstalled(this, new GameControllerEventArgs(this, stopWatch.Elapsed.TotalSeconds));
                        return;
                    }

                    await Task.Delay(Playnite.Timer.SecondsToMilliseconds(5));
                }
            });
        }
Пример #2
0
        public async void StartRunningWatcher()
        {
            watcherToken = new CancellationTokenSource();
            await Task.Run(async() =>
            {
                var stopWatch = Stopwatch.StartNew();
                var id        = Game.ToSteamGameID();
                var gameState = Steam.GetAppState(id);

                while (true)
                {
                    if (watcherToken.IsCancellationRequested)
                    {
                        return;
                    }

                    gameState = Steam.GetAppState(id);
                    if (gameState.Running == true)
                    {
                        OnStarted(this, new GameControllerEventArgs(this, stopWatch.Elapsed.TotalSeconds));
                        stopWatch.Restart();
                        break;
                    }

                    await Task.Delay(Playnite.Timer.SecondsToMilliseconds(2));
                }

                while (true)
                {
                    if (watcherToken.IsCancellationRequested)
                    {
                        return;
                    }

                    gameState = Steam.GetAppState(id);
                    if (gameState.Running == false)
                    {
                        stopWatch.Stop();
                        OnStopped(this, new GameControllerEventArgs(this, stopWatch.Elapsed.TotalSeconds));
                        return;
                    }

                    await Task.Delay(Playnite.Timer.SecondsToMilliseconds(5));
                }
            });
        }
Пример #3
0
        public async void StartUninstallWatcher()
        {
            watcherToken = new CancellationTokenSource();
            stopWatch    = Stopwatch.StartNew();
            var id = Game.ToSteamGameID();

            while (true)
            {
                if (watcherToken.IsCancellationRequested)
                {
                    return;
                }

                var gameState = Steam.GetAppState(id);
                if (gameState.Installed == false)
                {
                    stopWatch.Stop();
                    OnUninstalled(this, new GameControllerEventArgs(this, stopWatch.Elapsed.TotalSeconds));
                    return;
                }

                await Task.Delay(Playnite.Common.Timer.SecondsToMilliseconds(5));
            }
        }