This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
AbstractParser.cs
executable file
·80 lines (64 loc) · 2.13 KB
/
AbstractParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Copyright (c) Jesse Freeman, Pixel Vision 8. All rights reserved.
//
// Licensed under the Microsoft Public License (MS-PL) except for a few
// portions of the code. See LICENSE file in the project root for full
// license information. Third-party libraries used by Pixel Vision 8 are
// under their own licenses. Please refer to those libraries for details
// on the license they use.
//
// Contributors
// --------------------------------------------------------
// This is the official list of Pixel Vision 8 contributors:
//
// Jesse Freeman - @JesseFreeman
// Christina-Antoinette Neofotistou @CastPixel
// Christer Kaitila - @McFunkypants
// Pedro Medeiros - @saint11
// Shawn Rakowski - @shwany
//
using System;
using System.Collections.Generic;
namespace PixelVision8.Runner
{
public abstract class AbstractParser : IAbstractParser
{
protected List<Action> _steps = new List<Action>();
public IFileLoader FileLoadHelper;
public int CurrentStep { get; protected set; }
protected string SourcePath;
public virtual byte[] bytes { get; set; }
public int totalSteps => _steps.Count;
public bool completed => CurrentStep >= totalSteps;
public virtual void CalculateSteps()
{
CurrentStep = 0;
// First step will always be to get the data needed to parse
if (!string.IsNullOrEmpty(SourcePath))
_steps.Add(LoadSourceData);
}
public virtual void LoadSourceData()
{
if (FileLoadHelper != null)
{
bytes = FileLoadHelper.ReadAllBytes(SourcePath);
}
StepCompleted();
}
public virtual void NextStep()
{
if (completed) return;
_steps[CurrentStep]();
}
public virtual void StepCompleted()
{
CurrentStep++;
}
public virtual void Dispose()
{
bytes = null;
FileLoadHelper = null;
_steps.Clear();
}
}
}