From ad412177ab564ba01aee6f7b2d20a610230c47f6 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 10 Jul 2022 21:37:01 -0500 Subject: [PATCH] [nostalgia/studio] MSVC fixes for NFDE file dialog --- src/nostalgia/studio/lib/filedialog.hpp | 11 +++++++++-- src/nostalgia/studio/lib/filedialog_nfd.cpp | 14 +++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/nostalgia/studio/lib/filedialog.hpp b/src/nostalgia/studio/lib/filedialog.hpp index 863bab22..5b302085 100644 --- a/src/nostalgia/studio/lib/filedialog.hpp +++ b/src/nostalgia/studio/lib/filedialog.hpp @@ -4,11 +4,18 @@ #pragma once +#include + namespace nostalgia::studio { struct FDFilterItem { - ox::String name; - ox::String spec; +#ifdef OX_OS_Windows + using String = ox::BasicString<8, wchar_t>; +#else + using String = ox::String; +#endif + String name; + String spec; }; ox::Result saveFile(const ox::Vector &exts) noexcept; diff --git a/src/nostalgia/studio/lib/filedialog_nfd.cpp b/src/nostalgia/studio/lib/filedialog_nfd.cpp index 5edbef90..9d9a71eb 100644 --- a/src/nostalgia/studio/lib/filedialog_nfd.cpp +++ b/src/nostalgia/studio/lib/filedialog_nfd.cpp @@ -14,8 +14,14 @@ namespace nostalgia::studio { static ox::Result toResult(nfdresult_t r, const NFD::UniquePathN &path) noexcept { switch (r) { - case NFD_OKAY: - return ox::String(path.get()); + case NFD_OKAY: { + ox::String out; + for (auto i = 0u; path.get()[i]; ++i) { + const auto c = static_cast(path.get()[i]); + oxIgnoreError(out.append(&c, 1)); + } + return out; + } case NFD_CANCEL: return OxError(1, "Operation cancelled"); default: @@ -28,7 +34,9 @@ ox::Result saveFile(const ox::Vector &filters) noexcep NFD::UniquePathN path; ox::Vector filterItems(filters.size()); for (auto i = 0u; const auto &f : filters) { - filterItems[i] = {f.name.c_str(), f.spec.c_str()}; + filterItems[i].name = f.name.c_str(); + filterItems[i].spec = f.spec.c_str(); + //filterItems[i] = {f.name.c_str(), f.spec.c_str()}; ++i; } return toResult(NFD::SaveDialog(path, filterItems.data(), filterItems.size()), path);