mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Add version parameter
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -20,7 +20,9 @@
|
|||||||
<directory>./</directory>
|
<directory>./</directory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>language-codes</include>
|
<include>language-codes</include>
|
||||||
|
<include>version.properties</include>
|
||||||
</includes>
|
</includes>
|
||||||
|
<filtering>true</filtering>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<testResources>
|
<testResources>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
|||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.VersionUtil;
|
||||||
import at.pcgamingfreaks.yaml.YAML;
|
import at.pcgamingfreaks.yaml.YAML;
|
||||||
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
@@ -75,6 +76,7 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exitIfHelp(cmd, options);
|
exitIfHelp(cmd, options);
|
||||||
|
exitIfVersion(cmd);
|
||||||
|
|
||||||
configPath = loadConfigPath(cmd, errors);
|
configPath = loadConfigPath(cmd, errors);
|
||||||
libraryPath = loadLibraryPath(cmd, errors);
|
libraryPath = loadLibraryPath(cmd, errors);
|
||||||
@@ -101,6 +103,7 @@ public class Config {
|
|||||||
private static Options initOptions() {
|
private static Options initOptions() {
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
options.addOption(optionOf(HELP, "h", false));
|
options.addOption(optionOf(HELP, "h", false));
|
||||||
|
options.addOption(optionOf(VERSION, "v", false));
|
||||||
options.addOption(optionOf(LIBRARY, "l", true));
|
options.addOption(optionOf(LIBRARY, "l", true));
|
||||||
options.addOption(optionOf(MKV_TOOL_NIX, "m", true));
|
options.addOption(optionOf(MKV_TOOL_NIX, "m", true));
|
||||||
options.addOption(optionOf(CONFIG_PATH, "c", 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) {
|
private File loadConfigPath(CommandLine cmd, ConfigErrors errors) {
|
||||||
File configPath = new File(cmd.getOptionValue(CONFIG_PATH.prop(), "config.yaml"));
|
File configPath = new File(cmd.getOptionValue(CONFIG_PATH.prop(), "config.yaml"));
|
||||||
if (configPath.isFile()) return configPath;
|
if (configPath.isFile()) return configPath;
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ public enum ConfigProperty {
|
|||||||
MKV_TOOL_NIX("mkvtoolnix", "Path to mkv tool nix installation"),
|
MKV_TOOL_NIX("mkvtoolnix", "Path to mkv tool nix installation"),
|
||||||
FORCED_KEYWORDS("forcedKeywords", "Additional keywords to identify forced tracks, combines with config file"),
|
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"),
|
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 property;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|||||||
@@ -3,11 +3,8 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ConfigErrors;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ConfigErrors;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -17,20 +14,16 @@ public class LanguageValidatorUtil {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
ISO3_LANGUAGES = load("language-codes");
|
ISO3_LANGUAGES = loadLanguageCodes();
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<String> load(String path) throws IOException{
|
private static Set<String> loadLanguageCodes() throws IOException {
|
||||||
if (new File(path).isFile()) {
|
|
||||||
return Files.lines(Path.of(path)).collect(Collectors.toSet());
|
|
||||||
} else {
|
|
||||||
try (BufferedReader bf = new BufferedReader(new InputStreamReader(
|
try (BufferedReader bf = new BufferedReader(new InputStreamReader(
|
||||||
Objects.requireNonNull(LanguageValidatorUtil.class.getClassLoader().getResourceAsStream(path))))) {
|
Objects.requireNonNull(LanguageValidatorUtil.class.getClassLoader().getResourceAsStream("language-codes"))))) {
|
||||||
return bf.lines().collect(Collectors.toSet());
|
return bf.lines().collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isLanguageValid(String language) {
|
public static boolean isLanguageValid(String language) {
|
||||||
return ISO3_LANGUAGES.contains(language);
|
return ISO3_LANGUAGES.contains(language);
|
||||||
|
|||||||
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
version.properties
Normal file
1
version.properties
Normal file
@@ -0,0 +1 @@
|
|||||||
|
version=${project.version}
|
||||||
Reference in New Issue
Block a user