Add NS-USBloader network-stopper feature (front-end implementation)

This commit is contained in:
Dmitry Isaenko 2020-09-29 02:54:18 +03:00
parent 22b18710a5
commit 45696881e2

View file

@ -25,6 +25,7 @@ import nsusbloader.ModelControllers.Log;
import nsusbloader.NSLDataTypes.EModule; import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.NSLDataTypes.EMsgType; import nsusbloader.NSLDataTypes.EMsgType;
import nsusbloader.COM.Helpers.NSSplitReader; import nsusbloader.COM.Helpers.NSSplitReader;
import nsusbloader.RainbowHexDump;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
@ -160,9 +161,7 @@ public class NETCommunications extends CancellableRunnable {
String line; String line;
LinkedList<String> tcpPacket = new LinkedList<>(); LinkedList<String> tcpPacket = new LinkedList<>();
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
//System.out.println(line); // Debug
if (line.trim().isEmpty()) { // If TCP packet is ended if (line.trim().isEmpty()) { // If TCP packet is ended
handleRequest(tcpPacket); // Proceed required things handleRequest(tcpPacket); // Proceed required things
tcpPacket.clear(); // Clear data and wait for next TCP packet tcpPacket.clear(); // Clear data and wait for next TCP packet
@ -170,8 +169,6 @@ public class NETCommunications extends CancellableRunnable {
else else
tcpPacket.add(line); // Otherwise collect data tcpPacket.add(line); // Otherwise collect data
} }
//System.out.println("<Socket Closed>");
// and reopen client sock
clientSocket.close(); clientSocket.close();
} }
} }
@ -188,6 +185,10 @@ public class NETCommunications extends CancellableRunnable {
* @return true if failed * @return true if failed
* */ * */
private void handleRequest(LinkedList<String> packet) throws Exception{ private void handleRequest(LinkedList<String> packet) throws Exception{
if (packet.get(0).startsWith("DROP")){
throw new Exception("All transfers finished");
}
File requestedFile; File requestedFile;
String reqFileName = packet.get(0).replaceAll("(^[A-z\\s]+/)|(\\s+?.*$)", ""); String reqFileName = packet.get(0).replaceAll("(^[A-z\\s]+/)|(\\s+?.*$)", "");