From 7b460d25d36338aaae9774bd3757cba42900601c Mon Sep 17 00:00:00 2001 From: afischerdev Date: Tue, 28 Dec 2021 10:49:56 +0100 Subject: [PATCH] add file check for A10 #379 --- .../btools/routingapp/BRouterActivity.java | 2 +- .../java/btools/routingapp/BRouterView.java | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java index 4b2e89a..9f933be 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java @@ -596,7 +596,7 @@ public class BRouterActivity extends Activity implements ActivityCompat.OnReques } } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R && checkExternalStorageWritable()) { res.add(Environment.getExternalStorageDirectory()); } diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java index 640c92f..3141278 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java @@ -123,6 +123,15 @@ public class BRouterView extends View { if (brd.isDirectory()) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q && !brd.getAbsolutePath().contains("/Android/media/btools.routingapp")) { + + // don't ask twice + String version = "v" + getContext().getString(R.string.app_version); + File vFile = new File(brd, "profiles2/"+version ); + if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.Q + && vFile.exists()) { + startSetup(baseDir, false); + return; + } String message = "(previous basedir " + baseDir + " has to migrate )"; ((BRouterActivity) getContext()).selectBasedir(((BRouterActivity) getContext()).getStorageDirectories(), guessBaseDir(), message); @@ -608,16 +617,18 @@ public class BRouterView extends View { break; String name = ze.getName(); File outfile = new File(path, name); - outfile.getParentFile().mkdirs(); - FileOutputStream fos = new FileOutputStream(outfile); + if (!outfile.exists()) { + outfile.getParentFile().mkdirs(); + FileOutputStream fos = new FileOutputStream(outfile); - for (; ; ) { - int len = zis.read(data, 0, 1024); - if (len < 0) - break; - fos.write(data, 0, len); + for (; ; ) { + int len = zis.read(data, 0, 1024); + if (len < 0) + break; + fos.write(data, 0, len); + } + fos.close(); } - fos.close(); } is.close(); return true;