From 9442d5fabc2f320f6e4320f2eda3a8362dc299d4 Mon Sep 17 00:00:00 2001 From: Speykious Date: Sun, 27 Mar 2022 18:50:20 +0200 Subject: [PATCH] Complete AutoGen examples --- ...logs.Net.Example.OpenDialogMultiple.csproj | 19 +++++++ .../Program.cs | 57 +++++++++++++++++++ ...eFileDialogs.Net.Example.PickFolder.csproj | 2 +- ...eFileDialogs.Net.Example.SaveDialog.csproj | 19 +++++++ .../Program.cs | 43 ++++++++++++++ NativeFileDialogs.NET.sln | 14 +++++ 6 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 Examples/AutoGen/NativeFileDialogs.Net.Example.OpenDialogMultiple/NativeFileDialogs.Net.Example.OpenDialogMultiple.csproj create mode 100644 Examples/AutoGen/NativeFileDialogs.Net.Example.OpenDialogMultiple/Program.cs create mode 100644 Examples/AutoGen/NativeFileDialogs.Net.Example.SaveDialog/NativeFileDialogs.Net.Example.SaveDialog.csproj create mode 100644 Examples/AutoGen/NativeFileDialogs.Net.Example.SaveDialog/Program.cs diff --git a/Examples/AutoGen/NativeFileDialogs.Net.Example.OpenDialogMultiple/NativeFileDialogs.Net.Example.OpenDialogMultiple.csproj b/Examples/AutoGen/NativeFileDialogs.Net.Example.OpenDialogMultiple/NativeFileDialogs.Net.Example.OpenDialogMultiple.csproj new file mode 100644 index 0000000..32702ee --- /dev/null +++ b/Examples/AutoGen/NativeFileDialogs.Net.Example.OpenDialogMultiple/NativeFileDialogs.Net.Example.OpenDialogMultiple.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + true + disable + enable + + + + + + + + + + + diff --git a/Examples/AutoGen/NativeFileDialogs.Net.Example.OpenDialogMultiple/Program.cs b/Examples/AutoGen/NativeFileDialogs.Net.Example.OpenDialogMultiple/Program.cs new file mode 100644 index 0000000..a58066b --- /dev/null +++ b/Examples/AutoGen/NativeFileDialogs.Net.Example.OpenDialogMultiple/Program.cs @@ -0,0 +1,57 @@ +// Copyright (c) Speykious +// This file is part of NativeFileDialogs.NET. +// NativeFileDialogs.NET is licensed under the Zlib License. See LICENSE for details. + +using System; +using NativeFileDialogs.AutoGen; + +unsafe +{ + nfd.NFD_Init(); + + NfdnfilteritemT[] filterItems = new[] + { + new NfdnfilteritemT + { + Name = "Source code", + Spec = "c,cpp,cc", + }, + new NfdnfilteritemT + { + Name = "Headers", + Spec = "h,hpp", + }, + }; + + IntPtr pathSet; + NfdresultT result = nfd.NFD_OpenDialogMultipleN(&pathSet, filterItems, (uint)filterItems.Length, null); + switch (result) + { + case NfdresultT.NFD_OKAY: + Console.WriteLine("Success!"); + uint count = 0; + nfd.NFD_PathSetGetCount(pathSet, ref count); + string[] outPaths = new string[count]; + + for (uint i = 0; i < count; i++) + { + sbyte* pathPtr; + nfd.NFD_PathSetGetPathN(pathSet, i, &pathPtr); + outPaths[i] = new string(pathPtr); + } + + nfd.NFD_PathSetFree(pathSet); + foreach (string path in outPaths) + Console.WriteLine($"- {path}"); + + break; + case NfdresultT.NFD_CANCEL: + Console.WriteLine("User pressed Cancel."); + break; + default: + Console.WriteLine($"Error: {nfd.NFD_GetError()}"); + break; + } + + nfd.NFD_Quit(); +} diff --git a/Examples/AutoGen/NativeFileDialogs.Net.Example.PickFolder/NativeFileDialogs.Net.Example.PickFolder.csproj b/Examples/AutoGen/NativeFileDialogs.Net.Example.PickFolder/NativeFileDialogs.Net.Example.PickFolder.csproj index 79dfaca..32702ee 100644 --- a/Examples/AutoGen/NativeFileDialogs.Net.Example.PickFolder/NativeFileDialogs.Net.Example.PickFolder.csproj +++ b/Examples/AutoGen/NativeFileDialogs.Net.Example.PickFolder/NativeFileDialogs.Net.Example.PickFolder.csproj @@ -1,6 +1,6 @@ - + Exe net6.0 true diff --git a/Examples/AutoGen/NativeFileDialogs.Net.Example.SaveDialog/NativeFileDialogs.Net.Example.SaveDialog.csproj b/Examples/AutoGen/NativeFileDialogs.Net.Example.SaveDialog/NativeFileDialogs.Net.Example.SaveDialog.csproj new file mode 100644 index 0000000..32702ee --- /dev/null +++ b/Examples/AutoGen/NativeFileDialogs.Net.Example.SaveDialog/NativeFileDialogs.Net.Example.SaveDialog.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + true + disable + enable + + + + + + + + + + + diff --git a/Examples/AutoGen/NativeFileDialogs.Net.Example.SaveDialog/Program.cs b/Examples/AutoGen/NativeFileDialogs.Net.Example.SaveDialog/Program.cs new file mode 100644 index 0000000..7cf8722 --- /dev/null +++ b/Examples/AutoGen/NativeFileDialogs.Net.Example.SaveDialog/Program.cs @@ -0,0 +1,43 @@ +// Copyright (c) Speykious +// This file is part of NativeFileDialogs.NET. +// NativeFileDialogs.NET is licensed under the Zlib License. See LICENSE for details. + +using System; +using NativeFileDialogs.AutoGen; + +unsafe +{ + nfd.NFD_Init(); + + NfdnfilteritemT[] filterItem = new[] + { + new NfdnfilteritemT + { + Name = "Source code", + Spec = "c,cpp,cc", + }, + new NfdnfilteritemT + { + Name = "Headers", + Spec = "h,hpp", + }, + }; + + sbyte* savePathPtr; + NfdresultT result = nfd.NFD_SaveDialogN(&savePathPtr, filterItem, (uint)filterItem.Length, null, "Untitled.c"); + switch (result) + { + case NfdresultT.NFD_OKAY: + Console.WriteLine("Success!"); + Console.WriteLine(new string(savePathPtr)); + break; + case NfdresultT.NFD_CANCEL: + Console.WriteLine("User pressed Cancel."); + break; + default: + Console.WriteLine($"Error: {nfd.NFD_GetError()}"); + break; + } + + nfd.NFD_Quit(); +} diff --git a/NativeFileDialogs.NET.sln b/NativeFileDialogs.NET.sln index 52b8190..24b01ed 100644 --- a/NativeFileDialogs.NET.sln +++ b/NativeFileDialogs.NET.sln @@ -19,6 +19,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NativeFileDialogs.Net.Examp EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NativeFileDialogs.Net.Example.PickFolder", "Examples\AutoGen\NativeFileDialogs.Net.Example.PickFolder\NativeFileDialogs.Net.Example.PickFolder.csproj", "{3922BD8E-E044-4DBF-83D6-9BBA1FFC0122}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NativeFileDialogs.Net.Example.OpenDialogMultiple", "Examples\AutoGen\NativeFileDialogs.Net.Example.OpenDialogMultiple\NativeFileDialogs.Net.Example.OpenDialogMultiple.csproj", "{FE187EC7-96DA-45B7-924A-7DACB9CF0D76}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NativeFileDialogs.Net.Example.SaveDialog", "Examples\AutoGen\NativeFileDialogs.Net.Example.SaveDialog\NativeFileDialogs.Net.Example.SaveDialog.csproj", "{A0F318E6-510E-401F-9C69-E62962075254}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -52,10 +56,20 @@ Global {3922BD8E-E044-4DBF-83D6-9BBA1FFC0122}.Debug|Any CPU.Build.0 = Debug|Any CPU {3922BD8E-E044-4DBF-83D6-9BBA1FFC0122}.Release|Any CPU.ActiveCfg = Release|Any CPU {3922BD8E-E044-4DBF-83D6-9BBA1FFC0122}.Release|Any CPU.Build.0 = Release|Any CPU + {FE187EC7-96DA-45B7-924A-7DACB9CF0D76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FE187EC7-96DA-45B7-924A-7DACB9CF0D76}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FE187EC7-96DA-45B7-924A-7DACB9CF0D76}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FE187EC7-96DA-45B7-924A-7DACB9CF0D76}.Release|Any CPU.Build.0 = Release|Any CPU + {A0F318E6-510E-401F-9C69-E62962075254}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0F318E6-510E-401F-9C69-E62962075254}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0F318E6-510E-401F-9C69-E62962075254}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0F318E6-510E-401F-9C69-E62962075254}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {130675E6-79D0-457D-AD33-ACFB03C12BAE} = {63ED5F3E-9FE3-4075-B612-CF85864AC12E} {870958BA-6E21-4E3A-9453-A8A97DF2728D} = {130675E6-79D0-457D-AD33-ACFB03C12BAE} {3922BD8E-E044-4DBF-83D6-9BBA1FFC0122} = {130675E6-79D0-457D-AD33-ACFB03C12BAE} + {FE187EC7-96DA-45B7-924A-7DACB9CF0D76} = {130675E6-79D0-457D-AD33-ACFB03C12BAE} + {A0F318E6-510E-401F-9C69-E62962075254} = {130675E6-79D0-457D-AD33-ACFB03C12BAE} EndGlobalSection EndGlobal