2020-10-05 21:25:39 +02:00
|
|
|
|
using LibHac.Common.Keys;
|
|
|
|
|
using LibHac.Fs;
|
2020-06-10 07:55:59 +02:00
|
|
|
|
using LibHac.Fs.Fsa;
|
2020-08-07 20:45:11 +02:00
|
|
|
|
using LibHac.FsSrv;
|
2022-04-23 21:38:10 +02:00
|
|
|
|
using LibHac.FsSystem;
|
2021-12-19 09:35:45 +01:00
|
|
|
|
using LibHac.Tools.Fs;
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
namespace LibHac.Tests.Fs.FileSystemClientTests;
|
|
|
|
|
|
|
|
|
|
public static class FileSystemServerFactory
|
2020-02-14 01:21:24 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
private static Horizon CreateHorizonImpl(bool sdCardInserted, out IFileSystem rootFs)
|
2020-02-14 01:21:24 +01:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
rootFs = new InMemoryFileSystem();
|
|
|
|
|
var keySet = new KeySet();
|
2021-05-17 07:52:27 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
var horizon = new Horizon(new HorizonConfiguration());
|
2021-05-17 07:52:27 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
HorizonClient fsServerClient = horizon.CreatePrivilegedHorizonClient();
|
|
|
|
|
var fsServer = new FileSystemServer(fsServerClient);
|
2021-05-17 07:52:27 +02:00
|
|
|
|
|
2022-04-23 21:38:10 +02:00
|
|
|
|
var random = new Random(12345);
|
|
|
|
|
RandomDataGenerator randomGenerator = buffer => random.NextBytes(buffer);
|
|
|
|
|
|
|
|
|
|
var defaultObjects = DefaultFsServerObjects.GetDefaultEmulatedCreators(rootFs, keySet, fsServer, randomGenerator);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
defaultObjects.SdCard.SetSdCardInsertionStatus(sdCardInserted);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
var config = new FileSystemServerConfig();
|
|
|
|
|
config.FsCreators = defaultObjects.FsCreators;
|
|
|
|
|
config.DeviceOperator = defaultObjects.DeviceOperator;
|
|
|
|
|
config.ExternalKeySet = new ExternalKeySet();
|
2022-04-23 21:38:10 +02:00
|
|
|
|
config.RandomGenerator = randomGenerator;
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
FileSystemServerInitializer.InitializeWithConfig(fsServerClient, fsServer, config);
|
|
|
|
|
return horizon;
|
|
|
|
|
}
|
2021-05-31 01:29:42 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
private static FileSystemClient CreateClientImpl(bool sdCardInserted, out IFileSystem rootFs)
|
|
|
|
|
{
|
|
|
|
|
Horizon horizon = CreateHorizonImpl(sdCardInserted, out rootFs);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
HorizonClient horizonClient = horizon.CreatePrivilegedHorizonClient();
|
2020-08-23 23:37:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
return horizonClient.Fs;
|
|
|
|
|
}
|
2020-02-14 01:21:24 +01:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
public static FileSystemClient CreateClient(bool sdCardInserted)
|
|
|
|
|
{
|
|
|
|
|
return CreateClientImpl(sdCardInserted, out _);
|
|
|
|
|
}
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
public static FileSystemClient CreateClient(out IFileSystem rootFs)
|
|
|
|
|
{
|
|
|
|
|
return CreateClientImpl(false, out rootFs);
|
|
|
|
|
}
|
2021-05-31 01:29:42 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
public static Horizon CreateHorizonServer()
|
|
|
|
|
{
|
|
|
|
|
return CreateHorizonImpl(true, out _);
|
2020-02-14 01:21:24 +01:00
|
|
|
|
}
|
2021-12-19 09:35:45 +01:00
|
|
|
|
}
|