- 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

View File

@@ -20,13 +20,13 @@ LOCAL_STATIC_LIBRARIES := libpng libjpeg
LOCAL_SHARED_LIBRARIES := SDL
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/$(MTG_PATH)/include \
$(LOCAL_PATH)/$(JGE_PATH)/include \
$(LOCAL_PATH)/$(JGE_PATH)/src/zipFS \
$(LOCAL_PATH)/$(BOOST_PATH) \
$(LOCAL_PATH)/$(JPEG_PATH) \
$(LOCAL_PATH)/$(PNG_PATH) \
$(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/$(MTG_PATH)/include \
$(LOCAL_PATH)/$(JGE_PATH)/include \
$(LOCAL_PATH)/$(JGE_PATH)/src/zipFS \
$(LOCAL_PATH)/$(BOOST_PATH) \
$(LOCAL_PATH)/$(JPEG_PATH) \
$(LOCAL_PATH)/$(PNG_PATH) \
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.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/AIMomirPlayer.cpp \
$(MTG_PATH)/src/AIPlayer.cpp \
$(MTG_PATH)/src/AIPlayerBaka.cpp \
$(MTG_PATH)/src/AIPlayerBaka.cpp \
$(MTG_PATH)/src/AIStats.cpp \
$(MTG_PATH)/src/AllAbilities.cpp \
$(MTG_PATH)/src/CardDescriptor.cpp \

View File

@@ -1,4 +1,5 @@
package net.wagic.utils;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
@@ -7,164 +8,167 @@ import java.util.Scanner;
import android.os.Environment;
import android.util.Log;
public class StorageOptions {
private static ArrayList<String> mMounts = new ArrayList<String>();
private static ArrayList<String> mVold = new ArrayList<String>();
public class StorageOptions
{
private static ArrayList<String> mMounts = new ArrayList<String>();
private static ArrayList<String> mVold = new ArrayList<String>();
public static String[] labels;
public static String[] paths;
public static int count = 0;
public static String defaultMountPoint;
public static void determineStorageOptions() {
initializeMountPoints();
readMountsFile();
readVoldFile();
compareMountsWithVold();
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 readMountsFile() {
/*
* 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
*
* 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
*/
public static String[] labels;
public static String[] paths;
public static int count = 0;
public static String defaultMountPoint;
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 );
}
}
public static void determineStorageOptions()
{
initializeMountPoints();
readMountsFile();
readVoldFile();
compareMountsWithVold();
testAndCleanMountsList();
setProperties();
}
private static void readVoldFile() {
/*
* 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
* and then pull out the path to the that mount point
* and add it to the arraylist
*/
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";
}
}
try {
Scanner scanner = new Scanner(new File("/system/etc/vold.fstab"));
while (scanner.hasNext()) {
String line = scanner.nextLine();
if (line.startsWith("dev_mount")) {
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 readMountsFile()
{
/*
* 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
*
* 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
*/
private static void compareMountsWithVold() {
/*
* Sometimes the two lists of mount points will be different.
* 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.
*/
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);
}
}
for (int i = 0; i < mMounts.size(); i++) {
String mount = mMounts.get(i);
if (!mVold.contains(mount))
mMounts.remove(i--);
}
private static void readVoldFile()
{
/*
* 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 and then pull out the path to the that mount point and add it to the arraylist
*/
// don't need this anymore, clear the vold list to reduce memory
// use and to prepare it for the next time it's needed.
mVold.clear();
}
try
{
Scanner scanner = new Scanner(new File("/system/etc/vold.fstab"));
while (scanner.hasNext())
{
String line = scanner.nextLine();
if (line.startsWith("dev_mount"))
{
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 testAndCleanMountsList() {
/*
* 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.
*/
private static void compareMountsWithVold()
{
/*
* Sometimes the two lists of mount points will be different. 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++) {
String mount = mMounts.get(i);
File root = new File(mount);
if (!root.exists() || !root.isDirectory() || !root.canWrite())
mMounts.remove(i--);
}
}
for (int i = 0; i < mMounts.size(); i++)
{
String mount = mMounts.get(i);
if (!mVold.contains(mount))
mMounts.remove(i--);
}
private static void setProperties() {
/*
* At this point all the paths in the list should be
* valid. Build the public properties.
*/
// don't need this anymore, clear the vold list to reduce memory
// use and to prepare it for the next time it's needed.
mVold.clear();
}
ArrayList<String> mLabels = new ArrayList<String>();
private static void testAndCleanMountsList()
{
/*
* 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.
*/
int i = 1;
for (String path: mMounts)
{ // 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()];
mLabels.toArray(labels);
for (int i = 0; i < mMounts.size(); i++)
{
String mount = mMounts.get(i);
File root = new File(mount);
if (!root.exists() || !root.isDirectory() || !root.canWrite())
mMounts.remove(i--);
}
}
paths = new String[mMounts.size()];
mMounts.toArray(paths);
private static void setProperties()
{
/*
* At this point all the paths in the list should be valid. Build the public properties.
*/
count = Math.min(labels.length, paths.length);
ArrayList<String> mLabels = new ArrayList<String>();
// 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();
}
int i = 1;
for (String path : mMounts)
{ // 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()];
mLabels.toArray(labels);
paths = new String[mMounts.size()];
mMounts.toArray(paths);
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