diff --git a/app/src/main/cpp/emu48-jni.c b/app/src/main/cpp/emu48-jni.c index edfb3d2..30fe528 100644 --- a/app/src/main/cpp/emu48-jni.c +++ b/app/src/main/cpp/emu48-jni.c @@ -141,6 +141,8 @@ void sendMenuItemCommand(int menuItem) { (*jniEnv)->CallVoidMethod(jniEnv, mainActivity, midStr, menuItem); } +TCHAR lastKMLFilename[MAX_PATH]; + BOOL getFirstKMLFilenameForType(BYTE chipsetType, TCHAR * firstKMLFilename, size_t firstKMLFilenameSize) { if(firstKMLFilename) { JNIEnv *jniEnv = getJNIEnvironment(); @@ -149,6 +151,11 @@ BOOL getFirstKMLFilenameForType(BYTE chipsetType, TCHAR * firstKMLFilename, size jobject resultString = (*jniEnv)->CallObjectMethod(jniEnv, mainActivity, midStr, (char)chipsetType); if (resultString) { const char *strReturn = (*jniEnv)->GetStringUTFChars(jniEnv, resultString, 0); + if(_tcscmp(lastKMLFilename, strReturn) == 0) { + (*jniEnv)->ReleaseStringUTFChars(jniEnv, resultString, strReturn); + return FALSE; + } + _tcscpy(lastKMLFilename, strReturn); _tcsncpy(firstKMLFilename, strReturn, firstKMLFilenameSize); (*jniEnv)->ReleaseStringUTFChars(jniEnv, resultString, strReturn); return TRUE; @@ -416,6 +423,7 @@ JNIEXPORT jint JNICALL Java_org_emulator_forty_eight_NativeLib_onFileOpen(JNIEnv _tcscpy(szBufferFilename, stateFilenameUTF8); chooseCurrentKmlMode = ChooseKmlMode_FILE_OPEN; + lastKMLFilename[0] = '\0'; BOOL result = OpenDocument(szBufferFilename); if (result) MruAdd(szBufferFilename); diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c index 8d046ae..60cbb45 100644 --- a/app/src/main/cpp/win32-layer.c +++ b/app/src/main/cpp/win32-layer.c @@ -94,22 +94,38 @@ HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, if(!settingsPort2wr && (dwDesiredAccess & GENERIC_WRITE)) return (HANDLE) INVALID_HANDLE_VALUE; } -// if(chooseCurrentKmlMode == ChooseKmlMode_FILE_OPEN && lpFileName[0] == '/') { -// TCHAR * fileExtension = _tcsrchr(lpFileName, _T('.')); -// if(fileExtension && ((fileExtension[1] == 'K' && fileExtension[2] == 'M' && fileExtension[3] == 'L') || -// (fileExtension[1] == 'k' && fileExtension[2] == 'm' && fileExtension[3] == 'l') -// )) { -// _tcscpy(szEmuDirectory, lpFileName); -// TCHAR * filename = _tcsrchr(szEmuDirectory, _T('/')); -// if(filename) { -// *filename = _T('\0'); -// } -// _tcscpy(szRomDirectory, szEmuDirectory); -// SetCurrentDirectory(szEmuDirectory); -// } -// } + TCHAR * foundDocumentScheme = _tcsstr(lpFileName, documentScheme); + if(chooseCurrentKmlMode == ChooseKmlMode_FILE_OPEN) { + // When we open a new E48 state document + TCHAR * fileExtension = _tcsrchr(lpFileName, _T('.')); + if(fileExtension && ((fileExtension[1] == 'K' && fileExtension[2] == 'M' && fileExtension[3] == 'L') || + (fileExtension[1] == 'k' && fileExtension[2] == 'm' && fileExtension[3] == 'l') + )) { + // And opening a KML file + if(lpFileName[0] == '/') { + // With a recorded standard file + _tcscpy(szEmuDirectory, lpFileName); + TCHAR * filename = _tcsrchr(szEmuDirectory, _T('/')); + if(filename) { + *filename = _T('\0'); + } + _tcscpy(szRomDirectory, szEmuDirectory); + SetCurrentDirectory(szEmuDirectory); + } else if(foundDocumentScheme) { + // With a recorded "document:" scheme, extract the folder URL with content:// scheme + _tcscpy(szEmuDirectory, lpFileName + _tcslen(documentScheme) * sizeof(TCHAR)); + TCHAR * filename = _tcschr(szEmuDirectory, _T('|')); + if(filename) { + *filename = _T('\0'); + } + _tcscpy(szRomDirectory, szEmuDirectory); + SetCurrentDirectory(szEmuDirectory); + } + } + } + if(!forceNormalFile && (szCurrentAssetDirectory || _tcsncmp(lpFileName, assetsPrefix, assetsPrefixLength) == 0) && foundDocumentScheme == NULL) { // Asset file TCHAR szFileName[MAX_PATH]; @@ -2009,15 +2025,18 @@ INT_PTR DialogBoxParam(HINSTANCE hInstance, LPCTSTR lpTemplateName, HWND hWndPar } else if(chooseCurrentKmlMode == ChooseKmlMode_FILE_NEW) { lstrcpy(szCurrentKml, szChosenCurrentKml); } else if(chooseCurrentKmlMode == ChooseKmlMode_FILE_OPEN) { - if(getFirstKMLFilenameForType(Chipset.type, szCurrentKml, sizeof(szCurrentKml) / sizeof(szCurrentKml[0]))) - showAlert(_T("Cannot find the KML template file, so, try another one."), 0); - else + if(!getFirstKMLFilenameForType(Chipset.type, szCurrentKml, sizeof(szCurrentKml) / sizeof(szCurrentKml[0]))) { showAlert(_T("Cannot find the KML template file, sorry."), 0); + return -1; + } +// else { +// showAlert(_T("Cannot find the KML template file, so, try another one."), 0); //TODO is it right? +// } } } else if(lpTemplateName == MAKEINTRESOURCE(IDD_KMLLOG)) { lpDialogFunc(NULL, WM_INITDIALOG, 0, 0); } - return NULL; + return IDOK; } HCURSOR SetCursor(HCURSOR hCursor) { //TODO diff --git a/app/src/main/java/org/emulator/forty/eight/MainActivity.java b/app/src/main/java/org/emulator/forty/eight/MainActivity.java index be50dce..6830a17 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -984,9 +984,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On private int onFileOpen(String url) { int result = NativeLib.onFileOpen(url); - setPort1Settings(NativeLib.getPort1Plugged(), NativeLib.getPort1Writable()); - displayFilename(url); - showKMLLog(); + if(result > 0) { + setPort1Settings(NativeLib.getPort1Plugged(), NativeLib.getPort1Writable()); + displayFilename(url); + showKMLLog(); + } else + showKMLLogForce(); updateNavigationDrawerItems(); return result; } @@ -1020,17 +1023,21 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On private void showKMLLog() { if(sharedPreferences.getBoolean("settings_alwaysdisplog", true)) { - String kmlLog = NativeLib.getKMLLog(); - new AlertDialog.Builder(this) - .setTitle("KML Script Compilation Result") - .setMessage(kmlLog) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - } - }).show(); + showKMLLogForce(); } } + private void showKMLLogForce() { + String kmlLog = NativeLib.getKMLLog(); + new AlertDialog.Builder(this) + .setTitle("KML Script Compilation Result") + .setMessage(kmlLog) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + } + }).show(); + } + final int GENERIC_READ = 1; final int GENERIC_WRITE = 2; Map parcelFileDescriptorPerFd = null;