diff --git a/src/main/java/nsusbloader/cli/TinfoilNetCli.java b/src/main/java/nsusbloader/cli/TinfoilNetCli.java index 88d1831..f6ffe2f 100644 --- a/src/main/java/nsusbloader/cli/TinfoilNetCli.java +++ b/src/main/java/nsusbloader/cli/TinfoilNetCli.java @@ -21,8 +21,15 @@ import nsusbloader.COM.NET.NETCommunications; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class TinfoilNetCli { @@ -119,8 +126,16 @@ private void parseFilesArguments() throws IncorrectSetupException{ for (; parseFileSince < arguments.length; parseFileSince++) { file = new File(arguments[parseFileSince]); - if (file.exists()) + + if (!file.exists()) { + continue; + } + + if (file.isDirectory()) { + filesList.addAll(fillListOfFiles(file)); + } else { filesList.add(file); + } } if (filesList.size() == 0) { @@ -129,6 +144,19 @@ private void parseFilesArguments() throws IncorrectSetupException{ } } + public List fillListOfFiles(File rootDir) { + try (Stream stream = Files.walk(rootDir.toPath())) { + return stream + .map(Path::toFile) + .filter(File::isFile) + .collect(Collectors.toList()); + } catch (IOException e) { + e.printStackTrace(); + } + + return Collections.emptyList(); + } + private void runTinfoilNetBackend() throws InterruptedException{ NETCommunications netCommunications = new NETCommunications( filesList, diff --git a/src/main/java/nsusbloader/cli/TinfoilUsbCli.java b/src/main/java/nsusbloader/cli/TinfoilUsbCli.java index 0d78f35..55ca96b 100644 --- a/src/main/java/nsusbloader/cli/TinfoilUsbCli.java +++ b/src/main/java/nsusbloader/cli/TinfoilUsbCli.java @@ -21,8 +21,14 @@ import nsusbloader.COM.USB.UsbCommunications; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class TinfoilUsbCli { @@ -49,8 +55,15 @@ private void parseFilesArguments() throws IncorrectSetupException{ for (String arg : arguments) { file = new File(arg); - if (file.exists()) + if (!file.exists()) { + continue; + } + + if (file.isDirectory()) { + filesList.addAll(fillListOfFiles(file)); + } else { filesList.add(file); + } } if (filesList.size() == 0) { @@ -59,6 +72,19 @@ private void parseFilesArguments() throws IncorrectSetupException{ } } + public List fillListOfFiles(File rootDir) { + try (Stream stream = Files.walk(rootDir.toPath())) { + return stream + .map(Path::toFile) + .filter(File::isFile) + .collect(Collectors.toList()); + } catch (IOException e) { + e.printStackTrace(); + } + + return Collections.emptyList(); + } + private void runTinfoilBackend() throws InterruptedException{ Runnable task = new UsbCommunications(filesList, "TinFoil", false); Thread thread = new Thread(task);