[IMPL] Changed to CLI tool

This commit is contained in:
2020-06-04 00:53:33 +02:00
parent aef1fdf9a5
commit e0a21b5d7c
10 changed files with 43 additions and 461 deletions

View File

@@ -10,36 +10,29 @@ 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() {
public void execute(String path) {
List<AttributeConfig> configPattern = ConfigUtil.loadConfig();
List<File> allValidPaths = null;
try(Scanner scanner = new Scanner(System.in)){
System.out.println("Please enter the path to the files which should be updated: ");
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){
List<FileAttribute> attributes = collector.loadAttributes(file);
for(AttributeConfig config : configPattern){
/*
* Creating new ArrayList, because the method removes elements from the list by reference
*/
boolean fileHasChanged = new ConfigProcessor(config).processConfig(file, new ArrayList<>(attributes));
if(fileHasChanged){
break;
List<File> allValidPaths = collector.loadFiles(path);
if(! allValidPaths.isEmpty()){
for(File file : allValidPaths){
List<FileAttribute> attributes = collector.loadAttributes(file);
for(AttributeConfig config : configPattern){
/*
* Creating new ArrayList, because the method removes elements from the list by reference
*/
boolean fileHasChanged = new ConfigProcessor(config).processConfig(file, new ArrayList<>(attributes));
if(fileHasChanged){
break;
}
}
}
}else{
log.error("Path is not valid!");
}
}
}