forked from XAYRGA/JAIMaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INAFile.cs
65 lines (57 loc) · 2.24 KB
/
INAFile.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace JaiMaker
{
public static class INAFile
{
public static Dictionary<int, Dictionary<int,string>> parse(string file)
{
var RETL = new Dictionary<int, Dictionary<int, string>>();
var STARR = File.ReadAllLines(file);
var currentBank = 0;
var BankDict = new Dictionary<int, string>();
RETL[currentBank] = BankDict;
for (int line = 0; line < STARR.Length; line++)
{
var currentLine = STARR[line];
if (currentLine.Length > 1) // Ignore blank lines.
{
if (currentLine[0] == ':')
{
var newBank = currentLine.Substring(1);
var newBankNumber = Convert.ToInt32(newBank);
BankDict = new Dictionary<int, string>();
currentBank = newBankNumber;
RETL[currentBank] = BankDict;
} else if (currentLine[0]=='/' || currentLine[0] == '\r' || currentLine[0] == '\n') {
// do nothing, comment.
}
else
{
if (currentLine.Contains("="))
{
var args = currentLine.Split('=');
try
{
var indexNumber = Convert.ToInt32(args[0]);
var name = args[1];
Console.WriteLine("BANK {0} {1} {2}", currentBank, indexNumber,name);
BankDict[indexNumber] = name;
} catch {
Console.WriteLine("Malformmed line in {0}, line {1}", file, line);
};
} else
{
Console.WriteLine("Malformmed line in {0}, line {1}", file, line);
}
}
}
}
return RETL;
}
}
}