-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
132 lines (114 loc) · 4.83 KB
/
Program.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using xayrga;
using Be.IO;
namespace ibnktool
{
public class minimizedIBNK
{
public uint globalID;
}
class Program
{
static void Main(string[] args)
{
crc32.reset();
#if DEBUG
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Console.WriteLine("!IBNKTOOL build in debug mode, do not push into release!");
Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Console.WriteLine("dump email: [email protected]");
Console.ForegroundColor = ConsoleColor.Gray;
#endif
/*
var bb = File.OpenRead("53.bnk");
var bw = new BeBinaryReader(bb);
Console.WriteLine("Reading 53.bnk");
Console.WriteLine("InstrumentBankV2 --> CreateFromStream()");
var w = InstrumentBankv2.CreateFromStream(bw);
Console.WriteLine($"Oscillators \t{w.Oscillators.Length}");
Console.WriteLine($"Sensors \t{w.SenseEffects.Length}");
Console.WriteLine($"RandEffs \t{w.RandEffects.Length}");
Console.WriteLine($"Instruments \t{w.Instruments.Length}");
Console.WriteLine($"PercRegions \t{w.PercussionMaps.Length}");
Console.WriteLine($"Percussions \t{w.Percussions.Length}");
Console.WriteLine($"List Size \t{w.List.Length}");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Read successful.");
Console.ForegroundColor = ConsoleColor.Gray;
File.WriteAllText("test_ibnk.json", JsonConvert.SerializeObject(w, Formatting.Indented));
*/
cmdarg.cmdargs = args;
var operation = cmdarg.assertArg(0, "Operation");
var version = cmdarg.assertArg(1, "Version");
util.consoleProgress_quiet = cmdarg.findDynamicFlagArgument("-quiet");
if (operation=="unpack")
{
var file = cmdarg.assertArg(2, "IBNK File");
var output = cmdarg.assertArg(3, "Output Folder");
cmdarg.assert(!File.Exists(file), $"{file} not found.");
var fh = File.OpenRead(file);
var mr = new BeBinaryReader(fh);
JInstrumentBankv1 bank = null;
try {bank = JInstrumentBankv1.CreateFromStream(mr);}
catch (Exception E){
#if DEBUG
Console.WriteLine(E.ToString());
#endif
cmdarg.assert($"Cannot deserialize IBNK\n\n{E.Message}");
}
var unp = new IBNKUnpacker();
unp.unpackV1(output, bank);
}
else if (operation == "unpackv2")
{
var file = cmdarg.assertArg(2, "IBNK File");
var output = cmdarg.assertArg(3, "Output Folder");
cmdarg.assert(!File.Exists(file), $"{file} not found.");
var fh = File.OpenRead(file);
var mr = new BeBinaryReader(fh);
InstrumentBankv2 bank = null;
try { bank = InstrumentBankv2.CreateFromStream(mr); }
catch (Exception E)
{
#if DEBUG
Console.WriteLine(E.ToString());
#endif
cmdarg.assert($"Cannot deserialize IBNK\n\n{E.Message}");
}
var unp = new IBNKUnpackerv2();
unp.unpackV2(output, bank);
}
else if ( operation=="pack")
{
var file = cmdarg.assertArg(2, "Project Folder");
var output = cmdarg.assertArg(3, "Output File");
cmdarg.assert(!File.Exists($"{file}/ibnk.json"), $"Cannot locate {file}/ibnk.json");
var wl = File.ReadAllText($"{file}/ibnk.json");
IBNKProjectV1 prj = null;
try
{
prj = JsonConvert.DeserializeObject<IBNKProjectV1>(wl);
} catch (Exception E)
{
cmdarg.assert($"Cannot deserialize project\n\n{E.Message}");
#if DEBUG
Console.WriteLine(E.ToString());
#endif
}
var pck = new BeBinaryWriter(File.OpenWrite(output));
var rpk = new IBNKPacker();
rpk.packV1(prj, $"{file}", pck);
} else
{
Console.WriteLine("ibnktool");
Console.WriteLine("ibnktool <operation> <ibnk version> <....<");
Console.WriteLine("ibnktool unpack 0 <input file> <output folder>");
Console.WriteLine("ibnktool pack 0 <input folder> <output file>");
}
}
}
}