Fix LogWindow treating everything as ascii

hopefully this doesn't break anything
This commit is contained in:
Morilli 2023-05-17 14:54:18 +02:00
parent f11b5bc9c4
commit 3d30f52e7c
2 changed files with 10 additions and 47 deletions

View File

@ -22,7 +22,7 @@ namespace BizHawk.Client.EmuHawk
// TODO: only show add to game db when this is a Rom details dialog
// Let user decide what type (instead of always adding it as a good dump)
private readonly List<string> _lines = new List<string>();
private LogStream _logStream;
private LogWriter _logWriter;
[RequiredService]
private IEmulator Emulator { get; set; }
@ -48,10 +48,9 @@ namespace BizHawk.Client.EmuHawk
private void Attach()
{
_logStream = new LogStream();
Log.HACK_LOG_STREAM = _logStream;
Console.SetOut(new StreamWriter(_logStream) { AutoFlush = true });
_logStream.Emit = appendInvoked;
_logWriter = new LogWriter();
Console.SetOut(_logWriter);
_logWriter.Emit = appendInvoked;
}
private void Detach()
@ -60,9 +59,8 @@ namespace BizHawk.Client.EmuHawk
{
AutoFlush = true
});
_logStream.Close();
_logStream = null;
Log.HACK_LOG_STREAM = null;
_logWriter.Close();
_logWriter = null;
}
public void ShowReport(string title, string report)
@ -208,47 +206,14 @@ namespace BizHawk.Client.EmuHawk
}
}
private class LogStream : Stream
private class LogWriter : TextWriter
{
public override bool CanRead => false;
public override bool CanSeek => false;
public override bool CanWrite => true;
public override void Flush()
public override void Write(char[] buffer, int offset, int count)
{
//TODO - maybe this will help with decoding
Emit(new string(buffer, offset, count));
}
public override long Length => throw new NotImplementedException();
public override long Position
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
public override int Read(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
// TODO - buffer undecoded characters (this may be important)
//(use decoder = System.Text.Encoding.Unicode.GetDecoder())
string str = Encoding.ASCII.GetString(buffer, offset, count);
Emit(str);
}
public override Encoding Encoding => Encoding.Unicode;
public Action<string> Emit;
}

View File

@ -58,8 +58,6 @@ namespace BizHawk.Common
}
// -------------- Default Logger Action --------------
public static Stream? HACK_LOG_STREAM;
private static readonly bool LogToConsole = false;
private static readonly bool LogToFile = false;