2018-06-22 21:05:29 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2018-06-21 18:16:51 +02:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace libhac
|
|
|
|
|
{
|
2018-06-26 00:26:47 +02:00
|
|
|
|
public class SdFs : IDisposable
|
2018-06-21 18:16:51 +02:00
|
|
|
|
{
|
|
|
|
|
public Keyset Keyset { get; }
|
|
|
|
|
public string RootDir { get; }
|
|
|
|
|
public string ContentsDir { get; }
|
|
|
|
|
public string[] Files { get; }
|
2018-06-26 00:26:47 +02:00
|
|
|
|
public List<Nca> Ncas { get; } = new List<Nca>();
|
|
|
|
|
private List<Nax0> Nax0s { get; } = new List<Nax0>();
|
2018-06-21 18:16:51 +02:00
|
|
|
|
|
|
|
|
|
public SdFs(Keyset keyset, string sdPath)
|
|
|
|
|
{
|
|
|
|
|
if (Directory.Exists(Path.Combine(sdPath, "Nintendo")))
|
|
|
|
|
{
|
|
|
|
|
RootDir = sdPath;
|
|
|
|
|
Keyset = keyset;
|
|
|
|
|
ContentsDir = Path.Combine(sdPath, "Nintendo", "Contents");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Files = Directory.GetFiles(ContentsDir, "00", SearchOption.AllDirectories).Select(Path.GetDirectoryName).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-26 00:26:47 +02:00
|
|
|
|
public void OpenAllNcas()
|
2018-06-21 18:16:51 +02:00
|
|
|
|
{
|
|
|
|
|
foreach (var file in Files)
|
|
|
|
|
{
|
2018-06-22 21:05:29 +02:00
|
|
|
|
Nca nca = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var sdPath = "/" + Util.GetRelativePath(file, ContentsDir).Replace('\\', '/');
|
2018-06-25 21:01:24 +02:00
|
|
|
|
var nax0 = Nax0.CreateFromPath(Keyset, file, sdPath);
|
2018-06-26 00:26:47 +02:00
|
|
|
|
Nax0s.Add(nax0);
|
|
|
|
|
nca = new Nca(Keyset, nax0.Stream, false);
|
2018-06-22 21:05:29 +02:00
|
|
|
|
nca.Name = Path.GetFileName(file);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"{ex.Message} {file}");
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-26 00:26:47 +02:00
|
|
|
|
if (nca != null) Ncas.Add(nca);
|
2018-06-21 18:16:51 +02:00
|
|
|
|
}
|
2018-06-26 00:26:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisposeNcas()
|
|
|
|
|
{
|
|
|
|
|
foreach (var nca in Ncas)
|
|
|
|
|
{
|
|
|
|
|
nca.Dispose();
|
|
|
|
|
}
|
|
|
|
|
Ncas.Clear();
|
2018-06-21 18:16:51 +02:00
|
|
|
|
|
2018-06-26 00:26:47 +02:00
|
|
|
|
foreach (var nax0 in Nax0s)
|
|
|
|
|
{
|
|
|
|
|
nax0.Dispose();
|
|
|
|
|
}
|
|
|
|
|
Nax0s.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
DisposeNcas();
|
2018-06-21 18:16:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|