[nostalgia/studio] MSVC fixes for NFDE file dialog

This commit is contained in:
Gary Talent 2022-07-10 21:37:01 -05:00
parent 1dddf4ad9d
commit ad412177ab
2 changed files with 20 additions and 5 deletions

View File

@ -4,11 +4,18 @@
#pragma once #pragma once
#include <ox/std/defines.hpp>
namespace nostalgia::studio { namespace nostalgia::studio {
struct FDFilterItem { struct FDFilterItem {
ox::String name; #ifdef OX_OS_Windows
ox::String spec; using String = ox::BasicString<8, wchar_t>;
#else
using String = ox::String;
#endif
String name;
String spec;
}; };
ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &exts) noexcept; ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &exts) noexcept;

View File

@ -14,8 +14,14 @@ namespace nostalgia::studio {
static ox::Result<ox::String> toResult(nfdresult_t r, const NFD::UniquePathN &path) noexcept { static ox::Result<ox::String> toResult(nfdresult_t r, const NFD::UniquePathN &path) noexcept {
switch (r) { switch (r) {
case NFD_OKAY: case NFD_OKAY: {
return ox::String(path.get()); ox::String out;
for (auto i = 0u; path.get()[i]; ++i) {
const auto c = static_cast<char>(path.get()[i]);
oxIgnoreError(out.append(&c, 1));
}
return out;
}
case NFD_CANCEL: case NFD_CANCEL:
return OxError(1, "Operation cancelled"); return OxError(1, "Operation cancelled");
default: default:
@ -28,7 +34,9 @@ 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] = {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; ++i;
} }
return toResult(NFD::SaveDialog(path, filterItems.data(), filterItems.size()), path); return toResult(NFD::SaveDialog(path, filterItems.data(), filterItems.size()), path);