Furnace has stopped.

• Diagnose later
This commit is contained in:
tildearrow 2022-11-05 19:24:14 -05:00
parent e75d1ef411
commit 6a6ca22ebe
3 changed files with 60 additions and 2 deletions

View file

@ -4,6 +4,8 @@
#ifdef USE_NFD
#include <nfd.h>
#elif defined(ANDROID)
#include <SDL.h>
#else
#include "../../extern/pfd-fixed/portable-file-dialogs.h"
#endif
@ -87,6 +89,45 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector<String> filter, c
#else
dialogO=new std::thread(_nfdThread,NFDState(false,header,filter,path,clickCallback,allowMultiple),&dialogOK,&nfdResult,&hasError);
#endif
#elif defined(ANDROID)
hasError=false;
if (jniEnv==NULL) {
jniEnv=(JNIEnv*)SDL_AndroidGetJNIEnv();
if (jniEnv==NULL) {
hasError=true;
logE("could not acquire JNI env!");
return false;
}
}
jobject activity=(jobject)SDL_AndroidGetActivity();
if (activity==NULL) {
hasError=true;
logE("the Activity is NULL!");
return false;
}
jclass class_=jniEnv->GetObjectClass(activity);
jmethodID showFileDialog=jniEnv->GetMethodID(class_,"showFileDialog","()B");
if (showFileDialog==NULL) {
logE("method showFileDialog not found!");
hasError=true;
jniEnv->DeleteLocalRef(class_);
jniEnv->DeleteLocalRef(activity);
return false;
}
jboolean mret=jniEnv->CallBooleanMethod(activity,showFileDialog);
if (!(bool)mret) {
hasError=true;
logW("could not open Android file picker...");
}
jniEnv->DeleteLocalRef(class_);
jniEnv->DeleteLocalRef(activity);
return true;
#else
dialogO=new pfd::open_file(header,path,filter,allowMultiple?(pfd::opt::multiselect):(pfd::opt::none));
hasError=!pfd::settings::available();
@ -113,6 +154,8 @@ bool FurnaceGUIFileDialog::openSave(String header, std::vector<String> filter, c
#else
dialogS=new std::thread(_nfdThread,NFDState(true,header,filter,path,NULL,false),&dialogOK,&nfdResult,&hasError);
#endif
#elif defined(ANDROID)
hasError=true; // TODO
#else
dialogS=new pfd::save_file(header,path,filter);
hasError=!pfd::settings::available();
@ -141,7 +184,9 @@ void FurnaceGUIFileDialog::close() {
#ifdef USE_NFD
dialogS->join();
#endif
#ifndef ANDROID
delete dialogS;
#endif
dialogS=NULL;
}
} else {
@ -149,7 +194,9 @@ void FurnaceGUIFileDialog::close() {
#ifdef USE_NFD
dialogO->join();
#endif
#ifndef ANDROID
delete dialogO;
#endif
dialogO=NULL;
}
}
@ -179,6 +226,9 @@ bool FurnaceGUIFileDialog::render(const ImVec2& min, const ImVec2& max) {
return true;
}
return false;
#elif defined(ANDROID)
// TODO: detect when file picker is closed
return false;
#else
if (saving) {
if (dialogS!=NULL) {