mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Avoid using java.nio since it breaks Quest Mode in Android app
This commit is contained in:
@@ -98,6 +98,35 @@ public final class FileUtil {
|
||||
return dir.delete();
|
||||
}
|
||||
|
||||
public static void copyFile(String sourceFilename, String destFilename) {
|
||||
File source = new File(sourceFilename);
|
||||
if (!source.exists()) { return; } //if source doesn't exist, nothing to copy
|
||||
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
try {
|
||||
is = new FileInputStream(source);
|
||||
os = new FileOutputStream(new File(destFilename));
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = is.read(buffer)) > 0) {
|
||||
os.write(buffer, 0, length);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
is.close();
|
||||
os.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String filename, String text) {
|
||||
FileUtil.writeFile(new File(filename), text);
|
||||
}
|
||||
|
||||
@@ -50,8 +50,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
@@ -369,12 +367,9 @@ public class QuestDataIO {
|
||||
|
||||
final File f = new File(ForgeConstants.QUEST_SAVE_DIR, qd.getName());
|
||||
//Copy the save file in case the save fails
|
||||
if (Files.exists(new File(f + ".dat").toPath())) {
|
||||
Files.copy(new File(f + ".dat").toPath(), new File(f + ".dat.bak").toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
FileUtil.copyFile(f + ".dat", f + ".dat.bak");
|
||||
QuestDataIO.savePacked(f + ".dat", xStream, qd);
|
||||
// QuestDataIO.saveUnpacked(f + ".xml", xStream, qd);
|
||||
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
//BugReporter.reportException(ex, "Error saving Quest Data.");
|
||||
|
||||
Reference in New Issue
Block a user