mirror of
https://github.com/AssetRipper/NativeFileDialogs.NET.git
synced 2026-11-13 18:07:38 -10:00
Fix string marshalling on Windows
This commit is contained in:
1 parent
92ddd55a44
commit
970c846e38
12 files changed
+847
-617
No files matched your search
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Speykious
|
||||
// Copyright (c) Speykious
|
||||
// This file is part of NativeFileDialogs.NET.
|
||||
// NativeFileDialogs.NET is licensed under the Zlib License. See LICENSE for details.
|
||||
|
||||
@@ -9,14 +9,14 @@ unsafe
|
||||
{
|
||||
nfd.NFD_Init();
|
||||
|
||||
NfdnfilteritemT[] filterItem = new[]
|
||||
Nfdu8filteritemT[] filterItem = new[]
|
||||
{
|
||||
new NfdnfilteritemT
|
||||
new Nfdu8filteritemT
|
||||
{
|
||||
Name = "Source code",
|
||||
Spec = "c,cpp,cc",
|
||||
},
|
||||
new NfdnfilteritemT
|
||||
new Nfdu8filteritemT
|
||||
{
|
||||
Name = "Headers",
|
||||
Spec = "h,hpp",
|
||||
@@ -24,7 +24,7 @@ unsafe
|
||||
};
|
||||
|
||||
sbyte* outPathPtr;
|
||||
NfdresultT result = nfd.NFD_OpenDialogN(&outPathPtr, filterItem, (uint)filterItem.Length, null);
|
||||
NfdresultT result = nfd.NFD_OpenDialogU8(&outPathPtr, filterItem, (uint)filterItem.Length, null);
|
||||
switch (result)
|
||||
{
|
||||
case NfdresultT.NFD_OKAY:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Speykious
|
||||
// Copyright (c) Speykious
|
||||
// This file is part of NativeFileDialogs.NET.
|
||||
// NativeFileDialogs.NET is licensed under the Zlib License. See LICENSE for details.
|
||||
|
||||
@@ -9,14 +9,14 @@ unsafe
|
||||
{
|
||||
nfd.NFD_Init();
|
||||
|
||||
NfdnfilteritemT[] filterItems = new[]
|
||||
Nfdu8filteritemT[] filterItems = new[]
|
||||
{
|
||||
new NfdnfilteritemT
|
||||
new Nfdu8filteritemT
|
||||
{
|
||||
Name = "Source code",
|
||||
Spec = "c,cpp,cc",
|
||||
},
|
||||
new NfdnfilteritemT
|
||||
new Nfdu8filteritemT
|
||||
{
|
||||
Name = "Headers",
|
||||
Spec = "h,hpp",
|
||||
@@ -24,7 +24,7 @@ unsafe
|
||||
};
|
||||
|
||||
IntPtr pathSet;
|
||||
NfdresultT result = nfd.NFD_OpenDialogMultipleN(&pathSet, filterItems, (uint)filterItems.Length, null);
|
||||
NfdresultT result = nfd.NFD_OpenDialogMultipleU8(&pathSet, filterItems, (uint)filterItems.Length, null);
|
||||
switch (result)
|
||||
{
|
||||
case NfdresultT.NFD_OKAY:
|
||||
@@ -36,7 +36,7 @@ unsafe
|
||||
for (uint i = 0; i < count; i++)
|
||||
{
|
||||
sbyte* pathPtr;
|
||||
nfd.NFD_PathSetGetPathN(pathSet, i, &pathPtr);
|
||||
nfd.NFD_PathSetGetPathU8(pathSet, i, &pathPtr);
|
||||
outPaths[i] = new string(pathPtr);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Speykious
|
||||
// Copyright (c) Speykious
|
||||
// This file is part of NativeFileDialogs.NET.
|
||||
// NativeFileDialogs.NET is licensed under the Zlib License. See LICENSE for details.
|
||||
|
||||
@@ -10,7 +10,7 @@ unsafe
|
||||
nfd.NFD_Init();
|
||||
|
||||
sbyte* outPathPtr;
|
||||
NfdresultT result = nfd.NFD_PickFolderN(&outPathPtr, null);
|
||||
NfdresultT result = nfd.NFD_PickFolderU8(&outPathPtr, null);
|
||||
switch (result)
|
||||
{
|
||||
case NfdresultT.NFD_OKAY:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Speykious
|
||||
// Copyright (c) Speykious
|
||||
// This file is part of NativeFileDialogs.NET.
|
||||
// NativeFileDialogs.NET is licensed under the Zlib License. See LICENSE for details.
|
||||
|
||||
@@ -9,14 +9,14 @@ unsafe
|
||||
{
|
||||
nfd.NFD_Init();
|
||||
|
||||
NfdnfilteritemT[] filterItem = new[]
|
||||
Nfdu8filteritemT[] filterItem = new[]
|
||||
{
|
||||
new NfdnfilteritemT
|
||||
new Nfdu8filteritemT
|
||||
{
|
||||
Name = "Source code",
|
||||
Spec = "c,cpp,cc",
|
||||
},
|
||||
new NfdnfilteritemT
|
||||
new Nfdu8filteritemT
|
||||
{
|
||||
Name = "Headers",
|
||||
Spec = "h,hpp",
|
||||
@@ -24,7 +24,7 @@ unsafe
|
||||
};
|
||||
|
||||
sbyte* savePathPtr;
|
||||
NfdresultT result = nfd.NFD_SaveDialogN(&savePathPtr, filterItem, (uint)filterItem.Length, null, "Untitled.c");
|
||||
NfdresultT result = nfd.NFD_SaveDialogU8(&savePathPtr, filterItem, (uint)filterItem.Length, null, "Untitled.c");
|
||||
switch (result)
|
||||
{
|
||||
case NfdresultT.NFD_OKAY:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <nfd.h>
|
||||
#include <new>
|
||||
|
||||
nfdpathsetenum_t& (nfdpathsetenum_t::*_0)(nfdpathsetenum_t&&) = &nfdpathsetenum_t::operator=;
|
||||
nfdnfilteritem_t& (nfdnfilteritem_t::*_1)(nfdnfilteritem_t&&) = &nfdnfilteritem_t::operator=;
|
||||
#include <nfd.h>
|
||||
#include <new>
|
||||
|
||||
nfdpathsetenum_t& (nfdpathsetenum_t::*_0)(nfdpathsetenum_t&&) = &nfdpathsetenum_t::operator=;
|
||||
nfdnfilteritem_t& (nfdnfilteritem_t::*_1)(nfdnfilteritem_t&&) = &nfdnfilteritem_t::operator=;
|
||||
nfdu8filteritem_t& (nfdu8filteritem_t::*_2)(nfdu8filteritem_t&&) = &nfdu8filteritem_t::operator=;
|
||||
@@ -22,8 +22,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="CppSharp.Runtime" Version="1.0.3" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||
<PackageReference Include="CppSharp.Runtime" Version="1.1.5.3168" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
// ----------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This is autogenerated code by CppSharp.
|
||||
// Do not edit this file or all your changes will be lost after re-generation.
|
||||
// </auto-generated>
|
||||
// ----------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
|
||||
using __IntPtr = global::System.IntPtr;
|
||||
[assembly:InternalsVisibleTo("nfd")]
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This is autogenerated code by CppSharp.
|
||||
// Do not edit this file or all your changes will be lost after re-generation.
|
||||
// </auto-generated>
|
||||
// ----------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention;
|
||||
using __IntPtr = global::System.IntPtr;
|
||||
[assembly:InternalsVisibleTo("nfd")]
|
||||
|
||||
#pragma warning disable CS0109 // Member does not hide an inherited member; new keyword is not required
|
||||
|
||||
+778
-563
File diff suppressed because it is too large.
Load diff
@@ -8,7 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="CppSharp" Version="1.0.1" />
|
||||
<PackageReference Include="CppSharp" Version="1.1.5.3168" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -6,20 +6,32 @@ using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
using CppSharp.Passes;
|
||||
using System.IO;
|
||||
|
||||
namespace NativeFileDialogs.CppSharpGenerator;
|
||||
|
||||
public class NativeFileDialogsLibrary : ILibrary
|
||||
{
|
||||
private const string lib_name = "NativeFileDialogs";
|
||||
private const string include_directory = "./include";
|
||||
|
||||
public void Setup(Driver driver)
|
||||
{
|
||||
Directory.CreateDirectory(include_directory);
|
||||
|
||||
string fileText = File.ReadAllText(@"../nativefiledialog-extended/src/include/nfd.h")
|
||||
.Replace("const nfdnfilteritem_t* filterList,", "const nfdnfilteritem_t filterList[],")
|
||||
.Replace("const nfdu8filteritem_t* filterList,", "const nfdu8filteritem_t filterList[],");
|
||||
//These replacements are necessary because CppSharp incorrectly generates the former as an object reference.
|
||||
|
||||
File.WriteAllText(include_directory + "/nfd.h", fileText);
|
||||
|
||||
DriverOptions options = driver.Options;
|
||||
options.GeneratorKind = GeneratorKind.CSharp;
|
||||
options.OutputDir = $"../{lib_name}.AutoGen";
|
||||
options.UseSpan = true;
|
||||
var module = options.AddModule("nfd");
|
||||
module.IncludeDirs.Add(@"../nativefiledialog-extended/src/include");
|
||||
module.IncludeDirs.Add(include_directory);
|
||||
module.Headers.Add("nfd.h");
|
||||
module.OutputNamespace = $"{lib_name}.AutoGen";
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -15,13 +15,13 @@ public static class Nfd
|
||||
public static NfdStatus OpenDialog(out string? outPath, IDictionary<string, string>? filters = null, string? defaultPath = null)
|
||||
{
|
||||
manager.PushDialog();
|
||||
NfdnfilteritemT[] filterItems = ToFilterItems(filters);
|
||||
Nfdu8filteritemT[] filterItems = ToFilterItems(filters);
|
||||
NfdStatus status;
|
||||
|
||||
unsafe
|
||||
{
|
||||
sbyte* outPathPtr;
|
||||
status = nfd.NFD_OpenDialogN(&outPathPtr, filterItems, (uint)filterItems.Length, defaultPath).ToNfdStatus();
|
||||
status = nfd.NFD_OpenDialogU8(&outPathPtr, filterItems, (uint)filterItems.Length, defaultPath).ToNfdStatus();
|
||||
outPath = status == NfdStatus.Cancelled ? null : new string(outPathPtr);
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ public static class Nfd
|
||||
public static NfdStatus OpenDialogMultiple(out string[]? outPaths, IDictionary<string, string>? filters = null, string? defaultPath = null)
|
||||
{
|
||||
manager.PushDialog();
|
||||
NfdnfilteritemT[] filterItems = ToFilterItems(filters);
|
||||
Nfdu8filteritemT[] filterItems = ToFilterItems(filters);
|
||||
NfdStatus status;
|
||||
|
||||
unsafe
|
||||
{
|
||||
IntPtr pathSet;
|
||||
status = nfd.NFD_OpenDialogMultipleN(&pathSet, filterItems, (uint)filterItems.Length, defaultPath).ToNfdStatus();
|
||||
status = nfd.NFD_OpenDialogMultipleU8(&pathSet, filterItems, (uint)filterItems.Length, defaultPath).ToNfdStatus();
|
||||
|
||||
if (status == NfdStatus.Ok)
|
||||
{
|
||||
@@ -49,7 +49,7 @@ public static class Nfd
|
||||
for (uint i = 0; i < count; i++)
|
||||
{
|
||||
sbyte* pathPtr;
|
||||
nfd.NFD_PathSetGetPathN(pathSet, i, &pathPtr);
|
||||
nfd.NFD_PathSetGetPathU8(pathSet, i, &pathPtr);
|
||||
outPaths[i] = new string(pathPtr);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public static class Nfd
|
||||
unsafe
|
||||
{
|
||||
sbyte* outPathPtr;
|
||||
status = nfd.NFD_PickFolderN(&outPathPtr, defaultPath).ToNfdStatus();
|
||||
status = nfd.NFD_PickFolderU8(&outPathPtr, defaultPath).ToNfdStatus();
|
||||
outPath = status == NfdStatus.Cancelled ? null : new string(outPathPtr);
|
||||
}
|
||||
|
||||
@@ -84,13 +84,13 @@ public static class Nfd
|
||||
public static NfdStatus SaveDialog(out string? savePath, IDictionary<string, string>? filters = null, string defaultName = "Untitled", string? defaultPath = null)
|
||||
{
|
||||
manager.PushDialog();
|
||||
NfdnfilteritemT[] filterItems = ToFilterItems(filters);
|
||||
Nfdu8filteritemT[] filterItems = ToFilterItems(filters);
|
||||
NfdStatus status;
|
||||
|
||||
unsafe
|
||||
{
|
||||
sbyte* savePathPtr;
|
||||
status = nfd.NFD_SaveDialogN(&savePathPtr, filterItems, (uint)filterItems.Length, defaultPath, defaultName).ToNfdStatus();
|
||||
status = nfd.NFD_SaveDialogU8(&savePathPtr, filterItems, (uint)filterItems.Length, defaultPath, defaultName).ToNfdStatus();
|
||||
savePath = status == NfdStatus.Cancelled ? null : new string(savePathPtr);
|
||||
}
|
||||
|
||||
@@ -98,16 +98,16 @@ public static class Nfd
|
||||
return status;
|
||||
}
|
||||
|
||||
internal static NfdnfilteritemT[] ToFilterItems(IDictionary<string, string>? filters)
|
||||
internal static Nfdu8filteritemT[] ToFilterItems(IDictionary<string, string>? filters)
|
||||
{
|
||||
if (filters == null)
|
||||
return Array.Empty<NfdnfilteritemT>();
|
||||
return Array.Empty<Nfdu8filteritemT>();
|
||||
|
||||
NfdnfilteritemT[] filterItems = new NfdnfilteritemT[filters.Count];
|
||||
Nfdu8filteritemT[] filterItems = new Nfdu8filteritemT[filters.Count];
|
||||
int i = 0;
|
||||
foreach ((string key, string value) in filters)
|
||||
{
|
||||
filterItems[i++] = new NfdnfilteritemT
|
||||
filterItems[i++] = new Nfdu8filteritemT
|
||||
{
|
||||
Name = key,
|
||||
Spec = value,
|
||||
|
||||
Reference in new issue
Block a user