This commit is contained in:
dgis 2019-02-11 21:22:26 +00:00
parent dedfcd680b
commit 333f1ca479
3 changed files with 63 additions and 29 deletions

View file

@ -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);

View file

@ -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

View file

@ -984,9 +984,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private int onFileOpen(String url) {
int result = NativeLib.onFileOpen(url);
if(result > 0) {
setPort1Settings(NativeLib.getPort1Plugged(), NativeLib.getPort1Writable());
displayFilename(url);
showKMLLog();
} else
showKMLLogForce();
updateNavigationDrawerItems();
return result;
}
@ -1020,6 +1023,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private void showKMLLog() {
if(sharedPreferences.getBoolean("settings_alwaysdisplog", true)) {
showKMLLogForce();
}
}
private void showKMLLogForce() {
String kmlLog = NativeLib.getKMLLog();
new AlertDialog.Builder(this)
.setTitle("KML Script Compilation Result")
@ -1029,7 +1037,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
}).show();
}
}
final int GENERIC_READ = 1;
final int GENERIC_WRITE = 2;