Add support for multiple library paths

This commit is contained in:
RatzzFatzz
2025-12-29 00:12:28 +01:00
parent be004e6146
commit 1165dd8380
5 changed files with 19 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
} }
protected List<File> getFiles() { protected List<File> getFiles() {
return Arrays.stream(config.getLibraryPaths()) return Arrays.stream(config.getLibraryPath())
.flatMap(path -> fileProcessor.loadDirectory(path.getPath(), config.getCoherent()).stream()) .flatMap(path -> fileProcessor.loadDirectory(path.getPath(), config.getCoherent()).stream())
.toList(); .toList();
} }

View File

@@ -24,7 +24,7 @@ public class SingleFileAttributeUpdater extends AttributeUpdater {
@Override @Override
protected List<File> getFiles() { protected List<File> getFiles() {
return Arrays.stream(config.getLibraryPaths()) return Arrays.stream(config.getLibraryPath())
.flatMap(path -> fileProcessor.loadFiles(path.getPath()).stream()) .flatMap(path -> fileProcessor.loadFiles(path.getPath()).stream())
.toList(); .toList();
} }

View File

@@ -2,10 +2,12 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation;
import jakarta.validation.ConstraintValidator; import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext; import jakarta.validation.ConstraintValidatorContext;
import lombok.extern.slf4j.Slf4j;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
@Slf4j
public class ValidFileValidator implements ConstraintValidator<ValidFile, File[]> { public class ValidFileValidator implements ConstraintValidator<ValidFile, File[]> {
@Override @Override
public void initialize(ValidFile constraintAnnotation) { public void initialize(ValidFile constraintAnnotation) {
@@ -13,6 +15,13 @@ public class ValidFileValidator implements ConstraintValidator<ValidFile, File[]
@Override @Override
public boolean isValid(File[] files, ConstraintValidatorContext context) { public boolean isValid(File[] files, ConstraintValidatorContext context) {
return files != null && files.length > 0 && Arrays.stream(files).allMatch(File::exists); if (files == null || files.length == 0) return false;
for (File file: files) {
if (!file.exists()) {
log.error("{} does not exist", file.getPath());
return false;
}
}
return true;
} }
} }

View File

@@ -30,7 +30,7 @@ public class InputConfig implements CommandLine.IVersionProvider {
@ValidFile(message = "does not exist") @ValidFile(message = "does not exist")
@CommandLine.Parameters(description = "paths to library", arity = "1..*") @CommandLine.Parameters(description = "paths to library", arity = "1..*")
private File[] libraryPaths; private File[] libraryPath;
@Option(names = {"-a", "--attribute-config"}, arity = "1..*", converter = AttributeConfigConverter.class, @Option(names = {"-a", "--attribute-config"}, arity = "1..*", converter = AttributeConfigConverter.class,
description = "List of audio:subtitle pairs for matching defaults in order (e.g. jpn:eng jpn:ger)") description = "List of audio:subtitle pairs for matching defaults in order (e.g. jpn:eng jpn:ger)")
@@ -91,7 +91,7 @@ public class InputConfig implements CommandLine.IVersionProvider {
return new StringJoiner(", ", InputConfig.class.getSimpleName() + "[", "]") return new StringJoiner(", ", InputConfig.class.getSimpleName() + "[", "]")
.add("configPath=" + configPath) .add("configPath=" + configPath)
.add("spec=" + spec) .add("spec=" + spec)
.add("libraryPath=" + libraryPaths) .add("libraryPath=" + libraryPath)
.add("attributeConfig=" + Arrays.toString(attributeConfig)) .add("attributeConfig=" + Arrays.toString(attributeConfig))
.add("mkvToolNix=" + mkvToolNix) .add("mkvToolNix=" + mkvToolNix)
.add("safeMode=" + safeMode) .add("safeMode=" + safeMode)

View File

@@ -23,17 +23,17 @@ class ValidationExecutionStrategyTest {
.setExecutionStrategy(new ValidationExecutionStrategy()) .setExecutionStrategy(new ValidationExecutionStrategy())
.parseArgs("-a", "ger:ger", "-m", TEST_MKVTOOLNIX_DIR, TEST_FILE); .parseArgs("-a", "ger:ger", "-m", TEST_MKVTOOLNIX_DIR, TEST_FILE);
assertEquals(TEST_FILE, underTest.getConfig().getLibraryPaths()[0].getPath().replace("\\", "/")); assertEquals(TEST_FILE, underTest.getConfig().getLibraryPath()[0].getPath().replace("\\", "/"));
assertEquals(TEST_MKVTOOLNIX_DIR, underTest.getConfig().getMkvToolNix().getPath().replace("\\", "/")); assertEquals(TEST_MKVTOOLNIX_DIR, underTest.getConfig().getMkvToolNix().getPath().replace("\\", "/"));
} }
private static Stream<Arguments> validateFailure() { private static Stream<Arguments> validateFailure() {
return Stream.of( return Stream.of(
Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): <libraryPaths>"), Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): <libraryPath>"),
Arguments.of(new String[]{"/arstarstarst"}, "libraryPaths does not exist"), Arguments.of(new String[]{"/arstarstarst"}, "libraryPath does not exist"),
Arguments.of(new String[]{TEST_DIR + " /arstarstarst"}, "libraryPaths does not exist"), Arguments.of(new String[]{TEST_DIR, "/arstarstarst"}, "libraryPath does not exist"),
Arguments.of(new String[]{"/arstarstarst", "-a",}, "Missing required parameter for option '--attribute-config' at index 0 (<attributeConfig>)"), Arguments.of(new String[]{"/arstarstarst", "-a",}, "Missing required parameter for option '--attribute-config' at index 0 (<attributeConfig>)"),
Arguments.of(new String[]{"/arstarstarst", "-a", "jpn:ger"}, "libraryPaths does not exist"), Arguments.of(new String[]{"/arstarstarst", "-a", "jpn:ger"}, "libraryPath does not exist"),
Arguments.of(new String[]{"/arstarstarst", "-m"}, "Missing required parameter for option '--mkvtoolnix' (<mkvToolNix>)"), Arguments.of(new String[]{"/arstarstarst", "-m"}, "Missing required parameter for option '--mkvtoolnix' (<mkvToolNix>)"),
Arguments.of(new String[]{"./", "-m", TEST_INVALID_DIR}, "mkvToolNix does not exist"), Arguments.of(new String[]{"./", "-m", TEST_INVALID_DIR}, "mkvToolNix does not exist"),
Arguments.of(new String[]{"./", "-t"}, "Missing required parameter for option '--threads' (<threads>)"), Arguments.of(new String[]{"./", "-t"}, "Missing required parameter for option '--threads' (<threads>)"),