Esempio n. 1
0
        private void SetupPlayForm(IGameFile gameFile)
        {
            m_currentPlayForm = new PlayForm(AppConfiguration, DataSourceAdapter);
            m_currentPlayForm.SaveSettings += m_currentPlayForm_SaveSettings;
            m_currentPlayForm.OnPreviewLaunchParameters += m_currentPlayForm_OnPreviewLaunchParameters;
            m_currentPlayForm.StartPosition              = FormStartPosition.CenterParent;

            List <ITabView> views = GetAdditionalTabViews();

            if (gameFile != null)
            {
                gameFile = DataSourceAdapter.GetGameFile(gameFile.FileName); //this file came from the grid, which does not have all info populated to save perfomance
            }
            m_currentPlayForm.Initialize(views, gameFile);

            SetDefaultSelections();

            if (gameFile != null)
            {
                IIWadData iwad = DataSourceAdapter.GetIWad(gameFile.GameFileID.Value);

                if (iwad != null)
                {
                    m_currentPlayForm.SelectedIWad = gameFile;
                }

                if (gameFile.SourcePortID.HasValue)
                {
                    m_currentPlayForm.SelectedSourcePort = DataSourceAdapter.GetSourcePort(gameFile.SourcePortID.Value);
                }

                if (gameFile.IWadID.HasValue)
                {
                    m_currentPlayForm.SelectedIWad = gameFile;
                    m_currentPlayForm.SelectedIWad = DataSourceAdapter.GetGameFileIWads().FirstOrDefault(x => x.IWadID == gameFile.IWadID);
                }

                if (!string.IsNullOrEmpty(gameFile.SettingsMap))
                {
                    m_currentPlayForm.SelectedMap = gameFile.SettingsMap;
                }
                if (!string.IsNullOrEmpty(gameFile.SettingsSkill))
                {
                    m_currentPlayForm.SelectedSkill = gameFile.SettingsSkill;
                }
                if (!string.IsNullOrEmpty(gameFile.SettingsExtraParams))
                {
                    m_currentPlayForm.ExtraParameters = gameFile.SettingsExtraParams;
                }
                if (!string.IsNullOrEmpty(gameFile.SettingsSpecificFiles))
                {
                    m_currentPlayForm.SpecificFiles = gameFile.SettingsSpecificFiles.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                }
            }

            m_currentPlayForm.InitializeComplete();
        }
Esempio n. 2
0
 private IGameFile GetGameFileForIWad(IGameFile gameFile)
 {
     return(DataSourceAdapter.GetGameFileIWads().FirstOrDefault(x => x.GameFileID.Value == gameFile.GameFileID.Value));
 }
Esempio n. 3
0
 private bool IsGameFileIwad(IGameFile gameFile)
 {
     return(DataSourceAdapter.GetGameFileIWads().Any(x => x.GameFileID.Value == gameFile.GameFileID.Value));
 }
Esempio n. 4
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);
            }
        }