From 4b83c804cf8558b482d3bc73821cf36d7a7c58bc Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sat, 23 Aug 2014 17:55:55 -0500 Subject: [PATCH] Throw an Exception when WorldSettings fail to create the required directory structure. --- core/WorldSettings.java | 41 +++++++++++++++++++---------- services/helpers/CompassRegion.java | 7 ++++- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/core/WorldSettings.java b/core/WorldSettings.java index bca4dcfd..17cb1d44 100644 --- a/core/WorldSettings.java +++ b/core/WorldSettings.java @@ -47,10 +47,6 @@ public class WorldSettings extends Configuration compass = new CompassService( AEFolder ); - File spawnData = new File( AEFolder, "spawndata" ); - if ( !spawnData.exists() || !spawnData.isDirectory() ) - spawnData.mkdir(); - for (int dimID : get( "DimensionManager", "StorageCells", new int[0] ).getIntList()) { storageCellDims.add( dimID ); @@ -85,7 +81,7 @@ public class WorldSettings extends Configuration fis = new FileInputStream( f ); NBTTagCompound data = null; - + try { data = CompressedStreamTools.readCompressed( fis ); @@ -95,9 +91,9 @@ public class WorldSettings extends Configuration data = new NBTTagCompound(); AELog.error( e ); } - + fis.close(); - + return data; } catch (Throwable e) @@ -121,16 +117,16 @@ public class WorldSettings extends Configuration { // save FileOutputStream fos = new FileOutputStream( f ); - + try { CompressedStreamTools.writeCompressed( data, fos ); } - catch( Throwable e ) + catch (Throwable e) { AELog.error( e ); } - + fos.close(); } catch (Throwable e) @@ -256,12 +252,29 @@ public class WorldSettings extends Configuration { File world = DimensionManager.getCurrentSaveRootDirectory(); - File f = new File( world.getPath() + File.separatorChar + "AE2" ); + File aeBaseFolder = new File( world.getPath() + File.separatorChar + "AE2" ); - if ( !f.exists() || !f.isDirectory() ) - f.mkdir(); + if ( !aeBaseFolder.exists() || !aeBaseFolder.isDirectory() ) + if ( !aeBaseFolder.mkdir() ) + { + throw new RuntimeException( "Failed to create " + aeBaseFolder.getAbsolutePath() ); + } - instance = new WorldSettings( f ); + File compass = new File( aeBaseFolder, "compass" ); + if ( !compass.exists() || !compass.isDirectory() ) + if ( !compass.mkdir() ) + { + throw new RuntimeException( "Failed to create " + compass.getAbsolutePath() ); + } + + File spawnData = new File( aeBaseFolder, "spawndata" ); + if ( !spawnData.exists() || !spawnData.isDirectory() ) + if ( !spawnData.mkdir() ) + { + throw new RuntimeException( "Failed to create " + spawnData.getAbsolutePath() ); + } + + instance = new WorldSettings( aeBaseFolder ); } return instance; diff --git a/services/helpers/CompassRegion.java b/services/helpers/CompassRegion.java index bbeb8ba1..2b9eb068 100644 --- a/services/helpers/CompassRegion.java +++ b/services/helpers/CompassRegion.java @@ -5,6 +5,8 @@ import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; +import appeng.core.AELog; + public class CompassRegion { @@ -159,7 +161,10 @@ public class CompassRegion File folderFile = new File( folder ); if ( !folderFile.exists() || !folderFile.isDirectory() ) - folderFile.mkdir(); + { + if ( !folderFile.mkdir() ) + AELog.info( "Failed to created AE2/compass/" ); + } return new File( folder + File.separatorChar + world + "_" + low_x + "_" + low_z + ".dat" ); }