Require the user to provide fonts in RyuFS/system

This commit is contained in:
Thog 2018-07-30 23:05:01 +02:00
parent 3277d3020f
commit df7a393584
No known key found for this signature in database
GPG key ID: 0CD291558FAFDBC6
6 changed files with 43 additions and 48 deletions

View file

@ -1,19 +0,0 @@
using System.IO;
using System.Reflection;
namespace Ryujinx.HLE.Font
{
static class EmbeddedResource
{
public static byte[] GetData(string Name)
{
Assembly Asm = typeof(EmbeddedResource).Assembly;
using (Stream ResStream = Asm.GetManifestResourceStream(Name))
{
BinaryReader Reader = new BinaryReader(ResStream);
return Reader.ReadBytes((int)Reader.BaseStream.Length);
}
}
}
}

View file

@ -3,8 +3,11 @@ using ChocolArm64.Memory;
using Ryujinx.HLE.Logging;
using Ryujinx.HLE.OsHle;
using Ryujinx.HLE.OsHle.Handles;
using Ryujinx.HLE.Resource;
using System;
using System.Collections.Generic;
using System.IO;
namespace Ryujinx.HLE.Font
{
@ -12,6 +15,8 @@ namespace Ryujinx.HLE.Font
{
private Logger Log;
private string FontsPath;
private object ShMemLock;
private (AMemory, long, long)[] ShMemPositions;
@ -20,9 +25,10 @@ namespace Ryujinx.HLE.Font
private uint[] LoadedFonts;
public SharedFontManager(Logger Log)
public SharedFontManager(Logger Log, string SystemPath)
{
this.Log = Log;
this.FontsPath = Path.Combine(SystemPath, "fonts");
ShMemLock = new object();
@ -30,17 +36,29 @@ namespace Ryujinx.HLE.Font
FontEmbeddedPaths = new Dictionary<SharedFontType, byte[]>()
{
{ SharedFontType.JapanUsEurope, EmbeddedResource.GetData("FontStandard") },
{ SharedFontType.SimplifiedChinese, EmbeddedResource.GetData("FontChineseSimplified") },
{ SharedFontType.SimplifiedChineseEx, EmbeddedResource.GetData("FontExtendedChineseSimplified") },
{ SharedFontType.TraditionalChinese, EmbeddedResource.GetData("FontChineseTraditional") },
{ SharedFontType.Korean, EmbeddedResource.GetData("FontKorean") },
{ SharedFontType.NintendoEx, EmbeddedResource.GetData("FontNintendoExtended") }
{ SharedFontType.JapanUsEurope, GetData("FontStandard") },
{ SharedFontType.SimplifiedChinese, GetData("FontChineseSimplified") },
{ SharedFontType.SimplifiedChineseEx, GetData("FontExtendedChineseSimplified") },
{ SharedFontType.TraditionalChinese, GetData("FontChineseTraditional") },
{ SharedFontType.Korean, GetData("FontKorean") },
{ SharedFontType.NintendoEx, GetData("FontNintendoExtended") }
};
LoadedFonts = new uint[FontEmbeddedPaths.Count];
}
public byte[] GetData(string FontName)
{
string FontFilePath = Path.Combine(FontsPath, $"{FontName}.ttf");
try
{
return File.ReadAllBytes(FontFilePath);
} catch (FileNotFoundException e)
{
throw new SystemResourceNotFoundException($"Font \"{FontName}.ttf\" not found. Please provide it in {FontsPath}", e);
}
}
public void MapFont(SharedFontType FontType, AMemory Memory, long Position)
{
// TODO: find what are the 8 bytes before the font

View file

@ -0,0 +1,14 @@
using System;
namespace Ryujinx.HLE.Resource
{
public class SystemResourceNotFoundException: Exception
{
public SystemResourceNotFoundException(string message, Exception inner)
: base(message, inner)
{
}
}
}

View file

@ -13,27 +13,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Font\FontChineseSimplified.ttf">
<LogicalName>FontChineseSimplified</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Font\FontChineseTraditional.ttf">
<LogicalName>FontChineseTraditional</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Font\FontExtendedChineseSimplified.ttf">
<LogicalName>FontExtendedChineseSimplified</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Font\FontKorean.ttf">
<LogicalName>FontKorean</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Font\FontNintendoExtended.ttf">
<LogicalName>FontNintendoExtended</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Font\FontStandard.ttf">
<LogicalName>FontStandard</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ChocolArm64\ChocolArm64.csproj" />
<ProjectReference Include="..\Ryujinx.Audio\Ryujinx.Audio.csproj" />

View file

@ -60,7 +60,7 @@ namespace Ryujinx.HLE
Hid = new Hid(Log);
Font = new SharedFontManager(Log);
Font = new SharedFontManager(Log, VFs.GetSystemPath());
Os.HidSharedMem.MemoryMapped += Hid.ShMemMap;
Os.HidSharedMem.MemoryUnmapped += Hid.ShMemUnmap;

View file

@ -8,6 +8,7 @@ namespace Ryujinx.HLE
private const string BasePath = "RyuFs";
private const string NandPath = "nand";
private const string SdCardPath = "sdmc";
private const string SystemPath = "system";
public Stream RomFs { get; private set; }
@ -45,6 +46,8 @@ namespace Ryujinx.HLE
public string GetGameSavesPath() => MakeDirAndGetFullPath(NandPath);
public string GetSystemPath() => MakeDirAndGetFullPath(SystemPath);
public string SwitchPathToSystemPath(string SwitchPath)
{
string[] Parts = SwitchPath.Split(":");