1
0
mirror of https://github.com/livingcomputermuseum/ContrAlto.git synced 2026-03-01 17:36:14 +00:00
Files
livingcomputermuseum.ContrAlto/Contralto/Scripting/ScriptReader.cs
Josh Dersch d96d232fd3 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.
2018-03-20 14:16:07 -07:00

67 lines
1.7 KiB
C#

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;
}
}