-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (38 loc) · 1.36 KB
/
Copy pathProgram.cs
File metadata and controls
41 lines (38 loc) · 1.36 KB
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
using System.Text;
using ICSharpCode.SharpZipLib.GZip;
namespace BFLExtractCsharp;
internal abstract class Program
{
private static int Main(string[] args)
{
foreach (var arg in args)
{
if (!File.Exists(arg))
{
Console.WriteLine("File not found: {0}", arg);
return 1;
}
Stream decompressed = new MemoryStream();
Console.WriteLine("Decompressing...");
try
{
GZip.Decompress(File.OpenRead(arg), decompressed, false);
}
catch (GZipException)
{
Console.WriteLine("Decompression failed - will continue assuming the file is not actually compressed");
decompressed = File.OpenRead(arg);
}
var buff = new byte[4];
decompressed.Position = 0;
decompressed.ReadExactly(buff);
var magic = Encoding.ASCII.GetString(buff);
var headerSize = magic == "CMPR" ? 8 : 0;
decompressed.Position = 0;
var outDir = Path.Join(new FileInfo(arg).DirectoryName, Path.GetFileNameWithoutExtension(arg) + "_extracted");
if (!Directory.Exists(outDir)) Directory.CreateDirectory(outDir);
_ = new BflFormat(decompressed, outDir, headerSize);
}
return 0;
}
}