From 5ba45e174e2e82aa79307a122d25c01842333658 Mon Sep 17 00:00:00 2001 From: mao Date: Thu, 23 Nov 2023 15:21:30 +0800 Subject: [PATCH] Support UTF-8 file path Add UTF-8 file path support for GLFW window and SDL window. --- src/Windowing/Silk.NET.Windowing.Glfw/GlfwWindow.cs | 2 +- src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Windowing/Silk.NET.Windowing.Glfw/GlfwWindow.cs b/src/Windowing/Silk.NET.Windowing.Glfw/GlfwWindow.cs index 2e364abcfa..15030d3772 100644 --- a/src/Windowing/Silk.NET.Windowing.Glfw/GlfwWindow.cs +++ b/src/Windowing/Silk.NET.Windowing.Glfw/GlfwWindow.cs @@ -731,7 +731,7 @@ protected override void RegisterCallbacks() for (var i = 0; i < count; i++) { var p = Marshal.ReadIntPtr(paths, i * IntPtr.Size); - arrayOfPaths[i] = Marshal.PtrToStringAnsi(p); + arrayOfPaths[i] = SilkMarshal.PtrToString((nint) p, NativeStringEncoding.UTF8) ?? ""; } FileDrop?.Invoke(arrayOfPaths); diff --git a/src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs b/src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs index 066cecafe7..bb3274c72e 100644 --- a/src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs +++ b/src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs @@ -7,6 +7,7 @@ using System.Runtime.CompilerServices; using Silk.NET.Core; using Silk.NET.Core.Contexts; +using Silk.NET.Core.Native; using Silk.NET.Maths; using Silk.NET.SDL; using Point = System.Drawing.Point; @@ -402,7 +403,8 @@ public override void ProcessEvents() } case EventType.Dropfile: { - _droppedFiles.Add(new string((sbyte*) @event.Drop.File)); + string path = SilkMarshal.PtrToString((nint) @event.Drop.File, NativeStringEncoding.UTF8) ?? ""; + _droppedFiles.Add(path); break; } default: