Fix CR comments & remove OS Validator

This commit is contained in:
2023-02-19 16:52:27 +01:00
parent ce9a2fc805
commit fe30d186df
7 changed files with 9 additions and 83 deletions

View File

@@ -34,7 +34,6 @@ public class Config {
private int threads;
private Pattern includePattern;
private boolean windows;
private boolean safeMode;
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs"));
@@ -60,9 +59,8 @@ public class Config {
* @return absolute path to desired application.
*/
public String getPathFor(MkvToolNix application) {
String executable = isWindows() ? application + ".exe" : application.toString();
return mkvToolNix.getAbsolutePath().endsWith("/") ? mkvToolNix.getAbsolutePath() + executable :
mkvToolNix.getAbsolutePath() + "/" + executable;
return mkvToolNix.getAbsolutePath().endsWith("/") ? mkvToolNix.getAbsolutePath() + application :
mkvToolNix.getAbsolutePath() + "/" + application;
}
@Override
@@ -72,7 +70,6 @@ public class Config {
.add("formatter=" + formatter).add("\n")
.add("configPath=" + configPath).add("\n")
.add("libraryPath=" + libraryPath).add("\n")
.add("isWindows=" + windows).add("\n")
.add("isSafeMode=" + safeMode).add("\n")
.add("forcedKeywords=" + forcedKeywords).add("\n")
.add("commentaryKeywords=" + commentaryKeywords).add("\n")

View File

@@ -18,12 +18,11 @@ import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsU
public class ConfigLoader {
private static final List<ConfigValidator<?>> VALIDATORS = List.of(
new ConfigPathValidator(CONFIG_PATH, false, Path.of("./config.yaml").toFile()),
new ConfigPathValidator(CONFIG_PATH, true, Path.of("./config.yaml").toFile()),
new PathValidator(LIBRARY, true, null),
new ThreadValidator(THREADS, false, 2),
new MkvToolNixPathValidator(MKV_TOOL_NIX, true, Path.of("C:\\Program Files\\MKVToolNix").toFile()),
new BooleanValidator(SAFE_MODE, false),
new OperatingSystemValidator(WINDOWS),
new PatternValidator(INCLUDE_PATTERN, false, Pattern.compile(".*")),
new SetValidator(FORCED_KEYWORDS, false, true),
new SetValidator(COMMENTARY_KEYWORDS, false, true),
@@ -104,13 +103,4 @@ public class ConfigLoader {
System.exit(0);
}
}
private static File loadConfigPath(CommandLine cmd) {
File configPath = new File(cmd.getOptionValue(CONFIG_PATH.prop(), "config.yaml"));
if (configPath.isFile()) return configPath;
System.out.println("invalid config path");
System.exit(1);
return null;
}
}

View File

@@ -1,31 +0,0 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
import at.pcgamingfreaks.yaml.YAML;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.lang3.StringUtils;
public class OperatingSystemValidator extends BooleanValidator {
public OperatingSystemValidator(ConfigProperty property) {
super(property, false);
}
/**
* Gather operating system from system properties.
*/
@Override
public ValidationResult validate(YAML yaml, CommandLine cmd) {
System.out.printf("%s: ", property.prop());
Boolean result = StringUtils.containsIgnoreCase(System.getProperty("os.name"), "windows");
if (!isValid(result) || !setValue(result)) {
System.out.println("invalid");
return ValidationResult.INVALID;
}
System.out.println("ok");
return ValidationResult.VALID;
}
}