[Android] Copy lua on app startup, and overwrite on upgrade
Geoffrey Métais
git at videolan.org
Thu Dec 20 14:31:26 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 20 14:30:17 2018 +0100| [6b7c667c9bf75535d6a9e8880babd9ba7617464c] | committer: Geoffrey Métais
Copy lua on app startup, and overwrite on upgrade
> https://code.videolan.org/videolan/vlc-android/commit/6b7c667c9bf75535d6a9e8880babd9ba7617464c
---
.../src/org/videolan/vlc/StartActivity.java | 2 ++
.../src/org/videolan/vlc/util/FileUtils.java | 25 ++++++++++++++++------
.../src/org/videolan/vlc/util/VLCInstance.java | 11 ----------
3 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/StartActivity.java b/vlc-android/src/org/videolan/vlc/StartActivity.java
index 50668bfe2..ed65b6065 100644
--- a/vlc-android/src/org/videolan/vlc/StartActivity.java
+++ b/vlc-android/src/org/videolan/vlc/StartActivity.java
@@ -40,6 +40,7 @@ import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Constants;
+import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.Settings;
import androidx.core.content.ContextCompat;
@@ -86,6 +87,7 @@ public class StartActivity extends FragmentActivity {
final boolean firstRun = savedVersionNumber == -1;
final boolean upgrade = firstRun || savedVersionNumber != currentVersionNumber;
if (upgrade) settings.edit().putInt(Constants.PREF_FIRST_RUN, currentVersionNumber).apply();
+ FileUtils.copyLua(getApplicationContext(), upgrade);
// Route search query
if (Intent.ACTION_SEARCH.equals(action) || "com.google.android.gms.actions.SEARCH_ACTION".equals(action)) {
startActivity(intent.setClass(this, tv ? org.videolan.vlc.gui.tv.SearchActivity.class : SearchActivity.class));
diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index 8bb57c006..52503c8f3 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -132,8 +132,20 @@ public class FileUtils {
}
}
+ public static void copyLua(final Context context, final boolean force) {
+ WorkersKt.runIO(new Runnable() {
+ @Override
+ public void run() {
+ final String destinationFolder = context.getDir("vlc",
+ Context.MODE_PRIVATE).getAbsolutePath() + "/.share/lua";
+ final AssetManager am = VLCApplication.getAppResources().getAssets();
+ copyAssetFolder(am, "lua", destinationFolder, force);
+ }
+ });
+ }
+
@WorkerThread
- static boolean copyAssetFolder(AssetManager assetManager, String fromAssetPath, String toPath) {
+ static boolean copyAssetFolder(AssetManager assetManager, String fromAssetPath, String toPath, boolean force) {
try {
final String[] files = assetManager.list(fromAssetPath);
if (files.length == 0) return false;
@@ -143,11 +155,13 @@ public class FileUtils {
if (file.contains("."))
res &= copyAsset(assetManager,
fromAssetPath + "/" + file,
- toPath + "/" + file);
+ toPath + "/" + file,
+ force);
else
res &= copyAssetFolder(assetManager,
fromAssetPath + "/" + file,
- toPath + "/" + file);
+ toPath + "/" + file,
+ force);
return res;
} catch (Exception e) {
e.printStackTrace();
@@ -156,10 +170,9 @@ public class FileUtils {
}
@WorkerThread
- private static boolean copyAsset(AssetManager assetManager,
- String fromAssetPath, String toPath) {
+ private static boolean copyAsset(AssetManager assetManager, String fromAssetPath, String toPath, boolean force) {
final File destFile = new File(toPath);
- if (destFile.exists()) return true;
+ if (!force && destFile.exists()) return true;
InputStream in = null;
OutputStream out = null;
try {
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
index e63aebf62..5188c06df 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
@@ -37,16 +37,6 @@ public class VLCInstance {
private static LibVLC sLibVLC = null;
- private static Runnable sCopyLua = new Runnable() {
- @Override
- public void run() {
- final String destinationFolder = VLCApplication.getAppContext().getDir("vlc",
- Context.MODE_PRIVATE).getAbsolutePath() + "/.share/lua";
- AssetManager am = VLCApplication.getAppResources().getAssets();
- FileUtils.copyAssetFolder(am, "lua", destinationFolder);
- }
- };
-
/** A set of utility functions for the VLC application */
public synchronized static LibVLC get() throws IllegalStateException {
if (sLibVLC == null) {
@@ -60,7 +50,6 @@ public class VLCInstance {
// TODO change LibVLC signature to accept a List instead of an ArrayList
sLibVLC = new LibVLC(context, VLCOptions.getLibOptions());
- WorkersKt.runIO(sCopyLua);
}
return sLibVLC;
}
More information about the Android
mailing list