Пример #1
0
        /// <summary>
        /// Updates a release from the backend.
        /// </summary>
        /// <param name="release"></param>
        public void Update(VpdbRelease release)
        {
            // no need to update if it's the same object.
            if (ReferenceEquals(this, release))
            {
                return;
            }

            Name      = release.Name;
            CreatedAt = release.CreatedAt;
            Authors   = release.Authors;
            Counter   = release.Counter;
            Game      = release.Game;
            Starred   = release.Starred;

            using (Versions.SuppressChangeNotifications()) {
                foreach (var version in release.Versions)
                {
                    var existingVersion = Versions.FirstOrDefault(v => version.Name.Equals(v.Name));
                    if (existingVersion != null)
                    {
                        Versions.Remove(existingVersion);
                    }
                    Versions.Add(version);
                }
            }
        }
Пример #2
0
        public GameResultItemViewModel(Game game, VpdbRelease release, VpdbVersion version, VpdbTableFile tableFile, ICommand closeCommand)
        {
            Game = game;
            Version = version;
            Release = release;
            TableFile = tableFile;

            SelectResult.Subscribe(_ =>
            {
                GameManager.LinkRelease(Game, release, tableFile.Reference.Id);
                MessageManager.LogReleaseLinked(game, release, tableFile.Reference.Id);

                closeCommand.Execute(null);
            });
        }
Пример #3
0
        /// <summary>
        /// Downloads a release including media and ROMs.
        /// </summary>
        /// <param name="release">Release to download</param>
        /// <param name="tableFile">File of the release to download</param>
        private void DownloadRelease(VpdbRelease release, VpdbTableFile tableFile)
        {
            // also fetch game data for media & co
            _vpdbClient.Api.GetGame(release.Game.Id).Subscribe(game =>  {

                var version = _databaseManager.GetVersion(release.Id, tableFile.Reference.Id);
                _logger.Info($"Downloading {game.DisplayName} - {release.Name} v{version?.Name} ({tableFile.Reference.Id})");

                var gameName = release.Game.DisplayName;
                var pbxPlatform = _platformManager.FindPlatform(tableFile);
                var vpdbPlatform = tableFile.Compatibility[0].Platform;

                // check if backglass image needs to be downloaded
                var backglassImagePath = Path.Combine(pbxPlatform.MediaPath, Job.MediaBackglassImages);
                if (!FileBaseExists(backglassImagePath, gameName)) {
                    _jobManager.AddJob(new Job(release, game.Media["backglass"], FileType.BackglassImage, vpdbPlatform));
                }

                // check if wheel image needs to be downloaded
                var wheelImagePath = Path.Combine(pbxPlatform.MediaPath, Job.MediaWheelImages);
                if (!FileBaseExists(wheelImagePath, gameName)) {
                    _jobManager.AddJob(new Job(release, game.Media["logo"], FileType.WheelImage, vpdbPlatform));
                }

                // queue table shot
                var tableImage = Path.Combine(pbxPlatform.MediaPath, Job.MediaTableImages);
                if (!FileBaseExists(tableImage, gameName)) {
                    _jobManager.AddJob(new Job(release, tableFile.Media["playfield_image"], FileType.TableImage, vpdbPlatform));
                }

                // todo check for ROM to be downloaded
                // todo also queue all remaining non-table files of the release.

                // queue for download
                var job = new Job(release, tableFile, FileType.TableFile, vpdbPlatform);
                _logger.Info("Created new job for {0} - {1} v{2} ({3}): {4}", job.Release.Game.DisplayName, job.Release.Name, job.Version.Name, job.File.Id, job.TableFile.ToString());
                _jobManager.AddJob(job);

                _currentlyDownloading.Remove(release.Id);

            }, exception => _vpdbClient.HandleApiError(exception, "retrieving game details during download"));
        }
Пример #4
0
        public VpdbTableFile FindLatestFile(VpdbRelease release, string currentFileId = null)
        {
            if (release == null) {
                return null;
            }
            var currentFile = _databaseManager.GetTableFile(release.Id, currentFileId);

            var file = release.Versions
                .SelectMany(v => v.Files)
                .Where(f => FlavorMatches(f, currentFile))
                .Select(f => new { f, weight = FlavorWeight(f, currentFile) })
                .OrderByDescending(x => x.weight)
                .ThenByDescending(x => x.f.ReleasedAt)
                .Select(x => x.f)
                .FirstOrDefault();

            // check for newer version
            if (file != null && currentFile != null) {
                var currentVersion = _databaseManager.GetVersion(release.Id, currentFile.Reference.Id);
                var latestVersion = _databaseManager.GetVersion(release.Id, file.Reference.Id);
                if (latestVersion != null && currentVersion != null && currentVersion.ReleasedAt >= latestVersion.ReleasedAt) {
                    _logger.Info("Update check: No update found.");
                    return null;
                }
                if (latestVersion != null && currentVersion != null) {
                    _logger.Info("Update check: Found new version from v{0} to v{1}", currentVersion.Name, latestVersion.Name);
                } else {
                    _logger.Warn("Update check: Failed to retrieve version for file {0}/{1}", file.Reference.Id, currentFile.Reference.Id);
                }
            }
            if (file == null) {
                _logger.Info("Update check: Nothing matched.");
            }

            return file;
        }
Пример #5
0
        /// <summary>
        /// Updates a release from the backend.
        /// </summary>
        /// <param name="release"></param>
        public void Update(VpdbRelease release)
        {
            // no need to update if it's the same object.
            if (ReferenceEquals(this, release)) {
                return;
            }

            Name = release.Name;
            CreatedAt = release.CreatedAt;
            Authors = release.Authors;
            Counter = release.Counter;
            Game = release.Game;
            Starred = release.Starred;

            using (Versions.SuppressChangeNotifications()) {
                foreach (var version in release.Versions) {
                    var existingVersion = Versions.FirstOrDefault(v => version.Name.Equals(v.Name));
                    if (existingVersion != null) {
                        Versions.Remove(existingVersion);
                    }
                    Versions.Add(version);
                }
            }
        }
Пример #6
0
        public void LinkRelease(Game game, VpdbRelease release, string fileId)
        {
            // update in case we didn't catch the last version.
            _vpdbClient.Api.GetRelease(release.Id).Subscribe(updatedRelease => {
                _logger.Info("Linking {0} to {1} ({2})", game, release, fileId);
                _databaseManager.AddOrUpdateRelease(release);
                game.ReleaseId = release.Id;
                game.FileId = fileId;
                _databaseManager.Save();

            }, exception => _vpdbClient.HandleApiError(exception, "retrieving release details during linking"));
        }
Пример #7
0
        public void AddOrUpdateRelease(VpdbRelease release)
        {
            if (!Database.Releases.ContainsKey(release.Id)) {
                _logger.Info("Adding new release data for release {0} ({1})", release.Id, release.Name);
                Database.Releases.Add(release.Id, release);

            } else {
                _logger.Info("Updating release data of release {0} ({1})", release.Id, release.Name);
                Database.Releases[release.Id].Update(release);
            }
        }
Пример #8
0
 public Message LogReleaseLinked(Game game, VpdbRelease release, string fileId)
 {
     var msg = new Message(MessageType.ReleaseLinked, MessageLevel.Info, new Dictionary<string, string> {
         { DataGameName, game.Id },
         { DataRelease, release.Id },
         { DataFile, fileId }
     });
     return Log(msg);
 }
Пример #9
0
 public Message LogReleaseDownloaded(VpdbRelease release, VpdbVersion version, VpdbFile file, double bytesPerSecond)
 {
     var msg = new Message(MessageType.ReleaseDownloaded, MessageLevel.Info, new Dictionary<string, string> {
         { DataRelease, release.Id },
         { DataReleaseName, release.Name },
         { DataVersion, version.Name },
         { DataFile, file.Id },
         { DataSubject, release.Game.DisplayName },
         { DownloadSpeed, $"{bytesPerSecond.Bytes().ToString("#.0")}/s" },
     });
     return Log(msg);
 }