Replace nativefiledialog with nativefiledialog-extended

This commit is contained in:
Luke Street 2022-08-28 14:06:58 -04:00
parent 66cc6254c7
commit 49362ef591
7 changed files with 23 additions and 29 deletions

6
.gitmodules vendored
View File

@ -42,9 +42,9 @@
path = extern/zeus path = extern/zeus
url = ../zeus.git url = ../zeus.git
branch = master branch = master
[submodule "extern/nativefiledialog"] [submodule "extern/nativefiledialog-extended"]
path = extern/nativefiledialog path = extern/nativefiledialog-extended
url = https://github.com/mlabbe/nativefiledialog.git url = https://github.com/btzy/nativefiledialog-extended.git
[submodule "extern/optick"] [submodule "extern/optick"]
path = extern/optick path = extern/optick
url = https://github.com/AxioDL/optick.git url = https://github.com/AxioDL/optick.git

View File

@ -242,6 +242,7 @@ public:
#endif #endif
if (!m_projectInitialized && !m_deferredProject.empty()) { if (!m_projectInitialized && !m_deferredProject.empty()) {
Log.report(logvisor::Info, FMT_STRING("Loading game from '{}'"), m_deferredProject);
if (CDvdFile::Initialize(m_deferredProject)) { if (CDvdFile::Initialize(m_deferredProject)) {
m_projectInitialized = true; m_projectInitialized = true;
m_cvarCommons.m_lastDiscPath->fromLiteral(m_deferredProject); m_cvarCommons.m_lastDiscPath->fromLiteral(m_deferredProject);

View File

@ -230,8 +230,8 @@ add_executable(metaforce CMain.cpp ${PLAT_SRCS}
ImGuiEntitySupport.hpp ImGuiEntitySupport.cpp) ImGuiEntitySupport.hpp ImGuiEntitySupport.cpp)
# RUNTIME_LIBRARIES repeated here for link ordering # RUNTIME_LIBRARIES repeated here for link ordering
target_link_libraries(metaforce PUBLIC RuntimeCommon RuntimeCommonB ${RUNTIME_LIBRARIES} ${PLAT_LIBS} aurora::main) target_link_libraries(metaforce PUBLIC RuntimeCommon RuntimeCommonB ${RUNTIME_LIBRARIES} ${PLAT_LIBS} aurora::main)
if (TARGET nativefiledialog) if (TARGET nfd)
target_link_libraries(metaforce PRIVATE nativefiledialog) target_link_libraries(metaforce PRIVATE nfd)
endif() endif()
target_compile_definitions(metaforce PUBLIC "-DMETAFORCE_TARGET_BYTE_ORDER=__BYTE_ORDER__") target_compile_definitions(metaforce PUBLIC "-DMETAFORCE_TARGET_BYTE_ORDER=__BYTE_ORDER__")

View File

@ -17,7 +17,7 @@
#include "ImGuiEngine.hpp" #include "ImGuiEngine.hpp"
#include "magic_enum.hpp" #include "magic_enum.hpp"
#ifdef NATIVEFILEDIALOG_SUPPORTED #ifdef NATIVEFILEDIALOG_SUPPORTED
#include "nfd.h" #include <nfd.hpp>
#endif #endif
#include <cstdarg> #include <cstdarg>
@ -51,7 +51,9 @@ std::set<TUniqueId> ImGuiConsole::inspectingEntities;
ImGuiPlayerLoadouts ImGuiConsole::loadouts; ImGuiPlayerLoadouts ImGuiConsole::loadouts;
ImGuiConsole::ImGuiConsole(CVarManager& cvarMgr, CVarCommons& cvarCommons) ImGuiConsole::ImGuiConsole(CVarManager& cvarMgr, CVarCommons& cvarCommons)
: m_cvarMgr(cvarMgr), m_cvarCommons(cvarCommons) {} : m_cvarMgr(cvarMgr), m_cvarCommons(cvarCommons) {
NFD::Init();
}
void ImGuiStringViewText(std::string_view text) { void ImGuiStringViewText(std::string_view text) {
// begin()/end() do not work on MSVC // begin()/end() do not work on MSVC
@ -690,13 +692,12 @@ void ImGuiConsole::ShowAboutWindow(bool preLaunch) {
#ifdef NATIVEFILEDIALOG_SUPPORTED #ifdef NATIVEFILEDIALOG_SUPPORTED
ImGui::Dummy(padding); ImGui::Dummy(padding);
if (ImGuiButtonCenter("Select Game")) { if (ImGuiButtonCenter("Select Game")) {
nfdchar_t* outPath = nullptr; NFD::UniquePathU8 outPath;
nfdresult_t nfdResult = NFD_OpenDialog(nullptr, nullptr, &outPath); nfdresult_t nfdResult = NFD::OpenDialog(outPath, nullptr, 0, nullptr);
if (nfdResult == NFD_OKAY) { if (nfdResult == NFD_OKAY) {
m_gameDiscSelected = outPath; m_gameDiscSelected = outPath.get();
free(outPath);
} else if (nfdResult != NFD_CANCEL) { } else if (nfdResult != NFD_CANCEL) {
Log.report(logvisor::Error, FMT_STRING("nativefiledialog error: {}"), NFD_GetError()); Log.report(logvisor::Error, FMT_STRING("nativefiledialog error: {}"), NFD::GetError());
} }
} }
#endif #endif
@ -1441,6 +1442,7 @@ void ImGuiConsole::PostUpdate() {
void ImGuiConsole::Shutdown() { void ImGuiConsole::Shutdown() {
dummyWorlds.clear(); dummyWorlds.clear();
stringTables.clear(); stringTables.clear();
NFD::Quit();
} }
static constexpr std::array GeneralItems{ static constexpr std::array GeneralItems{

23
extern/CMakeLists.txt vendored
View File

@ -75,25 +75,16 @@ endif ()
add_subdirectory(jbus EXCLUDE_FROM_ALL) add_subdirectory(jbus EXCLUDE_FROM_ALL)
add_subdirectory(kabufuda EXCLUDE_FROM_ALL) add_subdirectory(kabufuda EXCLUDE_FROM_ALL)
add_library(nativefiledialog STATIC EXCLUDE_FROM_ALL nativefiledialog/src/nfd_common.c) option(NFD_PORTAL "Use xdg-desktop-portal instead of GTK" ON)
target_include_directories(nativefiledialog PUBLIC nativefiledialog/src/include)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux") if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_sources(nativefiledialog PRIVATE nativefiledialog/src/nfd_gtk.c) add_subdirectory(nativefiledialog-extended)
target_compile_definitions(nativefiledialog INTERFACE NATIVEFILEDIALOG_SUPPORTED) target_compile_definitions(nfd INTERFACE NATIVEFILEDIALOG_SUPPORTED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
target_link_libraries(nativefiledialog PRIVATE ${GTK3_LIBRARIES})
target_compile_options(nativefiledialog PRIVATE ${GTK3_CFLAGS_OTHER} -Wno-format-truncation -Wno-stringop-truncation)
target_include_directories(nativefiledialog PRIVATE ${GTK3_INCLUDE_DIRS})
target_link_directories(nativefiledialog PRIVATE ${GTK3_LIBRARY_DIRS})
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_sources(nativefiledialog PRIVATE nativefiledialog/src/nfd_cocoa.m) add_subdirectory(nativefiledialog-extended)
target_compile_definitions(nativefiledialog INTERFACE NATIVEFILEDIALOG_SUPPORTED) target_compile_definitions(nfd INTERFACE NATIVEFILEDIALOG_SUPPORTED)
# TODO link flags
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(nativefiledialog PRIVATE nativefiledialog/src/nfd_win.cpp) add_subdirectory(nativefiledialog-extended)
target_compile_definitions(nativefiledialog INTERFACE NATIVEFILEDIALOG_SUPPORTED) target_compile_definitions(nfd INTERFACE NATIVEFILEDIALOG_SUPPORTED)
else () else ()
message(WARNING "nativefiledialog unsupported for ${CMAKE_SYSTEM_NAME}") message(WARNING "nativefiledialog unsupported for ${CMAKE_SYSTEM_NAME}")
endif () endif ()

@ -1 +0,0 @@
Subproject commit 67345b80ebb429ecc2aeda94c478b3bcc5f7888e

1
extern/nativefiledialog-extended vendored Submodule

@ -0,0 +1 @@
Subproject commit e018ec82bc86240c80161ac616fd7da8bdcd85db