private MetaDataForm CreateMetaForm() { MetaDataForm form = new MetaDataForm(); form.StartPosition = FormStartPosition.CenterParent; form.GameFileEdit.SetCheckBoxesChecked(true); form.GameFileEdit.CommentsChecked = false; return(form); }
private async void updateMetadataToolStripMenuItem_Click(object sender, EventArgs e) { IdGamesDataAdapater adapter = new IdGamesDataAdapater(AppConfiguration.IdGamesUrl, AppConfiguration.ApiPage, AppConfiguration.MirrorUrl); IGameFile[] localFiles = SelectedItems(GetCurrentViewControl()); if (localFiles.Length > 0) { bool showForm = true, showError = true, updateView = false; m_cancelMetaUpdate = false; DialogResult result = DialogResult.Cancel; MetaDataForm form = CreateMetaForm(); ProgressBarForm progress = InitMetaProgressBar(); foreach (IGameFile localFile in localFiles) { try { Enabled = false; progress.DisplayText = string.Format("Searching for {0}...", localFile.FileNameNoPath); progress.Show(this); IEnumerable <IGameFile> remoteFiles = await Task.Run(() => GetMetaFiles(adapter, localFile.FileNameNoPath)); Enabled = true; progress.Hide(); if (remoteFiles == null || m_cancelMetaUpdate) { break; } if (!remoteFiles.Any()) { if (showError) { showError = HandleMetaError(localFile); } } else { IGameFile remoteFile = HandleMultipleMetaFilesFound(localFile, remoteFiles); if (remoteFile != null) { form.GameFileEdit.SetDataSource(remoteFile, new ITagData[] { }); if (showForm) //OK = Accept current file, Yes = Accept All files { result = form.ShowDialog(this); } if (result != DialogResult.Cancel) { List <GameFileFieldType> fields = form.GameFileEdit.UpdateDataSource(localFile); showForm = (result == DialogResult.OK); if (fields.Count > 0) { updateView = HandleUpdateMetaFields(localFile, fields); } } } } } catch { Enabled = true; progress.Hide(); MessageBox.Show(this, "Failed to fetch metadata from the id games mirror.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; //not expected, break from loop } } if (updateView) { HandleSelectionChange(GetCurrentViewControl(), true); } } }