From bd192ba47a31755705472b16e20914e3b591d189 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 18 Dec 2022 21:52:46 -0600 Subject: [PATCH] [nostalgia/studio] Fix FDFilterItem to work on Windows --- src/nostalgia/studio/lib/filedialog.hpp | 13 +++++++++++-- src/nostalgia/studio/lib/filedialog_nfd.cpp | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/nostalgia/studio/lib/filedialog.hpp b/src/nostalgia/studio/lib/filedialog.hpp index 5b302085..121ce8f2 100644 --- a/src/nostalgia/studio/lib/filedialog.hpp +++ b/src/nostalgia/studio/lib/filedialog.hpp @@ -10,12 +10,21 @@ namespace nostalgia::studio { struct FDFilterItem { #ifdef OX_OS_Windows - using String = ox::BasicString<8, wchar_t>; + using String = ox::Vector; #else - using String = ox::String; + using String = ox::Vector; #endif String name; String spec; + constexpr FDFilterItem() noexcept = default; + constexpr FDFilterItem(ox::CRStringView pName, ox::CRStringView pSpec) noexcept { + name.resize(pName.len() + 1); + memcpy(name.data(), pName.data(), pName.len()); + name.back().value = 0; + spec.resize(pSpec.len() + 1); + memcpy(spec.data(), pSpec.data(), pSpec.len()); + spec.back().value = 0; + } }; 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 401c75c8..0e6e5673 100644 --- a/src/nostalgia/studio/lib/filedialog_nfd.cpp +++ b/src/nostalgia/studio/lib/filedialog_nfd.cpp @@ -34,8 +34,8 @@ 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].name = f.name.c_str(); - filterItems[i].spec = f.spec.c_str(); + filterItems[i].name = f.name.data(); + filterItems[i].spec = f.spec.data(); ++i; } return toResult(NFD::SaveDialog(path, filterItems.data(), filterItems.size()), path);