This commit is contained in:
Dmitry Isaenko 2020-02-20 05:19:42 +03:00
parent 7b2e77a08a
commit 30923d95eb
3 changed files with 48 additions and 16 deletions

View file

@ -8,7 +8,7 @@
<name>NS-USBloader</name>
<artifactId>ns-usbloader</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.1-SNAPSHOT</version>
<url>https://github.com/developersu/ns-usbloader/</url>
<description>

View file

@ -124,20 +124,35 @@ public class NETCommunications extends Task<Void> { // todo: thows IOException?
catch (SocketException | UnknownHostException e2) {
logPrinter.print("NET: Can't get your computer IP using Renmin Ribao server. Returned:\n\t"+e2.getMessage(), EMsgType.FAIL);
logPrinter.print("Try using 'Expert mode' and set IP manually.", EMsgType.INFO);
this.showAvalIpExamples();
isValid = false;
close(EFileStatus.FAILED);
return;
}
}
}
// Say hello to MacOS Catalina
// Also this part could be used instead of what we have above. One day it has to be tested on all platforms and fixed (replace code above).
if (hostIP.equals("0.0.0.0")) {
Socket scoketK;
try {
Enumeration enumeration = NetworkInterface.getNetworkInterfaces();
while (enumeration.hasMoreElements()) {
NetworkInterface n = (NetworkInterface) enumeration.nextElement();
Enumeration enumeration1 = n.getInetAddresses();
while (enumeration1.hasMoreElements()) {
InetAddress i = (InetAddress) enumeration1.nextElement();
logPrinter.print("Check for: " + i.getHostAddress(), EMsgType.INFO);
}
}
}
catch (SocketException socketException) { // Good block.
logPrinter.print("Can't determine possible variants. Returned:\n\t"+socketException.getMessage(), EMsgType.FAIL);
}
scoketK = new Socket();
scoketK.connect(new InetSocketAddress("google.com", 80));
hostIP = scoketK.getLocalAddress().getHostAddress();
scoketK.close();
} catch (Exception scoketKex) {
scoketKex.printStackTrace();
logPrinter.print("NET: Can't get your computer IP using Google server (InetSocketAddress). Returned:\n\t"+scoketKex.getMessage(), EMsgType.INFO);
try {
scoketK = new Socket();
scoketK.connect(new InetSocketAddress("people.com.cn", 80));
hostIP = scoketK.getLocalAddress().getHostAddress();
scoketK.close();
} catch (Exception scoketKexx) {
scoketKex.printStackTrace();
logPrinter.print("NET: Can't get your computer IP using Renmin Ribao server (InetSocketAddress). Returned:\n\t"+scoketKexx.getMessage(), EMsgType.FAIL);
logPrinter.print("Try using 'Expert mode' and set IP manually.", EMsgType.INFO);
this.showAvalIpExamples();
isValid = false;
close(EFileStatus.FAILED);
return;
@ -212,6 +227,23 @@ public class NETCommunications extends Task<Void> { // todo: thows IOException?
}
isValid = true;
}
/**
* Show possible variants to log area
* */
private void showAvalIpExamples(){
try {
Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
while (enumeration.hasMoreElements()) {
NetworkInterface n = enumeration.nextElement();
Enumeration<InetAddress> enumeration1 = n.getInetAddresses();
while (enumeration1.hasMoreElements())
logPrinter.print("Check for: " + enumeration1.nextElement().getHostAddress(), EMsgType.INFO);
}
}
catch (SocketException socketException) { // Good block.
logPrinter.print("Can't determine possible variants. Returned:\n\t"+socketException.getMessage(), EMsgType.FAIL);
}
}
/**
* Override cancel block to close connection by ourselves
* */

View file

@ -13,7 +13,7 @@ import java.util.ResourceBundle;
public class NSLMain extends Application {
public static final String appVersion = "v2.0";
public static final String appVersion = "v2.1";
@Override
public void start(Stage primaryStage) throws Exception{