Example #1
0
        /// <summary>
        /// Builds the argument line in order to start DOSBox.
        /// </summary>
        /// <param name="selectedGame">Game the user wants to start.</param>
        /// <param name="forSetupExe">
        /// Whether or not we are starting the game's setup utility or the game itself.
        /// </param>
        /// <param name="dosBoxExePath">The path to DOSBox.exe.</param>
        /// <param name="dosboxDefaultConfFilePath">The .conf file to use for DOSBox.</param>
        /// <param name="dosboxDefaultLangFilePath">The .lng file to use for DOSBox.</param>
        /// <returns>.</returns>
        public static string BuildArgs(Game selectedGame, bool forSetupExe, string dosBoxExePath, string dosboxDefaultConfFilePath, string dosboxDefaultLangFilePath)
        {
            if (selectedGame == null)
            {
                return(string.Empty);
            }
            var configFile = new DOSBoxConfigFile(selectedGame.DBConfPath);

            //Arguments string for DOSBox.exe
            string dosboxArgs = string.Empty;

            if (string.IsNullOrWhiteSpace(dosBoxExePath) == true || dosBoxExePath == "dosbox.exe isn't is the same directory as AmpShell.exe!" || File.Exists(dosBoxExePath) == false)
            {
                throw new FileNotFoundException("DOSBox not found!");
            }

            dosboxArgs += AddCustomConfigFile(selectedGame, dosboxDefaultConfFilePath);

            dosboxArgs += AddPrefsLangFile(dosboxDefaultLangFilePath);

            dosboxArgs += AddAdditionalCommands(selectedGame, forSetupExe, configFile);

            //corresponds to the Fullscreen checkbox in GameForm
            if (selectedGame.InFullScreen == true)
            {
                dosboxArgs += " -fullscreen";
            }

            //corresponds to the "no console" checkbox in the GameForm
            if (selectedGame.NoConsole == true)
            {
                dosboxArgs += " -noconsole";
            }

            //corresponds to the "quit on exit (only for .exe)" checkbox in the GameForm
            if (selectedGame.QuitOnExit == true)
            {
                dosboxArgs += " -exit";
            }

            return(dosboxArgs);
        }
Example #2
0
        private static string AddAdditionalCommands(Game selectedGame, bool forSetupExe, DOSBoxConfigFile configFile)
        {
            string dosboxArgs = string.Empty;

            if (configFile.IsAutoExecSectionUsed() == true)
            {
                return(dosboxArgs);
            }

            //The arguments for DOSBox begins with the game executable (.exe, .bat, or .com)
            if (string.IsNullOrWhiteSpace(selectedGame.DOSEXEPath) == false)
            {
                if (!forSetupExe)
                {
                    dosboxArgs = $"\"{selectedGame.DOSEXEPath}\"";
                }
                else
                {
                    dosboxArgs = $"\"{selectedGame.SetupEXEPath}\"";
                }
            }

            //the game directory mounted as C (if the DOSEXEPath is specified, the DOSEXEPath parent directory will be mounted as C: by DOSBox
            //hence the "else if" instead of "if".
            else if (string.IsNullOrWhiteSpace(selectedGame.Directory) == false)
            {
                dosboxArgs = $" -c \"mount c '{selectedGame.Directory}'\"";
            }

            //Path for the game's CD image (.bin, .cue, or .iso) mounted as D:
            if (string.IsNullOrWhiteSpace(selectedGame.CDPath) == false)
            {
                //put ' and not " after imgmount (or else the path will be misunderstood by DOSBox).
                if (selectedGame.CDIsAnImage == true)
                {
                    dosboxArgs += $" -c \"imgmount";
                    if (selectedGame.MountAsFloppy == true)
                    {
                        dosboxArgs += $" a '{selectedGame.CDPath}' -t floppy\"";
                    }
                    else
                    {
                        dosboxArgs += $" d '{selectedGame.CDPath}' -t iso\"";
                    }
                }
                else
                {
                    bool addedMountOptions;
                    if (selectedGame.UseIOCTL == true)
                    {
                        addedMountOptions = true;
                        dosboxArgs       += $" -c \"mount d '{selectedGame.CDPath}' -t cdrom -usecd 0 -ioctl";
                    }
                    else if (selectedGame.MountAsFloppy == true)
                    {
                        addedMountOptions = true;
                        dosboxArgs       += $" -c \"mount a '{selectedGame.CDPath}' -t floppy";
                    }
                    else
                    {
                        addedMountOptions = true;
                        dosboxArgs       += $" -c \"mount d '{selectedGame.CDPath}'";
                    }
                    if (string.IsNullOrWhiteSpace(selectedGame.CDLabel) == false && addedMountOptions)
                    {
                        dosboxArgs += $" -label {selectedGame.CDLabel}";
                    }
                    if (addedMountOptions)
                    {
                        dosboxArgs += '"';
                    }
                }
            }

            //Additional user commands for the game
            if (string.IsNullOrWhiteSpace(selectedGame.AdditionalCommands) == false)
            {
                dosboxArgs += $" {selectedGame.AdditionalCommands}";
            }

            return(dosboxArgs);
        }