Fix a major issue which prevented to open a state file (with a custom KML script) with Android 10.

This commit is contained in:
dgis 2020-05-11 23:52:01 +02:00
parent 2b2308d93f
commit f53a8f35d2
7 changed files with 99 additions and 77 deletions

View file

@ -76,6 +76,7 @@ Version 1.8beta3 (2020-04-XX)
- Save the settings at the end of the state file.
- Transform all child activities with dialog fragments (to prevent unwanted state save).
- Fix an issue with the numpad keys which send the arrow keys and the numbers at the same time.
- Fix a major issue which prevented to open a state file (with a custom KML script) with Android 10.
Version 1.7 (2019-12-12)
@ -194,7 +195,6 @@ The Eric's Real scripts ("real*.kml" and "real*.bmp/png") are embedded in this a
TODO
- Add a settings to switch between dark and light theme.
- Increase the loading speed (for Charlemagne faceplates) if possible.
- Add the name of the file in the toast "State saved".
- The clock seems unsynchronized sometimes.

View file

@ -76,6 +76,7 @@ Version 1.8beta3 (2020-04-XX)
- Save the settings at the end of the state file.
- Transform all child activities with dialog fragments (to prevent unwanted state save).
- Fix an issue with the numpad keys which send the arrow keys and the numbers at the same time.
- Fix a major issue which prevented to open a state file (with a custom KML script) with Android 10.
Version 1.7 (2019-12-12)

View file

@ -121,8 +121,23 @@ HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
if(chooseCurrentKmlMode == ChooseKmlMode_FILE_OPEN || chooseCurrentKmlMode == ChooseKmlMode_CHANGE_KML) {
// When we open a new E48 state document
// Deal with the KML file and its containing folder
if(foundDocumentScheme) {
// With a recorded "document:" scheme, extract the folder URL with content:// scheme
// document: is only for a KML file
_tcscpy(szEmuDirectory, lpFileName + _tcslen(documentScheme) * sizeof(TCHAR));
TCHAR * filename = _tcschr(szEmuDirectory, _T('|'));
if(filename) {
*filename = _T('\0');
}
#if EMUXX == 48
_tcscpy(szRomDirectory, szEmuDirectory);
#endif
SetCurrentDirectory(szEmuDirectory);
} else {
TCHAR * fileExtension = _tcsrchr(lpFileName, _T('.'));
if(fileExtension && ((fileExtension[1] == 'K' && fileExtension[2] == 'M' && fileExtension[3] == 'L') ||
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
@ -137,17 +152,17 @@ HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
_tcscpy(szRomDirectory, szEmuDirectory);
#endif
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');
}
#if EMUXX == 48
_tcscpy(szRomDirectory, szEmuDirectory);
#endif
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');
// }
//#if EMUXX == 48
// _tcscpy(szRomDirectory, szEmuDirectory);
//#endif
// SetCurrentDirectory(szEmuDirectory);
} else {
_tcscpy(szEmuDirectory, "assets/calculators/");
#if EMUXX == 48
@ -157,6 +172,7 @@ HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
}
}
}
}
if(!forceNormalFile
&& (szCurrentAssetDirectory || _tcsncmp(lpFileName, assetsPrefix, assetsPrefixLength) == 0)
@ -2899,6 +2915,8 @@ INT_PTR DialogBoxParam(HINSTANCE hInstance, LPCTSTR lpTemplateName, HWND hWndPar
} else if(chooseCurrentKmlMode == ChooseKmlMode_FILE_NEW) {
lstrcpy(szCurrentKml, szChosenCurrentKml);
} else if(chooseCurrentKmlMode == ChooseKmlMode_FILE_OPEN) {
// We are here because we open a state file and the embedded KML path is not reachable.
// So, we try to find a correct KML file in the current Custom KML scripts folder.
if(!getFirstKMLFilenameForType(Chipset.type, szCurrentKml, sizeof(szCurrentKml) / sizeof(szCurrentKml[0]))) {
showAlert(_T("Cannot find the KML template file, sorry."), 0);
return -1;

View file

@ -39,7 +39,7 @@ import java.util.Set;
public class MainScreenView extends PanAndScaleView {
protected static final String TAG = "MainScreenView";
protected final boolean debug = true;
protected final boolean debug = false;
private Paint paintFullCalc = new Paint();
private Paint paintLCD = new Paint();

View file

@ -158,14 +158,12 @@ public class Utils {
int maximumTextureSize = 0;
// Iterate through all the configurations to located the maximum texture size
for (int i = 0; i < totalConfigurations[0]; i++)
{
for (int i = 0; i < totalConfigurations[0]; i++) {
// Only need to check for width since opengl textures are always squared
egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);
// Keep track of the maximum texture size
if (maximumTextureSize < textureSize[0])
{
if (maximumTextureSize < textureSize[0]) {
maximumTextureSize = textureSize[0];
}

View file

@ -47,6 +47,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.FileProvider;
import androidx.core.view.GravityCompat;
import androidx.documentfile.provider.DocumentFile;
@ -107,7 +108,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
public static final int INTENT_PORT2LOAD = 6;
public static final int INTENT_PICK_KML_FOLDER_FOR_NEW_FILE = 7;
public static final int INTENT_PICK_KML_FOLDER_FOR_CHANGING = 8;
public static final int INTENT_PICK_KML_FOLDER_FOR_SETTINGS = 9;
public static final int INTENT_PICK_KML_FOLDER_FOR_SECURITY = 10;
public static final int INTENT_CREATE_RAM_CARD = 11;
public static final int INTENT_MACRO_LOAD = 12;
@ -537,66 +537,63 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
Pattern patternGlobalModel = Pattern.compile("\\s*Model\\s+\"(.*)\"");
Matcher m;
for (String calculatorFilename : calculatorsAssetFilenames) {
if (calculatorFilename.toLowerCase().lastIndexOf(".kml") != -1) {
BufferedReader reader = null;
try {
Uri calculatorsAssetFilenameUri = Uri.parse(calculatorFilename);
DocumentFile documentFile = DocumentFile.fromSingleUri(this, calculatorsAssetFilenameUri);
if(documentFile != null) {
Uri fileUri = documentFile.getUri();
InputStream inputStream = getContentResolver().openInputStream(fileUri);
if(inputStream != null) {
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
// do reading, usually loop until end of file reading
String mLine;
boolean inGlobal = false;
String title = null;
String model = null;
while ((mLine = reader.readLine()) != null) {
//process line
if (mLine.indexOf("Global") == 0) {
inGlobal = true;
title = null;
model = null;
continue;
BufferedReader reader = null;
try {
Uri calculatorsAssetFilenameUri = Uri.parse(calculatorFilename);
DocumentFile documentFile = DocumentFile.fromSingleUri(this, calculatorsAssetFilenameUri);
if(documentFile != null) {
Uri fileUri = documentFile.getUri();
InputStream inputStream = getContentResolver().openInputStream(fileUri);
if(inputStream != null) {
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
// do reading, usually loop until end of file reading
String mLine;
boolean inGlobal = false;
String title = null;
String model = null;
while ((mLine = reader.readLine()) != null) {
//process line
if (mLine.indexOf("Global") == 0) {
inGlobal = true;
title = null;
model = null;
continue;
}
if (inGlobal) {
if (mLine.indexOf("End") == 0) {
KMLScriptItem newKMLScriptItem = new KMLScriptItem();
newKMLScriptItem.filename = kmlFolderUseDefault ? calculatorFilename : "document:" + kmlFolderURL + "|" + calculatorFilename;
newKMLScriptItem.title = title;
newKMLScriptItem.model = model;
kmlScripts.add(newKMLScriptItem);
break;
}
if (inGlobal) {
if (mLine.indexOf("End") == 0) {
KMLScriptItem newKMLScriptItem = new KMLScriptItem();
newKMLScriptItem.filename = kmlFolderUseDefault ? calculatorFilename : "document:" + kmlFolderURL + "|" + calculatorFilename;
newKMLScriptItem.title = title;
newKMLScriptItem.model = model;
kmlScripts.add(newKMLScriptItem);
break;
}
m = patternGlobalTitle.matcher(mLine);
if (m.find()) {
title = m.group(1);
}
m = patternGlobalModel.matcher(mLine);
if (m.find()) {
model = m.group(1);
}
m = patternGlobalTitle.matcher(mLine);
if (m.find()) {
title = m.group(1);
}
m = patternGlobalModel.matcher(mLine);
if (m.find()) {
model = m.group(1);
}
}
}
}
} catch (IOException e) {
//log the exception
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
//log the exception
}
}
} catch (IOException e) {
//log the exception
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
//log the exception
}
}
}
}
}
Collections.sort(kmlScripts, (lhs, rhs) -> lhs.title.compareTo(rhs.title));
@ -652,10 +649,21 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
private void newFileFromKML(String kmlScriptFilename) {
int result = NativeLib.onFileNew(kmlScriptFilename);
// Eventually, close the previous state file
NativeLib.onFileClose();
showCalculatorView(false);
displayFilename("");
// Reset the embedded settings to the common settings
settings.setIsDefaultSettings(false);
settings.clearEmbeddedStateSettings();
// Update the Emu VM with the new settings
updateFromPreferences(null, false);
// Create a new genuine state file
int result = NativeLib.onFileNew(kmlScriptFilename);
if(result > 0) {
settings.setIsDefaultSettings(false);
settings.clearEmbeddedStateSettings();
showCalculatorView(true);
displayFilename("");
showKMLLog();
@ -1077,7 +1085,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
case INTENT_PICK_KML_FOLDER_FOR_NEW_FILE:
case INTENT_PICK_KML_FOLDER_FOR_CHANGING:
case INTENT_PICK_KML_FOLDER_FOR_SETTINGS:
case INTENT_PICK_KML_FOLDER_FOR_SECURITY: {
if(debug) Log.d(TAG, "onActivityResult INTENT_PICK_KML_FOLDER " + url);
settings.putBoolean("settings_kml_default", false);
@ -1092,8 +1099,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
case INTENT_PICK_KML_FOLDER_FOR_CHANGING:
OnViewScript();
break;
case INTENT_PICK_KML_FOLDER_FOR_SETTINGS:
break;
case INTENT_PICK_KML_FOLDER_FOR_SECURITY:
new AlertDialog.Builder(this)
.setTitle(getString(R.string.message_open_security_retry))
@ -1175,7 +1180,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
// Eventually, close the previous state file
NativeLib.onFileClose();
settings.setIsDefaultSettings(true);
//settings.setIsDefaultSettings(true);
showCalculatorView(false);
displayFilename("");

View file

@ -26,7 +26,7 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/settings_category_ui_title">
<ListPreference
<ListPreference
android:key="settings_auto_layout"
android:title="@string/settings_auto_layout_title"
android:dialogTitle="@string/settings_auto_layout_title"