Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow directories to be used to fill filelist #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/main/java/nsusbloader/cli/TinfoilNetCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
Expand All @@ -129,6 +144,19 @@ private void parseFilesArguments() throws IncorrectSetupException{
}
}

public List<File> fillListOfFiles(File rootDir) {
try (Stream<Path> 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,
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/nsusbloader/cli/TinfoilUsbCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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) {
Expand All @@ -59,6 +72,19 @@ private void parseFilesArguments() throws IncorrectSetupException{
}
}

public List<File> fillListOfFiles(File rootDir) {
try (Stream<Path> 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);
Expand Down