[IMPL] Updating files (complete refactor mostly done)

This commit is contained in:
RatzzFatzz
2020-04-08 19:47:55 +02:00
parent cf2fdcb30e
commit 8e5770babd
4 changed files with 163 additions and 9 deletions

View File

@@ -4,24 +4,38 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.AttributeConfig;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.intimpl.MkvFileCollector;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ConfigUtil;
import lombok.extern.log4j.Log4j2;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
@Log4j2
public class AttributeUpdaterKernel {
MkvFileCollector collector = new MkvFileCollector();
public void execute() {
List<AttributeConfig> configPattern = ConfigUtil.loadConfig();
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter the path to the files which should be updated: ");
List<File> allValidPaths = collector.loadFiles(scanner.nextLine());
List<File> allValidPaths = null;
do{
allValidPaths = collector.loadFiles(scanner.nextLine());
if(allValidPaths == null){
System.out.println("Please enter a valid path: ");
}
}while(allValidPaths == null);
log.info(allValidPaths.size() + " files where found and will now be processed!");
for(File file: allValidPaths) {
for(File file : allValidPaths){
List<FileAttribute> attributes = collector.loadAttributes(file);
for(AttributeConfig config: configPattern) {
boolean fileIsChanged = config.processConfig(file, attributes);
if(fileIsChanged) {
for(AttributeConfig config : configPattern){
/*
* Creating new ArrayList, because the method removes elements from the list by reference
*/
boolean fileIsChanged = config.processConfig(file, new ArrayList<>(attributes));
if(fileIsChanged){
break;
}
}