diff --git a/src/gui/fileDialog.cpp b/src/gui/fileDialog.cpp index f64f72cbb..bd54bf0fe 100644 --- a/src/gui/fileDialog.cpp +++ b/src/gui/fileDialog.cpp @@ -25,9 +25,10 @@ struct NFDState { }; // TODO: filter -void _nfdThread(const NFDState state, std::atomic* ok, String* result) { +void _nfdThread(const NFDState state, std::atomic* ok, String* result, bool* errorOutput) { nfdchar_t* out=NULL; nfdresult_t ret=NFD_CANCEL; + errorOutput=false; if (state.isSave) { ret=NFD_SaveDialog(state.filter,state.path.c_str(),&out,state.clickCallback); @@ -49,6 +50,7 @@ void _nfdThread(const NFDState state, std::atomic* ok, String* result) { case NFD_ERROR: (*result)=""; logE("NFD error! %s\n",NFD_GetError()); + (*errorOutput)=true; break; default: logE("NFD unknown return code %d!\n",ret); @@ -68,14 +70,16 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector filter, c #ifdef USE_NFD dialogOK=false; #ifdef NFD_NON_THREADED - _nfdThread(NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult); + _nfdThread(NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult,&hasError); #else - dialogO=new std::thread(_nfdThread,NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult); + dialogO=new std::thread(_nfdThread,NFDState(false,header,filter,path,clickCallback),&dialogOK,&nfdResult,&hasError); #endif #else dialogO=new pfd::open_file(header,path,filter); + hasError=!pfd::settings::available(); #endif } else { + hasError=false; ImGuiFileDialog::Instance()->DpiScale=dpiScale; ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,0,clickCallback); } @@ -92,14 +96,16 @@ bool FurnaceGUIFileDialog::openSave(String header, std::vector filter, c #ifdef USE_NFD dialogOK=false; #ifdef NFD_NON_THREADED - _nfdThread(NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult); + _nfdThread(NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult,&hasError); #else - dialogS=new std::thread(_nfdThread,NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult); + dialogS=new std::thread(_nfdThread,NFDState(true,header,filter,path,NULL),&dialogOK,&nfdResult,&hasError); #endif #else dialogS=new pfd::save_file(header,path,filter); + hasError=!pfd::settings::available(); #endif } else { + hasError=false; ImGuiFileDialog::Instance()->DpiScale=dpiScale; ImGuiFileDialog::Instance()->OpenModal("FileDialog",header,noSysFilter,path,1,nullptr,ImGuiFileDialogFlags_ConfirmOverwrite); } @@ -193,6 +199,10 @@ bool FurnaceGUIFileDialog::isOpen() { return opened; } +bool FurnaceGUIFileDialog::isError() { + return hasError; +} + String FurnaceGUIFileDialog::getPath() { if (sysDialog) { if (curPath.size()>1) { diff --git a/src/gui/fileDialog.h b/src/gui/fileDialog.h index 6724eb951..f3edd2884 100644 --- a/src/gui/fileDialog.h +++ b/src/gui/fileDialog.h @@ -28,6 +28,7 @@ class FurnaceGUIFileDialog { bool sysDialog; bool opened; bool saving; + bool hasError; String curPath; String fileName; #ifdef USE_NFD @@ -46,12 +47,14 @@ class FurnaceGUIFileDialog { void close(); bool render(const ImVec2& min, const ImVec2& max); bool isOpen(); + bool isError(); String getPath(); String getFileName(); explicit FurnaceGUIFileDialog(bool system): sysDialog(system), opened(false), saving(false), + hasError(false), dialogO(NULL), dialogS(NULL) {} }; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 642572d38..c6a58c083 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -3221,6 +3221,13 @@ bool FurnaceGUI::loop() { workingDirROM=fileDialog->getPath()+DIR_SEPARATOR_STR; break; } + if (fileDialog->isError()) { +#if defined(_WIN32) || defined(__APPLE__) + showError("there was an error in the file dialog! you may want to report this issue to:\nhttps://github.com/tildearrow/furnace/issues\ncheck the Log Viewer (window > log viewer) for more information.\n\nfor now please disable the system file picker in Settings > General."); +#else + showError("Zenity/KDialog not available!\nplease install one of these, or disable the system file picker in Settings > General."); +#endif + } if (fileDialog->accepted()) { fileName=fileDialog->getFileName(); if (fileName!="") {