Make path of lastFileExecution platform dependent

This commit is contained in:
RatzzFatzz
2026-01-15 12:40:09 +01:00
parent ff38457af1
commit cce84f5c15
3 changed files with 42 additions and 14 deletions

View File

@@ -6,6 +6,10 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.RollingFileAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Configurator;
import picocli.CommandLine;
@@ -39,7 +43,14 @@ public class CommandRunner implements Runnable {
System.out.println("Safemode active. No files will be changed!");
}
LastExecutionHandler lastExecutionHandler = config.isOnlyNewFiles() ? new LastExecutionHandler("./last-executions.yml") : null;
String userLocal = getLogDirectory();
if (userLocal == null) {
log.error("Could not load log4j2 log info");
System.out.println("Could not load log4j2 log info");
System.exit(1);
}
LastExecutionHandler lastExecutionHandler = config.isOnlyNewFiles() ? new LastExecutionHandler(userLocal) : null;
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate(), lastExecutionHandler);
FileProcessor fileProcessor = new CachedFileProcessor(new MkvFileProcessor(config.getMkvToolNix(), fileFilter));
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired());
@@ -49,4 +60,19 @@ public class CommandRunner implements Runnable {
: new SingleFileAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler);
kernel.execute();
}
public String getLogDirectory() {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
for (org.apache.logging.log4j.core.Appender appender : config.getAppenders().values()) {
if (appender instanceof RollingFileAppender rollingFileAppender) {
String fileName = rollingFileAppender.getFileName();
return new java.io.File(fileName).getParentFile().getParent();
}
}
log.warn("No file appender found in configuration");
return null;
}
}

View File

@@ -11,11 +11,12 @@ import java.util.Properties;
@Slf4j
public class LastExecutionHandler {
private static final String FILE_NAME = "last-execution.properties";
private final File file;
private final Properties lastFileExecution;
public LastExecutionHandler(String path) {
file = new File(path);
file = new File(path + "/" + FILE_NAME);
lastFileExecution = loadLastFileExecution(file);
}
@@ -24,7 +25,7 @@ public class LastExecutionHandler {
try (FileInputStream in = new FileInputStream(file)) {
properties.load(in);
} catch (IOException e) {
log.warn("Couldn't find or read {}", file.getPath(), e);
log.info("Couldn't find or read {}", file.getPath(), e);
}
return properties;
}