-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile2CppByteArray.csx
More file actions
46 lines (37 loc) · 975 Bytes
/
File2CppByteArray.csx
File metadata and controls
46 lines (37 loc) · 975 Bytes
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
#!/usr/bin/env dotnet-script
// https://github.com/vurdalakov/scripttools/
if (Args.Count != 1)
{
Console.WriteLine("Usage: File2CppByteArray.csx <file-name>");
Environment.Exit(1);
}
var filePath = Args[0];
var fileName = Path.GetFileNameWithoutExtension(filePath);
var i = 0;
using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None))
{
Console.WriteLine($"// {filePath}");
Console.WriteLine($"const unsigned char {fileName}[{fileStream.Length}] =");
Console.Write("{");
while (true)
{
var b = fileStream.ReadByte();
if (b < 0)
{
break;
}
if (0 == (i % 32))
{
Console.WriteLine();
Console.Write(" ");
}
Console.Write($"0x{b:X02},");
i++;
if ((i % 32) > 0)
{
Console.Write(" ");
}
}
Console.WriteLine();
Console.WriteLine("};");
}