-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
66 lines (55 loc) · 1.9 KB
/
Copy pathProgram.cs
File metadata and controls
66 lines (55 loc) · 1.9 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
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 AssetsTools.NET;
using AssetsTools.NET.Extra;
if (args.Length is < 1 or > 2) {
Console.WriteLine("Usage: Rebundle_LZMA <input_bundle> [output_bundle]");
Console.WriteLine("Compresses an asset bundle using LZMA compression");
Console.WriteLine("If no [output_bundle] is specified, the compressed file will be saved with '_LZMA' added to the input filename");
return 1;
}
string inputPath = args[0];
string outputPath;
if (!File.Exists(inputPath)) {
Console.WriteLine($"Error: Input file '{inputPath}' not found.");
return 1;
}
if (args.Length == 1) { //input only
outputPath = Path.Combine(
Path.GetDirectoryName(inputPath)!,
$"{Path.GetFileNameWithoutExtension(inputPath)}_LZMA{Path.GetExtension(inputPath)}"
);
} else { //output folder or file specified
string outputPart = args[1];
if (Path.HasExtension(outputPart)) {
outputPath = outputPart;
} else {
outputPath = Path.Combine(outputPart, $"{Path.GetFileName(inputPath)}");
}
}
if (string.IsNullOrEmpty(outputPath)) {
Console.WriteLine("Error: Output path is invalid.");
return 1;
}
string? output = Path.GetDirectoryName(outputPath);
//not empty, create output directory if needed
if (!string.IsNullOrWhiteSpace(output)) {
Console.WriteLine($"Creating output directory: {output}");
Directory.CreateDirectory(output);
}
try {
Console.WriteLine($"Loading bundle from: {inputPath}");
var assetsManager = new AssetsManager();
var bundle = assetsManager.LoadBundleFile(inputPath);
try {
Console.WriteLine("Compressing bundle with LZMA...");
using var outputStream = File.Create(outputPath);
using var outputWriter = new AssetsFileWriter(outputStream);
bundle.file.Pack(outputWriter, AssetBundleCompressionType.LZMA);
Console.WriteLine($"Successfully compressed bundle to: {outputPath}");
return 0;
} finally {
assetsManager.UnloadBundleFile(bundle);
}
} catch (Exception ex) {
Console.WriteLine($"Error: {ex.Message}");
return 1;
}