2018-11-18 20:37:41 +01:00
|
|
|
|
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-05 01:52:39 +01:00
|
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
private StorageId StorageId;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public ILocationResolver(StorageId StorageId)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
2018-11-18 20:37:41 +01: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-05 01:52:39 +01:00
|
|
|
|
this.StorageId = StorageId;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteInfoHtmlNcaPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long DeleteInfoHtmlNcaPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
DeleteContentPath(Context, TitleId, ContentType.Manual);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteDocHtmlNcaPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long DeleteDocHtmlNcaPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
DeleteContentPath(Context, TitleId, ContentType.Manual);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteControlNcaPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long DeleteControlNcaPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
DeleteContentPath(Context, TitleId, ContentType.Control);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteProgramNcaPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long DeleteProgramNcaPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
DeleteContentPath(Context, TitleId, ContentType.Program);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ClearLocationResolver2()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long ClearLocationResolver2(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
Context.Device.System.ContentManager.RefreshEntries(StorageId, 1);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetProgramNcaPath2()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long SetProgramNcaPath2(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
RedirectPath(Context, TitleId, 1, ContentType.Program);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedirectApplicationControlPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long RedirectApplicationControlPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
RedirectPath(Context, TitleId, 1, ContentType.Control);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedirectApplicationHtmlDocumentPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long RedirectApplicationHtmlDocumentPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
RedirectPath(Context, TitleId, 1, ContentType.Manual);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedirectApplicationLegalInformationPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long RedirectApplicationLegalInformationPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
RedirectPath(Context, TitleId, 1, ContentType.Manual);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveDataPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long ResolveDataPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
if (ResolvePath(Context, TitleId, ContentType.Data) || ResolvePath(Context, TitleId, ContentType.AocData))
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveApplicationHtmlDocumentPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long ResolveApplicationHtmlDocumentPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
if (ResolvePath(Context, TitleId, ContentType.Manual))
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveApplicationLegalInformationPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long ResolveApplicationLegalInformationPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
if (ResolvePath(Context, TitleId, ContentType.Manual))
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveApplicationControlPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long ResolveApplicationControlPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
if (ResolvePath(Context, TitleId, ContentType.Control))
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.AccessDenied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RedirectProgramPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long RedirectProgramPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
RedirectPath(Context, TitleId, 0, ContentType.Program);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Refresh()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long Refresh(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
Context.Device.System.ContentManager.RefreshEntries(StorageId, 1);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ResolveProgramPath()
|
2018-12-05 01:52:39 +01:00
|
|
|
|
public long ResolveProgramPath(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
if (ResolvePath(Context, TitleId, ContentType.Program))
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return MakeError(ErrorModule.Lr, LrErr.ProgramLocationEntryNotFound);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
private void RedirectPath(ServiceCtx Context, long TitleId, int Flag, ContentType ContentType)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
string ContentPath = ReadUtf8String(Context);
|
|
|
|
|
LocationEntry NewLocation = new LocationEntry(ContentPath, Flag, TitleId, ContentType);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
Context.Device.System.ContentManager.RedirectLocation(NewLocation, StorageId);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
private bool ResolvePath(ServiceCtx Context, long TitleId,ContentType ContentType)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
ContentManager ContentManager = Context.Device.System.ContentManager;
|
|
|
|
|
string ContentPath = ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.Program);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(ContentPath))
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
long Position = Context.Request.RecvListBuff[0].Position;
|
|
|
|
|
long Size = Context.Request.RecvListBuff[0].Size;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
byte[] ContentPathBuffer = Encoding.UTF8.GetBytes(ContentPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
Context.Memory.WriteBytes(Position, ContentPathBuffer);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
private void DeleteContentPath(ServiceCtx Context, long TitleId, ContentType ContentType)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
|
ContentManager ContentManager = Context.Device.System.ContentManager;
|
|
|
|
|
string ContentPath = ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.Manual);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
|
ContentManager.ClearEntry(TitleId, ContentType.Manual, StorageId);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|