2019-05-31 20:31:10 -04:00
|
|
|
|
using LibHac.Fs.NcaUtils;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
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-06 06:16:24 -05:00
|
|
|
|
private Dictionary<int, ServiceProcessRequest> _commands;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
private StorageId _storageId;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public ILocationResolver(StorageId storageId)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
_commands = new Dictionary<int, ServiceProcessRequest>
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
{ 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-06 06:16:24 -05:00
|
|
|
|
_storageId = storageId;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteInfoHtmlNcaPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long DeleteInfoHtmlNcaPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
DeleteContentPath(context, titleId, ContentType.Manual);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteDocHtmlNcaPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long DeleteDocHtmlNcaPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
DeleteContentPath(context, titleId, ContentType.Manual);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteControlNcaPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long DeleteControlNcaPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
DeleteContentPath(context, titleId, ContentType.Control);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteProgramNcaPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long DeleteProgramNcaPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
DeleteContentPath(context, titleId, ContentType.Program);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ClearLocationResolver2()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long ClearLocationResolver2(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
context.Device.System.ContentManager.RefreshEntries(_storageId, 1);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetProgramNcaPath2()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long SetProgramNcaPath2(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
RedirectPath(context, titleId, 1, ContentType.Program);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedirectApplicationControlPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long RedirectApplicationControlPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
RedirectPath(context, titleId, 1, ContentType.Control);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedirectApplicationHtmlDocumentPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long RedirectApplicationHtmlDocumentPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
RedirectPath(context, titleId, 1, ContentType.Manual);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedirectApplicationLegalInformationPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long RedirectApplicationLegalInformationPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
RedirectPath(context, titleId, 1, ContentType.Manual);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveDataPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long ResolveDataPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2019-05-31 20:31:10 -04:00
|
|
|
|
if (ResolvePath(context, titleId, ContentType.Data) || ResolvePath(context, titleId, ContentType.PublicData))
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveApplicationHtmlDocumentPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long ResolveApplicationHtmlDocumentPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (ResolvePath(context, titleId, ContentType.Manual))
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveApplicationLegalInformationPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long ResolveApplicationLegalInformationPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (ResolvePath(context, titleId, ContentType.Manual))
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveApplicationControlPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long ResolveApplicationControlPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (ResolvePath(context, titleId, ContentType.Control))
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedirectProgramPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long RedirectProgramPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
RedirectPath(context, titleId, 0, ContentType.Program);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Refresh()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long Refresh(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
context.Device.System.ContentManager.RefreshEntries(_storageId, 1);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveProgramPath()
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long ResolveProgramPath(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (ResolvePath(context, titleId, ContentType.Program))
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.ProgramLocationEntryNotFound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
private void RedirectPath(ServiceCtx context, long titleId, int flag, ContentType contentType)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
string contentPath = ReadUtf8String(context);
|
|
|
|
|
LocationEntry newLocation = new LocationEntry(contentPath, flag, titleId, contentType);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
context.Device.System.ContentManager.RedirectLocation(newLocation, _storageId);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
private bool ResolvePath(ServiceCtx context, long titleId,ContentType contentType)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
ContentManager contentManager = context.Device.System.ContentManager;
|
|
|
|
|
string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, ContentType.Program);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(contentPath))
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long position = context.Request.RecvListBuff[0].Position;
|
|
|
|
|
long size = context.Request.RecvListBuff[0].Size;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
byte[] contentPathBuffer = Encoding.UTF8.GetBytes(contentPath);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
context.Memory.WriteBytes(position, contentPathBuffer);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
private void DeleteContentPath(ServiceCtx context, long titleId, ContentType contentType)
|
2018-11-18 14:37:41 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
ContentManager contentManager = context.Device.System.ContentManager;
|
|
|
|
|
string contentPath = contentManager.GetInstalledContentPath(titleId, _storageId, ContentType.Manual);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
contentManager.ClearEntry(titleId, ContentType.Manual, _storageId);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|