From df7a3935848356ce202b39a6b1714d6599890207 Mon Sep 17 00:00:00 2001 From: Thog Date: Mon, 30 Jul 2018 23:05:01 +0200 Subject: [PATCH] Require the user to provide fonts in RyuFS/system --- Ryujinx.HLE/Font/EmbeddedResource.cs | 19 ----------- Ryujinx.HLE/Font/SharedFontManager.cs | 32 +++++++++++++++---- .../SystemResourceNotFoundException.cs | 14 ++++++++ Ryujinx.HLE/Ryujinx.HLE.csproj | 21 ------------ Ryujinx.HLE/Switch.cs | 2 +- Ryujinx.HLE/VirtualFileSystem.cs | 3 ++ 6 files changed, 43 insertions(+), 48 deletions(-) delete mode 100644 Ryujinx.HLE/Font/EmbeddedResource.cs create mode 100644 Ryujinx.HLE/Resource/SystemResourceNotFoundException.cs diff --git a/Ryujinx.HLE/Font/EmbeddedResource.cs b/Ryujinx.HLE/Font/EmbeddedResource.cs deleted file mode 100644 index c6f26c3a6d..0000000000 --- a/Ryujinx.HLE/Font/EmbeddedResource.cs +++ /dev/null @@ -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); - } - } - } -} diff --git a/Ryujinx.HLE/Font/SharedFontManager.cs b/Ryujinx.HLE/Font/SharedFontManager.cs index 62b0401c73..1c0ff95000 100644 --- a/Ryujinx.HLE/Font/SharedFontManager.cs +++ b/Ryujinx.HLE/Font/SharedFontManager.cs @@ -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.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 diff --git a/Ryujinx.HLE/Resource/SystemResourceNotFoundException.cs b/Ryujinx.HLE/Resource/SystemResourceNotFoundException.cs new file mode 100644 index 0000000000..7473acf0c3 --- /dev/null +++ b/Ryujinx.HLE/Resource/SystemResourceNotFoundException.cs @@ -0,0 +1,14 @@ +using System; + +namespace Ryujinx.HLE.Resource +{ + public class SystemResourceNotFoundException: Exception + { + + public SystemResourceNotFoundException(string message, Exception inner) + : base(message, inner) + { + } + + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Ryujinx.HLE.csproj b/Ryujinx.HLE/Ryujinx.HLE.csproj index 17c4a542d7..f7fb84a588 100644 --- a/Ryujinx.HLE/Ryujinx.HLE.csproj +++ b/Ryujinx.HLE/Ryujinx.HLE.csproj @@ -13,27 +13,6 @@ true - - - FontChineseSimplified - - - FontChineseTraditional - - - FontExtendedChineseSimplified - - - FontKorean - - - FontNintendoExtended - - - FontStandard - - - diff --git a/Ryujinx.HLE/Switch.cs b/Ryujinx.HLE/Switch.cs index 24c160a2b2..a80ca86c19 100644 --- a/Ryujinx.HLE/Switch.cs +++ b/Ryujinx.HLE/Switch.cs @@ -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; diff --git a/Ryujinx.HLE/VirtualFileSystem.cs b/Ryujinx.HLE/VirtualFileSystem.cs index df1fc9db13..31b8e184ce 100644 --- a/Ryujinx.HLE/VirtualFileSystem.cs +++ b/Ryujinx.HLE/VirtualFileSystem.cs @@ -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(":");