Пример #1
0
        /*
         * public IDownloadManager DownloadRelease(string releaseId, string currentFileId = null)
         * {
         *      // ignore if already launched
         *      if (_currentlyDownloading.Contains(releaseId)) {
         *              _logger.Warn("Skipping already queued release {0}.", releaseId);
         *              return this;
         *      }
         *      _currentlyDownloading.Add(releaseId);
         *
         *      // retrieve release details
         *      _logger.Info("Retrieving details for release {0} before downloading..", releaseId);
         *      _vpdbManager.GetRelease(releaseId).ObserveOn(Scheduler.Default).Subscribe(release => {
         *
         *              // match file based on settings
         *              var file = FindLatestFile(release, currentFileId);
         *
         *              // check if match
         *              if (file == null) {
         *                      _logger.Info("Nothing matched current flavor configuration, skipping.");
         *                      _currentlyDownloading.Remove(releaseId);
         *                      return;
         *              }
         *
         *              // download
         *              DownloadRelease(release, file);
         *
         *      }, exception => _vpdbManager.HandleApiError(exception, "retrieving release details during download"));
         *
         *      return this;
         * }*/

        public IDownloadManager DownloadRelease(AggregatedGame game)
        {
            var release   = game.MappedRelease;
            var tableFile = game.MappedTableFile;

            // also fetch game data for media & co
            _vpdbManager.GetGame(release.Game.Id, true).Subscribe(g => {
                var version = _databaseManager.GetVersion(release.Id, tableFile.Reference.Id);
                _logger.Info($"Checking what to download for {g.DisplayName} - {release.Name} v{version?.Name} ({tableFile.Reference.Id})");

                var gameName  = release.Game.DisplayName;
                var system    = _pinballXManager.FindSystem(tableFile);
                var platform  = tableFile.Compatibility[0].Platform;
                var fileTypes = new List <FileType>();

                // check if backglass image needs to be downloaded
                var backglassImagePath = Path.Combine(system.MediaPath, Job.MediaBackglassImages);
                if (!FileBaseExists(backglassImagePath, gameName))
                {
                    fileTypes.Add(FileType.BackglassImage);
                    _jobManager.AddJob(new Job(release, g.Backglass, FileType.BackglassImage, platform));
                }

                // check if wheel image needs to be downloaded
                var wheelImagePath = Path.Combine(system.MediaPath, Job.MediaWheelImages);
                if (!FileBaseExists(wheelImagePath, gameName))
                {
                    fileTypes.Add(FileType.WheelImage);
                    _jobManager.AddJob(new Job(release, g.Logo, FileType.WheelImage, platform));
                }

                // queue table shot
                var tableImage = Path.Combine(system.MediaPath, Job.MediaTableImages);
                if (!FileBaseExists(tableImage, gameName))
                {
                    fileTypes.Add(FileType.TableImage);
                    _jobManager.AddJob(new Job(release, tableFile.PlayfieldImage, FileType.TableImage, platform));
                }

                // todo check for ROM to be downloaded, path at HKEY_CURRENT_USER\SOFTWARE\Freeware\Visual PinMame\globals
                // todo also queue all remaining non-table files of the release.

                // queue for download
                var job = new Job(release, tableFile, FileType.TableFile, platform);
                fileTypes.Add(FileType.TableFile);
                _logger.Info("Found {0} file type(s) to download: {1}", fileTypes.Count, string.Join(", ", fileTypes));
                _jobManager.AddJob(job);
                game.SetJob(job);
                _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, tableFile.ToString());

                _currentlyDownloading.Remove(release.Id);
            }, exception => _vpdbManager.HandleApiError(exception, "retrieving game details during download"));
            return(this);
        }
Пример #2
0
        /// <summary>
        /// Adds a downloaded game to the PinballX database.
        /// </summary>
        /// <param name="job">Job of the downloaded game</param>
        private void AddGame(Job job)
        {
            _logger.Info("Adding {0} to PinballX database...", job.Release);

            var tableFile = _databaseManager.GetTableFile(job.Release.Id, job.File.Id);
            var platform  = _pinballXManager.FindSystem(tableFile);

            if (platform == null)
            {
                _logger.Warn("Cannot find platform for release {0} ({1}), aborting.", job.Release.Id, string.Join(",", tableFile.Compatibility));
                return;
            }
            var newGame = _pinballXManager.NewGame(job);

            // adding the game (updating the xml) forces a new rescan. but it's
            // async so in order to avoid race conditions, we put this into a
            // "linking" queue, meaning on the next update, it will also get
            // linked.
            _gamesToLink.Add(new Tuple <string, string, string>(newGame.Description, job.Release.Id, job.File.Id));

            // save new game to Vpdb.xml (and trigger rescan)
            _pinballXManager.AddGame(newGame);
        }