[nostalgia/studio] Fix FDFilterItem to work on Windows

This commit is contained in:
Gary Talent 2022-12-18 21:52:46 -06:00
parent e2d5090f44
commit bd192ba47a
2 changed files with 13 additions and 4 deletions

View File

@ -10,12 +10,21 @@ namespace nostalgia::studio {
struct FDFilterItem { struct FDFilterItem {
#ifdef OX_OS_Windows #ifdef OX_OS_Windows
using String = ox::BasicString<8, wchar_t>; using String = ox::Vector<wchar_t>;
#else #else
using String = ox::String; using String = ox::Vector<char>;
#endif #endif
String name; String name;
String spec; 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<ox::String> saveFile(const ox::Vector<FDFilterItem> &exts) noexcept; ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &exts) noexcept;

View File

@ -34,8 +34,8 @@ ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &filters) noexcep
NFD::UniquePathN path; NFD::UniquePathN path;
ox::Vector<nfdnfilteritem_t, 5> filterItems(filters.size()); ox::Vector<nfdnfilteritem_t, 5> filterItems(filters.size());
for (auto i = 0u; const auto &f : filters) { for (auto i = 0u; const auto &f : filters) {
filterItems[i].name = f.name.c_str(); filterItems[i].name = f.name.data();
filterItems[i].spec = f.spec.c_str(); filterItems[i].spec = f.spec.data();
++i; ++i;
} }
return toResult(NFD::SaveDialog(path, filterItems.data(), filterItems.size()), path); return toResult(NFD::SaveDialog(path, filterItems.data(), filterItems.size()), path);