-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDecompressFs.cs
67 lines (62 loc) · 2.11 KB
/
DecompressFs.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
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using LibHac;
using LibHac.Fs;
using nsZip.LibHacExtensions;
using Zstandard.Net;
namespace nsZip
{
public static class DecompressFs
{
public static void ProcessFs(IFileSystem sourceFs, IFileSystem destFs, Output Out)
{
foreach (var file in sourceFs.EnumerateEntries().Where(item => item.Type == DirectoryEntryType.File))
{
using (IFile srcFile = sourceFs.OpenFile(file.FullPath, OpenMode.Read))
using (var decStorage = new DecompressionStorage(srcFile))
{
var destName = $"{file.Name.Substring(0, file.Name.LastIndexOf('.'))}";
using (IFile outputFile = FolderTools.CreateAndOpen(file, destFs, destName, decStorage.GetSize()))
{
decStorage.CopyTo(outputFile.AsStorage());
}
}
}
}
public static void GetTitleKeys(IFileSystem sourceFs, Keyset keyset, Output Out)
{
foreach (var entry in sourceFs.EnumerateEntries().Where(item => item.Type == DirectoryEntryType.File))
{
if (entry.Name.EndsWith(".tik.nsz"))
{
using (IFile srcFile = sourceFs.OpenFile(entry.Name, OpenMode.Read))
using (var decStorage = new DecompressionStorage(srcFile))
{
TitleKeyTools.ExtractKey(decStorage.AsStream(), entry.Name, keyset, Out);
}
}
}
}
public static void ExtractTickets(IFileSystem sourceFs, string outDirPath, Keyset keyset, Output Out)
{
var OutDirFs = new LocalFileSystem(outDirPath);
IDirectory destRoot = OutDirFs.OpenDirectory("/", OpenDirectoryMode.All);
foreach (var entry in sourceFs.EnumerateEntries().Where(item => item.Type == DirectoryEntryType.File))
{
if (entry.Name.EndsWith(".tik.nsz") || entry.Name.EndsWith(".cert.nsz"))
{
var outFilePath = Path.Combine(outDirPath, Path.GetFileNameWithoutExtension(entry.Name));
using (IFile srcFile = sourceFs.OpenFile(entry.Name, OpenMode.Read))
using (var decStorage = new DecompressionStorage(srcFile))
using (FileStream outputFile = File.OpenWrite(outFilePath))
{;
decStorage.CopyToStream(outputFile);
}
}
}
}
}
}