Skip to content

Commit dc995e1

Browse files
committed
Add CLI support for Tinfoil/Awoo USB-install mode.
1 parent 51938df commit dc995e1

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

src/main/java/nsusbloader/cli/CommandLineInterface.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public CommandLineInterface(String[] args) {
6161
new TinfoilNet(tfnArguments);
6262
return;
6363
}
64+
if (cli.hasOption("t") || cli.hasOption("tinfoil")){
65+
final String[] tfArguments = cli.getOptionValues("tinfoil");
66+
new TinfoilUsb(tfArguments);
67+
return;
68+
}
6469
}
6570
catch (ParseException pe){
6671
System.out.println(pe.getLocalizedMessage() +
@@ -116,6 +121,13 @@ private Options createCliOptions(){
116121
.hasArgs()
117122
.argName("...")
118123
.build();
124+
/* Tinfoil/Awoo USB */
125+
final Option tinfoilOption = Option.builder("t")
126+
.longOpt("tinfoil")
127+
.desc("Install via Tinfoil/Awoo USB mode.")
128+
.hasArgs()
129+
.argName("FILE1 ...")
130+
.build();
119131

120132

121133
final OptionGroup group = new OptionGroup();
@@ -124,6 +136,7 @@ private Options createCliOptions(){
124136
group.addOption(cleanSettingsOption);
125137
group.addOption(versionOption);
126138
group.addOption(helpOption);
139+
group.addOption(tinfoilOption);
127140

128141
options.addOptionGroup(group);
129142

src/main/java/nsusbloader/cli/TinfoilNet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private void parseFilesArguments() throws IncorrectSetupException{
123123
}
124124

125125
if (filesList.size() == 0) {
126-
throw new IncorrectSetupException("File(s) doesn't exists.\n" +
126+
throw new IncorrectSetupException("File(s) doesn't exist.\n" +
127127
"Try 'ns-usbloader -n help' for more information.");
128128
}
129129
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package nsusbloader.cli;
2+
3+
import nsusbloader.COM.ICommunications;
4+
import nsusbloader.COM.USB.UsbCommunications;
5+
6+
import java.io.File;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
public class TinfoilUsb {
11+
12+
private final String[] arguments;
13+
private List<File> filesList;
14+
15+
public TinfoilUsb(String[] arguments) throws InterruptedException, IncorrectSetupException{
16+
this.arguments = arguments;
17+
checkArguments();
18+
parseFilesArguments();
19+
runTinfoilBackend();
20+
}
21+
22+
private void checkArguments() throws IncorrectSetupException{
23+
if (arguments == null || arguments.length == 0) {
24+
throw new IncorrectSetupException("No files?\n" +
25+
"Try 'ns-usbloader -h' for more information.");
26+
}
27+
}
28+
29+
private void parseFilesArguments() throws IncorrectSetupException{
30+
filesList = new ArrayList<>();
31+
File file;
32+
33+
for (String arg : arguments) {
34+
file = new File(arg);
35+
if (file.exists())
36+
filesList.add(file);
37+
}
38+
39+
if (filesList.size() == 0) {
40+
throw new IncorrectSetupException("File(s) doesn't exist.\n" +
41+
"Try 'ns-usbloader -n help' for more information.");
42+
}
43+
}
44+
45+
private void runTinfoilBackend() throws InterruptedException{
46+
ICommunications task = new UsbCommunications(filesList, "TinFoil", false);
47+
Thread thread = new Thread(task);
48+
thread.start();
49+
thread.join();
50+
}
51+
}

0 commit comments

Comments
 (0)