mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-01-10 23:29:43 +00:00
Allow access to toplevel of external storage
This commit is contained in:
parent
0eb4dad0da
commit
bc6719d712
@ -338,14 +338,17 @@ public class Apple2DisksMenu implements Apple2MenuView {
|
||||
disksList.setEnabled(true);
|
||||
|
||||
String disksDir = pathStackAsDirectory();
|
||||
boolean isRootPath = false;
|
||||
if (disksDir == null) {
|
||||
isRootPath = true;
|
||||
final boolean isRootPath = (disksDir == null);
|
||||
final File extStorageDir = Apple2Utils.getExternalStorageDirectory(mActivity);
|
||||
if (isRootPath) {
|
||||
disksDir = Apple2Utils.getDataDir(mActivity) + File.separator + "disks"; // default path
|
||||
}
|
||||
|
||||
File dir = new File(disksDir);
|
||||
while (disksDir.charAt(disksDir.length() - 1) == File.separatorChar) {
|
||||
disksDir = disksDir.substring(0, disksDir.length() - 1);
|
||||
}
|
||||
|
||||
File dir = new File(disksDir);
|
||||
final File[] files = dir.listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
name = name.toLowerCase();
|
||||
@ -370,29 +373,40 @@ public class Apple2DisksMenu implements Apple2MenuView {
|
||||
|
||||
Arrays.sort(files);
|
||||
|
||||
File extStorageDir = Apple2Utils.getExternalStorageDirectory(mActivity);
|
||||
File downloadsDir = Apple2Utils.getDownloadsDirectory(mActivity);
|
||||
final File realExtStorageDir = Apple2Utils.getRealExternalStorageDirectory(mActivity);
|
||||
final boolean isStoragePath = !isRootPath && (realExtStorageDir != null) && disksDir.equalsIgnoreCase(realExtStorageDir.getAbsolutePath());
|
||||
if (isStoragePath) {
|
||||
// promote apple2ix directory to top of list
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].getName().equals("apple2ix")) {
|
||||
if (i > 0) {
|
||||
System.arraycopy(/*src:*/files, /*srcPos:*/0, /*dst:*/files, /*dstPos:*/1, /*length:*/i);
|
||||
files[0] = new File(realExtStorageDir, "apple2ix");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final boolean includeExternalStoragePath = (extStorageDir != null && isRootPath);
|
||||
final boolean includeDownloadsPath = (downloadsDir != null && isRootPath);
|
||||
final int offset = includeExternalStoragePath ? (includeDownloadsPath ? 2 : 1) : (includeDownloadsPath ? 1 : 0);
|
||||
final int offset = includeExternalStoragePath ? 1 : 0;
|
||||
final String[] fileNames = new String[files.length + offset];
|
||||
final String[] filePaths = new String[files.length + offset];
|
||||
final boolean[] isDirectory = new boolean[files.length + offset];
|
||||
|
||||
int idx = 0;
|
||||
// first external storage link should be /sdcard/apple2ix to encourage this form of organization
|
||||
if (includeExternalStoragePath) {
|
||||
fileNames[idx] = Apple2Utils.getExternalStorageDirectory(mActivity).getAbsolutePath();
|
||||
isDirectory[idx] = true;
|
||||
++idx;
|
||||
}
|
||||
if (includeDownloadsPath) {
|
||||
fileNames[idx] = downloadsDir.getAbsolutePath();
|
||||
filePaths[idx] = Apple2Utils.getRealExternalStorageDirectory(mActivity).getAbsolutePath();
|
||||
fileNames[idx] = mActivity.getResources().getString(R.string.storage);
|
||||
isDirectory[idx] = true;
|
||||
++idx;
|
||||
}
|
||||
|
||||
for (File file : files) {
|
||||
isDirectory[idx] = file.isDirectory();
|
||||
fileNames[idx] = file.getName();
|
||||
filePaths[idx] = file.getName();
|
||||
fileNames[idx] = filePaths[idx];
|
||||
if (isDirectory[idx]) {
|
||||
fileNames[idx] += File.separator;
|
||||
}
|
||||
@ -469,11 +483,11 @@ public class Apple2DisksMenu implements Apple2MenuView {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||
if (isDirectory[position]) {
|
||||
Log.d(TAG, "Descending to path : " + fileNames[position]);
|
||||
if (parentIsRootPath && !new File(fileNames[position]).isAbsolute()) {
|
||||
pushPathStack(parentDisksDir + File.separator + fileNames[position]);
|
||||
Log.d(TAG, "Descending to path : " + filePaths[position]);
|
||||
if (parentIsRootPath && !new File(filePaths[position]).isAbsolute()) {
|
||||
pushPathStack(parentDisksDir + File.separator + filePaths[position]);
|
||||
} else {
|
||||
pushPathStack(fileNames[position]);
|
||||
pushPathStack(filePaths[position]);
|
||||
}
|
||||
dynamicSetup();
|
||||
ListView disksList = (ListView) mDisksView.findViewById(R.id.listView_settings);
|
||||
|
@ -39,7 +39,7 @@ public class Apple2Utils {
|
||||
|
||||
private static String sDataDir = null;
|
||||
private static File sExternalFilesDir = null;
|
||||
private static File sDownloadFilesDir = null;
|
||||
private static File sRealExternalFilesDir = null;
|
||||
|
||||
public static boolean readEntireFile(File file, StringBuilder fileData) {
|
||||
final int maxAttempts = 5;
|
||||
@ -109,17 +109,17 @@ public class Apple2Utils {
|
||||
}
|
||||
|
||||
String storageState = Environment.getExternalStorageState();
|
||||
if (!storageState.equals(Environment.MEDIA_MOUNTED)) {
|
||||
// 2015/10/28 : do not expose sExternalFilesDir/sDownloadFilesDir unless they are writable
|
||||
if (!Environment.MEDIA_MOUNTED.equals(storageState)) {
|
||||
// 2015/10/28 : do not expose sExternalFilesDir unless it is writable
|
||||
break;
|
||||
}
|
||||
|
||||
File externalStorageDir = Environment.getExternalStorageDirectory();
|
||||
if (externalStorageDir == null) {
|
||||
File realExternalStorageDir = Environment.getExternalStorageDirectory();
|
||||
if (realExternalStorageDir == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
File externalDir = new File(externalStorageDir, "apple2ix"); // /sdcard/apple2ix
|
||||
File externalDir = new File(realExternalStorageDir, "apple2ix"); // /sdcard/apple2ix
|
||||
if (!externalDir.exists()) {
|
||||
boolean made = externalDir.mkdirs();
|
||||
if (!made) {
|
||||
@ -129,15 +129,15 @@ public class Apple2Utils {
|
||||
}
|
||||
|
||||
sExternalFilesDir = externalDir;
|
||||
sDownloadFilesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||
sRealExternalFilesDir = realExternalStorageDir;
|
||||
} while (false);
|
||||
|
||||
return sExternalFilesDir;
|
||||
}
|
||||
|
||||
public static File getDownloadsDirectory(Apple2Activity activity) {
|
||||
public static File getRealExternalStorageDirectory(Apple2Activity activity) {
|
||||
getExternalStorageDirectory(activity);
|
||||
return sDownloadFilesDir;
|
||||
return sRealExternalFilesDir;
|
||||
}
|
||||
|
||||
// HACK NOTE 2015/02/22 : Apparently native code cannot easily access stuff in the APK ... so copy various resources
|
||||
|
@ -170,6 +170,7 @@
|
||||
<string name="settings_advanced_summary">Warning: these settings may degrade performance</string>
|
||||
<string name="settings_advanced_joystick">Advanced joystick/keypad settings</string>
|
||||
<string name="settings_advanced_joystick_summary">Advanced settings and performance tuning</string>
|
||||
<string name="storage">/storage/</string>
|
||||
<string name="touch_menu_enable">Enable touch menus</string>
|
||||
<string name="touch_menu_enable_summary">Enables soft menu buttons in top screen corners</string>
|
||||
<string name="video_configure">Configure video…</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user