This source file includes following definitions.
- ensureAllDirectoriesExist
- getGpacAppDirectory
- getGpacConfigDirectory
- getGpacFontDirectory
- getGpacModulesDirectory
- getGpacLibsDirectory
- getGpacCacheDirectory
- getGpacGuiDirectory
- getGpacShaderDirectory
- getGpacLogDirectory
- createDirIfNotExist
- getGpacConfigFile
- getGpacLastRevFile
- getConfigAsText
package com.gpac.Osmo4;
import java.io.File;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
import android.util.Log;
public class GpacConfig {
private final static String LOG_GPAC_CONFIG = GpacConfig.class.getSimpleName();
public GpacConfig(Context context) {
String dataDir;
try {
if (context == null || context.getPackageManager() == null) {
dataDir = Environment.getDataDirectory() + "/data/com.gpac.Osmo4/";
Log.e(LOG_GPAC_CONFIG, "Cannot get context or PackageManager, using default directory=" + dataDir);
} else
dataDir = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0).dataDir;
} catch (NameNotFoundException e) {
Log.e(LOG_GPAC_CONFIG, "This is bad, we cannot find ourself : " + context.getPackageName(), e);
throw new RuntimeException("Cannot find package " + context.getPackageName(), e);
}
gpacAppDirectory = dataDir + '/';
Log.v(LOG_GPAC_CONFIG, "Using directory " + gpacAppDirectory + " for osmo");
gpacCacheDirectory = context.getCacheDir().getAbsolutePath();
Log.v(LOG_GPAC_CONFIG, "Using directory " + gpacCacheDirectory + " for cache");
gpacLibsDirectory = dataDir + "/lib/";
Log.v(LOG_GPAC_CONFIG, "Using directory " + gpacLibsDirectory + " for libraries");
gpacGuiDirectory = dataDir + "/gui/";
Log.v(LOG_GPAC_CONFIG, "Using directory " + gpacGuiDirectory + " for GUI");
gpacShaderDirectory = dataDir + "/shaders/";
Log.v(LOG_GPAC_CONFIG, "Using directory " + gpacShaderDirectory + " for shader files");
File osmo = new File(Environment.getExternalStorageDirectory(), "osmo");
gpacLogDirectory = osmo.getAbsolutePath() + "/log/";
Log.v(LOG_GPAC_CONFIG, "Using directory " + gpacLogDirectory + " for log files");
File gpac_cfg = new File(osmo.getAbsolutePath(), "GPAC.cfg");
if (gpac_cfg.exists())
gpacConfigDirectory = osmo.getAbsolutePath() + "/";
else
gpacConfigDirectory = null;
}
public GpacConfig ensureAllDirectoriesExist() {
for (String s : new String[] { gpacAppDirectory, gpacCacheDirectory, gpacShaderDirectory, gpacLogDirectory }) {
createDirIfNotExist(s);
}
return this;
}
public String getGpacAppDirectory() {
return gpacAppDirectory;
}
public String getGpacConfigDirectory() {
return gpacConfigDirectory;
}
public String getGpacFontDirectory() {
return gpacFontDirectory;
}
public String getGpacModulesDirectory() {
return gpacLibsDirectory;
}
public String getGpacLibsDirectory() {
return gpacLibsDirectory;
}
public String getGpacCacheDirectory() {
return gpacCacheDirectory;
}
public String getGpacGuiDirectory() {
return gpacGuiDirectory;
}
public String getGpacShaderDirectory() {
return gpacShaderDirectory;
}
public String getGpacLogDirectory() {
return gpacLogDirectory;
}
private final String gpacAppDirectory;
private final String gpacConfigDirectory;
private final String gpacFontDirectory = "/system/fonts/";
private final String gpacLibsDirectory;
private final String gpacCacheDirectory;
private final String gpacGuiDirectory;
private final String gpacShaderDirectory;
private final String gpacLogDirectory;
private static boolean createDirIfNotExist(String path) {
File f = new File(path);
if (!f.exists()) {
if (!f.mkdirs()) {
Log.e(LOG_GPAC_CONFIG, "Failed to create directory " + path);
return false;
} else {
Log.i(LOG_GPAC_CONFIG, "Created directory " + path);
}
}
return true;
}
public File getGpacConfigFile() {
return new File(getGpacConfigDirectory(), "GPAC.cfg");
}
public File getGpacLastRevFile() {
return new File(getGpacConfigDirectory(), "lastRev.txt");
}
public String getConfigAsText() {
StringBuilder sb = new StringBuilder();
sb.append("GpacAppDirectory=").append(getGpacAppDirectory()).append('\n');
sb.append("GpacModulesDirectory=").append(getGpacModulesDirectory()).append('\n');
sb.append("GpacFontDirectory=").append(getGpacFontDirectory()).append('\n');
sb.append("GpacCacheDirectory=").append(getGpacCacheDirectory()).append('\n');
sb.append("GpacGuiDirectory=").append(getGpacGuiDirectory()).append('\n');
sb.append("GpacShaderDirectory=").append(getGpacShaderDirectory()).append('\n');
return sb.toString();
}
}