mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Fix CR comments & remove OS Validator
This commit is contained in:
@@ -70,7 +70,7 @@ public class AttributeUpdaterKernel {
|
||||
log.info("Updated {}", file.getAbsolutePath());
|
||||
} catch (IOException | RuntimeException e) {
|
||||
statistic.failedChanging();
|
||||
log.warn("File couldn't be updated: '{}', Error: {}", file.getAbsoluteFile(), e.getMessage().replaceAll("\\R|\\n", "\\s"));
|
||||
log.warn("File couldn't be updated: '{}', Error: {}", file.getAbsoluteFile(), e.getMessage().replaceAll("\\r|\\n", " "));
|
||||
}
|
||||
}
|
||||
} else if (fileInfo.isUnableToApplyConfig()) {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,12 @@ import static java.lang.String.format;
|
||||
@Log4j2
|
||||
public class MkvFileProcessor implements FileProcessor {
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private final String[] forcedKeywords = new String[]{"forced", "signs"};
|
||||
private static final String DISABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=0 ";
|
||||
private static final String ENABLE_DEFAULT_TRACK = "--edit track:%s --set flag-default=1 ";
|
||||
private static final String ENABLE_FORCED_TRACK = "--edit track:%s --set flag-forced=1 ";
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<FileAttribute> loadAttributes(File file) {
|
||||
Map<String, Object> jsonMap;
|
||||
@@ -155,7 +155,7 @@ public class MkvFileProcessor implements FileProcessor {
|
||||
|
||||
InputStream inputstream = Runtime.getRuntime().exec(sb.toString()).getInputStream();
|
||||
String output = IOUtils.toString(new InputStreamReader(inputstream));
|
||||
if (output.contains("Error")) throw new RuntimeException(output);
|
||||
log.debug(output);
|
||||
if (output.contains("Error")) throw new RuntimeException(output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
||||
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
class ConfigTest {
|
||||
private static final File TEST_MKVTOOLNIX_DIR = Path.of("src/test/resources/mkvtoolnix").toFile();
|
||||
private static final File TEST_MKVTOOLNIX_EXE_DIR = Path.of("src/test/resources/mkvtoolnix_exe").toFile();
|
||||
|
||||
@Test
|
||||
void getPathForWindows() {
|
||||
Config.getInstance().setWindows(true);
|
||||
Config.getInstance().setMkvToolNix(TEST_MKVTOOLNIX_EXE_DIR);
|
||||
|
||||
assert Config.getInstance().getPathFor(MkvToolNix.MKV_MERGER).endsWith(MkvToolNix.MKV_MERGER + ".exe");
|
||||
assert Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT).endsWith(MkvToolNix.MKV_PROP_EDIT + ".exe");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPathForUnix() {
|
||||
Config.getInstance().setWindows(false);
|
||||
Config.getInstance().setMkvToolNix(TEST_MKVTOOLNIX_DIR);
|
||||
|
||||
assert Config.getInstance().getPathFor(MkvToolNix.MKV_MERGER).endsWith(MkvToolNix.MKV_MERGER.toString());
|
||||
assert Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT).endsWith(MkvToolNix.MKV_PROP_EDIT.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user