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 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 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user