[IMPL] read path to mkvtoolnix

This commit is contained in:
RatzzFatzz
2019-11-22 11:59:02 +01:00
parent 5aeddfa968
commit 25e9fd6f3f
7 changed files with 114 additions and 5 deletions

View File

@@ -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!");
}
}
}

View File

@@ -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<String> 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();
}
}

View File

@@ -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

View File

@@ -0,0 +1,3 @@
public class MainTest {
}

View File

@@ -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();
}
}
}

View File

View File