| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- using LibHac.FsSystem.NcaUtils;
- using Ryujinx.HLE.FileSystem;
- using Ryujinx.HLE.FileSystem.Content;
- using System.Text;
- using static Ryujinx.HLE.Utilities.StringUtils;
- namespace Ryujinx.HLE.HOS.Services.Ncm.Lr.LocationResolverManager
- {
- class ILocationResolver : IpcService
- {
- private StorageId _storageId;
- public ILocationResolver(StorageId storageId)
- {
- _storageId = storageId;
- }
- [CommandHipc(0)]
- // ResolveProgramPath(u64 titleId)
- public ResultCode ResolveProgramPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- if (ResolvePath(context, titleId, NcaContentType.Program))
- {
- return ResultCode.Success;
- }
- else
- {
- return ResultCode.ProgramLocationEntryNotFound;
- }
- }
- [CommandHipc(1)]
- // RedirectProgramPath(u64 titleId)
- public ResultCode RedirectProgramPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- RedirectPath(context, titleId, 0, NcaContentType.Program);
- return ResultCode.Success;
- }
- [CommandHipc(2)]
- // ResolveApplicationControlPath(u64 titleId)
- public ResultCode ResolveApplicationControlPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- if (ResolvePath(context, titleId, NcaContentType.Control))
- {
- return ResultCode.Success;
- }
- else
- {
- return ResultCode.AccessDenied;
- }
- }
- [CommandHipc(3)]
- // ResolveApplicationHtmlDocumentPath(u64 titleId)
- public ResultCode ResolveApplicationHtmlDocumentPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- if (ResolvePath(context, titleId, NcaContentType.Manual))
- {
- return ResultCode.Success;
- }
- else
- {
- return ResultCode.AccessDenied;
- }
- }
- [CommandHipc(4)]
- // ResolveDataPath(u64 titleId)
- public ResultCode ResolveDataPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- if (ResolvePath(context, titleId, NcaContentType.Data) || ResolvePath(context, titleId, NcaContentType.PublicData))
- {
- return ResultCode.Success;
- }
- else
- {
- return ResultCode.AccessDenied;
- }
- }
- [CommandHipc(5)]
- // RedirectApplicationControlPath(u64 titleId)
- public ResultCode RedirectApplicationControlPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- RedirectPath(context, titleId, 1, NcaContentType.Control);
- return ResultCode.Success;
- }
- [CommandHipc(6)]
- // RedirectApplicationHtmlDocumentPath(u64 titleId)
- public ResultCode RedirectApplicationHtmlDocumentPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- RedirectPath(context, titleId, 1, NcaContentType.Manual);
- return ResultCode.Success;
- }
- [CommandHipc(7)]
- // ResolveApplicationLegalInformationPath(u64 titleId)
- public ResultCode ResolveApplicationLegalInformationPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- if (ResolvePath(context, titleId, NcaContentType.Manual))
- {
- return ResultCode.Success;
- }
- else
- {
- return ResultCode.AccessDenied;
- }
- }
- [CommandHipc(8)]
- // RedirectApplicationLegalInformationPath(u64 titleId)
- public ResultCode RedirectApplicationLegalInformationPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- RedirectPath(context, titleId, 1, NcaContentType.Manual);
- return ResultCode.Success;
- }
- [CommandHipc(9)]
- // Refresh()
- public ResultCode Refresh(ServiceCtx context)
- {
- context.Device.System.ContentManager.RefreshEntries(_storageId, 1);
- return ResultCode.Success;
- }
- [CommandHipc(10)]
- // SetProgramNcaPath2(u64 titleId)
- public ResultCode SetProgramNcaPath2(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- RedirectPath(context, titleId, 1, NcaContentType.Program);
- return ResultCode.Success;
- }
- [CommandHipc(11)]
- // ClearLocationResolver2()
- public ResultCode ClearLocationResolver2(ServiceCtx context)
- {
- context.Device.System.ContentManager.RefreshEntries(_storageId, 1);
- return ResultCode.Success;
- }
- [CommandHipc(12)]
- // DeleteProgramNcaPath(u64 titleId)
- public ResultCode DeleteProgramNcaPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- DeleteContentPath(context, titleId, NcaContentType.Program);
- return ResultCode.Success;
- }
- [CommandHipc(13)]
- // DeleteControlNcaPath(u64 titleId)
- public ResultCode DeleteControlNcaPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- DeleteContentPath(context, titleId, NcaContentType.Control);
- return ResultCode.Success;
- }
- [CommandHipc(14)]
- // DeleteDocHtmlNcaPath(u64 titleId)
- public ResultCode DeleteDocHtmlNcaPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- DeleteContentPath(context, titleId, NcaContentType.Manual);
- return ResultCode.Success;
- }
- [CommandHipc(15)]
- // DeleteInfoHtmlNcaPath(u64 titleId)
- public ResultCode DeleteInfoHtmlNcaPath(ServiceCtx context)
- {
- ulong titleId = context.RequestData.ReadUInt64();
- DeleteContentPath(context, titleId, NcaContentType.Manual);
- return ResultCode.Success;
- }
- private void RedirectPath(ServiceCtx context, ulong titleId, int flag, NcaContentType contentType)
- {
- string contentPath = ReadUtf8String(context);
- LocationEntry newLocation = new LocationEntry(contentPath, flag, titleId, contentType);
- context.Device.System.ContentManager.RedirectLocation(newLocation, _storageId);
- }
- private bool ResolvePath(ServiceCtx context, ulong titleId, NcaContentType contentType)
- {
- ContentManager contentManager = context.Device.System.ContentManager;
- string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, NcaContentType.Program);
- if (!string.IsNullOrWhiteSpace(contentPath))
- {
- ulong position = context.Request.RecvListBuff[0].Position;
- ulong size = context.Request.RecvListBuff[0].Size;
- byte[] contentPathBuffer = Encoding.UTF8.GetBytes(contentPath);
- context.Memory.Write(position, contentPathBuffer);
- }
- else
- {
- return false;
- }
- return true;
- }
- private void DeleteContentPath(ServiceCtx context, ulong titleId, NcaContentType contentType)
- {
- ContentManager contentManager = context.Device.System.ContentManager;
- string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, NcaContentType.Manual);
- contentManager.ClearEntry(titleId, NcaContentType.Manual, _storageId);
- }
- }
- }
|