Fix last-execution file saving

This commit is contained in:
2023-04-08 21:07:44 +02:00
parent 094b772257
commit 9330deb75f
4 changed files with 163 additions and 144 deletions

View File

@@ -72,17 +72,22 @@ public class Config {
@Override @Override
public String toString() { public String toString() {
return new StringJoiner(", ", Config.class.getSimpleName() + "[", "]") return new StringJoiner(", ", Config.class.getSimpleName() + "[", "]")
.add("parser=" + parser).add("\n") .add("parser=" + parser)
.add("formatter=" + formatter).add("\n") .add("formatter=" + formatter)
.add("configPath=" + configPath).add("\n") .add("configPath=" + configPath)
.add("libraryPath=" + libraryPath).add("\n") .add("libraryPath=" + libraryPath)
.add("isSafeMode=" + safeMode).add("\n") .add("mkvToolNix=" + mkvToolNix)
.add("forcedKeywords=" + forcedKeywords).add("\n") .add("threads=" + threads)
.add("commentaryKeywords=" + commentaryKeywords).add("\n") .add("includePattern=" + includePattern)
.add("excludedDirectories=" + excludedDirectories).add("\n") .add("safeMode=" + safeMode)
.add("threadCount=" + threads).add("\n") .add("coherent=" + coherent)
.add("includePattern=" + includePattern).add("\n") .add("forceCoherent=" + forceCoherent)
.add("mkvToolNixPath='" + mkvToolNix + "'").add("\n") .add("onlyNewFiles=" + onlyNewFiles)
.add("filterDate=" + filterDate)
.add("forcedKeywords=" + forcedKeywords)
.add("commentaryKeywords=" + commentaryKeywords)
.add("excludedDirectories=" + excludedDirectories)
.add("preferredSubtitles=" + preferredSubtitles)
.add("attributeConfig=" + attributeConfig) .add("attributeConfig=" + attributeConfig)
.toString(); .toString();
} }

View File

@@ -6,17 +6,18 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
import at.pcgamingfreaks.yaml.YAML; import at.pcgamingfreaks.yaml.YAML;
import at.pcgamingfreaks.yaml.YamlKeyNotFoundException; import at.pcgamingfreaks.yaml.YamlKeyNotFoundException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.lang3.StringUtils; 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.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.StringJoiner;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Predicate; import java.util.function.Predicate;
@Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
public abstract class ConfigValidator<FieldType> { public abstract class ConfigValidator<FieldType> {
protected final ConfigProperty property; protected final ConfigProperty property;
@@ -157,4 +158,13 @@ public abstract class ConfigValidator<FieldType> {
public int getWeight() { public int getWeight() {
return 50; return 50;
} }
@Override
public String toString() {
return new StringJoiner(", ", ConfigValidator.class.getSimpleName() + "[", "]")
.add("property=" + property)
.add("required=" + required)
.add("defaultValue=" + defaultValue)
.toString();
}
} }

View File

@@ -17,7 +17,7 @@ import java.util.Date;
@Slf4j @Slf4j
public class DateValidator extends ConfigValidator<Date> { public class DateValidator extends ConfigValidator<Date> {
private static final Date INVALID_DATE = new Date(0); private static final Date INVALID_DATE = new Date(0);
private static final Date DEFAULT_DATE = new Date(1); private static final Date DEFAULT_DATE = new Date(1000);
public DateValidator(ConfigProperty property, boolean required) { public DateValidator(ConfigProperty property, boolean required) {
super(property, required, null); super(property, required, 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(), DateUtils.convert(DEFAULT_DATE))); return parse(yaml.getString(Config.getInstance().getLibraryPath().getAbsolutePath().replace("\\", "/"), 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;

View File

@@ -150,6 +150,10 @@ public abstract class AttributeUpdaterKernel {
} }
protected void endProcess() { protected void endProcess() {
if (Config.getInstance().isSafeMode()) {
return;
}
try { try {
String filePath = AppDirsFactory.getInstance().getUserConfigDir(ProjectUtil.getProjectName(), null, null); String filePath = AppDirsFactory.getInstance().getUserConfigDir(ProjectUtil.getProjectName(), null, null);
@@ -162,7 +166,7 @@ public abstract class AttributeUpdaterKernel {
} }
YAML yaml = new YAML(lastExecutionFile); YAML yaml = new YAML(lastExecutionFile);
yaml.set(Config.getInstance().getLibraryPath().getAbsolutePath(), DateUtils.convert(new Date())); yaml.set(Config.getInstance().getLibraryPath().getAbsolutePath().replace("\\", "/"), 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: ", e); // TODO