mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
[IMPL] read path to mkvtoolnix
This commit is contained in:
@@ -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 class Main {
|
||||||
public static void main(String[] args) {
|
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!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package config;
|
|||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -12,8 +12,8 @@ import java.util.stream.Stream;
|
|||||||
@Log4j2
|
@Log4j2
|
||||||
public class MKVToolProperties {
|
public class MKVToolProperties {
|
||||||
private String directoryPath;
|
private String directoryPath;
|
||||||
private Path mkvmergePath;
|
private String mkvmergePath;
|
||||||
private Path mkvpropeditPath;
|
private String mkvpropeditPath;
|
||||||
|
|
||||||
public MKVToolProperties() {
|
public MKVToolProperties() {
|
||||||
try(Stream<String> stream = Files.lines(Paths.get("mkvDirectoryPath"))) {
|
try(Stream<String> stream = Files.lines(Paths.get("mkvDirectoryPath"))) {
|
||||||
@@ -22,8 +22,18 @@ public class MKVToolProperties {
|
|||||||
log.fatal(e.getMessage());
|
log.fatal(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
mkvmergePath = Paths.get(directoryPath + "mkvmerge.exe");
|
if(!directoryPath.endsWith("\\")) {
|
||||||
mkvpropeditPath = Paths.get(directoryPath + "mkvpropedit.exe");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
src/main/resources/log4j2.yaml
Normal file
28
src/main/resources/log4j2.yaml
Normal 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
|
||||||
3
src/test/java/MainTest.java
Normal file
3
src/test/java/MainTest.java
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
public class MainTest {
|
||||||
|
|
||||||
|
}
|
||||||
31
src/test/java/config/MKVToolPropertiesTest.java
Normal file
31
src/test/java/config/MKVToolPropertiesTest.java
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
0
src/test/resources/mkvmerge.exe
Normal file
0
src/test/resources/mkvmerge.exe
Normal file
0
src/test/resources/mkvpropedit.exe
Normal file
0
src/test/resources/mkvpropedit.exe
Normal file
Reference in New Issue
Block a user