Skip to content

Commit

Permalink
Fixed #174
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Aug 7, 2024
1 parent 2a886b6 commit 3f26197
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 28 deletions.
143 changes: 115 additions & 28 deletions extensions/filedialogs/src/arc/filedialogs/FileDialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,140 @@ public class FileDialogs{
#include <tinyfiledialogs.h>
#ifdef __WIN32__
#include <cwchar>
#endif
*/

public static void loadNatives() throws UnsatisfiedLinkError{
new SharedLibraryLoader().load("arc-filedialogs");
}

public static native @Nullable String saveFileDialog(String title, String defaultPathAndFile, String[] patterns, String filterDescription); /*
const char *param[20];
jsize stringCount = 0;
if(patterns != NULL){
stringCount = (*env).GetArrayLength(patterns);
//note: windows versions have to manually use UTF-16 versions of string because windows sucks

public static native @Nullable String saveFileDialog(String obj_title, String obj_defaultPathAndFile, String[] patterns, String obj_filterDescription); /*MANUAL
#ifdef __WIN32__
const jchar* title = env->GetStringChars(obj_title, 0);
const jchar* defaultPathAndFile = env->GetStringChars(obj_defaultPathAndFile, 0);
const jchar* filterDescription = env->GetStringChars(obj_filterDescription, 0);
const jchar *param[20];
jsize stringCount = 0;
if(patterns != NULL){
stringCount = (*env).GetArrayLength(patterns);
for(int i = 0; i < stringCount; i++){
param[i] = env->GetStringChars((jstring)env->GetObjectArrayElement(patterns, i), NULL);
}
}
const wchar_t* result = tinyfd_saveFileDialogW((wchar_t*)title, (wchar_t*)defaultPathAndFile, stringCount, (wchar_t**)param, (wchar_t*)filterDescription);
for(int i = 0; i < stringCount; i++){
param[i] = env->GetStringUTFChars((jstring)env->GetObjectArrayElement(patterns, i), NULL);
if(patterns != NULL){
for(int i = 0; i < stringCount; i++){
env->ReleaseStringChars((jstring)env->GetObjectArrayElement(patterns, i), param[i]);
}
}
}
const char* result = tinyfd_saveFileDialog(title, defaultPathAndFile, stringCount, param, filterDescription);
env->ReleaseStringChars(obj_title, title);
env->ReleaseStringChars(obj_defaultPathAndFile, defaultPathAndFile);
env->ReleaseStringChars(obj_filterDescription, filterDescription);
if(patterns != NULL){
for(int i = 0; i < stringCount; i++){
env->ReleaseStringUTFChars((jstring)env->GetObjectArrayElement(patterns, i), param[i]);
return env->NewString((jchar*)result, wcslen(result));
#else
char* title = (char*)env->GetStringUTFChars(obj_title, 0);
char* defaultPathAndFile = (char*)env->GetStringUTFChars(obj_defaultPathAndFile, 0);
char* filterDescription = (char*)env->GetStringUTFChars(obj_filterDescription, 0);
const char *param[20];
jsize stringCount = 0;
if(patterns != NULL){
stringCount = (*env).GetArrayLength(patterns);
for(int i = 0; i < stringCount; i++){
param[i] = env->GetStringUTFChars((jstring)env->GetObjectArrayElement(patterns, i), NULL);
}
}
}
return env->NewStringUTF(result);
const char* result = tinyfd_saveFileDialog(title, defaultPathAndFile, stringCount, param, filterDescription);
if(patterns != NULL){
for(int i = 0; i < stringCount; i++){
env->ReleaseStringUTFChars((jstring)env->GetObjectArrayElement(patterns, i), param[i]);
}
}
env->ReleaseStringUTFChars(obj_title, title);
env->ReleaseStringUTFChars(obj_defaultPathAndFile, defaultPathAndFile);
env->ReleaseStringUTFChars(obj_filterDescription, filterDescription);
return env->NewStringUTF(result);
#endif
*/

public static native @Nullable String openFileDialog(String title, String defaultPathAndFile, String[] patterns, String filterDescription, boolean allowMultipleSelects); /*
const char *param[20];
jsize stringCount = 0;
if(patterns != NULL){
stringCount = (*env).GetArrayLength(patterns);
public static native @Nullable String openFileDialog(String obj_title, String obj_defaultPathAndFile, String[] patterns, String obj_filterDescription, boolean allowMultipleSelects); /*MANUAL
#ifdef __WIN32__
const jchar* title = env->GetStringChars(obj_title, 0);
const jchar* defaultPathAndFile = env->GetStringChars(obj_defaultPathAndFile, 0);
const jchar* filterDescription = env->GetStringChars(obj_filterDescription, 0);
const jchar *param[20];
jsize stringCount = 0;
if(patterns != NULL){
stringCount = (*env).GetArrayLength(patterns);
for(int i = 0; i < stringCount; i++){
param[i] = env->GetStringUTFChars((jstring)env->GetObjectArrayElement(patterns, i), NULL);
for(int i = 0; i < stringCount; i++){
param[i] = env->GetStringChars((jstring)env->GetObjectArrayElement(patterns, i), NULL);
}
}
}
const char* result = tinyfd_openFileDialog(title, defaultPathAndFile, stringCount, param, filterDescription, allowMultipleSelects);
const wchar_t* result = tinyfd_openFileDialogW((wchar_t*)title, (wchar_t*)defaultPathAndFile, stringCount, (wchar_t**)param, (wchar_t*)filterDescription, allowMultipleSelects);
if(patterns != NULL){
for(int i = 0; i < stringCount; i++){
env->ReleaseStringUTFChars((jstring)env->GetObjectArrayElement(patterns, i), param[i]);
if(patterns != NULL){
for(int i = 0; i < stringCount; i++){
env->ReleaseStringChars((jstring)env->GetObjectArrayElement(patterns, i), param[i]);
}
}
}
return env->NewStringUTF(result);
env->ReleaseStringChars(obj_title, title);
env->ReleaseStringChars(obj_defaultPathAndFile, defaultPathAndFile);
env->ReleaseStringChars(obj_filterDescription, filterDescription);
return env->NewString((jchar*)result, wcslen(result));
#else
char* title = (char*)env->GetStringUTFChars(obj_title, 0);
char* defaultPathAndFile = (char*)env->GetStringUTFChars(obj_defaultPathAndFile, 0);
char* filterDescription = (char*)env->GetStringUTFChars(obj_filterDescription, 0);
const char *param[20];
jsize stringCount = 0;
if(patterns != NULL){
stringCount = (*env).GetArrayLength(patterns);
for(int i = 0; i < stringCount; i++){
param[i] = env->GetStringUTFChars((jstring)env->GetObjectArrayElement(patterns, i), NULL);
}
}
const char* result = tinyfd_openFileDialog(title, defaultPathAndFile, stringCount, param, filterDescription, allowMultipleSelects);
if(patterns != NULL){
for(int i = 0; i < stringCount; i++){
env->ReleaseStringUTFChars((jstring)env->GetObjectArrayElement(patterns, i), param[i]);
}
}
env->ReleaseStringUTFChars(obj_title, title);
env->ReleaseStringUTFChars(obj_defaultPathAndFile, defaultPathAndFile);
env->ReleaseStringUTFChars(obj_filterDescription, filterDescription);
return env->NewStringUTF(result);
#endif
*/
}
Binary file modified natives/natives-filedialogs/libs/arc-filedialogs.dll
Binary file not shown.
Binary file modified natives/natives-filedialogs/libs/arc-filedialogs64.dll
Binary file not shown.
Binary file modified natives/natives-filedialogs/libs/libarc-filedialogs64.so
Binary file not shown.

0 comments on commit 3f26197

Please sign in to comment.