aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2018-08-18 18:03:04 +1000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2018-08-18 18:03:04 +1000
commit5a5552cde7c60d2cdbbdf009aef9888f4a3e08f9 (patch)
tree7cd230304edd93a0a7121c9b87e6281c10dec980 /src/Java/gtPlusPlus/core/util
parentae6844407be97824e2db9355fdcf04608592a7a9 (diff)
downloadGT5-Unofficial-5a5552cde7c60d2cdbbdf009aef9888f4a3e08f9.tar.gz
GT5-Unofficial-5a5552cde7c60d2cdbbdf009aef9888f4a3e08f9.tar.bz2
GT5-Unofficial-5a5552cde7c60d2cdbbdf009aef9888f4a3e08f9.zip
+ Added Forming Press mode to the Large Bending Machine. Closes #347.
+ Added a command to dump TC aspect information from all Items & Blocks. Use /DA or /DumpAspects to begin the process. $ Fixed PSS not accepting any tier Hatches. Closes #354, also fixes https://github.com/GTNewHorizons/NewHorizons/issues/3470. $ Fixed Hand-Pumps duping things, because other modders can't follow guidelines. Closes #353. $ Fixed a rare bug involving Hand-Pumps & EU items having getDisplayName() called on them. $ Fixed an issue where some Multiblocks had a bad GUI. $ Removed TC libs from my custom Railcraft build.
Diffstat (limited to 'src/Java/gtPlusPlus/core/util')
-rw-r--r--src/Java/gtPlusPlus/core/util/data/FileUtils.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/util/data/FileUtils.java b/src/Java/gtPlusPlus/core/util/data/FileUtils.java
new file mode 100644
index 0000000000..d7d6b9e36e
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/util/data/FileUtils.java
@@ -0,0 +1,95 @@
+package gtPlusPlus.core.util.data;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.List;
+
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.util.Utils;
+
+public class FileUtils {
+
+ private static final Charset utf8 = StandardCharsets.UTF_8;
+
+ public static boolean doesFileExist(File f) {
+ if (f != null && f.exists() && !f.isDirectory()) {
+ return true;
+ }
+ return false;
+ }
+
+ public static File createFile(String path, String filename, String extension) {
+ File file = new File(Utils.getMcDir(), path + filename + extension);
+ boolean blnCreated = false;
+ Logger.INFO("Trying to use path "+file.getPath());
+ try {
+ Logger.INFO("Trying to use path "+file.getCanonicalPath());
+ Logger.INFO("Trying to use absolute path "+file.getAbsolutePath());
+ blnCreated = file.createNewFile();
+ } catch (IOException ioe) {
+ Logger.INFO("Error while creating a new empty file :" + ioe);
+ return null;
+ }
+ return blnCreated ? file : null;
+ }
+
+ public static File getFile(String filename, String extension) {
+ return getFile("", filename, extension);
+ }
+
+ public static File getFile(String path, String filename, String extension) {
+ if (path == null || path.length() <= 0) {
+ path = "";
+ }
+ else {
+ path = path + "/";
+ }
+ if (filename == null || filename.length() <= 0) {
+ return null;
+ }
+ if (extension == null || extension.length() <= 0) {
+ extension = ".txt";
+ }
+ else {
+ extension = "." + extension;
+ }
+ File file = new File(Utils.getMcDir(), path + filename + extension);
+ boolean doesExist = doesFileExist(file);
+
+ if (doesExist) {
+ Logger.INFO("Found File: " + file.getAbsolutePath());
+ return file;
+ } else {
+ Logger.INFO("Creating file, as it was not found.");
+ return createFile(path, filename, extension);
+ }
+ }
+
+ public static boolean appendListToFile(File file, List<String> content) {
+ try {
+ long oldSize;
+ long newSize;
+ if (doesFileExist(file)) {
+ Path p = Paths.get(file.getPath());
+ if (p != null && Files.isWritable(p)) {
+ oldSize = Files.size(p);
+ try {
+ Files.write(p, content, utf8, StandardOpenOption.APPEND);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ newSize = Files.size(p);
+ return newSize > oldSize;
+ }
+ }
+ } catch (IOException e) {
+ }
+ return false;
+ }
+}