Fix eventual deletion of tmp replay files

If the same replay has crashed twice and both times the tmp replay file
is discarded, the older one should be permanently deleted.
This commit is contained in:
johni0702
2016-08-22 13:04:36 +02:00
parent ee6f074c75
commit 1cf3d3a95a

View File

@@ -15,6 +15,7 @@ import de.johni0702.minecraft.gui.element.GuiLabel;
import de.johni0702.minecraft.gui.layout.CustomLayout; import de.johni0702.minecraft.gui.layout.CustomLayout;
import de.johni0702.minecraft.gui.layout.HorizontalLayout; import de.johni0702.minecraft.gui.layout.HorizontalLayout;
import de.johni0702.minecraft.gui.layout.VerticalLayout; import de.johni0702.minecraft.gui.layout.VerticalLayout;
import org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -63,8 +64,12 @@ public class RestoreReplayGui extends AbstractGuiScreen<RestoreReplayGui> {
}); });
noButton.onClick(() -> { noButton.onClick(() -> {
try { try {
Files.move(new File(file.getParentFile(), file.getName() + ".tmp"), File tmp = new File(file.getParentFile(), file.getName() + ".tmp");
new File(file.getParentFile(), file.getName() + ".del")); File deleted = new File(file.getParentFile(), file.getName() + ".del");
if (deleted.exists()) {
FileUtils.deleteDirectory(deleted);
}
Files.move(tmp, deleted);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }