Exemplo n.º 1
0
        private void SyncIWads(FileAddResults fileAddResults)
        {
            foreach (string file in fileAddResults.GetAllFiles())
            {
                IGameFile gameFile = DataSourceAdapter.GetGameFile(file);

                if (gameFile != null && !gameFile.IWadID.HasValue)
                {
                    DataSourceAdapter.InsertIWad(new IWadData()
                    {
                        GameFileID = gameFile.GameFileID.Value, FileName = file, Name = file
                    });
                    var iwad = DataSourceAdapter.GetIWads().OrderBy(x => x.IWadID).LastOrDefault();

                    IWadInfo wadInfo = IWadInfo.GetIWadInfo(gameFile.FileName);
                    gameFile.Title = wadInfo == null?Path.GetFileNameWithoutExtension(gameFile.FileName).ToUpper() : wadInfo.Title;

                    DataSourceAdapter.UpdateGameFile(gameFile, new GameFileFieldType[] { GameFileFieldType.Title });

                    if (iwad != null)
                    {
                        gameFile.IWadID = iwad.IWadID;
                        DataSourceAdapter.UpdateGameFile(gameFile, new[] { GameFileFieldType.IWadID });
                    }
                }
            }

            UpdateLocal();
            HandleTabSelectionChange();
        }
Exemplo n.º 2
0
        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)
            {
                return;
            }

            bool showForm = true, showError = true, updateView = false;

            m_cancelMetaUpdate = false;
            DialogResult    result   = DialogResult.Cancel;
            MetaDataForm    form     = CreateMetaForm();
            ProgressBarForm progress = InitMetaProgressBar();
            List <string>   iwadWarn = new List <string>();
            HashSet <int>   iwads    = new HashSet <int>(DataSourceAdapter.GetGameFileIWads().Select(x => x.GameFileID.Value));

            foreach (IGameFile localFile in localFiles)
            {
                if (iwads.Contains(localFile.GameFileID.Value))
                {
                    IWadInfo info = IWadInfo.GetIWadInfo(localFile.FileNameNoPath);
                    if (info != null && !info.HasMetadata)
                    {
                        iwadWarn.Add(localFile.FileNameNoPath);
                        continue;
                    }
                }

                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);
            }

            if (iwadWarn.Count > 0)
            {
                MessageBox.Show(this, "The following are IWADs and will not exist in idgames: " + string.Join(", ", iwadWarn),
                                "IWAD Files", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }