Skip to content

Commit b4405dc

Browse files
committed
ANDROID: cleanup file access handling
1 parent 5e53c34 commit b4405dc

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -952,13 +952,7 @@ protected Response getFile(String path, boolean asset) throws IOException {
952952
log("Opened " + name + " " + length + " bytes");
953953
result = new Response(getAssets().open(name), length);
954954
} else {
955-
File file = getFile(_storage.getExternal(), path);
956-
if (file == null) {
957-
file = getFile(_storage.getMedia(), path);
958-
}
959-
if (file == null) {
960-
file = getFile(_storage.getInternal(), path);
961-
}
955+
File file = getFile(path);
962956
if (file != null) {
963957
result = new Response(new FileInputStream(file), file.length());
964958
} else {
@@ -992,20 +986,11 @@ protected void renameFile(String from, String to) throws IOException {
992986
if (to == null || !to.endsWith(".bas")) {
993987
throw new IOException("Invalid file name: " + to);
994988
}
995-
File toFile = getFile(_storage.getInternal(), to);
996-
if (toFile == null) {
997-
toFile = getFile(_storage.getExternal(), to);
998-
}
989+
File toFile = getFile(to);
999990
if (toFile != null) {
1000991
throw new IOException("File already exists");
1001992
}
1002-
File fromFile = getFile(_storage.getInternal(), from);
1003-
if (fromFile == null) {
1004-
fromFile = getFile(_storage.getExternal(), from);
1005-
}
1006-
if (fromFile == null) {
1007-
fromFile = getFile(_storage.getInternal(), from);
1008-
}
993+
File fromFile = getFile(from);
1009994
if (fromFile == null) {
1010995
throw new IOException("Previous file does not exist");
1011996
}
@@ -1033,6 +1018,17 @@ private File getFile(String parent, String path) {
10331018
return result;
10341019
}
10351020

1021+
private File getFile(String path) {
1022+
File file = getFile(_storage.getExternal(), path);
1023+
if (file == null) {
1024+
file = getFile(_storage.getMedia(), path);
1025+
}
1026+
if (file == null) {
1027+
file = getFile(_storage.getInternal(), path);
1028+
}
1029+
return file;
1030+
}
1031+
10361032
private long getFileLength(String name) throws IOException {
10371033
Long length = fileLengths.get(name);
10381034
if (length == null) {

0 commit comments

Comments
 (0)