Made Screenshots save as soon as the file is ready to allow compatibility with non-unix file systems

Seriously Windows, why do you have to lock the file?
This commit is contained in:
Marius Metzger
2015-04-14 22:07:28 +02:00
parent df183cd5a6
commit ce6df4b9be
2 changed files with 17 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ import java.io.IOException;
import javax.swing.JOptionPane;
import eu.crushedpixel.replaymod.registry.FileCopyHandler;
import org.apache.commons.io.FilenameUtils;
import net.minecraft.client.Minecraft;
@@ -73,6 +74,8 @@ public class ReplayMod
public static final ApiClient apiClient = new ApiClient();
public static FileCopyHandler fileCopyHandler;
// The instance of your mod that Forge uses.
@Instance(value = "ReplayModID")
public static ReplayMod instance;
@@ -84,6 +87,9 @@ public class ReplayMod
replaySettings = new ReplaySettings();
replaySettings.readValues();
fileCopyHandler = new FileCopyHandler();
fileCopyHandler.start();
}
@EventHandler
@@ -119,7 +125,7 @@ public class ReplayMod
//clean up replay_recordings folder
removeTmcprFiles();
/*
boolean auth = false;
try {
auth = AuthenticationHandler.hasDonated(Minecraft.getMinecraft().getSession().getPlayerID());
@@ -132,7 +138,7 @@ public class ReplayMod
JOptionPane.showMessageDialog(null, "It seems like you didn't donate, so you can't use the Replay Mod yet.");
FMLCommonHandler.instance().exitJava(0, false);
}
*/
}
private void removeTmcprFiles() {

View File

@@ -21,6 +21,9 @@ import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import java.io.*;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -309,22 +312,19 @@ public class ReplayFileIO {
public static void addThumbToZip(File zipFile, File thumb) throws IOException {
// get a temp file
File tempFile = File.createTempFile(zipFile.getName(), null);
File tempFile = File.createTempFile(zipFile.getName(), null, zipFile.getParentFile());
// delete it, otherwise you cannot rename your existing zip to it.
tempFile.delete();
zipFile.renameTo(tempFile);
byte[] buf = new byte[1024];
ZipInputStream zin = new ZipInputStream(new FileInputStream(tempFile));
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFile));
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tempFile));
ZipEntry entry = zin.getNextEntry();
while (entry != null) {
String name = entry.getName();
boolean isThumb = name.contains("thumb");
if(!isThumb) {
if (!isThumb) {
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(name));
// Transfer bytes from the ZIP file to the output file
@@ -356,6 +356,7 @@ public class ReplayFileIO {
// Complete the ZIP file
out.close();
tempFile.delete();
ReplayMod.fileCopyHandler.registerModifiedFile(tempFile, zipFile);
}
}