コード例 #1
0
        private SteamConnectService()
        {
            mCurrent = this;

            SteamApps    = new SourceCache <SteamApp, uint>(t => t.AppId);
            DownloadApps = new SourceCache <SteamApp, uint>(t => t.AppId);

            DownloadApps
            .Connect()
            .Subscribe(_ =>
            {
                foreach (var app in DownloadApps.Items)
                {
                    var optional = SteamApps.Lookup(app.AppId);
                    if (optional.HasValue)
                    {
                        var value             = optional.Value;
                        value.InstalledDir    = app.InstalledDir;
                        value.State           = app.State;
                        value.SizeOnDisk      = app.SizeOnDisk;
                        value.LastOwner       = app.LastOwner;
                        value.BytesToDownload = app.BytesToDownload;
                        value.BytesDownloaded = app.BytesDownloaded;
                        value.BytesToStage    = app.BytesToStage;
                        value.BytesStaged     = app.BytesStaged;
                        value.LastUpdated     = app.LastUpdated;
                    }
                }
            });

            this.WhenValueChanged(x => x.IsWatchSteamDownloading, false)
            .Subscribe(x =>
            {
                if (x)
                {
                    InitializeDownloadGameList();
                    if (OperatingSystem2.IsLinux)
                    {
                        IPlatformService.Instance.TryGetSystemUserPassword();
                    }
                    SteamTool.StartWatchSteamDownloading(app =>
                    {
                        var optional = DownloadApps.Lookup(app.AppId);
                        if (!optional.HasValue)
                        {
                            DownloadApps.AddOrUpdate(app);
                        }
                        else
                        {
                            var current             = optional.Value;
                            current.InstalledDir    = app.InstalledDir;
                            current.State           = app.State;
                            current.SizeOnDisk      = app.SizeOnDisk;
                            current.LastOwner       = app.LastOwner;
                            current.BytesToDownload = app.BytesToDownload;
                            current.BytesDownloaded = app.BytesDownloaded;
                            current.BytesToStage    = app.BytesToStage;
                            current.BytesStaged     = app.BytesStaged;
                            current.LastUpdated     = app.LastUpdated;
                        }

                        if (WatchDownloadingSteamAppIds.Contains(app.AppId))
                        {
                            if (app.IsDownloading)
                            {
                                app.IsWatchDownloading = true;
                            }
                            else
                            {
                                WatchDownloadingSteamAppIds.Remove(app.AppId);
                                if (!WatchDownloadingSteamAppIds.Any())
                                {
                                    WatchDownloadingComplete();
                                }
                            }
                        }
                    }, appid =>
                    {
                        DownloadApps.RemoveKey(appid);
                    });
                }
                else
                {
                    SteamTool.StopWatchSteamDownloading();
                }
            });
        }