LibHac/tests/LibHac.Tests/HorizonFactory.cs

40 lines
1.3 KiB
C#
Raw Normal View History

using LibHac.Bcat;
using LibHac.Common.Keys;
using LibHac.Fs.Fsa;
using LibHac.FsSrv;
using LibHac.FsSystem;
using LibHac.Tools.Fs;
2021-11-14 20:08:57 +01:00
namespace LibHac.Tests;
public static class HorizonFactory
{
2021-11-14 20:08:57 +01:00
public static Horizon CreateBasicHorizon()
{
2021-11-14 20:08:57 +01:00
IFileSystem rootFs = new InMemoryFileSystem();
var keySet = new KeySet();
2021-11-14 20:08:57 +01:00
var horizon = new Horizon(new HorizonConfiguration());
2021-11-14 20:08:57 +01:00
HorizonClient fsServerClient = horizon.CreatePrivilegedHorizonClient();
var fsServer = new FileSystemServer(fsServerClient);
var random = new Random(12345);
RandomDataGenerator randomGenerator = buffer => random.NextBytes(buffer);
var defaultObjects = DefaultFsServerObjects.GetDefaultEmulatedCreators(rootFs, keySet, fsServer, randomGenerator);
2021-11-14 20:08:57 +01:00
var config = new FileSystemServerConfig();
config.FsCreators = defaultObjects.FsCreators;
config.StorageDeviceManagerFactory = defaultObjects.StorageDeviceManagerFactory;
2021-11-14 20:08:57 +01:00
config.ExternalKeySet = new ExternalKeySet();
config.RandomGenerator = randomGenerator;
2021-11-14 20:08:57 +01:00
FileSystemServerInitializer.InitializeWithConfig(fsServerClient, fsServer, config);
2021-11-14 20:08:57 +01:00
HorizonClient bcatServerClient = horizon.CreateHorizonClient();
_ = new BcatServer(bcatServerClient);
2021-11-14 20:08:57 +01:00
return horizon;
}
}