Revert "cleanup ArgParser"
This reverts commit 84593b2d48
.
magical fix to magically broken avi dumping
This commit is contained in:
parent
a03ed17c8a
commit
c330541c35
|
@ -5,35 +5,35 @@ using System.IO;
|
|||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
// parses command line arguments and adds the values to a class attribute
|
||||
// default values are null for strings and false for boolean
|
||||
// the last value will overwrite previously set values
|
||||
// unrecognized parameters are simply ignored or in the worst case assumed to be a ROM name [cmdRom]
|
||||
public class ArgParser
|
||||
//parses command line arguments and adds the values to a class attribute
|
||||
//default values are null for strings and false for boolean
|
||||
//the last value will overwrite previously set values
|
||||
//unrecognized parameters are simply ignored or in the worst case assumed to be a ROM name [cmdRom]
|
||||
{
|
||||
public string CmdRom { get; set; }
|
||||
public string CmdLoadSlot { get; set; }
|
||||
public string CmdLoadState { get; set; }
|
||||
public string CmdConfigFile { get; set; }
|
||||
public string CmdMovie { get; set; }
|
||||
public string CmdDumpType { get; set; }
|
||||
public string CmdDumpName { get; set; }
|
||||
public HashSet<int> CurrAviWriterFrameList { get; set; } = new HashSet<int>();
|
||||
public int AutoDumpLength { get; set; }
|
||||
public bool AutoCloseOnDump { get; set; }
|
||||
|
||||
public string cmdRom = null;
|
||||
public string cmdLoadSlot = null;
|
||||
public string cmdLoadState = null;
|
||||
public string cmdConfigPath = null;
|
||||
public string cmdConfigFile = null;
|
||||
public string cmdMovie = null;
|
||||
public string cmdDumpType = null;
|
||||
public string cmdDumpName = null;
|
||||
public HashSet<int> _currAviWriterFrameList;
|
||||
public int _autoDumpLength;
|
||||
public bool _autoCloseOnDump = false;
|
||||
// chrome is never shown, even in windowed mode
|
||||
public bool Chromeless { get; set; }
|
||||
public bool StartFullscreen { get; set; }
|
||||
public string LuaScript { get; set; }
|
||||
public bool LuaConsole { get; set; }
|
||||
public bool PrintVersion { get; set; }
|
||||
public int SocketPort { get; set; }
|
||||
public string SocketIp { get; set; }
|
||||
public string MmfFilename { get; set; }
|
||||
public string UrlGet { get; set; }
|
||||
public string UrlPost { get; set; }
|
||||
public bool? AudioSync { get; set; }
|
||||
public bool _chromeless = false;
|
||||
public bool startFullscreen = false;
|
||||
public string luaScript = null;
|
||||
public bool luaConsole = false;
|
||||
public bool printVersion = false;
|
||||
public int socket_port = 0;
|
||||
public string socket_ip = null;
|
||||
public string mmf_filename = null;
|
||||
public string URL_get = null;
|
||||
public string URL_post = null;
|
||||
public bool? audiosync = null;
|
||||
|
||||
/// <exception cref="ArgParserException"><c>--socket_ip</c> passed without specifying <c>--socket_port</c> or vice-versa</exception>
|
||||
public void ParseArguments(string[] args)
|
||||
|
@ -52,139 +52,131 @@ namespace BizHawk.Client.EmuHawk
|
|||
var arg = args[i].ToLower();
|
||||
if (arg.StartsWith("--load-slot="))
|
||||
{
|
||||
CmdLoadSlot = arg.Substring(arg.IndexOf('=') + 1);
|
||||
cmdLoadSlot = arg.Substring(arg.IndexOf('=') + 1);
|
||||
}
|
||||
|
||||
if (arg.StartsWith("--load-state="))
|
||||
{
|
||||
CmdLoadState = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
cmdLoadState = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
}
|
||||
if (arg.StartsWith("--config="))
|
||||
{
|
||||
CmdConfigFile = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
cmdConfigFile = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
}
|
||||
else if (arg.StartsWith("--movie="))
|
||||
{
|
||||
CmdMovie = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
cmdMovie = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
}
|
||||
else if (arg.StartsWith("--dump-type="))
|
||||
{
|
||||
CmdDumpType = arg.Substring(arg.IndexOf('=') + 1);
|
||||
cmdDumpType = arg.Substring(arg.IndexOf('=') + 1);
|
||||
}
|
||||
else if (arg.StartsWith("--dump-frames="))
|
||||
{
|
||||
string list = arg.Substring(arg.IndexOf('=') + 1);
|
||||
string[] items = list.Split(',');
|
||||
CurrAviWriterFrameList = new HashSet<int>();
|
||||
_currAviWriterFrameList = new HashSet<int>();
|
||||
foreach (string item in items)
|
||||
{
|
||||
CurrAviWriterFrameList.Add(int.Parse(item));
|
||||
_currAviWriterFrameList.Add(int.Parse(item));
|
||||
}
|
||||
|
||||
// automatically set dump length to maximum frame
|
||||
AutoDumpLength = CurrAviWriterFrameList.OrderBy(x => x).Last();
|
||||
_autoDumpLength = _currAviWriterFrameList.OrderBy(x => x).Last();
|
||||
}
|
||||
else if (arg.StartsWith("--version"))
|
||||
{
|
||||
PrintVersion = true;
|
||||
printVersion = true;
|
||||
}
|
||||
else if (arg.StartsWith("--dump-name="))
|
||||
{
|
||||
CmdDumpName = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
cmdDumpName = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
}
|
||||
else if (arg.StartsWith("--dump-length="))
|
||||
{
|
||||
if (int.TryParse(arg.Substring(arg.IndexOf('=') + 1), out int autoDumpLength))
|
||||
{
|
||||
AutoDumpLength = autoDumpLength;
|
||||
}
|
||||
int.TryParse(arg.Substring(arg.IndexOf('=') + 1), out _autoDumpLength);
|
||||
}
|
||||
else if (arg.StartsWith("--dump-close"))
|
||||
{
|
||||
AutoCloseOnDump = true;
|
||||
_autoCloseOnDump = true;
|
||||
}
|
||||
else if (arg.StartsWith("--chromeless"))
|
||||
{
|
||||
Chromeless = true;
|
||||
_chromeless = true;
|
||||
}
|
||||
else if (arg.StartsWith("--fullscreen"))
|
||||
{
|
||||
StartFullscreen = true;
|
||||
startFullscreen = true;
|
||||
}
|
||||
else if (arg.StartsWith("--lua="))
|
||||
{
|
||||
LuaScript = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
LuaConsole = true;
|
||||
luaScript = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
luaConsole = true;
|
||||
}
|
||||
else if (arg.StartsWith("--luaconsole"))
|
||||
{
|
||||
LuaConsole = true;
|
||||
luaConsole = true;
|
||||
}
|
||||
else if (arg.StartsWith("--socket_port="))
|
||||
{
|
||||
if (int.TryParse(arg.Substring(arg.IndexOf('=') + 1), out int socketPort))
|
||||
{
|
||||
SocketPort = socketPort;
|
||||
}
|
||||
int.TryParse(arg.Substring(arg.IndexOf('=') + 1), out socket_port);
|
||||
}
|
||||
else if (arg.StartsWith("--socket_ip="))
|
||||
{
|
||||
SocketIp = arg.Substring(arg.IndexOf('=') + 1);
|
||||
socket_ip = arg.Substring(arg.IndexOf('=') + 1);
|
||||
}
|
||||
else if (arg.StartsWith("--mmf="))
|
||||
{
|
||||
MmfFilename = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
mmf_filename = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
}
|
||||
else if (arg.StartsWith("--url_get="))
|
||||
{
|
||||
UrlGet = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
URL_get = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
}
|
||||
else if (arg.StartsWith("--url_post="))
|
||||
{
|
||||
UrlPost = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
URL_post = args[i].Substring(args[i].IndexOf('=') + 1);
|
||||
}
|
||||
else if (arg.StartsWith("--audiosync="))
|
||||
{
|
||||
AudioSync = arg.Substring(arg.IndexOf('=') + 1) == "true";
|
||||
audiosync = arg.Substring(arg.IndexOf('=') + 1) == "true";
|
||||
}
|
||||
else
|
||||
{
|
||||
CmdRom = args[i];
|
||||
cmdRom = args[i];
|
||||
}
|
||||
}
|
||||
|
||||
// initialize HTTP communication
|
||||
if (UrlGet != null || UrlPost != null)
|
||||
//initialize HTTP communication
|
||||
if (URL_get != null || URL_post != null)
|
||||
{
|
||||
GlobalWin.httpCommunication = new Communication.HttpCommunication();
|
||||
if (UrlGet != null)
|
||||
if (URL_get != null)
|
||||
{
|
||||
GlobalWin.httpCommunication.GetUrl = UrlGet;
|
||||
GlobalWin.httpCommunication.GetUrl = URL_get;
|
||||
}
|
||||
if (UrlPost != null)
|
||||
if (URL_post != null)
|
||||
{
|
||||
GlobalWin.httpCommunication.PostUrl = UrlPost;
|
||||
GlobalWin.httpCommunication.PostUrl = URL_post;
|
||||
}
|
||||
}
|
||||
|
||||
// initialize socket server
|
||||
if (SocketIp != null && SocketPort > 0)
|
||||
if (socket_ip != null && socket_port > 0)
|
||||
{
|
||||
GlobalWin.socketServer = new Communication.SocketServer();
|
||||
GlobalWin.socketServer.SetIp(SocketIp, SocketPort);
|
||||
GlobalWin.socketServer.SetIp(socket_ip, socket_port);
|
||||
}
|
||||
else if (SocketIp == null ^ SocketPort == 0)
|
||||
else if (socket_ip == null ^ socket_port == 0)
|
||||
{
|
||||
throw new ArgParserException("Socket server needs both --socket_ip and --socket_port. Socket server was not started");
|
||||
}
|
||||
|
||||
// initialize mapped memory files
|
||||
if (MmfFilename != null)
|
||||
//initialize mapped memory files
|
||||
if (mmf_filename != null)
|
||||
{
|
||||
GlobalWin.memoryMappedFiles = new Communication.MemoryMappedFiles
|
||||
{
|
||||
Filename = MmfFilename
|
||||
};
|
||||
GlobalWin.memoryMappedFiles = new Communication.MemoryMappedFiles();
|
||||
GlobalWin.memoryMappedFiles.Filename = mmf_filename;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +185,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
return args.FirstOrDefault(arg => arg.StartsWith("--config=", StringComparison.InvariantCultureIgnoreCase))?.Substring(9);
|
||||
}
|
||||
}
|
||||
|
||||
public class ArgParserException : Exception
|
||||
{
|
||||
public ArgParserException(string message) : base(message)
|
||||
|
|
|
@ -2966,7 +2966,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
bool showMenuVisible = _inFullscreen || !MainMenuStrip.Visible; // need to always be able to restore this as an emergency measure
|
||||
|
||||
if (_argParser.Chromeless)
|
||||
if (_argParser._chromeless)
|
||||
{
|
||||
showMenuVisible = true; // I decided this was always possible in chrome-less mode, we'll see what they think
|
||||
}
|
||||
|
|
|
@ -370,14 +370,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
Location = new Point(Config.MainWndx, Config.MainWndy);
|
||||
}
|
||||
|
||||
if (_argParser.CmdRom != null)
|
||||
if (_argParser.cmdRom != null)
|
||||
{
|
||||
// Commandline should always override auto-load
|
||||
var ioa = OpenAdvancedSerializer.ParseWithLegacy(_argParser.CmdRom);
|
||||
LoadRom(_argParser.CmdRom, new LoadRomArgs { OpenAdvanced = ioa });
|
||||
var ioa = OpenAdvancedSerializer.ParseWithLegacy(_argParser.cmdRom);
|
||||
LoadRom(_argParser.cmdRom, new LoadRomArgs { OpenAdvanced = ioa });
|
||||
if (Game == null)
|
||||
{
|
||||
MessageBox.Show($"Failed to load {_argParser.CmdRom} specified on commandline");
|
||||
MessageBox.Show($"Failed to load {_argParser.cmdRom} specified on commandline");
|
||||
}
|
||||
}
|
||||
else if (Config.RecentRoms.AutoLoad && !Config.RecentRoms.Empty)
|
||||
|
@ -385,12 +385,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
LoadRomFromRecent(Config.RecentRoms.MostRecent);
|
||||
}
|
||||
|
||||
if (_argParser.AudioSync.HasValue)
|
||||
if (_argParser.audiosync.HasValue)
|
||||
{
|
||||
Config.VideoWriterAudioSync = _argParser.AudioSync.Value;
|
||||
Config.VideoWriterAudioSync = _argParser.audiosync.Value;
|
||||
}
|
||||
|
||||
if (_argParser.CmdMovie != null)
|
||||
if (_argParser.cmdMovie != null)
|
||||
{
|
||||
_suppressSyncSettingsWarning = true; // We don't want to be nagged if we are attempting to automate
|
||||
if (Game == null)
|
||||
|
@ -401,24 +401,24 @@ namespace BizHawk.Client.EmuHawk
|
|||
// If user picked a game, then do the commandline logic
|
||||
if (!Game.IsNullInstance())
|
||||
{
|
||||
var movie = MovieService.Get(_argParser.CmdMovie);
|
||||
var movie = MovieService.Get(_argParser.cmdMovie);
|
||||
MovieSession.ReadOnly = true;
|
||||
|
||||
// if user is dumping and didn't supply dump length, make it as long as the loaded movie
|
||||
if (_argParser.AutoDumpLength == 0)
|
||||
if (_argParser._autoDumpLength == 0)
|
||||
{
|
||||
_argParser.AutoDumpLength = movie.InputLogLength;
|
||||
_argParser._autoDumpLength = movie.InputLogLength;
|
||||
}
|
||||
|
||||
// Copy pasta from drag & drop
|
||||
if (MovieImport.IsValidMovieExtension(Path.GetExtension(_argParser.CmdMovie)))
|
||||
if (MovieImport.IsValidMovieExtension(Path.GetExtension(_argParser.cmdMovie)))
|
||||
{
|
||||
ProcessMovieImport(_argParser.CmdMovie, true);
|
||||
ProcessMovieImport(_argParser.cmdMovie, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartNewMovie(movie, false);
|
||||
Config.RecentMovies.Add(_argParser.CmdMovie);
|
||||
Config.RecentMovies.Add(_argParser.cmdMovie);
|
||||
}
|
||||
|
||||
_suppressSyncSettingsWarning = false;
|
||||
|
@ -445,20 +445,20 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
if (_argParser.StartFullscreen || Config.StartFullscreen)
|
||||
if (_argParser.startFullscreen || Config.StartFullscreen)
|
||||
{
|
||||
_needsFullscreenOnLoad = true;
|
||||
}
|
||||
|
||||
if (!Game.IsNullInstance())
|
||||
{
|
||||
if (_argParser.CmdLoadState != null)
|
||||
if (_argParser.cmdLoadState != null)
|
||||
{
|
||||
LoadState(_argParser.CmdLoadState, Path.GetFileName(_argParser.CmdLoadState));
|
||||
LoadState(_argParser.cmdLoadState, Path.GetFileName(_argParser.cmdLoadState));
|
||||
}
|
||||
else if (_argParser.CmdLoadSlot != null)
|
||||
else if (_argParser.cmdLoadSlot != null)
|
||||
{
|
||||
LoadQuickSave($"QuickSave{_argParser.CmdLoadSlot}");
|
||||
LoadQuickSave($"QuickSave{_argParser.cmdLoadSlot}");
|
||||
}
|
||||
else if (Config.AutoLoadLastSaveSlot)
|
||||
{
|
||||
|
@ -467,15 +467,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
//start Lua Console if requested in the command line arguments
|
||||
if (_argParser.LuaConsole)
|
||||
if (_argParser.luaConsole)
|
||||
{
|
||||
Tools.Load<LuaConsole>();
|
||||
}
|
||||
//load Lua Script if requested in the command line arguments
|
||||
if (_argParser.LuaScript != null)
|
||||
if (_argParser.luaScript != null)
|
||||
{
|
||||
if (OSTailoredCode.IsUnixHost) Console.WriteLine($"The Lua environment can currently only be created on Windows, {_argParser.LuaScript} will not be loaded.");
|
||||
else Tools.LuaConsole.LoadLuaFile(_argParser.LuaScript);
|
||||
if (OSTailoredCode.IsUnixHost) Console.WriteLine($"The Lua environment can currently only be created on Windows, {_argParser.luaScript} will not be loaded.");
|
||||
else Tools.LuaConsole.LoadLuaFile(_argParser.luaScript);
|
||||
}
|
||||
|
||||
SetStatusBar();
|
||||
|
@ -486,10 +486,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
// start dumping, if appropriate
|
||||
if (_argParser.CmdDumpType != null && _argParser.CmdDumpName != null)
|
||||
if (_argParser.cmdDumpType != null && _argParser.cmdDumpName != null)
|
||||
{
|
||||
if (OSTailoredCode.IsUnixHost) Console.WriteLine("A/V dump requires Win32 API calls, ignored");
|
||||
else RecordAv(_argParser.CmdDumpType, _argParser.CmdDumpName);
|
||||
else RecordAv(_argParser.cmdDumpType, _argParser.cmdDumpName);
|
||||
}
|
||||
|
||||
SetMainformMovieInfo();
|
||||
|
@ -517,7 +517,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
// Simply exit the program if the version is asked for
|
||||
if (_argParser.PrintVersion)
|
||||
if (_argParser.printVersion)
|
||||
{
|
||||
// Print the version
|
||||
Console.WriteLine(VersionInfo.GetEmuVersion());
|
||||
|
@ -1113,15 +1113,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
// TODO - maybe apply a hack tracked during fullscreen here to override it
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
MainMenuStrip.Visible = Config.DispChrome_MenuFullscreen && !_argParser.Chromeless;
|
||||
MainStatusBar.Visible = Config.DispChrome_StatusBarFullscreen && !_argParser.Chromeless;
|
||||
MainMenuStrip.Visible = Config.DispChrome_MenuFullscreen && !_argParser._chromeless;
|
||||
MainStatusBar.Visible = Config.DispChrome_StatusBarFullscreen && !_argParser._chromeless;
|
||||
}
|
||||
else
|
||||
{
|
||||
MainStatusBar.Visible = Config.DispChrome_StatusBarWindowed && !_argParser.Chromeless;
|
||||
MainMenuStrip.Visible = Config.DispChrome_MenuWindowed && !_argParser.Chromeless;
|
||||
MaximizeBox = MinimizeBox = Config.DispChrome_CaptionWindowed && !_argParser.Chromeless;
|
||||
if (Config.DispChrome_FrameWindowed == 0 || _argParser.Chromeless)
|
||||
MainStatusBar.Visible = Config.DispChrome_StatusBarWindowed && !_argParser._chromeless;
|
||||
MainMenuStrip.Visible = Config.DispChrome_MenuWindowed && !_argParser._chromeless;
|
||||
MaximizeBox = MinimizeBox = Config.DispChrome_CaptionWindowed && !_argParser._chromeless;
|
||||
if (Config.DispChrome_FrameWindowed == 0 || _argParser._chromeless)
|
||||
{
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
}
|
||||
|
@ -1552,7 +1552,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
if (!Config.DispChrome_CaptionWindowed || _argParser.Chromeless)
|
||||
if (!Config.DispChrome_CaptionWindowed || _argParser._chromeless)
|
||||
{
|
||||
str = "";
|
||||
}
|
||||
|
@ -3413,9 +3413,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
try
|
||||
{
|
||||
// is this the best time to handle this? or deeper inside?
|
||||
if (_argParser.CurrAviWriterFrameList != null)
|
||||
if (_argParser._currAviWriterFrameList != null)
|
||||
{
|
||||
if (!_argParser.CurrAviWriterFrameList.Contains(Emulator.Frame))
|
||||
if (!_argParser._currAviWriterFrameList.Contains(Emulator.Frame))
|
||||
{
|
||||
goto HANDLE_AUTODUMP;
|
||||
}
|
||||
|
@ -3498,13 +3498,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
HANDLE_AUTODUMP:
|
||||
if (_argParser.AutoDumpLength > 0)
|
||||
if (_argParser._autoDumpLength > 0)
|
||||
{
|
||||
_argParser.AutoDumpLength--;
|
||||
if (_argParser.AutoDumpLength == 0) // finish
|
||||
_argParser._autoDumpLength--;
|
||||
if (_argParser._autoDumpLength == 0) // finish
|
||||
{
|
||||
StopAv();
|
||||
if (_argParser.AutoCloseOnDump)
|
||||
if (_argParser._autoCloseOnDump)
|
||||
{
|
||||
_exitRequestPending = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue