forked from WolvenKit/WolvenKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DumpCache.cs
79 lines (70 loc) · 2.56 KB
/
DumpCache.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
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WolvenKit.Bundles;
using WolvenKit.Cache;
using WolvenKit.Common;
using WolvenKit.Common.Extensions;
using WolvenKit.Common.Model;
using WolvenKit.CR2W;
using WolvenKit.CR2W.Types;
namespace WolvenKit.Console
{
public static partial class ConsoleFunctions
{
public static async Task<int> Cache(CacheOptions options)
{
if (options.dump || options.extract)
{
// initial checks
var inputFileInfo = new FileInfo(options.path);
if (!inputFileInfo.Exists)
return 0;
var outDir = inputFileInfo.Directory;
if (outDir == null)
return 0;
if (!outDir.Exists)
Directory.CreateDirectory(outDir.FullName);
if (inputFileInfo.Extension != ".cache")
return 0;
if (inputFileInfo.Name != "texture.cache")
{
System.Console.WriteLine($@"Only texture.caches are currently suported. {options.path}.");
return 0;
}
// load texture cache
// switch chache types
var txc = new TextureCache(inputFileInfo.FullName);
if (options.dump)
{
txc.DumpInfo();
System.Console.WriteLine($@"Finished dumping {options.path}.");
}
if (options.extract)
{
foreach (var x in txc.Files)
{
string fullpath = Path.Combine(outDir.FullName, x.Name);
x.Extract(new BundleFileExtractArgs(fullpath, EUncookExtension.dds));
System.Console.WriteLine($@"Finished extracting {x.Name}");
}
System.Console.WriteLine($@"Finished extracting {options.path}.");
}
}
if (options.create)
{
if (!Directory.Exists(options.path))
return 0;
var txc = new TextureCache();
txc.LoadFiles(options.path);
txc.Write(Path.Combine(options.path, "texture.cache"));
System.Console.WriteLine($@"Finished creating {options.path}.");
}
return 1;
}
}
}