diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 6054a64..b9befe0 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,5 +1,42 @@ +import config.MKVToolProperties; +import lombok.extern.log4j.Log4j2; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.util.Scanner; + +@Log4j2 public class Main { public static void main(String[] args) { + File path = new File("mkvDirectoryPath"); + MKVToolProperties prop; + if(!path.exists()) { + while(true) { + readPath(); + prop = new MKVToolProperties(); + if(prop.pathsAreValid()) { + break; + } + } + log.info("Path is valid!"); + }else if(path.exists()) { + prop = new MKVToolProperties(); + if(!prop.pathsAreValid()) { + readPath(); + } + log.info("Path is valid!"); + } + } + private static void readPath() { + System.out.println("Please enter a valid path to mkvtoolnix!"); + Scanner input = new Scanner(System.in); + try(PrintWriter out = new PrintWriter("mkvDirectoryPath", "UTF-8")){ + out.print(input.nextLine()); + }catch(FileNotFoundException | UnsupportedEncodingException e) { + log.error("File not found!"); + } } } diff --git a/src/main/java/config/MKVToolProperties.java b/src/main/java/config/MKVToolProperties.java index 36722b3..c4953ed 100644 --- a/src/main/java/config/MKVToolProperties.java +++ b/src/main/java/config/MKVToolProperties.java @@ -2,9 +2,9 @@ package config; import lombok.extern.log4j.Log4j2; +import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -12,8 +12,8 @@ import java.util.stream.Stream; @Log4j2 public class MKVToolProperties { private String directoryPath; - private Path mkvmergePath; - private Path mkvpropeditPath; + private String mkvmergePath; + private String mkvpropeditPath; public MKVToolProperties() { try(Stream stream = Files.lines(Paths.get("mkvDirectoryPath"))) { @@ -22,8 +22,18 @@ public class MKVToolProperties { log.fatal(e.getMessage()); } - mkvmergePath = Paths.get(directoryPath + "mkvmerge.exe"); - mkvpropeditPath = Paths.get(directoryPath + "mkvpropedit.exe"); + if(!directoryPath.endsWith("\\")) { + directoryPath += "\\"; + } + mkvmergePath = directoryPath + "mkvmerge.exe"; + mkvpropeditPath = directoryPath + "mkvpropedit.exe"; } + + public boolean pathsAreValid() { + File mkvmergeFile = new File(mkvmergePath); + File mkvpropeditFile = new File(mkvpropeditPath); + + return mkvmergeFile.exists() && mkvpropeditFile.exists(); + } } diff --git a/src/main/resources/log4j2.yaml b/src/main/resources/log4j2.yaml new file mode 100644 index 0000000..6355c6c --- /dev/null +++ b/src/main/resources/log4j2.yaml @@ -0,0 +1,28 @@ +Configuration: + name: DefaultLogger + Appenders: + Console: + name: Console_Out + PatternLayout: + Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable" + ThresholdFilter: + level: debug + File: + name: FileAppender + fileName: default.log + PatternLayout: + Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable" + ThresholdFilter: + level: info + Loggers: + Root: + level: debug + AppenderRef: + - ref: Console_Out + - ref: FileAppender + Logger: + name: "com.zaxxer.hikari.HikariConfig" + level: info + AppenderRef: + - ref: Console_Out + - ref: FileAppender \ No newline at end of file diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java new file mode 100644 index 0000000..895a398 --- /dev/null +++ b/src/test/java/MainTest.java @@ -0,0 +1,3 @@ +public class MainTest { + +} diff --git a/src/test/java/config/MKVToolPropertiesTest.java b/src/test/java/config/MKVToolPropertiesTest.java new file mode 100644 index 0000000..cd07add --- /dev/null +++ b/src/test/java/config/MKVToolPropertiesTest.java @@ -0,0 +1,31 @@ +package config; + +import lombok.extern.log4j.Log4j2; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; + +@Log4j2 +public class MKVToolPropertiesTest { + + @Test + public void testPathIsValid() { + try(PrintWriter out = new PrintWriter("mkvDirectoryPath", "UTF-8")){ + out.print("test/resources"); + }catch(FileNotFoundException | UnsupportedEncodingException e){ + log.error("File not found!"); + } + try(PrintWriter out = new PrintWriter("mkvDirectoryPath", "UTF-8")){ + out.print("test/resources/"); + }catch(FileNotFoundException | UnsupportedEncodingException e){ + log.error("File not found!"); + }finally{ + File file = new File("mkvDirectoryPath"); + file.delete(); + } + + } +} diff --git a/src/test/resources/mkvmerge.exe b/src/test/resources/mkvmerge.exe new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/mkvpropedit.exe b/src/test/resources/mkvpropedit.exe new file mode 100644 index 0000000..e69de29