public void SetDataSource(ISourcePort sourcePort)
        {
            m_directory = sourcePort.Directory.GetPossiblyRelativePath();
            m_exec      = sourcePort.Executable;

            txtName.Text = txtExec.Text = txtExtensions.Text = txtFileOption.Text
                                                                   = txtParameters.Text = string.Empty;

            if (!string.IsNullOrEmpty(sourcePort.Name))
            {
                txtName.Text = sourcePort.Name;
            }
            if (sourcePort.Directory != null && sourcePort.Executable != null)
            {
                txtExec.Text = sourcePort.Executable;
            }
            if (!string.IsNullOrEmpty(sourcePort.SupportedExtensions))
            {
                txtExtensions.Text = sourcePort.SupportedExtensions;
            }
            if (!string.IsNullOrEmpty(sourcePort.FileOption))
            {
                txtFileOption.Text = sourcePort.FileOption;
            }
            if (!string.IsNullOrEmpty(sourcePort.ExtraParameters))
            {
                txtParameters.Text = sourcePort.ExtraParameters;
            }
        }
        public void InsertSourcePort(ISourcePort sourcePort)
        {
            string insert = @"insert into SourcePorts (Name,Executable,SupportedExtensions,Directory,SettingsFiles,LaunchType,FileOption,ExtraParameters) 
                values(@Name,@Executable,@SupportedExtensions,@Directory,@SettingsFiles,@LaunchType,@FileOption,@ExtraParameters)";

            DataAccess.ExecuteNonQuery(insert, GetSourcePortParams(sourcePort));
        }
        public IEnumerable <IFileData> HandleNewScreenshots(ISourcePort sourcePort, IGameFile gameFile, string[] files)
        {
            List <IFileData> ret = new List <IFileData>();

            if (gameFile != null && gameFile.GameFileID.HasValue)
            {
                foreach (string file in files)
                {
                    try
                    {
                        FileInfo fi       = new FileInfo(file);
                        string   fileName = Guid.NewGuid().ToString() + fi.Extension;
                        fi.CopyTo(Path.Combine(ScreenshotDirectory.GetFullPath(), fileName));
                        FileData fileData = new FileData();
                        fileData.FileName     = fileName;
                        fileData.GameFileID   = gameFile.GameFileID.Value;
                        fileData.SourcePortID = sourcePort.SourcePortID;
                        fileData.FileTypeID   = FileType.Screenshot;

                        DataSourceAdapter.InsertFile(fileData);
                        ret.Add(fileData);
                    }
                    catch
                    {
                        //failed, nothing to do
                    }
                }
            }

            return(ret);
        }
        private void HandleCopySaveGames(IGameFile gameFile, ISourcePort sourcePort)
        {
            m_saveGames = DataSourceAdapter.GetFiles(gameFile, FileType.SaveGame).ToArray();
            SaveGameHandler saveGameHandler = new SaveGameHandler(DataSourceAdapter, AppConfiguration.SaveGameDirectory);

            saveGameHandler.CopySaveGamesToSourcePort(sourcePort, m_saveGames);
        }
        public void CalculateAdditionalFiles(IGameFile iwad, ISourcePort sourcePort)
        {
            SetExtraAdditionalFilesFromSettings(iwad, sourcePort);

            IGameFile   lastIwad       = m_selectedIWad;
            ISourcePort lastSourcePort = m_selectedSourcePort;

            if (lastIwad == null)
            {
                lastIwad = iwad;
            }
            if (lastSourcePort == null)
            {
                lastSourcePort = sourcePort;
            }

            List <IGameFile> gameFiles    = m_currentFiles;
            List <IGameFile> originalList = gameFiles.ToList();
            List <IGameFile> newTypeFiles = GetAdditionalFiles(iwad, sourcePort);
            List <IGameFile> oldTypeFiles = GetAdditionalFiles(lastIwad, lastSourcePort);

            gameFiles.RemoveAll(x => oldTypeFiles.Contains(x));

            gameFiles.AddRange(newTypeFiles);

            gameFiles         = SortByOriginal(gameFiles, originalList);
            m_currentFiles    = gameFiles.Distinct().ToList();
            m_currentNewFiles = gameFiles.Except(originalList).ToList();

            m_selectedIWad       = iwad;
            m_selectedSourcePort = sourcePort;
        }
Beispiel #6
0
        private void BuildLaunchString(StringBuilder sb, ISourcePort sourcePort, List <string> files)
        {
            string[]      dehExt   = new string[] { ".deh", ".bex" }; //future - should be configurable
            List <string> dehFiles = new List <string>();

            if (files.Count > 0)
            {
                sb.Append(sourcePort.FileParameter(new SpData()));
                //if (!string.IsNullOrEmpty(sourcePort.FileOption))
                //    sb.Append(string.Concat(" ", sourcePort.FileOption, " ")); //" -file "

                foreach (string str in files)
                {
                    FileInfo fi = new FileInfo(str);
                    if (!dehExt.Contains(fi.Extension.ToLower()))
                    {
                        sb.Append(string.Format("\"{0}\" ", str));
                    }
                    else
                    {
                        dehFiles.Add(str);
                    }
                }
            }

            if (dehFiles.Count > 0)
            {
                sb.Append(" -deh ");

                foreach (string str in dehFiles)
                {
                    sb.Append(string.Format("\"{0}\" ", str));
                }
            }
        }
        private void SetDefaultSelections()
        {
            int    port  = (int)AppConfiguration.GetTypedConfigValue(ConfigType.DefaultSourcePort, typeof(int));
            int    iwad  = (int)AppConfiguration.GetTypedConfigValue(ConfigType.DefaultIWad, typeof(int));
            string skill = (string)AppConfiguration.GetTypedConfigValue(ConfigType.DefaultSkill, typeof(string));

            ISourcePort sourcePort = DataSourceAdapter.GetSourcePorts().FirstOrDefault(x => x.SourcePortID == port);

            if (sourcePort != null)
            {
                m_currentPlayForm.SelectedSourcePort = sourcePort;
            }

            IIWadData iwadSource = DataSourceAdapter.GetIWads().FirstOrDefault(x => x.IWadID == Convert.ToInt32(iwad));

            if (iwadSource != null)
            {
                GameFileGetOptions      options      = new GameFileGetOptions(new GameFileSearchField(GameFileFieldType.GameFileID, iwadSource.GameFileID.Value.ToString()));
                IEnumerable <IGameFile> gameFileIwad = DataSourceAdapter.GetGameFiles(options);
                if (gameFileIwad.Any())
                {
                    m_currentPlayForm.SelectedIWad = gameFileIwad.First();
                }
            }

            if (skill != null)
            {
                m_currentPlayForm.SelectedSkill = skill;
            }
        }
Beispiel #8
0
        private void BuildLaunchString(StringBuilder sb, ISourcePort sourcePort, List <string> files)
        {
            List <string> dehFiles = new List <string>();

            if (files.Count > 0)
            {
                sb.Append(sourcePort.FileParameter(new SpData()));
                var dehExtensions = Util.GetDehackedExtensions();

                foreach (string str in files)
                {
                    FileInfo fi = new FileInfo(str);
                    if (!dehExtensions.Contains(fi.Extension.ToLower()))
                    {
                        sb.Append(string.Format("\"{0}\" ", str));
                    }
                    else
                    {
                        dehFiles.Add(str);
                    }
                }
            }

            if (dehFiles.Count > 0)
            {
                sb.Append(" -deh ");

                foreach (string str in dehFiles)
                {
                    sb.Append(string.Format("\"{0}\" ", str));
                }
            }
        }
Beispiel #9
0
        public void CopySaveGamesToSourcePort(ISourcePort sourcePort, IFileData[] files)
        {
            files = files.Where(x => x.SourcePortID == sourcePort.SourcePortID).ToArray();

            foreach (IFileData file in files)
            {
                string   fileName = Path.Combine(sourcePort.Directory.GetFullPath(), file.OriginalFileName);
                FileInfo fiFrom   = new FileInfo(Path.Combine(SaveGameDirectory.GetFullPath(), file.FileName));
                try
                {
                    if (fiFrom.Exists)
                    {
                        DirectoryInfo di = new DirectoryInfo(Path.Combine(sourcePort.Directory.GetFullPath(), file.OriginalFilePath));

                        if (!di.Exists)
                        {
                            di.Create();
                        }

                        fiFrom.CopyTo(fileName);
                    }
                }
                catch
                {
                    //failed, nothing to do
                }
            }
        }
        private List <IGameFile> GetAdditionalFiles(IGameFile gameIwad, ISourcePort sourcePort)
        {
            IEnumerable <IGameFile> exclude = new IGameFile[] { m_gameFile };

            return(GetAdditionalFiles(AddFilesType.IWAD, gameIwad, sourcePort)
                   .Union(GetAdditionalFiles(AddFilesType.SourcePort, gameIwad, sourcePort))
                   .Except(exclude).ToList());
        }
Beispiel #11
0
        private List <IGameFile> GetAdditionalFiles(IGameFile gameIwad, ISourcePort sourcePort)
        {
            var iwadExclude = Util.GetSourcePortAdditionalFiles(m_adapter, gameIwad);

            return(GetAdditionalFiles(AddFilesType.IWAD, gameIwad, sourcePort).Except(iwadExclude)
                   .Union(GetAdditionalFiles(AddFilesType.SourcePort, gameIwad, sourcePort))
                   .Except(new IGameFile[] { m_gameFile }).ToList());
        }
        public void UpdateSourcePort(ISourcePort sourcePort)
        {
            string query = @"update SourcePorts set 
            Name = @Name, Executable = @Executable, SupportedExtensions = @SupportedExtensions,
            Directory = @Directory, SettingsFiles = @SettingsFiles, LaunchType = @LaunchType, FileOption = @FileOption, ExtraParameters = @ExtraParameters
            where SourcePortID = @sourcePortID";

            DataAccess.ExecuteNonQuery(query, GetSourcePortParams(sourcePort));
        }
 public void UpdateDataSource(ISourcePort sourcePort)
 {
     sourcePort.Name                = txtName.Text;
     sourcePort.Directory           = new LauncherPath(m_directory);
     sourcePort.Executable          = m_exec;
     sourcePort.SupportedExtensions = txtExtensions.Text;
     sourcePort.FileOption          = txtFileOption.Text;
     sourcePort.ExtraParameters     = txtParameters.Text;
 }
        private void CreateFileDetectors(ISourcePort sourcePort)
        {
            m_screenshotDetectors = CreateDefaultScreenshotDetectors();
            m_screenshotDetectors.Add(CreateScreenshotDetector(sourcePort.Directory.GetFullPath()));
            Array.ForEach(m_screenshotDetectors.ToArray(), x => x.StartDetection());

            m_saveFileDetectors = CreateDefaulSaveGameDetectors();
            m_saveFileDetectors.Add(CreateSaveGameDetector(sourcePort.Directory.GetFullPath()));
            Array.ForEach(m_saveFileDetectors.ToArray(), x => x.StartDetection());
        }
Beispiel #15
0
        public static string[] GetSupportedExtensions(ISourcePort sourcePort)
        {
            string[] supportedExtensions = new string[] { };

            if (sourcePort != null)
            {
                supportedExtensions = sourcePort.SupportedExtensions.Split(new string[] { ", ", "," }, StringSplitOptions.RemoveEmptyEntries);
            }

            return(supportedExtensions);
        }
Beispiel #16
0
        public override bool Equals(object obj)
        {
            ISourcePort sourcePort = obj as ISourcePort;

            if (sourcePort != null)
            {
                return(sourcePort.SourcePortID == SourcePortID);
            }

            return(false);
        }
 private void CopySaveGames(IGameFile gameFile, ISourcePort sourcePort)
 {
     if (gameFile != null) //BUG: what if it's iwad?
     {
         HandleCopySaveGames(gameFile, sourcePort);
     }
     else if (IsGameFileIwad(gameFile))
     {
         gameFile = GetGameFileForIWad(gameFile);
         HandleCopySaveGames(gameFile, sourcePort);
     }
 }
Beispiel #18
0
        private void PopulateDemos()
        {
            ISourcePort sourcePort = cmbSourcePorts.SelectedItem as ISourcePort;

            if (GameFile.GameFileID.HasValue)
            {
                IEnumerable <IFileData> demoFiles = m_adapter.GetFiles(GameFile, FileType.Demo)
                                                    .Where(x => x.SourcePortID == sourcePort.SourcePortID);

                cmbDemo.DataSource = demoFiles.ToList();
            }
        }
Beispiel #19
0
        private void cmbSourcePorts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbSourcePorts.SelectedItem != null && GameFile != null)
            {
                PopulateDemos();
                ISourcePort sourcePort = cmbSourcePorts.SelectedItem as ISourcePort;
                chkSaveStats.Enabled = SaveStatisticsSupported(sourcePort);
                AddExtraAdditionalFiles();
            }

            m_lastSourcePort = SelectedSourcePort;
        }
        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();
            }
        }
        private void SetExtraAdditionalFilesFromSettings(IGameFile iwad, ISourcePort sourcePort)
        {
            m_iwadAdditionalFiles.Clear();
            m_sourcePortAdditionalFiles.Clear();

            if (iwad != null)
            {
                if (!iwad.Equals(m_gameFile))
                {
                    m_iwadAdditionalFiles = GetAdditionalFiles(AddFilesType.IWAD, iwad, sourcePort);
                }
                m_sourcePortAdditionalFiles = GetAdditionalFiles(AddFilesType.SourcePort, iwad, sourcePort);
            }
        }
        public static bool Supported(ISourcePort sourcePort)
        {
            string exe = sourcePort.Executable.ToLower();

            if (exe.Contains("zdoom.exe"))
            {
                return(true);
            }
            if (exe.Contains("zandronum.exe"))
            {
                return(true);
            }

            return(false);
        }
        public static ISourcePort CreateSourcePort(ISourcePortData sourcePortData)
        {
            ISourcePort[] sourcePorts = new ISourcePort[]
            {
                new ZDoomSourcePort(sourcePortData),
                new BoomSourcePort(sourcePortData),
                new DoomsdaySourcePort(sourcePortData),
                new CNDoomSourcePort(sourcePortData),
                new ChocolateDoomSourcePort(sourcePortData),
                new CrispyDoomSourcePort(sourcePortData),
                new GenericSourcePort(sourcePortData)
            };

            return(sourcePorts.First(x => x.Supported()));
        }
Beispiel #24
0
        private void ctrlFiles_CellFormatting(object sender, AdditionalFilesEventArgs e)
        {
            IGameFile   gameFile = e.Item as IGameFile;
            IGameFile   iwad     = SelectedIWad;
            ISourcePort port     = cmbSourcePorts.SelectedValue as ISourcePort;

            if (m_handler.IsIWadFile(gameFile))
            {
                e.DisplayText = string.Format("{0} ({1})", gameFile.FileName, Util.RemoveExtension(iwad.FileName));
            }
            if (m_handler.IsSourcePortFile(gameFile))
            {
                e.DisplayText = string.Format("{0} ({1})", gameFile.FileName, port.Name);
            }
        }
Beispiel #25
0
        private int?GetSourcePort(string port)
        {
            ISourcePort sp = m_sourcePorts.FirstOrDefault(x => x.Name.Equals(port, StringComparison.InvariantCultureIgnoreCase));

            if (sp == null)
            {
                m_errors.Add(string.Format("Could not find Source Port - {0}", port));
            }

            if (sp != null)
            {
                return(sp.SourcePortID);
            }

            return(null);
        }
        private List <DbParameter> GetSourcePortParams(ISourcePort sourcePort)
        {
            List <DbParameter> parameters = new List <DbParameter>();

            parameters.Add(DataAccess.DbAdapter.CreateParameter("Name", sourcePort.Name == null ? string.Empty : sourcePort.Name));
            parameters.Add(DataAccess.DbAdapter.CreateParameter("Executable", sourcePort.Executable == null ? string.Empty : sourcePort.Executable));
            parameters.Add(DataAccess.DbAdapter.CreateParameter("SupportedExtensions", sourcePort.SupportedExtensions == null ? string.Empty : sourcePort.SupportedExtensions));
            parameters.Add(DataAccess.DbAdapter.CreateParameter("Directory", sourcePort.Directory == null ? string.Empty : sourcePort.Directory.GetPossiblyRelativePath()));
            parameters.Add(DataAccess.DbAdapter.CreateParameter("SettingsFiles", sourcePort.SettingsFiles == null ? string.Empty : sourcePort.SettingsFiles));
            parameters.Add(DataAccess.DbAdapter.CreateParameter("SourcePortID", sourcePort.SourcePortID));
            parameters.Add(DataAccess.DbAdapter.CreateParameter("LaunchType", sourcePort.LaunchType));
            parameters.Add(DataAccess.DbAdapter.CreateParameter("FileOption", sourcePort.FileOption == null ? string.Empty : sourcePort.FileOption));
            parameters.Add(DataAccess.DbAdapter.CreateParameter("ExtraParameters", sourcePort.ExtraParameters == null ? string.Empty : sourcePort.ExtraParameters));

            return(parameters);
        }
        private void HandlePlay(IEnumerable <IGameFile> gameFiles, ISourcePort sourcePort)
        {
            LaunchData launchData = GetLaunchFiles(gameFiles);

            if (launchData.Success)
            {
                if (launchData.GameFile == null)
                {
                    var iwad = DataSourceAdapter.GetIWad((int)AppConfiguration.GetTypedConfigValue(ConfigType.DefaultIWad, typeof(int)));
                    if (iwad != null)
                    {
                        GameFileGetOptions options = new GameFileGetOptions(new GameFileSearchField(GameFileFieldType.GameFileID, iwad.GameFileID.Value.ToString()));
                        launchData.GameFile = DataSourceAdapter.GetGameFiles(options).FirstOrDefault();
                    }
                }

                if (launchData.GameFile != null)
                {
                    SetupPlayForm(launchData.GameFile);
                    if (sourcePort != null)
                    {
                        m_currentPlayForm.SelectedSourcePort = sourcePort;
                    }

                    if (m_currentPlayForm.ShowDialog(this) == DialogResult.OK)
                    {
                        try
                        {
                            HandlePlaySettings(m_currentPlayForm, launchData.GameFile);
                            if (m_currentPlayForm.SelectedSourcePort != null)
                            {
                                m_playInProgress = StartPlay(launchData.GameFile, m_currentPlayForm.SelectedSourcePort);
                            }
                        }
                        catch (IOException)
                        {
                            MessageBox.Show(this, "The file is in use and cannot be launched. Please close any programs that may be using the file and try again.", "File In Use",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(launchData.ErrorTitle))
            {
                MessageBox.Show(this, launchData.ErrorTitle, launchData.ErrorDescription, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void HandleEdit()
        {
            if (SelectedItem != null)
            {
                SourcePortEditForm editForm   = new SourcePortEditForm(m_adapter, m_tabViews, m_launchType);
                ISourcePort        sourcePort = SelectedItem;
                editForm.SetDataSource(sourcePort);
                editForm.StartPosition = FormStartPosition.CenterParent;

                if (editForm.ShowDialog(this) == DialogResult.OK)
                {
                    editForm.UpdateDataSource(sourcePort);
                    m_adapter.UpdateSourcePort(sourcePort);
                    ResetData();
                }
            }
        }
Beispiel #29
0
        private bool SaveStatisticsSupported(ISourcePort sourcePort)
        {
            if (BoomStatsReader.Supported(sourcePort))
            {
                return(true);
            }
            if (ZDoomStatsReader.Supported(sourcePort))
            {
                return(true);
            }
            if (CNDoomStatsReader.Supported(sourcePort))
            {
                return(true);
            }

            return(false);
        }
Beispiel #30
0
        public void HandleUpdateSaveGames(ISourcePort sourcePort, IGameFile gameFile, IFileData[] files)
        {
            foreach (IFileData file in files)
            {
                FileInfo fi = new FileInfo(Path.Combine(sourcePort.Directory.GetFullPath(), file.OriginalFileName));

                if (fi.Exists)
                {
                    try
                    {
                        fi.CopyTo(Path.Combine(SaveGameDirectory.GetFullPath(), file.FileName), true);
                    }
                    catch
                    {
                        //failed, nothing to do
                    }
                }
            }
        }