Skip to content

Commit

Permalink
Fixed DeleteFilesOnUpgrade option not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
pelya committed May 29, 2013
1 parent 0d5436f commit 1bae3af
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions project/java/Settings.java
Expand Up @@ -355,7 +355,7 @@ static void Load( final MainActivity p )
Log.i("SDL", "libSDL: old cfg version " + cfgVersion + ", our version " + p.getApplicationVersion());
if( cfgVersion != p.getApplicationVersion() )
{
DeleteFilesOnUpgrade();
DeleteFilesOnUpgrade(p);
if( Globals.ResetSdlConfigForThisVersion )
{
Log.i("SDL", "libSDL: old cfg version " + cfgVersion + ", our version " + p.getApplicationVersion() + " and we need to clean up config file");
Expand All @@ -370,7 +370,7 @@ static void Load( final MainActivity p )
} catch( FileNotFoundException e ) {
} catch( SecurityException e ) {
} catch ( IOException e ) {
DeleteFilesOnUpgrade();
DeleteFilesOnUpgrade(p);
if( Globals.ResetSdlConfigForThisVersion )
{
Log.i("SDL", "libSDL: old cfg version unknown or too old, our version " + p.getApplicationVersion() + " and we need to clean up config file");
Expand Down Expand Up @@ -2608,24 +2608,40 @@ public static boolean deleteRecursively(File dir)
{
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
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()
public static boolean deleteRecursivelyAndLog(File dir)
{
Log.v("SDL", "Deleting old file: " + dir.getAbsolutePath() + " exists " + dir.exists());
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(final MainActivity p)
{
String [] files = Globals.DeleteFilesOnUpgrade.split(" ");
for(String path: files) {
for(String path: files)
{
if( path.equals("") )
continue;
File f = new File( Globals.DataDir + "/" + path );
if( !f.exists() )
continue;
deleteRecursively(f);

deleteRecursivelyAndLog(new File( SdcardAppPath.getPath(p) + "/" + path ));
deleteRecursivelyAndLog(new File( p.getFilesDir().getAbsolutePath() + "/" + path ));
deleteRecursivelyAndLog(new File( SdcardAppPath.deprecatedPath(p) + "/" + path ));
}
}
public static void DeleteSdlConfigOnUpgradeAndRestart(final MainActivity p)
Expand Down

0 comments on commit 1bae3af

Please sign in to comment.