mirror of
https://github.com/livingcomputermuseum/ContrAlto.git
synced 2026-03-01 09:31:03 +00:00
Initial commit of changes for 1.2.3. This includes:
- Scripting support: Allows for recording and playback of mouse/keyboard input and various system control actions. Simple (i.e. basic) scripting format. - Fix for stale packets left in ethernet input queue; packets received by pcap while Alto's receiver is off are discarded. - Mouse input made more accurate, and tweaked to avoid Alto microcode bug that causes erroneous mouse inputs under very rare circumstances on real hardware, but much more frequently under emulation. - Small code cleanup here and there. Moved many UI strings to resources, many more to go.
This commit is contained in:
66
Contralto/Scripting/ScriptReader.cs
Normal file
66
Contralto/Scripting/ScriptReader.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Contralto.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contralto.Scripting
|
||||
{
|
||||
public class ScriptReader
|
||||
{
|
||||
public ScriptReader(string scriptPath)
|
||||
{
|
||||
_scriptReader = new StreamReader(scriptPath);
|
||||
}
|
||||
|
||||
public ScriptAction ReadNext()
|
||||
{
|
||||
if (_scriptReader == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//
|
||||
// Read the next action from the script file,
|
||||
// skipping over comments and empty lines.
|
||||
//
|
||||
while (true)
|
||||
{
|
||||
if (_scriptReader.EndOfStream)
|
||||
{
|
||||
// End of the stream, return null to indicate this,
|
||||
// and close the stream.
|
||||
_scriptReader.Close();
|
||||
_scriptReader = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
string line = _scriptReader.ReadLine().Trim();
|
||||
|
||||
// Skip empty or comment lines.
|
||||
if (string.IsNullOrWhiteSpace(line) ||
|
||||
line.StartsWith("#"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return ScriptAction.Parse(line);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.Write(LogComponent.Scripting, "Invalid script; error: {0}.", e.Message);
|
||||
_scriptReader.Close();
|
||||
_scriptReader = null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private StreamReader _scriptReader;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user