Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for EOF instead of always throwing exceptions when loading files #52

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Character/Types/Adf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void Load (Stream fs, CharacterDocument doc, CharacterHandler ha
page.Font.Load (br);

WaitEventArgs args = new WaitEventArgs ();
while (true) {
while (!fs.IsEOF()) {
p.X = rClip.Left;
for (int x=0; x<80; x++) {
byte ch = br.ReadByte ();
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Character/Types/Ansi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override bool DetectAnimation (Stream stream)
var bs = new BufferedStream (stream, 1024);
var br = new BinaryReader (bs);
int read = 0;
while (read < 2048 && true) {
while (read < 2048 && !stream.IsEOF()) {
byte curByte = br.ReadByte ();
read++;
if (curByte == 27) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Character/Types/Ansi.load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public void Load(Stream fs, Canvas canvas, Palette palette, WaitEventHandler onW
{
var args = new WaitEventArgs();
byte curByte = br.ReadByte();
while (true && (!fs.CanSeek || fs.Position < fs.Length))
while (!fs.IsEOF())
{
if (onWait != null)
onWait(this, args);
Expand Down
4 changes: 2 additions & 2 deletions Source/Pablo/Formats/Character/Types/Atascii.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override bool DetectAnimation(Stream stream)
{

var br = new BinaryReader(stream);
while (true)
while (!stream.IsEOF())
{
byte b = br.ReadByte();
switch (b)
Expand Down Expand Up @@ -154,7 +154,7 @@ public override void Load(Stream fs, CharacterDocument document, CharacterHandle
var ce = new CanvasElement(32, 7);
p = rClip.Location;
var args = new WaitEventArgs();
while (true)
while (!fs.IsEOF())
{
document.OnWait(args);
if (args.Exit)
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Character/Types/Avatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public override void Load(Stream fs, CharacterDocument doc, CharacterHandler han
try
{
WaitEventArgs args = new WaitEventArgs();
while (true)
while (!fs.IsEOF())
{
doc.OnWait(args);
if (args.Exit)
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Character/Types/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public override void Load(Stream fs, CharacterDocument doc, CharacterHandler han
CanvasElement ce = new CanvasElement(32, 7);
p = rClip.Location;
WaitEventArgs args = new WaitEventArgs();
while (true)
while (!fs.IsEOF())
{
doc.OnWait(args);
if (args.Exit)
Expand Down
4 changes: 2 additions & 2 deletions Source/Pablo/Formats/Character/Types/CG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override bool DetectAnimation(Stream stream)
{

var br = new BinaryReader(stream);
while (true)
while (!stream.IsEOF())
{
byte b = br.ReadByte();
switch (b)
Expand Down Expand Up @@ -153,7 +153,7 @@ public override void Load(Stream fs, CharacterDocument document, CharacterHandle
var ce = new CanvasElement(32, 7);
p = rClip.Location;
var args = new WaitEventArgs();
while (true)
while (!fs.IsEOF())
{
document.OnWait(args);
if (args.Exit)
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Character/Types/CtrlA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void Load (Stream stream, CharacterDocument doc, Handler handler)
p = rClip.Location;
attr = CanvasElement.Default.Attribute;
try {
while (true) {
while (!stream.IsEOF()) {
var b = br.ReadByte ();

if (b == 1) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Character/Types/Tundra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected static Point Load(Stream stream, Canvas canvas, Palette pal)
{
var br = new BinaryReader(stream);
var attr = new Attribute(0, 0);
while (true)
while (!stream.IsEOF())
{
var command = br.ReadByte();

Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Pix/FormatPix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override void Load(Stream fs, Document document)

try
{
while (true)
while (!fs.IsEOF())
{
b = br.ReadByte();
switch ((char)b)
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Rip/FormatRip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Load (Stream stream, RipDocument document, RipHandler handler)

try {
var args = new WaitEventArgs ();
while (true) {
while (!stream.IsEOF()) {
if (document.AnimateView) {
document.OnWait (args);
if (args.Exit)
Expand Down
2 changes: 1 addition & 1 deletion Source/Pablo/Formats/Rip/LidgrenExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void ReadCommands (this NetIncomingMessage message, RipDocument do
var stream = message.ReadStream ();
var reader = new BinaryReader (stream);
try {
while (true) {
while (!stream.IsEOF()) {
char b = (char)reader.ReadRipByte ();
if (b == '|') {

Expand Down
15 changes: 15 additions & 0 deletions Source/Pablo/StreamExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.IO;

namespace Pablo
{
static class StreamExtensions
{
public static bool IsEOF(this Stream stream)
{
if (!stream.CanSeek)
return false;
return stream.Position >= stream.Length;
}
}
}