Fixed #2591 / Fixed #2591 / Fixed #2589 / Fixed #2587

This commit is contained in:
Anuken
2020-09-18 11:21:50 -04:00
parent c71be9ae32
commit 6b6783f201
21 changed files with 4512 additions and 4335 deletions

View File

@@ -3,6 +3,7 @@ package mindustry.io;
import arc.*;
import arc.files.*;
import arc.struct.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.game.EventType.*;
@@ -41,7 +42,7 @@ public class SaveIO{
if(exists) file.moveTo(backupFileFor(file));
try{
write(file);
}catch(Exception e){
}catch(Throwable e){
if(exists) backupFileFor(file).moveTo(file);
throw new RuntimeException(e);
}
@@ -56,9 +57,9 @@ public class SaveIO{
}
public static boolean isSaveValid(Fi file){
try{
return isSaveValid(new DataInputStream(new InflaterInputStream(file.read(bufferSize))));
}catch(Exception e){
try(DataInputStream stream = new DataInputStream(new InflaterInputStream(file.read(bufferSize)))){
return isSaveValid(stream);
}catch(Throwable e){
return false;
}
}
@@ -67,8 +68,8 @@ public class SaveIO{
try{
getMeta(stream);
return true;
}catch(Exception e){
e.printStackTrace();
}catch(Throwable e){
Log.err(e);
return false;
}
}
@@ -76,8 +77,8 @@ public class SaveIO{
public static SaveMeta getMeta(Fi file){
try{
return getMeta(getStream(file));
}catch(Exception e){
e.printStackTrace();
}catch(Throwable e){
Log.err(e);
return getMeta(getBackupStream(file));
}
}
@@ -120,7 +121,7 @@ public class SaveIO{
}else{
getVersion().write(stream, tags);
}
}catch(Exception e){
}catch(Throwable e){
throw new RuntimeException(e);
}
}
@@ -134,7 +135,7 @@ public class SaveIO{
//try and load; if any exception at all occurs
load(new InflaterInputStream(file.read(bufferSize)), context);
}catch(SaveException e){
e.printStackTrace();
Log.err(e);
Fi backup = file.sibling(file.name() + "-backup." + file.extension());
if(backup.exists()){
load(new InflaterInputStream(backup.read(bufferSize)), context);
@@ -154,7 +155,7 @@ public class SaveIO{
ver.read(stream, counter, context);
Events.fire(new SaveLoadEvent());
}catch(Exception e){
}catch(Throwable e){
throw new SaveException(e);
}finally{
world.setGenerating(false);