Skip to content

Commit 0420d89

Browse files
committed
fix: 优化取外置路径的逻辑
1 parent da65f47 commit 0420d89

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

project/android/app/src/main/java/com/zeromake/onscripter/MainActivity.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import android.content.Context;
66
import android.content.DialogInterface;
77
import android.content.Intent;
8-
import android.graphics.Color;
98
import android.graphics.Point;
109
import android.os.Build;
1110
import android.os.Environment;
@@ -19,9 +18,7 @@
1918
import android.view.View;
2019
import android.widget.AdapterView;
2120
import android.widget.ArrayAdapter;
22-
import android.widget.Button;
2321
import android.widget.ImageView;
24-
import android.widget.LinearLayout;
2522
import android.widget.ListAdapter;
2623
import android.widget.ListView;
2724
import android.widget.PopupWindow;
@@ -182,7 +179,7 @@ private void chooseDir() {
182179
}
183180

184181
public void loadCurrentDirectory() {
185-
if (Globals.CurrentDirectoryPathForLauncher == null || Globals.CurrentDirectoryPathForLauncher.equals("")) {
182+
if (Globals.CurrentDirectoryPathForLauncher == null || Globals.CurrentDirectoryPathForLauncher.isEmpty()) {
186183
return;
187184
}
188185
try {
@@ -315,7 +312,7 @@ private void loadGameItem(Game game) {
315312
updateBackground(game.background);
316313
}
317314
if (game.cover != null) {
318-
updateCover(game.cover, game.background == null);
315+
updateCover(game.cover);
319316
} else {
320317
this.cover.setImageDrawable(getResources().getDrawable(R.drawable.dbkg_und));
321318
if (game.background == null) {
@@ -324,7 +321,7 @@ private void loadGameItem(Game game) {
324321
}
325322
}
326323

327-
private void updateCover(String cover, boolean b) {
324+
private void updateCover(String cover) {
328325
ImageLoader.getInstance().displayImage("file:/" + cover, this.cover, Settings.getDisplayImageOptions());
329326
}
330327

project/android/app/src/main/java/com/zeromake/onscripter/Settings.java

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.io.File;
1010
import java.util.ArrayList;
11+
import java.util.Arrays;
1112
import java.util.TreeSet;
1213

1314
public class Settings {
@@ -38,7 +39,7 @@ public static void SaveGlobals(Activity activity) {
3839

3940
private static void setupCurrentDirectory() {
4041
if (Globals.CurrentDirectoryPathForLauncher != null) {
41-
if (Globals.CurrentDirectoryPathForLauncher.equals("")) {
42+
if (Globals.CurrentDirectoryPathForLauncher.isEmpty()) {
4243
Globals.CurrentDirectoryPathForLauncher = null;
4344
} else {
4445
File file = new File(Globals.CurrentDirectoryPathForLauncher);
@@ -51,58 +52,63 @@ private static void setupCurrentDirectory() {
5152
ArrayList<String> arrayList = new ArrayList<>();
5253
TreeSet<String> treeSet = new TreeSet<>();
5354
TreeSet<String> validDirectory = new TreeSet<>();
55+
validDirectory.add(Environment.getExternalStorageDirectory().getAbsolutePath());
56+
for (String inlineSd: Globals.FallbackDirectoryPathArray) {
57+
File inlineSdF = new File(inlineSd);
58+
if (inlineSdF.exists() && inlineSdF.isDirectory() && inlineSdF.canRead()) {
59+
validDirectory.add(inlineSd);
60+
}
61+
}
62+
TreeSet<String> validEnvDirectory = new TreeSet<>();
63+
String str2 = System.getenv("EXTERNAL_STORAGE");
64+
if (str2 != null) {
65+
validEnvDirectory.add(str2);
66+
}
67+
String str3 = System.getenv("EXTERNAL_STORAGE2");
68+
if (str3 != null) {
69+
validEnvDirectory.add(str3);
70+
}
71+
String str4 = System.getenv("EXTERNAL_ALT_STORAGE");
72+
if (str4 != null) {
73+
validEnvDirectory.add(str4);
74+
}
75+
String str5 = System.getenv("SECOND_VOLUME_STORAGE");
76+
if (str5 != null) {
77+
validEnvDirectory.add(str5);
78+
}
79+
String str6 = System.getenv("THIRD_VOLUME_STORAGE");
80+
if (str6 != null) {
81+
validEnvDirectory.add(str6);
82+
}
83+
String str7 = System.getenv("SECONDARY_STORAGE");
84+
if (str7 != null) {
85+
validEnvDirectory.add(str7);
86+
}
87+
String str8 = System.getenv("EXTERNAL_STORAGE_ALL");
88+
if (str8 != null) {
89+
validEnvDirectory.addAll(Arrays.asList(str8.split(";")));
90+
}
91+
5492
for (String str : Globals.CURRENT_DIRECTORY_PATH_TEMPLATE_ARRAY) {
5593
if (!str.contains("${SDCARD}")) {
5694
treeSet.add(str);
5795
} else {
5896
treeSet.add(str.replace("${SDCARD}", Environment.getExternalStorageDirectory().getAbsolutePath()));
59-
validDirectory.add(Environment.getExternalStorageDirectory().getAbsolutePath());
60-
for (String inlineSd: Globals.FallbackDirectoryPathArray) {
61-
File inlineSdF = new File(inlineSd);
62-
if (inlineSdF.exists() && inlineSdF.isDirectory() && inlineSdF.canRead()) {
63-
treeSet.add(str.replace("${SDCARD}", inlineSd));
64-
validDirectory.add(inlineSd);
65-
}
66-
}
67-
String str2 = System.getenv("EXTERNAL_STORAGE");
68-
if (str2 != null) {
69-
treeSet.add(str.replace("${SDCARD}", str2));
70-
}
71-
String str3 = System.getenv("EXTERNAL_STORAGE2");
72-
if (str3 != null) {
73-
treeSet.add(str.replace("${SDCARD}", str3));
74-
}
75-
String str4 = System.getenv("EXTERNAL_ALT_STORAGE");
76-
if (str4 != null) {
77-
treeSet.add(str.replace("${SDCARD}", str4));
97+
for (String inlineSd : validDirectory) {
98+
treeSet.add(str.replace("${SDCARD}", inlineSd));
7899
}
79-
String str5 = System.getenv("SECOND_VOLUME_STORAGE");
80-
if (str5 != null) {
81-
treeSet.add(str.replace("${SDCARD}", str5));
82-
}
83-
String str6 = System.getenv("THIRD_VOLUME_STORAGE");
84-
if (str6 != null) {
85-
treeSet.add(str.replace("${SDCARD}", str6));
86-
}
87-
String str7 = System.getenv("SECONDARY_STORAGE");
88-
if (str7 != null) {
89-
treeSet.add(str.replace("${SDCARD}", str7));
90-
}
91-
String str8 = System.getenv("EXTERNAL_STORAGE_ALL");
92-
if (str8 != null) {
93-
for (String str9 : str8.split(";")) {
94-
treeSet.add(str.replace("${SDCARD}", str9));
95-
}
100+
for (String envSd: validEnvDirectory) {
101+
treeSet.add(str.replace("${SDCARD}", envSd));
96102
}
97103
}
98104
for (String s : treeSet) {
99105
File file2 = new File(s);
100106
if (file2.exists() && file2.isDirectory() && file2.canRead() && file2.canWrite()) {
101107
String absolutePath = file2.getAbsolutePath();
102-
if (Globals.CurrentDirectoryPathForLauncher == null || Globals.CurrentDirectoryPathForLauncher.equals("")) {
108+
if (Globals.CurrentDirectoryPathForLauncher == null || Globals.CurrentDirectoryPathForLauncher.isEmpty()) {
103109
Globals.CurrentDirectoryPathForLauncher = absolutePath;
104110
}
105-
if (Globals.CurrentDirectoryPath == null || Globals.CurrentDirectoryPath.equals("")) {
111+
if (Globals.CurrentDirectoryPath == null || Globals.CurrentDirectoryPath.isEmpty()) {
106112
Globals.CurrentDirectoryPath = absolutePath;
107113
}
108114
arrayList.add(absolutePath);

0 commit comments

Comments
 (0)