From 7ec319364948168219dbf1ea0344b55729df5f65 Mon Sep 17 00:00:00 2001 From: dgis Date: Sun, 25 Nov 2018 22:44:31 +0000 Subject: [PATCH] --- app/CMakeLists.txt | 2 ++ app/build.gradle | 6 ++--- app/src/main/cpp/emu48-jni.c | 9 ++++---- app/src/main/cpp/win32-layer.c | 42 +++++++++++++++------------------- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 3a195c6..50892f5 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -80,6 +80,8 @@ find_library( # Sets the name of the path variable. target_link_libraries( # Specifies the target library. native-lib + android + # Links the target library to the log library # included in the NDK. ${log-lib}) \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index b18d4c5..c1709b6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,7 +33,7 @@ dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:design:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +// testImplementation 'junit:junit:4.12' +// androidTestImplementation 'com.android.support.test:runner:1.0.2' +// androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } diff --git a/app/src/main/cpp/emu48-jni.c b/app/src/main/cpp/emu48-jni.c index 32a6839..5423d8b 100644 --- a/app/src/main/cpp/emu48-jni.c +++ b/app/src/main/cpp/emu48-jni.c @@ -3,6 +3,8 @@ // #include #include +#include +#include JNIEXPORT jstring JNICALL Java_com_regis_cosnier_emu48_MainActivity_stringFromJNI( @@ -14,10 +16,9 @@ Java_com_regis_cosnier_emu48_MainActivity_stringFromJNI( } extern void emu48Start(); -#include -#include +extern AAssetManager * assetManager; -JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_MainActivity_emu48Start(JNIEnv *env, jobject thisz, jobject assetManager) { - AAssetManager * mgr = (AAssetManager *)assetManager; +JNIEXPORT void JNICALL Java_com_regis_cosnier_emu48_MainActivity_emu48Start(JNIEnv *env, jobject thisz, jobject assetMgr) { + assetManager = AAssetManager_fromJava(env, assetMgr); emu48Start(); } diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c index 58554d0..ffd3e68 100644 --- a/app/src/main/cpp/win32-layer.c +++ b/app/src/main/cpp/win32-layer.c @@ -4,12 +4,13 @@ #include #include #include +#include +#include +#include "resource.h" HANDLE hWnd; LPTSTR szTitle; -//static HANDLE gEventId; - DWORD GetCurrentDirectory(DWORD nBufferLength, LPTSTR lpBuffer) { if(getcwd(lpBuffer, nBufferLength)) { @@ -26,28 +27,25 @@ BOOL SetCurrentDirectory(LPCTSTR path) return chdir(path); } -#include -#include -#include +AAssetManager * assetManager; + HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPVOID lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, LPVOID hTemplateFile) { if(strncmp(lpFileName, "assets/", 7) == 0) { - AAssetDir* assetDir = AAssetManager_openDir(mgr, ""); - const char* filename = (const char*)NULL; - while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) { - AAsset* asset = AAssetManager_open(mgr, filename, AASSET_MODE_STREAMING); - char buf[BUFSIZ]; - int nb_read = 0; - FILE* out = fopen(filename, "w"); - while ((nb_read = AAsset_read(asset, buf, BUFSIZ)) > 0) - fwrite(buf, nb_read, 1, out); - fclose(out); - AAsset_close(asset); - } - AAssetDir_close(assetDir); + + AAsset* asset = AAssetManager_open(assetManager, "calculators/real48sx.kml", AASSET_MODE_STREAMING); + char buf[BUFSIZ]; + int nb_read = 0; + nb_read = AAsset_read(asset, buf, BUFSIZ); + AAsset_close(asset); +// } +// AAssetDir* assetDir = AAssetManager_openDir(assetManager, ""); +// const char* filename = (const char*)NULL; +// while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) { +// AAssetDir_close(assetDir); HANDLE handle = malloc(sizeof(_HANDLE)); handle->handleType = HANDLE_TYPE_FILE; - handle->fileDescriptor = fd; + //handle->fileDescriptor = fd; handle->fileIsAsset = TRUE; return handle; } else { @@ -779,7 +777,7 @@ INT_PTR DialogBoxParam(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndPare } HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData) { //TODO - return NULL; + return INVALID_HANDLE_VALUE; } BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData) { //TODO @@ -801,13 +799,11 @@ PIDLIST_ABSOLUTE SHBrowseForFolderA(LPBROWSEINFOA lpbi) { //TODO return NULL; } -//extern INT_PTR CALLBACK ChooseKMLProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); -#include "resource.h" extern TCHAR szCurrentKml[MAX_PATH]; INT_PTR DialogBoxParamA(HINSTANCE hInstance, LPCSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) { //TODO if(lpTemplateName == MAKEINTRESOURCE(IDD_CHOOSEKML)) { - lstrcpy(szCurrentKml, "hello.kml"); + lstrcpy(szCurrentKml, "assets/calculators/real48sx.kml"); } return NULL; }