Esempio n. 1
0
        public bool RunUtility(IGameFile gameFile)
        {
            SpecificFilesForm form = new SpecificFilesForm();

            form.AutoCheckSupportedExtensions(false);
            form.ShowPkContentsCheckBox(true);
            form.Initialize(m_config.GameFileDirectory, new IGameFile[] { gameFile }, SourcePort.GetSupportedExtensions(m_utility),
                            new string[] { }, m_config.TempDirectory);
            form.StartPosition = FormStartPosition.CenterParent;

            if (form.ShowDialog(m_parent) == DialogResult.OK)
            {
                var files = form.GetPathedSpecificFiles();

                GameFilePlayAdapter adapter = new GameFilePlayAdapter();
                StringBuilder       sb      = new StringBuilder();
                adapter.HandleGameFile(gameFile, sb, m_config.GameFileDirectory, m_config.TempDirectory, m_utility, files); //this checks File.Exists and might not be same file

                try
                {
                    if (!string.IsNullOrEmpty(m_utility.ExtraParameters))
                    {
                        sb.Append(" " + m_utility.ExtraParameters);
                    }

                    Process.Start(m_utility.GetFullExecutablePath(), sb.ToString().Trim());
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        private void m_currentPlayForm_OnPreviewLaunchParameters(object sender, EventArgs e)
        {
            GameFilePlayAdapter playAdapter = CreatePlayAdapter(m_currentPlayForm, playAdapter_ProcessExited, AppConfiguration);

            playAdapter.ExtractFiles = false;
            ShowLaunchParameters(playAdapter, m_currentPlayForm.GameFile, m_currentPlayForm.SelectedSourcePort);
        }
Esempio n. 3
0
        private void HandleDetectorFiles(GameFilePlayAdapter adapter, IGameFile gameFile)
        {
            ScreenshotHandler screenshotHandler = new ScreenshotHandler(DataSourceAdapter, AppConfiguration.ScreenshotDirectory);

            screenshotHandler.HandleNewScreenshots(adapter.SourcePort, gameFile, GetNewScreenshots());
            SaveGameHandler savegameHandler = new SaveGameHandler(DataSourceAdapter, AppConfiguration.SaveGameDirectory);

            savegameHandler.HandleNewSaveGames(adapter.SourcePort, gameFile, GetNewSaveGames());
            savegameHandler.HandleUpdateSaveGames(adapter.SourcePort, gameFile, m_saveGames);
        }
Esempio n. 4
0
        private void HandleProcessExited(object sender)
        {
            if (m_filterForm != null)
            {
                m_filterForm.Close();
                m_filterForm = null;
            }

            GameFilePlayAdapter adapter = sender as GameFilePlayAdapter;
            DateTime            dtExit  = DateTime.Now;

            Directory.SetCurrentDirectory(m_workingDirectory);
            m_playInProgress = false;

            if (adapter.SourcePort != null)
            {
                IGameFile gameFile = adapter.GameFile;

                if (gameFile != null)
                {
                    SetMinutesPlayed(dtExit, gameFile);
                }

                if (!string.IsNullOrEmpty(adapter.RecordedFileName))
                {
                    HandleRecordedDemo(adapter, gameFile);
                }

                HandleDetectorFiles(adapter, gameFile);

                if (m_statsReader != null)
                {
                    m_statsReader.Stop();

                    if (m_statsReader.ReadOnClose)
                    {
                        m_statsReader.ReadNow();
                    }

                    if (m_statsReader.Errors.Length > 0)
                    {
                        HandleStatReaderErrors(m_statsReader);
                    }

                    m_statsReader = null;
                }
            }

            IGameFileView view = GetCurrentViewControl();

            view.UpdateGameFile(adapter.GameFile);
            HandleSelectionChange(view, true);
        }
Esempio n. 5
0
        private bool StartPlay(IGameFile gameFile, ISourcePortData sourcePort, bool screenFilter)
        {
            GameFilePlayAdapter playAdapter = CreatePlayAdapter(m_currentPlayForm, playAdapter_ProcessExited, AppConfiguration);

            m_saveGames = new IFileData[] { };

            if (AppConfiguration.CopySaveFiles)
            {
                CopySaveGames(gameFile, sourcePort);
            }
            CreateFileDetectors(sourcePort);

            if (m_currentPlayForm.PreviewLaunchParameters)
            {
                ShowLaunchParameters(playAdapter, gameFile, sourcePort);
            }

            bool isGameFileIwad = IsGameFileIwad(gameFile);

            if (m_currentPlayForm.SaveStatistics)
            {
                SetupStatsReader(sourcePort, gameFile);
            }

            if (playAdapter.Launch(AppConfiguration.GameFileDirectory, AppConfiguration.TempDirectory,
                                   gameFile, sourcePort, isGameFileIwad))
            {
                m_currentPlayFile = gameFile;

                if (gameFile != null)
                {
                    gameFile.LastPlayed = DateTime.Now;
                    m_dtStartPlay       = DateTime.Now;
                    DataSourceAdapter.UpdateGameFile(gameFile, new GameFileFieldType[] { GameFileFieldType.LastPlayed });
                    UpdateDataSourceViews(gameFile);
                }
            }
            else
            {
                MessageBox.Show(this, playAdapter.LastError, "Launch Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (screenFilter)
            {
                m_filterForm = new FilterForm(Screen.FromControl(this), m_currentPlayForm.GetFilterSettings());
                m_filterForm.Show(this);
            }

            return(true);
        }
Esempio n. 6
0
        private void m_currentPlayForm_OnPreviewLaunchParameters(object sender, EventArgs e)
        {
            GameFilePlayAdapter playAdapter = CreatePlayAdapter(m_currentPlayForm, playAdapter_ProcessExited, AppConfiguration);

            playAdapter.ExtractFiles = false;
            if (m_currentPlayForm.SettingsValid(out string err))
            {
                ShowLaunchParameters(playAdapter, m_currentPlayForm.GameFile, m_currentPlayForm.SelectedSourcePort);
            }
            else
            {
                MessageBox.Show(this, err, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 7
0
        private void SetupStatsReader(ISourcePort sourcePort, GameFilePlayAdapter playAdapter, IGameFile gameFile)
        {
            m_statsReader = CreateStatisticsReader(sourcePort, gameFile);

            if (m_statsReader != null)
            {
                if (!string.IsNullOrEmpty(m_statsReader.LaunchParameter))
                {
                    playAdapter.ExtraParameters += m_statsReader.LaunchParameter;
                }
                m_statsReader.NewStastics += m_statsReader_NewStastics;
                m_statsReader.Start();
            }
        }
Esempio n. 8
0
        private void ShowLaunchParameters(GameFilePlayAdapter playAdapter, IGameFile gameFile, ISourcePortData sourcePort)
        {
            TextBoxForm form = new TextBoxForm
            {
                Text          = "Launch Parameters",
                StartPosition = FormStartPosition.CenterParent
            };

            string launchParameters = playAdapter.GetLaunchParameters(AppConfiguration.GameFileDirectory,
                                                                      AppConfiguration.TempDirectory, gameFile, sourcePort, IsGameFileIwad(gameFile));

            if (launchParameters != null)
            {
                launchParameters = launchParameters.Replace(@" -", string.Concat(Environment.NewLine, " -"));
                launchParameters = launchParameters.Replace("\" \"", string.Concat("\"", Environment.NewLine, " \""));
                if (launchParameters.StartsWith(Environment.NewLine))
                {
                    launchParameters = launchParameters.Substring(Environment.NewLine.Length);
                }
                string individualFiles = string.Empty;

                if (m_currentPlayForm.SpecificFiles != null && m_currentPlayForm.SpecificFiles.Length > 0)
                {
                    individualFiles = Environment.NewLine + string.Format("Selected Files: {0}", string.Join(", ", m_currentPlayForm.SpecificFiles));
                }

                string sourcePortParams = string.Empty;
                if (!string.IsNullOrEmpty(sourcePort.ExtraParameters))
                {
                    sourcePortParams = string.Concat(Environment.NewLine, Environment.NewLine, "Paramters from source port: ", sourcePort.ExtraParameters);
                }

                form.DisplayText = string.Concat(launchParameters, Environment.NewLine, Environment.NewLine,
                                                 string.Format("Supported Extensions: {0}", sourcePort.SupportedExtensions),
                                                 individualFiles,
                                                 sourcePortParams,
                                                 Environment.NewLine, Environment.NewLine,
                                                 "*** If files appear to be missing check the 'Select Individual Files' option and supported extensions options in the Source Port form of the selected source port.");
            }
            else
            {
                form.DisplayText = "Failed to generate launch parameters";
            }

            form.SelectDisplayText(0, 0);
            form.ShowDialog(this);
        }
Esempio n. 9
0
        private void HandleRecordedDemo(GameFilePlayAdapter adapter, IGameFile gameFile)
        {
            DirectoryInfo di     = new DirectoryInfo(AppConfiguration.TempDirectory.GetFullPath());
            FileInfo      fiTemp = new FileInfo(adapter.RecordedFileName);
            FileInfo      fi     = di.GetFiles().FirstOrDefault(x => x.Name.Contains(fiTemp.Name));

            if (fi != null && fi.Exists)
            {
                DemoHandler demoHandler = new DemoHandler(DataSourceAdapter, AppConfiguration.DemoDirectory);
                demoHandler.HandleNewDemo(adapter.SourcePort, gameFile, fi.FullName,
                                          m_currentPlayForm.RecordDescriptionText);
            }
            else
            {
                MessageBox.Show(this, "Could not find the demo file. Does this source port support recording?", "Demo Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 10
0
        private static GameFilePlayAdapter CreatePlayAdapter(PlayForm form, EventHandler processExited, AppConfiguration appConfig)
        {
            GameFilePlayAdapter playAdapter = new GameFilePlayAdapter();

            playAdapter.IWad            = form.SelectedIWad;
            playAdapter.Map             = form.SelectedMap;
            playAdapter.Skill           = form.SelectedSkill;
            playAdapter.Record          = form.Record;
            playAdapter.SpecificFiles   = form.SpecificFiles;
            playAdapter.AdditionalFiles = form.GetAdditionalFiles().ToArray();
            playAdapter.PlayDemo        = form.PlayDemo;
            playAdapter.ExtraParameters = form.ExtraParameters;
            playAdapter.ProcessExited  += processExited;
            if (form.SelectedDemo != null)
            {
                playAdapter.PlayDemoFile = Path.Combine(appConfig.DemoDirectory.GetFullPath(), form.SelectedDemo.FileName);
            }
            return(playAdapter);
        }
Esempio n. 11
0
        private GameFilePlayAdapter CreatePlayAdapter(PlayForm form, EventHandler processExited, AppConfiguration appConfig)
        {
            GameFilePlayAdapter playAdapter = new GameFilePlayAdapter();

            playAdapter.IWad            = form.SelectedIWad;
            playAdapter.Map             = form.SelectedMap;
            playAdapter.Skill           = form.SelectedSkill;
            playAdapter.Record          = form.Record;
            playAdapter.SpecificFiles   = form.SpecificFiles;
            playAdapter.AdditionalFiles = form.GetAdditionalFiles().ToArray();
            playAdapter.PlayDemo        = form.PlayDemo;
            playAdapter.ExtraParameters = form.ExtraParameters;
            playAdapter.SaveStatistics  = form.SaveStatistics;

            if (form.LoadLatestSave)
            {
                if (!AppConfiguration.CopySaveFiles)
                {
                    MessageCheckBox message = new MessageCheckBox("Copy Save Files Disabled",
                                                                  "Copy save files is disabled and the load latest save feature may not function.\n\nSelect the check box below to enable this setting.",
                                                                  "Enable Setting", SystemIcons.Warning);
                    message.StartPosition = FormStartPosition.CenterParent;
                    message.ShowDialog(this);
                    if (message.Checked)
                    {
                        AppConfiguration.EnableCopySaveFiles();
                    }
                }
                playAdapter.LoadSaveFile = GetLoadLatestSave(form.GameFile, form.SelectedSourcePort);
            }

            playAdapter.ProcessExited += processExited;
            if (form.SelectedDemo != null)
            {
                playAdapter.PlayDemoFile = Path.Combine(appConfig.DemoDirectory.GetFullPath(), form.SelectedDemo.FileName);
            }
            return(playAdapter);
        }