mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Clean-up
This commit is contained in:
@@ -69,6 +69,10 @@ public class Config {
|
||||
mkvToolNix.getAbsolutePath() + "/" + application;
|
||||
}
|
||||
|
||||
public String getNormalizedLibraryPath() {
|
||||
return this.getLibraryPath().getAbsolutePath().replace("\\", "/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", Config.class.getSimpleName() + "[", "]")
|
||||
|
||||
@@ -100,10 +100,16 @@ public abstract class ConfigValidator<FieldType> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if overwriting this property is necessary.
|
||||
*/
|
||||
protected boolean isOverwritingNecessary() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link FieldType} to overwrite result with.
|
||||
*/
|
||||
protected FieldType overwriteValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DateValidator extends ConfigValidator<Date> {
|
||||
return DEFAULT_DATE;
|
||||
}
|
||||
YAML yaml = new YAML(lastExecutionFile);
|
||||
return parse(yaml.getString(Config.getInstance().getLibraryPath().getAbsolutePath().replace("\\", "/"), DateUtils.convert(DEFAULT_DATE)));
|
||||
return parse(yaml.getString(Config.getInstance().getNormalizedLibraryPath(), DateUtils.convert(DEFAULT_DATE)));
|
||||
} catch (YamlInvalidContentException | IOException e) {
|
||||
log.error("Couldn't open last-execution.properties");
|
||||
return INVALID_DATE;
|
||||
|
||||
@@ -15,7 +15,9 @@ import java.util.Date;
|
||||
@Slf4j
|
||||
public class FileFilter {
|
||||
static boolean accept(File pathName, String[] fileExtensions) {
|
||||
if (hasProperFileExtension(pathName, fileExtensions) && isIncluded(pathName) && isNewer(pathName)) {
|
||||
if (hasProperFileExtension(pathName, fileExtensions)
|
||||
&& hasMatchingPattern(pathName)
|
||||
&& isNewer(pathName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -27,7 +29,7 @@ public class FileFilter {
|
||||
return StringUtils.endsWithAny(pathName.getAbsolutePath().toLowerCase(), fileExtensions);
|
||||
}
|
||||
|
||||
private static boolean isIncluded(File pathName) {
|
||||
private static boolean hasMatchingPattern(File pathName) {
|
||||
return Config.getInstance().getIncludePattern().matcher(pathName.getName()).matches();
|
||||
}
|
||||
|
||||
@@ -38,7 +40,7 @@ public class FileFilter {
|
||||
BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class);
|
||||
return isNewer(DateUtils.convert(attributes.creationTime().toMillis()));
|
||||
} catch (IOException e) {
|
||||
log.warn("File attributes could not be read. This could have XX reason"); // TODO
|
||||
log.warn("File attributes could not be read.", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -46,12 +48,4 @@ public class FileFilter {
|
||||
private static boolean isNewer(Date creationDate) {
|
||||
return creationDate.toInstant().isAfter(Config.getInstance().getFilterDate().toInstant());
|
||||
}
|
||||
|
||||
private static boolean isNewerThanLastExecution(File pathName) {
|
||||
// if (Config.getInstance().isOnlyNewFiles()) {
|
||||
// return isNewer(pathName);
|
||||
// }
|
||||
// return true;
|
||||
return !Config.getInstance().isOnlyNewFiles() || isNewer(pathName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,15 +161,13 @@ public abstract class AttributeUpdaterKernel {
|
||||
if (!configDir.exists()) configDir.mkdirs();
|
||||
|
||||
File lastExecutionFile = Path.of(filePath + "/last-execution.yml").toFile();
|
||||
if (!lastExecutionFile.exists()) {
|
||||
lastExecutionFile.createNewFile();
|
||||
}
|
||||
if (!lastExecutionFile.exists()) lastExecutionFile.createNewFile();
|
||||
|
||||
YAML yaml = new YAML(lastExecutionFile);
|
||||
yaml.set(Config.getInstance().getLibraryPath().getAbsolutePath().replace("\\", "/"), DateUtils.convert(new Date()));
|
||||
yaml.set(Config.getInstance().getNormalizedLibraryPath(), DateUtils.convert(new Date()));
|
||||
yaml.save(lastExecutionFile);
|
||||
} catch (IOException | YamlInvalidContentException e) {
|
||||
log.error("last-execution.yml could not be created: ", e); // TODO
|
||||
log.error("last-execution.yml could not be created or read.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class DateUtils {
|
||||
|
||||
/**
|
||||
* Convert String to date.
|
||||
* @return parsed date, null if exception occurs
|
||||
* @return parsed date, defaultDate if exception occurs
|
||||
*/
|
||||
public static Date convert(String date, Date defaultDate) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user