mirror of
https://github.com/love2d/love-android.git
synced 2026-08-20 04:31:26 +02:00
Only copy game archive if it's requested.
This commit is contained in:
@@ -22,7 +22,6 @@ package org.love2d.android;
|
|||||||
|
|
||||||
import org.libsdl.app.SDLActivity;
|
import org.libsdl.app.SDLActivity;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -60,6 +59,7 @@ public class GameActivity extends SDLActivity {
|
|||||||
public static final int RECORD_AUDIO_REQUEST_CODE = 3;
|
public static final int RECORD_AUDIO_REQUEST_CODE = 3;
|
||||||
private static boolean immersiveActive = false;
|
private static boolean immersiveActive = false;
|
||||||
private static boolean mustCacheArchive = false;
|
private static boolean mustCacheArchive = false;
|
||||||
|
private static boolean needToCopyGameInArchive = false;
|
||||||
private boolean storagePermissionUnnecessary = false;
|
private boolean storagePermissionUnnecessary = false;
|
||||||
private boolean shortEdgesMode = false;
|
private boolean shortEdgesMode = false;
|
||||||
public boolean embed = false;
|
public boolean embed = false;
|
||||||
@@ -210,41 +210,32 @@ public class GameActivity extends SDLActivity {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No game specified via the intent data or embed build is used.
|
// No game specified via the intent data or embed build is used.
|
||||||
// Check whether we have a game.love in our assets.
|
// Load game archive only when needed.
|
||||||
boolean game_love_in_assets = false;
|
needToCopyGameInArchive = true;
|
||||||
try {
|
|
||||||
List<String> assets = Arrays.asList(getAssets().list(""));
|
|
||||||
game_love_in_assets = assets.contains("game.love");
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.d("GameActivity", "could not list application assets:" + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (game_love_in_assets) {
|
|
||||||
// If we have a game.love in our assets folder copy it to the cache folder
|
|
||||||
// so that we can load it from native LÖVE code
|
|
||||||
String destination_file = this.getCacheDir().getPath() + "/game.love";
|
|
||||||
|
|
||||||
try {
|
|
||||||
InputStream gameStream = getAssets().open("game.love");
|
|
||||||
if (mustCacheArchive && copyAssetFile(gameStream, destination_file))
|
|
||||||
gamePath = destination_file;
|
|
||||||
else
|
|
||||||
gamePath = "game.love";
|
|
||||||
storagePermissionUnnecessary = true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d("GameActivity", "Could not open game.love from assets: " + e.getMessage());
|
|
||||||
gamePath = "";
|
|
||||||
storagePermissionUnnecessary = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
gamePath = "";
|
|
||||||
storagePermissionUnnecessary = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("GameActivity", "new gamePath: " + gamePath);
|
Log.d("GameActivity", "new gamePath: " + gamePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void copyGameInsideArchive() {
|
||||||
|
try {
|
||||||
|
// If we have a game.love in our assets folder copy it to the cache folder
|
||||||
|
// so that we can load it from native LÖVE code
|
||||||
|
AssetManager assetManager = getAssetManager();
|
||||||
|
InputStream gameStream = assetManager.open("game.love");
|
||||||
|
|
||||||
|
String destination_file = this.getCacheDir().getPath() + "/game.love";
|
||||||
|
if (mustCacheArchive && copyAssetFile(gameStream, destination_file))
|
||||||
|
gamePath = destination_file;
|
||||||
|
else
|
||||||
|
gamePath = "game.love";
|
||||||
|
storagePermissionUnnecessary = true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
// There's no game.love in our assets
|
||||||
|
Log.d("GameActivity", "Could not open game.love from assets: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void checkLovegameFolder() {
|
protected void checkLovegameFolder() {
|
||||||
// If no game.love was found and embed flavor is not used, fall back to the game in
|
// If no game.love was found and embed flavor is not used, fall back to the game in
|
||||||
// <external storage>/Android/data/<package name>/games/lovegame
|
// <external storage>/Android/data/<package name>/games/lovegame
|
||||||
@@ -317,11 +308,13 @@ public class GameActivity extends SDLActivity {
|
|||||||
Log.d("GameActivity", "called getGamePath(), game path = " + gamePath);
|
Log.d("GameActivity", "called getGamePath(), game path = " + gamePath);
|
||||||
|
|
||||||
if (gamePath.length() > 0) {
|
if (gamePath.length() > 0) {
|
||||||
if(self.storagePermissionUnnecessary || self.hasExternalStoragePermission()) {
|
if (self.storagePermissionUnnecessary || self.hasExternalStoragePermission()) {
|
||||||
return gamePath;
|
return gamePath;
|
||||||
} else {
|
} else {
|
||||||
Log.d("GameActivity", "cannot open game " + gamePath + ": no external storage permission given!");
|
Log.d("GameActivity", "cannot open game " + gamePath + ": no external storage permission given!");
|
||||||
}
|
}
|
||||||
|
} else if (needToCopyGameInArchive) {
|
||||||
|
self.copyGameInsideArchive();
|
||||||
} else {
|
} else {
|
||||||
self.checkLovegameFolder();
|
self.checkLovegameFolder();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user