Added option to remove specified file from SD card on upgrade

This commit is contained in:
pelya
2012-02-14 16:44:29 +02:00
parent c10bc16d67
commit 5ad654500f
3 changed files with 38 additions and 1 deletions

View File

@@ -304,6 +304,7 @@ class Settings
System.out.println("libSDL: Settings.Load(): loaded settings successfully");
settingsFile.close();
DeleteFilesOnUpgrade();
return;
} catch( FileNotFoundException e ) {
@@ -314,7 +315,7 @@ class Settings
Globals.DataDir = Globals.DownloadToSdcard ?
Environment.getExternalStorageDirectory().getAbsolutePath() + "/app-data/" + Globals.class.getPackage().getName() :
p.getFilesDir().getAbsolutePath();
DeleteFilesOnUpgrade();
// This code fails for both of my phones!
/*
Configuration c = new Configuration();
@@ -2418,6 +2419,29 @@ class Settings
}
}
public static boolean deleteRecursively(File dir)
{
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteRecursively(new File(dir, children[i]));
if (!success)
return false;
}
}
return dir.delete();
}
public static void DeleteFilesOnUpgrade()
{
String [] files = Globals.DeleteFilesOnUpgrade.split(" ");
for(String path: files) {
File f = new File( Globals.DataDir + "/" + path );
if( !f.exists() )
continue;
deleteRecursively(f);
}
}
// ===============================================================================================
static void Apply(Activity p)