mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Clean-up
This commit is contained in:
@@ -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,18 +29,18 @@ 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();
|
||||
}
|
||||
|
||||
private static boolean isNewer(File pathName) {
|
||||
Config config = Config.getInstance();
|
||||
if (config.getFilterDate() == null) return true;
|
||||
try {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user