From 0cb8a29d036c7e293ea46509345fcb2904aea4e2 Mon Sep 17 00:00:00 2001 From: FongMi Date: Wed, 21 Feb 2024 13:55:27 +0800 Subject: [PATCH] Clean code --- .../java/com/github/catvod/utils/Path.java | 24 +++++++++---------- .../java/com/github/catvod/utils/Shell.java | 19 +++------------ 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/catvod/src/main/java/com/github/catvod/utils/Path.java b/catvod/src/main/java/com/github/catvod/utils/Path.java index 4f28ceaee..8435e9d0d 100644 --- a/catvod/src/main/java/com/github/catvod/utils/Path.java +++ b/catvod/src/main/java/com/github/catvod/utils/Path.java @@ -19,7 +19,7 @@ public class Path { private static final String TAG = Path.class.getSimpleName(); - private static File check(File file) { + private static File mkdir(File file) { if (!file.exists()) file.mkdirs(); return file; } @@ -45,39 +45,39 @@ public class Path { } public static File tv() { - return check(new File(root() + File.separator + "TV")); + return mkdir(new File(root() + File.separator + "TV")); } public static File so() { - return check(new File(files() + File.separator + "so")); + return mkdir(new File(files() + File.separator + "so")); } public static File js() { - return check(new File(cache() + File.separator + "js")); + return mkdir(new File(cache() + File.separator + "js")); } public static File py() { - return check(new File(cache() + File.separator + "py")); + return mkdir(new File(cache() + File.separator + "py")); } public static File jar() { - return check(new File(cache() + File.separator + "jar")); + return mkdir(new File(cache() + File.separator + "jar")); } public static File doh() { - return check(new File(cache() + File.separator + "doh")); + return mkdir(new File(cache() + File.separator + "doh")); } public static File exo() { - return check(new File(cache() + File.separator + "exo")); + return mkdir(new File(cache() + File.separator + "exo")); } public static File jpa() { - return check(new File(cache() + File.separator + "jpa")); + return mkdir(new File(cache() + File.separator + "jpa")); } public static File thunder() { - return check(new File(cache() + File.separator + "thunder")); + return mkdir(new File(cache() + File.separator + "thunder")); } public static File root(String name) { @@ -85,7 +85,7 @@ public class Path { } public static File root(String child, String name) { - return new File(check(new File(root(), child)), name); + return new File(mkdir(new File(root(), child)), name); } public static File cache(String name) { @@ -105,7 +105,7 @@ public class Path { } public static File thunder(String name) { - return check(new File(thunder(), name)); + return mkdir(new File(thunder(), name)); } public static File local(String path) { diff --git a/catvod/src/main/java/com/github/catvod/utils/Shell.java b/catvod/src/main/java/com/github/catvod/utils/Shell.java index 40462f6ae..9563e9c11 100644 --- a/catvod/src/main/java/com/github/catvod/utils/Shell.java +++ b/catvod/src/main/java/com/github/catvod/utils/Shell.java @@ -1,26 +1,13 @@ package com.github.catvod.utils; -import java.io.DataOutputStream; - public class Shell { - private static final String COMMAND_SH = "sh"; - private static final String COMMAND_EXIT = "exit\n"; - private static final String COMMAND_LINE_END = "\n"; - public static void exec(String command) { try { - Process p = Runtime.getRuntime().exec(COMMAND_SH); - DataOutputStream dos = new DataOutputStream(p.getOutputStream()); - dos.write(command.getBytes()); - dos.writeBytes(COMMAND_LINE_END); - dos.writeBytes(COMMAND_EXIT); - dos.flush(); - dos.close(); - p.waitFor(); - p.destroy(); + int code = Runtime.getRuntime().exec(command).waitFor(); + if (code != 0) throw new RuntimeException("Shell command failed with exit code " + code); } catch (Exception e) { e.printStackTrace(); } } -} +} \ No newline at end of file