- code foramtting only mostly of whitespace for readability of a few Android files

This commit is contained in:
rolzad73@gmail.com
2013-06-01 16:02:10 +00:00
parent 8a7d5f4490
commit a400cabfc7
3 changed files with 956 additions and 873 deletions
+8 -8
View File
@@ -20,13 +20,13 @@ LOCAL_STATIC_LIBRARIES := libpng libjpeg
LOCAL_SHARED_LIBRARIES := SDL LOCAL_SHARED_LIBRARIES := SDL
LOCAL_C_INCLUDES := \ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/$(SDL_PATH)/include \ $(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/$(MTG_PATH)/include \ $(LOCAL_PATH)/$(MTG_PATH)/include \
$(LOCAL_PATH)/$(JGE_PATH)/include \ $(LOCAL_PATH)/$(JGE_PATH)/include \
$(LOCAL_PATH)/$(JGE_PATH)/src/zipFS \ $(LOCAL_PATH)/$(JGE_PATH)/src/zipFS \
$(LOCAL_PATH)/$(BOOST_PATH) \ $(LOCAL_PATH)/$(BOOST_PATH) \
$(LOCAL_PATH)/$(JPEG_PATH) \ $(LOCAL_PATH)/$(JPEG_PATH) \
$(LOCAL_PATH)/$(PNG_PATH) \ $(LOCAL_PATH)/$(PNG_PATH) \
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.cpp \ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.cpp \
$(MTG_PATH)/src/AbilityParser.cpp \ $(MTG_PATH)/src/AbilityParser.cpp \
@@ -36,7 +36,7 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.cpp \
$(MTG_PATH)/src/AIHints.cpp \ $(MTG_PATH)/src/AIHints.cpp \
$(MTG_PATH)/src/AIMomirPlayer.cpp \ $(MTG_PATH)/src/AIMomirPlayer.cpp \
$(MTG_PATH)/src/AIPlayer.cpp \ $(MTG_PATH)/src/AIPlayer.cpp \
$(MTG_PATH)/src/AIPlayerBaka.cpp \ $(MTG_PATH)/src/AIPlayerBaka.cpp \
$(MTG_PATH)/src/AIStats.cpp \ $(MTG_PATH)/src/AIStats.cpp \
$(MTG_PATH)/src/AllAbilities.cpp \ $(MTG_PATH)/src/AllAbilities.cpp \
$(MTG_PATH)/src/CardDescriptor.cpp \ $(MTG_PATH)/src/CardDescriptor.cpp \
@@ -1,4 +1,5 @@
package net.wagic.utils; package net.wagic.utils;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -7,164 +8,167 @@ import java.util.Scanner;
import android.os.Environment; import android.os.Environment;
import android.util.Log; import android.util.Log;
public class StorageOptions { public class StorageOptions
private static ArrayList<String> mMounts = new ArrayList<String>(); {
private static ArrayList<String> mVold = new ArrayList<String>(); private static ArrayList<String> mMounts = new ArrayList<String>();
private static ArrayList<String> mVold = new ArrayList<String>();
public static String[] labels; public static String[] labels;
public static String[] paths; public static String[] paths;
public static int count = 0; public static int count = 0;
public static String defaultMountPoint; public static String defaultMountPoint;
public static void determineStorageOptions() { public static void determineStorageOptions()
initializeMountPoints(); {
readMountsFile(); initializeMountPoints();
readVoldFile(); readMountsFile();
compareMountsWithVold(); readVoldFile();
testAndCleanMountsList(); compareMountsWithVold();
setProperties(); testAndCleanMountsList();
} setProperties();
}
private static void initializeMountPoints()
{
try
{
defaultMountPoint = Environment.getExternalStorageDirectory().getCanonicalPath();
} catch (Exception ioEx)
{
// an error occurred trying to get the canonical path, use '/mnt/sdcard' instead
defaultMountPoint = "/mnt/sdcard";
}
}
private static void initializeMountPoints() private static void readMountsFile()
{ {
try /*
{ * Scan the /proc/mounts file and look for lines like this: /dev/block/vold/179:1 /mnt/sdcard vfat
defaultMountPoint = Environment.getExternalStorageDirectory().getCanonicalPath(); * rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
} *
catch (Exception ioEx) * When one is found, split it into its elements and then pull out the path to the that mount point and add it to the arraylist
{ */
// an error occurred trying to get the canonical path, use '/mnt/sdcard' instead
defaultMountPoint = "/mnt/sdcard";
}
}
try
{
Scanner scanner = new Scanner(new File("/proc/mounts"));
while (scanner.hasNext())
{
String line = scanner.nextLine();
if (line.startsWith("/dev/block/vold/"))
{
String[] lineElements = line.split(" ");
lineElements[1].replaceAll(":.*$", "");
mMounts.add(lineElements[1]);
}
}
} catch (FileNotFoundException fnfex)
{
// if proc/mount doesn't exist we just use
Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point");
mMounts.add(defaultMountPoint);
} catch (Exception e)
{
Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file");
mMounts.add(defaultMountPoint);
}
}
private static void readMountsFile() { private static void readVoldFile()
/* {
* Scan the /proc/mounts file and look for lines like this: /*
* /dev/block/vold/179:1 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0 * Scan the /system/etc/vold.fstab file and look for lines like this: dev_mount sdcard /mnt/sdcard 1 /devices/platform/s3c-sdhci.0/mmc_host/mmc0
* *
* When one is found, split it into its elements * When one is found, split it into its elements and then pull out the path to the that mount point and add it to the arraylist
* and then pull out the path to the that mount point */
* and add it to the arraylist
*/
try { try
Scanner scanner = new Scanner(new File("/proc/mounts")); {
while (scanner.hasNext()) { Scanner scanner = new Scanner(new File("/system/etc/vold.fstab"));
String line = scanner.nextLine(); while (scanner.hasNext())
if (line.startsWith("/dev/block/vold/")) { {
String[] lineElements = line.split(" "); String line = scanner.nextLine();
lineElements[1].replaceAll(":.*$", ""); if (line.startsWith("dev_mount"))
mMounts.add(lineElements[1]); {
} String[] lineElements = line.split(" ");
} lineElements[2] = lineElements[2].replaceAll(":.*$", "");
} mVold.add(lineElements[2]);
catch (FileNotFoundException fnfex){ }
// if proc/mount doesn't exist we just use }
Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point"); } catch (FileNotFoundException fnfex)
mMounts.add( defaultMountPoint ); {
} catch (Exception e) { // if vold.fstab doesn't exist we use the value gathered from the Environment
Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file"); Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point");
mMounts.add( defaultMountPoint ); mMounts.add(defaultMountPoint);
} } catch (Exception e)
} {
Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file");
mMounts.add(defaultMountPoint);
}
}
private static void readVoldFile() { private static void compareMountsWithVold()
/* {
* Scan the /system/etc/vold.fstab file and look for lines like this: /*
* dev_mount sdcard /mnt/sdcard 1 /devices/platform/s3c-sdhci.0/mmc_host/mmc0 * Sometimes the two lists of mount points will be different. We only want those mount points that are in both list.
* *
* When one is found, split it into its elements * Compare the two lists together and remove items that are not in both lists.
* and then pull out the path to the that mount point */
* and add it to the arraylist
*/
try { for (int i = 0; i < mMounts.size(); i++)
Scanner scanner = new Scanner(new File("/system/etc/vold.fstab")); {
while (scanner.hasNext()) { String mount = mMounts.get(i);
String line = scanner.nextLine(); if (!mVold.contains(mount))
if (line.startsWith("dev_mount")) { mMounts.remove(i--);
String[] lineElements = line.split(" "); }
lineElements[2] = lineElements[2].replaceAll(":.*$", "");
mVold.add(lineElements[2]);
}
}
}
catch (FileNotFoundException fnfex){
// if vold.fstab doesn't exist we use the value gathered from the Environment
Log.i(StorageOptions.class.getCanonicalName(), fnfex.getMessage() + ": assuming " + defaultMountPoint + " is the only mount point");
mMounts.add( defaultMountPoint );
}
catch (Exception e) {
Log.e(StorageOptions.class.getCanonicalName(), e.getMessage() + ": unknown exception while reading mounts file");
mMounts.add( defaultMountPoint );
}
}
private static void compareMountsWithVold() { // don't need this anymore, clear the vold list to reduce memory
/* // use and to prepare it for the next time it's needed.
* Sometimes the two lists of mount points will be different. mVold.clear();
* We only want those mount points that are in both list. }
*
* Compare the two lists together and remove items that are not in both lists.
*/
for (int i = 0; i < mMounts.size(); i++) { private static void testAndCleanMountsList()
String mount = mMounts.get(i); {
if (!mVold.contains(mount)) /*
mMounts.remove(i--); * Now that we have a cleaned list of mount paths Test each one to make sure it's a valid and available path. If it is not, remove it from the list.
} */
// don't need this anymore, clear the vold list to reduce memory for (int i = 0; i < mMounts.size(); i++)
// use and to prepare it for the next time it's needed. {
mVold.clear(); String mount = mMounts.get(i);
} File root = new File(mount);
if (!root.exists() || !root.isDirectory() || !root.canWrite())
mMounts.remove(i--);
}
}
private static void testAndCleanMountsList() { private static void setProperties()
/* {
* Now that we have a cleaned list of mount paths /*
* Test each one to make sure it's a valid and * At this point all the paths in the list should be valid. Build the public properties.
* available path. If it is not, remove it from */
* the list.
*/
for (int i = 0; i < mMounts.size(); i++) { ArrayList<String> mLabels = new ArrayList<String>();
String mount = mMounts.get(i);
File root = new File(mount);
if (!root.exists() || !root.isDirectory() || !root.canWrite())
mMounts.remove(i--);
}
}
private static void setProperties() { int i = 1;
/* for (String path : mMounts)
* At this point all the paths in the list should be { // TODO: /mnt/sdcard is assumed to always mean internal storage. Use this comparison until there is a better way to do this
* valid. Build the public properties. if ("/mnt/sdcard".equalsIgnoreCase(path))
*/ mLabels.add("Built-in Storage");
else
mLabels.add("External SD Card " + i++);
}
ArrayList<String> mLabels = new ArrayList<String>(); labels = new String[mLabels.size()];
mLabels.toArray(labels);
int i = 1; paths = new String[mMounts.size()];
for (String path: mMounts) mMounts.toArray(paths);
{ // TODO: /mnt/sdcard is assumed to always mean internal storage. Use this comparison until there is a better way to do this
if ("/mnt/sdcard".equalsIgnoreCase(path))
mLabels.add("Built-in Storage");
else
mLabels.add("External SD Card " + i++);
}
labels = new String[mLabels.size()]; count = Math.min(labels.length, paths.length);
mLabels.toArray(labels);
paths = new String[mMounts.size()]; // don't need this anymore, clear the mounts list to reduce memory
mMounts.toArray(paths); // use and to prepare it for the next time it's needed.
mMounts.clear();
count = Math.min(labels.length, paths.length); }
// don't need this anymore, clear the mounts list to reduce memory
// use and to prepare it for the next time it's needed.
mMounts.clear();
}
} }
File diff suppressed because it is too large Load Diff