mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
Add version parameter
This commit is contained in:
@@ -2,6 +2,7 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
||||
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.VersionUtil;
|
||||
import at.pcgamingfreaks.yaml.YAML;
|
||||
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
||||
import lombok.AccessLevel;
|
||||
@@ -75,6 +76,7 @@ public class Config {
|
||||
}
|
||||
|
||||
exitIfHelp(cmd, options);
|
||||
exitIfVersion(cmd);
|
||||
|
||||
configPath = loadConfigPath(cmd, errors);
|
||||
libraryPath = loadLibraryPath(cmd, errors);
|
||||
@@ -101,6 +103,7 @@ public class Config {
|
||||
private static Options initOptions() {
|
||||
Options options = new Options();
|
||||
options.addOption(optionOf(HELP, "h", false));
|
||||
options.addOption(optionOf(VERSION, "v", false));
|
||||
options.addOption(optionOf(LIBRARY, "l", true));
|
||||
options.addOption(optionOf(MKV_TOOL_NIX, "m", true));
|
||||
options.addOption(optionOf(CONFIG_PATH, "c", true));
|
||||
@@ -121,6 +124,13 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
private void exitIfVersion(CommandLine cmd) {
|
||||
if (cmd.hasOption(VERSION.prop())) {
|
||||
System.out.printf("MKV Audio Subtitle Changer Version %s%n", VersionUtil.getVersion());
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
private File loadConfigPath(CommandLine cmd, ConfigErrors errors) {
|
||||
File configPath = new File(cmd.getOptionValue(CONFIG_PATH.prop(), "config.yaml"));
|
||||
if (configPath.isFile()) return configPath;
|
||||
|
||||
@@ -9,7 +9,8 @@ public enum ConfigProperty {
|
||||
MKV_TOOL_NIX("mkvtoolnix", "Path to mkv tool nix installation"),
|
||||
FORCED_KEYWORDS("forcedKeywords", "Additional keywords to identify forced tracks, combines with config file"),
|
||||
EXCLUDE_DIRECTORY("exclude-directories", "Directories to be excluded, combines with config file"),
|
||||
HELP("help", "\"for help this is\" - Yoda");
|
||||
HELP("help", "\"for help this is\" - Yoda"),
|
||||
VERSION("version", "Display version");
|
||||
|
||||
private final String property;
|
||||
private final String description;
|
||||
|
||||
@@ -3,11 +3,8 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ConfigErrors;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -17,18 +14,14 @@ public class LanguageValidatorUtil {
|
||||
|
||||
static {
|
||||
try {
|
||||
ISO3_LANGUAGES = load("language-codes");
|
||||
ISO3_LANGUAGES = loadLanguageCodes();
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
private static Set<String> load(String path) throws IOException{
|
||||
if (new File(path).isFile()) {
|
||||
return Files.lines(Path.of(path)).collect(Collectors.toSet());
|
||||
} else {
|
||||
try(BufferedReader bf = new BufferedReader(new InputStreamReader(
|
||||
Objects.requireNonNull(LanguageValidatorUtil.class.getClassLoader().getResourceAsStream(path))))) {
|
||||
return bf.lines().collect(Collectors.toSet());
|
||||
}
|
||||
private static Set<String> loadLanguageCodes() throws IOException {
|
||||
try (BufferedReader bf = new BufferedReader(new InputStreamReader(
|
||||
Objects.requireNonNull(LanguageValidatorUtil.class.getClassLoader().getResourceAsStream("language-codes"))))) {
|
||||
return bf.lines().collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class VersionUtil {
|
||||
public static String getVersion() {
|
||||
try (InputStream propertiesStream = VersionUtil.class.getClassLoader().getResourceAsStream("version.properties")) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(propertiesStream);
|
||||
|
||||
return properties.getProperty("version");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user