Exemplo n.º 1
0
        private void SetPictures()
        {
            if (progressBar.Maximum > progressBar.Value)
            {
                progressBar.Invoke((MethodInvoker) delegate
                {
                    progressBar.Maximum = progressBar.Value;
                });
            }

            syncRomsCount = 0;

            var notSyncedRoms = Roms.Where(x => !string.IsNullOrEmpty(x.Id) &&
                                           (missingBoxartPictures.Contains(x.Name) ||
                                            missingTitlePictures.Contains(x.Name) ||
                                            missingGameplayPictures.Contains(x.Name))).ToList();

            syncRomsCount = 0;
            ThreadStopped = false;

            progressBar.Invoke((MethodInvoker) delegate
            {
                progressBar.Value   = 0;
                progressBar.Maximum = notSyncedRoms.Count;
            });

            foreach (var rom in notSyncedRoms)
            {
                if (StopThread)
                {
                    StopThread = false;
                    Thread.CurrentThread.Abort();
                    comboBoxPlatform_SelectedIndexChanged(null, new EventArgs());
                }

                if (progressBar.Maximum > progressBar.Value)
                {
                    progressBar.Invoke((MethodInvoker) delegate
                    {
                        progressBar.Value++;
                    });
                }

                var boxArtMissing   = missingBoxartPictures.Contains(rom.Name);
                var titleMissing    = missingTitlePictures.Contains(rom.Name);
                var gameplayMissing = missingGameplayPictures.Contains(rom.Name);

                if (boxArtMissing || titleMissing || gameplayMissing)
                {
                    string boxUrl      = string.Empty;
                    string titleUrl    = string.Empty;
                    string gameplayUrl = string.Empty;

                    var access = "";
                    var found  = APIFunctions.GetGameArtUrls(rom.Id, out boxUrl, out titleUrl, out gameplayUrl, out access);
                    labelAccessLeftCount.Text = access;

                    var updateBoxart   = boxArtMissing && !string.IsNullOrEmpty(boxUrl);
                    var updateTitle    = titleMissing && !string.IsNullOrEmpty(titleUrl);
                    var updateGameplay = gameplayMissing && !string.IsNullOrEmpty(gameplayUrl);

                    if (!found || (!updateBoxart && !updateTitle && !updateGameplay))
                    {
                        LogMessage("MISSING PICTURES NOT FOUND - " + rom.Name);
                        continue;
                    }

                    syncRomsCount++;

                    if (updateBoxart)
                    {
                        LogMessage("UPDATING BOXART PICTURE - " + rom.Name);
                        SyncDataFunctions.SavePictureFromUrl(rom, boxUrl, Values.BoxartFolder, checkBoxSaveAsJpg.Checked);
                    }

                    if (updateTitle)
                    {
                        LogMessage("UPDATING TITLE PICTURE - " + rom.Name);
                        SyncDataFunctions.SavePictureFromUrl(rom, titleUrl, Values.TitleFolder, checkBoxSaveAsJpg.Checked);
                    }

                    if (updateGameplay)
                    {
                        LogMessage("UPDATING GAMEPLAY PICTURE - " + rom.Name);
                        SyncDataFunctions.SavePictureFromUrl(rom, gameplayUrl, Values.GameplayFolder, checkBoxSaveAsJpg.Checked);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void buttonGetRomData_Click(object sender, EventArgs e)
        {
            try
            {
                //FormWait.ShowWait(this);

                if (textBoxId.Text == string.Empty)
                {
                    textBoxId.Text = SyncDataFunctions.DiscoverGameId(SelectedRom);

                    if (string.IsNullOrEmpty(textBoxId.Text))
                    {
                        FormCustomMessage.ShowError("Could not discover TheGamesDB Id");
                        return;
                    }
                }

                var access = "";
                var game   = APIFunctions.GetGameDetails(textBoxId.Text, SelectedRom.Platform, out access);

                if (game == null)
                {
                    FormCustomMessage.ShowError("Could not get rom data");
                    return;
                }

                textBoxDBName.Text = game.DBName;

                if (radioButtonOnlyMissing.Checked)
                {
                    if (string.IsNullOrEmpty(textBoxPublisher.Text))
                    {
                        textBoxPublisher.Text = game.Publisher;
                    }

                    if (string.IsNullOrEmpty(textBoxDeveloper.Text))
                    {
                        textBoxDeveloper.Text = game.Developer;
                    }

                    if (string.IsNullOrEmpty(textBoxDescription.Text))
                    {
                        textBoxDescription.Text = game.Description;
                    }

                    if (string.IsNullOrEmpty(textBoxYearReleased.Text))
                    {
                        textBoxYearReleased.Text = game.YearReleased;
                    }

                    if (string.IsNullOrEmpty(textBoxRating.Text))
                    {
                        textBoxRating.Text = game.Rating.ToString("#.#");
                    }

                    if (string.IsNullOrEmpty(comboBoxGenre.Text))
                    {
                        comboBoxGenre.SelectedValue = game.Genre != null ? game.Genre.Name : string.Empty;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(game.Publisher))
                    {
                        textBoxPublisher.Text = game.Publisher;
                    }

                    if (!string.IsNullOrEmpty(game.Developer))
                    {
                        textBoxDeveloper.Text = game.Developer;
                    }

                    if (!string.IsNullOrEmpty(game.Description))
                    {
                        textBoxDescription.Text = game.Description;
                    }

                    if (!string.IsNullOrEmpty(game.YearReleased))
                    {
                        textBoxYearReleased.Text = game.YearReleased;
                    }

                    if (game.Rating != 0)
                    {
                        textBoxRating.Text = game.Rating.ToString("#.#");
                    }
                }

                var box      = RomFunctions.GetRomPicture(SelectedRom, Values.BoxartFolder);
                var title    = RomFunctions.GetRomPicture(SelectedRom, Values.TitleFolder);
                var gameplay = RomFunctions.GetRomPicture(SelectedRom, Values.GameplayFolder);

                bool missingBox      = string.IsNullOrEmpty(box);
                bool missingTitle    = string.IsNullOrEmpty(title);
                bool missingGameplay = string.IsNullOrEmpty(gameplay);

                if (!missingBox && !missingTitle && !missingGameplay)
                {
                    //FormWait.CloseWait();
                    return;
                }

                string boxUrl      = string.Empty;
                string titleUrl    = string.Empty;
                string gameplayUrl = string.Empty;

                var found = APIFunctions.GetGameArtUrls(textBoxId.Text, out boxUrl, out titleUrl, out gameplayUrl, out access);

                if (!found)
                {
                    //FormWait.CloseWait();
                    return;
                }

                if (missingBox)
                {
                    Functions.SavePictureFromUrl(SelectedRom, boxUrl, Values.BoxartFolder, checkBoxSaveAsJpg.Checked);
                    boxToDeleteIfCanceled = RomFunctions.GetRomPicture(SelectedRom, Values.BoxartFolder);
                }

                if (missingTitle && !string.IsNullOrEmpty(titleUrl))
                {
                    Functions.SavePictureFromUrl(SelectedRom, titleUrl, Values.TitleFolder, checkBoxSaveAsJpg.Checked);
                    titleToDeleteIfCanceled = RomFunctions.GetRomPicture(SelectedRom, Values.TitleFolder);
                }

                if (missingGameplay && !string.IsNullOrEmpty(gameplayUrl))
                {
                    Functions.SavePictureFromUrl(SelectedRom, gameplayUrl, Values.GameplayFolder, checkBoxSaveAsJpg.Checked);
                    gameplayToDeleteIfCanceled = RomFunctions.GetRomPicture(SelectedRom, Values.GameplayFolder);
                }

                MessageBox.Show("Remaining access: " + access);
            }
            catch (Exception ex)
            {
                //FormWait.CloseWait();
                FormCustomMessage.ShowError(ex.Message);
            }
            finally
            {
                //FormWait.CloseWait();
            }
        }