v1.2.0: deleted games now empty the main file instead of deleting it
This commit is contained in:
@@ -29,6 +29,7 @@ import com.badlogic.gdx.utils.GdxRuntimeException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils {
|
||||||
|
|
||||||
@@ -115,13 +116,17 @@ public class FileUtils {
|
|||||||
|
|
||||||
public static boolean fileExists( String name ){
|
public static boolean fileExists( String name ){
|
||||||
FileHandle file = getFileHandle( name );
|
FileHandle file = getFileHandle( name );
|
||||||
return file.exists() && !file.isDirectory();
|
return file.exists() && !file.isDirectory() && file.length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean deleteFile( String name ){
|
public static boolean deleteFile( String name ){
|
||||||
return getFileHandle( name ).delete();
|
return getFileHandle( name ).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setFileEmpty(String name ){
|
||||||
|
getFileHandle( name ).writeBytes(new byte[0], true);
|
||||||
|
}
|
||||||
|
|
||||||
// Directories
|
// Directories
|
||||||
|
|
||||||
public static boolean dirExists( String name ){
|
public static boolean dirExists( String name ){
|
||||||
@@ -139,6 +144,17 @@ public class FileUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArrayList<String> filesInDir( String name ){
|
||||||
|
FileHandle dir = getFileHandle( name );
|
||||||
|
ArrayList result = new ArrayList();
|
||||||
|
if (dir != null && dir.isDirectory()){
|
||||||
|
for (FileHandle file : dir.list()){
|
||||||
|
result.add(file.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// bundle reading
|
// bundle reading
|
||||||
|
|
||||||
//only works for base path
|
//only works for base path
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Blacksmith;
|
|||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Ghost;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Ghost;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Imp;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Imp;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Wandmaker;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.Wandmaker;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Ankh;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||||
@@ -53,7 +52,6 @@ import com.shatteredpixel.shatteredpixeldungeon.levels.CityLevel;
|
|||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.DeadEndLevel;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.DeadEndLevel;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.HallsLevel;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.HallsLevel;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.LastLevel;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.LastLevel;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.LastShopLevel;
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.Level;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.CavesBossLevel;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.CavesBossLevel;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.levels.CityBossLevel;
|
import com.shatteredpixel.shatteredpixeldungeon.levels.CityBossLevel;
|
||||||
@@ -667,12 +665,20 @@ public class Dungeon {
|
|||||||
|
|
||||||
public static void deleteGame( int save, boolean deleteLevels ) {
|
public static void deleteGame( int save, boolean deleteLevels ) {
|
||||||
|
|
||||||
FileUtils.deleteFile(GamesInProgress.gameFile(save));
|
|
||||||
|
|
||||||
if (deleteLevels) {
|
if (deleteLevels) {
|
||||||
|
String folder = GamesInProgress.gameFolder(save);
|
||||||
|
for (String file : FileUtils.filesInDir(folder)){
|
||||||
|
if (file.contains("depth")){
|
||||||
|
FileUtils.deleteFile(folder + "/" + file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ArrayList<String> files = FileUtils.filesInDir(GamesInProgress.gameFolder(save));
|
||||||
FileUtils.deleteDir(GamesInProgress.gameFolder(save));
|
FileUtils.deleteDir(GamesInProgress.gameFolder(save));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//we empty this file instead of delete due to steam cloud only persisting file deletions locally
|
||||||
|
FileUtils.setFileEmpty(GamesInProgress.gameFile(save));
|
||||||
|
|
||||||
GamesInProgress.delete( save );
|
GamesInProgress.delete( save );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ public class GamesInProgress {
|
|||||||
private static final String DEPTH_FILE = "depth%d.dat";
|
private static final String DEPTH_FILE = "depth%d.dat";
|
||||||
|
|
||||||
public static boolean gameExists( int slot ){
|
public static boolean gameExists( int slot ){
|
||||||
return FileUtils.dirExists(Messages.format(GAME_FOLDER, slot));
|
return FileUtils.dirExists(gameFolder(slot))
|
||||||
|
&& FileUtils.fileExists(gameFile(slot));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String gameFolder( int slot ){
|
public static String gameFolder( int slot ){
|
||||||
|
|||||||
+1
-2
@@ -149,8 +149,7 @@ public class WndGameInProgress extends Window {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSelect( int index ) {
|
protected void onSelect( int index ) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
FileUtils.deleteDir(GamesInProgress.gameFolder(slot));
|
Dungeon.deleteGame(slot, true);
|
||||||
GamesInProgress.setUnknown(slot);
|
|
||||||
ShatteredPixelDungeon.switchNoFade(StartScene.class);
|
ShatteredPixelDungeon.switchNoFade(StartScene.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user