v1.2.0: fixed errors with new save deletion logic

This commit is contained in:
Evan Debenham 2022-03-22 13:57:09 -04:00
parent 6dc26622b2
commit cfddbfc650
3 changed files with 17 additions and 8 deletions

View File

@ -118,13 +118,25 @@ public class FileUtils {
FileHandle file = getFileHandle( name );
return file.exists() && !file.isDirectory() && file.length() > 0;
}
//returns length of a file in bytes, or 0 if file does not exist
public static long fileLength( String name ){
FileHandle file = getFileHandle( name );
if (!file.exists() || file.isDirectory()){
return 0;
} else {
return file.length();
}
}
public static boolean deleteFile( String name ){
return getFileHandle( name ).delete();
}
public static void setFileEmpty(String name ){
getFileHandle( name ).writeBytes(new byte[0], true);
//replaces a file with zeroes, for as many bytes as given
//This is helpful as some cloud sync systems do not persist deleted or empty files
public static void zeroFile( String name, int bytes ){
getFileHandle( name ).writeBytes(new byte[bytes], false);
}
// Directories

View File

@ -672,12 +672,9 @@ public class Dungeon {
FileUtils.deleteFile(folder + "/" + file);
}
}
ArrayList<String> files = FileUtils.filesInDir(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));
FileUtils.zeroFile(GamesInProgress.gameFile(save), 1);
GamesInProgress.delete( save );
}

View File

@ -50,7 +50,7 @@ public class GamesInProgress {
public static boolean gameExists( int slot ){
return FileUtils.dirExists(gameFolder(slot))
&& FileUtils.fileExists(gameFile(slot));
&& FileUtils.fileLength(gameFile(slot)) > 1;
}
public static String gameFolder( int slot ){
@ -74,7 +74,7 @@ public class GamesInProgress {
public static ArrayList<Info> checkAll(){
ArrayList<Info> result = new ArrayList<>();
for (int i = 0; i <= MAX_SLOTS; i++){
for (int i = 1; i <= MAX_SLOTS; i++){
Info curr = check(i);
if (curr != null) result.add(curr);
}