forked from XAYRGA/ibnktool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
89 lines (76 loc) · 2.98 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
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
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=="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>");
}
}
}
}