Skip to content

Commit

Permalink
catch corrupted files
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored and Wide-Cat committed Oct 31, 2023
1 parent b996ff0 commit 775b8c3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/meteordevelopment/meteorclient/systems/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import meteordevelopment.meteorclient.utils.misc.ISerializable;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtIo;
import net.minecraft.util.crash.CrashException;
import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.io.IOException;
import java.time.LocalDate;

public abstract class System<T> implements ISerializable<T> {
private final String name;
Expand Down Expand Up @@ -64,7 +67,16 @@ public void load(File folder) {
if (folder != null) file = new File(folder, file.getName());

if (file.exists()) {
fromTag(NbtIo.read(file));
try {
fromTag(NbtIo.read(file));
} catch (CrashException e) {
String backupName = FilenameUtils.removeExtension(file.getName()) + "-" + LocalDate.now() + ".backup.nbt";
File backup = new File(file.getParentFile(), backupName);
StreamUtils.copy(file, backup);
MeteorClient.LOG.error("Error loading " + this.name + ". Possibly corrupted?");
MeteorClient.LOG.info("Saved settings backup to '" + backup + "'.");
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
Expand Down

0 comments on commit 775b8c3

Please sign in to comment.