mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Expand date filter by last execution overwrite
This commit is contained in:
@@ -11,12 +11,11 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public abstract class ConfigValidator<FieldType> {
|
public abstract class ConfigValidator<FieldType> {
|
||||||
@@ -38,7 +37,9 @@ public abstract class ConfigValidator<FieldType> {
|
|||||||
Optional<FieldType> cmdResult = provideDataCmd().apply(cmd, property);
|
Optional<FieldType> cmdResult = provideDataCmd().apply(cmd, property);
|
||||||
Optional<FieldType> yamlResult = provideDataYaml().apply(yaml, property);
|
Optional<FieldType> yamlResult = provideDataYaml().apply(yaml, property);
|
||||||
|
|
||||||
if (cmdResult.isPresent()) {
|
if (isOverwritingNecessary()){
|
||||||
|
result = overwriteValue();
|
||||||
|
} else if (cmdResult.isPresent()) {
|
||||||
result = cmdResult.get();
|
result = cmdResult.get();
|
||||||
} else if (yamlResult.isPresent()) {
|
} else if (yamlResult.isPresent()) {
|
||||||
result = yamlResult.get();
|
result = yamlResult.get();
|
||||||
@@ -98,6 +99,14 @@ public abstract class ConfigValidator<FieldType> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isOverwritingNecessary() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected FieldType overwriteValue() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse input parameter to desired format.
|
* Parse input parameter to desired format.
|
||||||
*
|
*
|
||||||
@@ -145,5 +154,11 @@ public abstract class ConfigValidator<FieldType> {
|
|||||||
&& StringUtils.equalsIgnoreCase(method.getName().replace("get", ""), property.prop().replace("-", ""));
|
&& StringUtils.equalsIgnoreCase(method.getName().replace("get", ""), property.prop().replace("-", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static Set<Integer> getDependentValidators() {
|
||||||
|
return Set.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getWeight() {
|
||||||
|
return getDependentValidators().stream().sorted().findFirst().orElse(100) - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,51 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class DateValidator extends ConfigValidator<Date> {
|
public class DateValidator extends ConfigValidator<Date> {
|
||||||
|
private static final Date DEFAULT_DATE = new Date(0);
|
||||||
|
|
||||||
public DateValidator(ConfigProperty property, boolean required) {
|
public DateValidator(ConfigProperty property, boolean required) {
|
||||||
super(property, required, null);
|
super(property, required, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isOverwritingNecessary() {
|
||||||
|
return Config.getInstance().isOnlyNewFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Date overwriteValue() {
|
||||||
|
Properties prop = new Properties();
|
||||||
|
try {
|
||||||
|
prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/last-execution.properties"));
|
||||||
|
return parse(prop.getProperty(Config.getInstance().getLibraryPath().getAbsolutePath()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Couldn't open last-execution.properties");
|
||||||
|
return DEFAULT_DATE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Date parse(String value) {
|
Date parse(String value) {
|
||||||
return DateUtils.convert(value); // TODO fix null return value
|
return DateUtils.convert(value, DEFAULT_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isValid(Date result) {
|
boolean isValid(Date result) {
|
||||||
return result != null;
|
return !result.equals(DEFAULT_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Set<Integer> getDependentValidators() {
|
||||||
|
return Set.of(PathValidator.getWeight(), BooleanValidator.getWeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ public class FileFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNewerThanLastExecution(File pathName) {
|
private static boolean isNewerThanLastExecution(File pathName) {
|
||||||
if (Config.getInstance().isOnlyNewFiles()) {
|
// if (Config.getInstance().isOnlyNewFiles()) {
|
||||||
return isNewer(pathName);
|
// return isNewer(pathName);
|
||||||
}
|
// }
|
||||||
return true;
|
// return true;
|
||||||
// return Config.getInstance().isOnlyNewFiles() && isNewer(pathName);
|
return !Config.getInstance().isOnlyNewFiles() || isNewer(pathName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ public class DateUtils {
|
|||||||
* Convert String to date.
|
* Convert String to date.
|
||||||
* @return parsed date, null if exception occurs
|
* @return parsed date, null if exception occurs
|
||||||
*/
|
*/
|
||||||
public static Date convert(String date) {
|
public static Date convert(String date, Date defaultDate) {
|
||||||
try {
|
try {
|
||||||
return dateFormat.parse(date);
|
return dateFormat.parse(date);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return null;
|
return defaultDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user