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;
|
mkvToolNix.getAbsolutePath() + "/" + application;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNormalizedLibraryPath() {
|
||||||
|
return this.getLibraryPath().getAbsolutePath().replace("\\", "/");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new StringJoiner(", ", Config.class.getSimpleName() + "[", "]")
|
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() {
|
protected boolean isOverwritingNecessary() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@link FieldType} to overwrite result with.
|
||||||
|
*/
|
||||||
protected FieldType overwriteValue() {
|
protected FieldType overwriteValue() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class DateValidator extends ConfigValidator<Date> {
|
|||||||
return DEFAULT_DATE;
|
return DEFAULT_DATE;
|
||||||
}
|
}
|
||||||
YAML yaml = new YAML(lastExecutionFile);
|
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) {
|
} catch (YamlInvalidContentException | IOException e) {
|
||||||
log.error("Couldn't open last-execution.properties");
|
log.error("Couldn't open last-execution.properties");
|
||||||
return INVALID_DATE;
|
return INVALID_DATE;
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import java.util.Date;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class FileFilter {
|
public class FileFilter {
|
||||||
static boolean accept(File pathName, String[] fileExtensions) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,18 +29,18 @@ public class FileFilter {
|
|||||||
return StringUtils.endsWithAny(pathName.getAbsolutePath().toLowerCase(), fileExtensions);
|
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();
|
return Config.getInstance().getIncludePattern().matcher(pathName.getName()).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNewer(File pathName) {
|
private static boolean isNewer(File pathName) {
|
||||||
Config config = Config.getInstance();
|
Config config = Config.getInstance();
|
||||||
if (config.getFilterDate() == null) return true;
|
if (config.getFilterDate() == null) return true;
|
||||||
try {
|
try {
|
||||||
BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class);
|
BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class);
|
||||||
return isNewer(DateUtils.convert(attributes.creationTime().toMillis()));
|
return isNewer(DateUtils.convert(attributes.creationTime().toMillis()));
|
||||||
} catch (IOException e) {
|
} 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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -46,12 +48,4 @@ public class FileFilter {
|
|||||||
private static boolean isNewer(Date creationDate) {
|
private static boolean isNewer(Date creationDate) {
|
||||||
return creationDate.toInstant().isAfter(Config.getInstance().getFilterDate().toInstant());
|
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();
|
if (!configDir.exists()) configDir.mkdirs();
|
||||||
|
|
||||||
File lastExecutionFile = Path.of(filePath + "/last-execution.yml").toFile();
|
File lastExecutionFile = Path.of(filePath + "/last-execution.yml").toFile();
|
||||||
if (!lastExecutionFile.exists()) {
|
if (!lastExecutionFile.exists()) lastExecutionFile.createNewFile();
|
||||||
lastExecutionFile.createNewFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
YAML yaml = new YAML(lastExecutionFile);
|
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);
|
yaml.save(lastExecutionFile);
|
||||||
} catch (IOException | YamlInvalidContentException e) {
|
} 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.
|
* 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) {
|
public static Date convert(String date, Date defaultDate) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user