Ryujinx/Ryujinx.HLE/HOS/Services/Lr/ILocationResolver.cs

266 lines
8.3 KiB
C#
Raw Normal View History

using LibHac;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.FileSystem.Content;
using Ryujinx.HLE.HOS.Ipc;
using System.Collections.Generic;
using System.Text;
using static Ryujinx.HLE.HOS.ErrorCode;
using static Ryujinx.HLE.Utilities.StringUtils;
namespace Ryujinx.HLE.HOS.Services.Lr
{
class ILocationResolver : IpcService
{
2018-12-01 20:01:59 +00:00
private Dictionary<int, ServiceProcessRequest> _commands;
2018-12-01 20:01:59 +00:00
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
2018-12-01 20:01:59 +00:00
private StorageId _storageId;
2018-12-01 20:01:59 +00:00
public ILocationResolver(StorageId storageId)
{
2018-12-01 20:01:59 +00:00
_commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, ResolveProgramPath },
{ 1, RedirectProgramPath },
{ 2, ResolveApplicationControlPath },
{ 3, ResolveApplicationHtmlDocumentPath },
{ 4, ResolveDataPath },
{ 5, RedirectApplicationControlPath },
{ 6, RedirectApplicationHtmlDocumentPath },
{ 7, ResolveApplicationLegalInformationPath },
{ 8, RedirectApplicationLegalInformationPath },
{ 9, Refresh },
{ 10, SetProgramNcaPath2 },
{ 11, ClearLocationResolver2 },
{ 12, DeleteProgramNcaPath },
{ 13, DeleteControlNcaPath },
{ 14, DeleteDocHtmlNcaPath },
{ 15, DeleteInfoHtmlNcaPath }
};
2018-12-01 20:01:59 +00:00
this._storageId = storageId;
}
// DeleteInfoHtmlNcaPath()
2018-12-01 20:01:59 +00:00
public long DeleteInfoHtmlNcaPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
DeleteContentPath(context, titleId, ContentType.Manual);
return 0;
}
// DeleteDocHtmlNcaPath()
2018-12-01 20:01:59 +00:00
public long DeleteDocHtmlNcaPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
DeleteContentPath(context, titleId, ContentType.Manual);
return 0;
}
// DeleteControlNcaPath()
2018-12-01 20:01:59 +00:00
public long DeleteControlNcaPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
DeleteContentPath(context, titleId, ContentType.Control);
return 0;
}
// DeleteProgramNcaPath()
2018-12-01 20:01:59 +00:00
public long DeleteProgramNcaPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
DeleteContentPath(context, titleId, ContentType.Program);
return 0;
}
// ClearLocationResolver2()
2018-12-01 20:01:59 +00:00
public long ClearLocationResolver2(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
context.Device.System.ContentManager.RefreshEntries(_storageId, 1);
return 0;
}
// SetProgramNcaPath2()
2018-12-01 20:01:59 +00:00
public long SetProgramNcaPath2(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
RedirectPath(context, titleId, 1, ContentType.Program);
return 0;
}
// RedirectApplicationControlPath()
2018-12-01 20:01:59 +00:00
public long RedirectApplicationControlPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
RedirectPath(context, titleId, 1, ContentType.Control);
return 0;
}
// RedirectApplicationHtmlDocumentPath()
2018-12-01 20:01:59 +00:00
public long RedirectApplicationHtmlDocumentPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
RedirectPath(context, titleId, 1, ContentType.Manual);
return 0;
}
// RedirectApplicationLegalInformationPath()
2018-12-01 20:01:59 +00:00
public long RedirectApplicationLegalInformationPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
RedirectPath(context, titleId, 1, ContentType.Manual);
return 0;
}
// ResolveDataPath()
2018-12-01 20:01:59 +00:00
public long ResolveDataPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
if (ResolvePath(context, titleId, ContentType.Data) || ResolvePath(context, titleId, ContentType.AocData))
{
return 0;
}
else
{
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
}
}
// ResolveApplicationHtmlDocumentPath()
2018-12-01 20:01:59 +00:00
public long ResolveApplicationHtmlDocumentPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
if (ResolvePath(context, titleId, ContentType.Manual))
{
return 0;
}
else
{
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
}
}
// ResolveApplicationLegalInformationPath()
2018-12-01 20:01:59 +00:00
public long ResolveApplicationLegalInformationPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
if (ResolvePath(context, titleId, ContentType.Manual))
{
return 0;
}
else
{
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
}
}
// ResolveApplicationControlPath()
2018-12-01 20:01:59 +00:00
public long ResolveApplicationControlPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
if (ResolvePath(context, titleId, ContentType.Control))
{
return 0;
}
else
{
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
}
}
// RedirectProgramPath()
2018-12-01 20:01:59 +00:00
public long RedirectProgramPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
RedirectPath(context, titleId, 0, ContentType.Program);
return 0;
}
// Refresh()
2018-12-01 20:01:59 +00:00
public long Refresh(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
context.Device.System.ContentManager.RefreshEntries(_storageId, 1);
return 0;
}
// ResolveProgramPath()
2018-12-01 20:01:59 +00:00
public long ResolveProgramPath(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
long titleId = context.RequestData.ReadInt64();
2018-12-01 20:01:59 +00:00
if (ResolvePath(context, titleId, ContentType.Program))
{
return 0;
}
else
{
return MakeError(ErrorModule.Lr, LrErr.ProgramLocationEntryNotFound);
}
}
2018-12-01 20:01:59 +00:00
private void RedirectPath(ServiceCtx context, long titleId, int flag, ContentType contentType)
{
2018-12-01 20:01:59 +00:00
string contentPath = ReadUtf8String(context);
LocationEntry newLocation = new LocationEntry(contentPath, flag, titleId, contentType);
2018-12-01 20:01:59 +00:00
context.Device.System.ContentManager.RedirectLocation(newLocation, _storageId);
}
2018-12-01 20:01:59 +00:00
private bool ResolvePath(ServiceCtx context, long titleId,ContentType contentType)
{
2018-12-01 20:01:59 +00:00
ContentManager contentManager = context.Device.System.ContentManager;
string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, ContentType.Program);
2018-12-01 20:01:59 +00:00
if (!string.IsNullOrWhiteSpace(contentPath))
{
2018-12-01 20:01:59 +00:00
long position = context.Request.RecvListBuff[0].Position;
long size = context.Request.RecvListBuff[0].Size;
2018-12-01 20:01:59 +00:00
byte[] contentPathBuffer = Encoding.UTF8.GetBytes(contentPath);
2018-12-01 20:01:59 +00:00
context.Memory.WriteBytes(position, contentPathBuffer);
}
else
{
return false;
}
return true;
}
2018-12-01 20:01:59 +00:00
private void DeleteContentPath(ServiceCtx context, long titleId, ContentType contentType)
{
2018-12-01 20:01:59 +00:00
ContentManager contentManager = context.Device.System.ContentManager;
string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, ContentType.Manual);
2018-12-01 20:01:59 +00:00
contentManager.ClearEntry(titleId, ContentType.Manual, _storageId);
}
}
}