aboutsummaryrefslogtreecommitdiff
path: root/updater/src/main/java/moe
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-10-14 21:20:34 +0200
committernea <romangraef@gmail.com>2022-10-14 21:20:34 +0200
commitf4e8a8b343125744a80bb49a433f7796bda2fe4a (patch)
tree048f134bf3f2ff167848025251102af48bed26a3 /updater/src/main/java/moe
downloadlibautoupdate-f4e8a8b343125744a80bb49a433f7796bda2fe4a.tar.gz
libautoupdate-f4e8a8b343125744a80bb49a433f7796bda2fe4a.tar.bz2
libautoupdate-f4e8a8b343125744a80bb49a433f7796bda2fe4a.zip
Working code
Diffstat (limited to 'updater/src/main/java/moe')
-rw-r--r--updater/src/main/java/moe/nea/libautoupdate/postexit/PostExitMain.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/updater/src/main/java/moe/nea/libautoupdate/postexit/PostExitMain.java b/updater/src/main/java/moe/nea/libautoupdate/postexit/PostExitMain.java
new file mode 100644
index 0000000..d143fee
--- /dev/null
+++ b/updater/src/main/java/moe/nea/libautoupdate/postexit/PostExitMain.java
@@ -0,0 +1,46 @@
+package moe.nea.libautoupdate.postexit;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+
+public class PostExitMain {
+ public static void main(String[] args) throws IOException {
+ File outputFile = new File(".autoupdates", "postexit.log");
+ outputFile.getParentFile().mkdirs();
+ PrintStream printStream = new PrintStream(new FileOutputStream(outputFile, true));
+ System.setErr(printStream);
+ System.setOut(printStream);
+
+ for (int i = 0; i < args.length; i++) {
+ switch (args[i].intern()) {
+ case "delete":
+ File file = new File(args[++i]);
+ System.out.println("Deleting " + file);
+ file.delete();
+ break;
+ case "move":
+ File from = new File(args[++i]);
+ File to = new File(args[++i]);
+ System.out.println("Moving " + from + " to " + to);
+ // Use Files.move instead of File.renameTo, since renameTo is not well-defined.
+ Files.move(from.toPath(), to.toPath(), StandardCopyOption.REPLACE_EXISTING);
+ break;
+ default:
+ System.out.println("Unknown instruction " + args[i]);
+ System.exit(1);
+ }
+ }
+ }
+
+ public void unlockedFile(File file) throws InterruptedException {
+ while (!file.exists() || !file.renameTo(file)) {
+ Thread.sleep(1000L);
+ }
+ file.getParentFile().mkdirs();
+ }
+
+}