diff --git a/src/LibHac/Horizon.cs b/src/LibHac/Horizon.cs index f9c30aae..a20960d5 100644 --- a/src/LibHac/Horizon.cs +++ b/src/LibHac/Horizon.cs @@ -1,4 +1,5 @@ -using System.Threading; +using System; +using System.Threading; using LibHac.Common; using LibHac.Diag; using LibHac.Fs.Shim; @@ -50,12 +51,10 @@ namespace LibHac return new HorizonClient(this, new ProcessId(processId)); } - public HorizonClient CreateHorizonClient(ProgramId programId, AccessControlBits.Bits fsPermissions) + public HorizonClient CreateHorizonClient(ProgramLocation location, AccessControlBits.Bits fsPermissions) { - HorizonClient client = CreateHorizonClient(); - - var dataHeader = new AccessControlDataHeader(); var descriptor = new AccessControlDescriptor(); + var dataHeader = new AccessControlDataHeader(); descriptor.Version = 1; dataHeader.Version = 1; @@ -63,11 +62,25 @@ namespace LibHac descriptor.AccessFlags = (ulong)fsPermissions; dataHeader.AccessFlags = (ulong)fsPermissions; - LoaderClient.Fs.RegisterProgram(client.ProcessId.Value, programId, StorageId.BuiltInUser, - SpanHelpers.AsReadOnlyByteSpan(in dataHeader), SpanHelpers.AsReadOnlyByteSpan(in descriptor)) - .ThrowIfFailure(); + return CreateHorizonClientImpl(location, SpanHelpers.AsReadOnlyByteSpan(in dataHeader), + SpanHelpers.AsReadOnlyByteSpan(in descriptor)); + } + + public HorizonClient CreateHorizonClient(ProgramLocation location, ReadOnlySpan fsAccessControlData, + ReadOnlySpan fsAccessControlDescriptor) + { + return CreateHorizonClientImpl(location, fsAccessControlData, fsAccessControlDescriptor); + } + + private HorizonClient CreateHorizonClientImpl(ProgramLocation location, ReadOnlySpan accessControlData, + ReadOnlySpan accessControlDescriptor) + { + HorizonClient client = CreateHorizonClient(); + + LoaderClient.Fs.RegisterProgram(client.ProcessId.Value, location.ProgramId, location.StorageId, + accessControlData, accessControlDescriptor).ThrowIfFailure(); return client; } } -} +} \ No newline at end of file diff --git a/src/LibHac/Ncm/ProgramLocation.cs b/src/LibHac/Ncm/ProgramLocation.cs new file mode 100644 index 00000000..b755c437 --- /dev/null +++ b/src/LibHac/Ncm/ProgramLocation.cs @@ -0,0 +1,14 @@ +namespace LibHac.Ncm +{ + public readonly struct ProgramLocation + { + public readonly ProgramId ProgramId; + public readonly StorageId StorageId; + + public ProgramLocation(ProgramId programId, StorageId storageId) + { + ProgramId = programId; + StorageId = storageId; + } + } +} \ No newline at end of file diff --git a/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs b/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs index 16a6df74..f05d9eb7 100644 --- a/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs +++ b/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs @@ -20,11 +20,14 @@ namespace LibHac.Tests.FsSrv var programs = new HorizonClient[count]; - programs[0] = hos.CreateHorizonClient(new ProgramId(1), AccessControlBits.Bits.RegisterProgramIndexMapInfo); + programs[0] = hos.CreateHorizonClient(new ProgramLocation(new ProgramId(1), StorageId.BuiltInSystem), + AccessControlBits.Bits.RegisterProgramIndexMapInfo); for (int i = 1; i < programs.Length; i++) { - programs[i] = hos.CreateHorizonClient(new ProgramId((ulong)(i + 1)), AccessControlBits.Bits.None); + programs[i] = + hos.CreateHorizonClient(new ProgramLocation(new ProgramId((ulong)(i + 1)), StorageId.BuiltInSystem), + AccessControlBits.Bits.None); } var map = new ProgramIndexMapInfo[count]; @@ -191,4 +194,4 @@ namespace LibHac.Tests.FsSrv Assert.False(manager.Get(new ProgramId(2)).HasValue); } } -} +} \ No newline at end of file