From 2322098c95b4af41358dcb5ce50fd0208e816d33 Mon Sep 17 00:00:00 2001 From: llk89 <27812632+llk89@users.noreply.github.com> Date: Thu, 1 Jul 2021 22:02:22 +0800 Subject: Stop checking for update as we are on our own now --- src/Java/gtPlusPlus/core/util/sys/GeoUtils.java | 119 --------------------- .../gtPlusPlus/core/util/sys/NetworkUtils.java | 99 ----------------- 2 files changed, 218 deletions(-) delete mode 100644 src/Java/gtPlusPlus/core/util/sys/GeoUtils.java delete mode 100644 src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java (limited to 'src/Java/gtPlusPlus/core/util/sys') diff --git a/src/Java/gtPlusPlus/core/util/sys/GeoUtils.java b/src/Java/gtPlusPlus/core/util/sys/GeoUtils.java deleted file mode 100644 index 0e5a33b948..0000000000 --- a/src/Java/gtPlusPlus/core/util/sys/GeoUtils.java +++ /dev/null @@ -1,119 +0,0 @@ -package gtPlusPlus.core.util.sys; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLConnection; - -import org.apache.http.client.utils.URIBuilder; - -import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.preloader.CORE_Preloader; - -public class GeoUtils { - - public static String determineUsersCountry(){ - if (!CORE_Preloader.DEBUG_MODE && !CORE.DEVENV) { - try { - if (NetworkUtils.checkNetworkIsAvailableWithValidInterface()){ - return getUsersCountry(); - } - else { - return "Offline."; - } - } catch (Throwable T){ - Logger.INFO("Failed to initialise GeoUtils."); - return "Failed."; - } - } - else { - return "Debug/Dev"; - } - } - - private static String getUsersIPAddress() { - try { - String webPage = "http://checkip.amazonaws.com/"; - URL url = new URL(webPage); - URLConnection urlConnection = url.openConnection(); - InputStream is = urlConnection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - int numCharsRead; - char[] charArray = new char[1024]; - StringBuffer sb = new StringBuffer(); - while ((numCharsRead = isr.read(charArray)) > 0) { - sb.append(charArray, 0, numCharsRead); - } - isr.close(); - String result = sb.toString(); - return result; - } catch (IOException e) {} - return "Error getting users IP."; - } - - private static String getUsersCountry() { - - //Get the IP - String ipAddress = getUsersIPAddress(); - - //Build a URL - URIBuilder builder = new URIBuilder() - .setScheme("http") - .setHost("ipinfo.io") - .setPath("/"+ipAddress+"/country/"); - - URI uri; - try { - //Convert the URI Builder to a URI, then to a URL - uri = builder.build(); - URL url = uri.toURL(); - - //Main Check method - try { - URLConnection urlConnection = url.openConnection(); - InputStream is = urlConnection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - int numCharsRead; - char[] charArray = new char[1024]; - StringBuffer sb = new StringBuffer(); - while ((numCharsRead = isr.read(charArray)) > 0) { - sb.append(charArray, 0, numCharsRead); - } - String temp = sb.toString(); - String result = temp.replaceAll("(\\r|\\n)", ""); - isr.close(); - return result; - //Catch block for bad connection - } catch (IOException e) { - Logger.INFO("Method 1 - Failed."); - } - - //Secondary method - try (java.util.Scanner s = new java.util.Scanner(url.openStream(), "UTF-8").useDelimiter("\\A")) { - String r = s.next(); - return r.replaceAll("(\\r|\\n)", ""); - //Catch block for bad connection - } catch (java.io.IOException e) { - Logger.INFO("Method 2 - Failed."); - } - - } - //Catch block for all the Bad URI/URL building - catch (URISyntaxException | MalformedURLException e1) { - if (e1 instanceof URISyntaxException){ - Logger.INFO("Bad URI Syntax for builder."); - } - else { - Logger.INFO("Malformed URL."); - } - Logger.INFO("Country Check - Failed."); - } - return "Error getting users Country. "+ipAddress; - } - -} diff --git a/src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java b/src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java deleted file mode 100644 index 1403713b3d..0000000000 --- a/src/Java/gtPlusPlus/core/util/sys/NetworkUtils.java +++ /dev/null @@ -1,99 +0,0 @@ -package gtPlusPlus.core.util.sys; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.*; -import java.util.Enumeration; - -import gtPlusPlus.api.objects.Logger; - -public class NetworkUtils { - - public static String getContentFromURL(final String args) { - if (checkNetworkIsAvailableWithValidInterface()){ - try { - URL url; - // get URL content - url = new URL(args); - final URLConnection conn = url.openConnection(); - // open the stream and put it into BufferedReader - final BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); - String inputLine; - String tempLine = null; - while ((inputLine = br.readLine()) != null) { - tempLine = inputLine; - } - br.close(); - return tempLine; - } - catch (final MalformedURLException e) { - Logger.INFO("Bad URL for Version Check."); - } - catch (final IOException e) { - Logger.INFO("IOException during Version Check."); - } - } - Logger.INFO("Network Not Available during Version Check."); - return "offline"; - } - - public static boolean checkNetworkIsAvailableWithValidInterface(){ - try { - if (hasValidNetworkInterface()){ - if (checkAddressWithTimeout("http://www.google.com", 100) || - checkAddressWithTimeout("http://www.baidu.com", 100) || - checkAddressWithTimeout("http://www.github.com/alkcorp/GTplusplus", 100) || - checkAddressWithTimeout("http://www.yahoo.com", 100)/* || - netIsAvailableGoogle() || - netIsAvailableBaidu() || - netIsAvailableGithub() || - netIsAvailableOther()*/){ - return true; - } - else { - Logger.INFO("No sites responded to network connectivity test."); - } - } - else { - Logger.INFO("Network Adapter was not valid."); - } - } - catch (SocketException e) {} - return false; - } - - private static boolean checkAddressWithTimeout(String URL, int timeout) { - - try { - InetAddress.getByName(URL).isReachable(timeout); //Replace with your name - return true; - } catch (Exception e) { - boolean result = false; - try { - URL urlObj = new URL(URL); - HttpURLConnection con = (HttpURLConnection) urlObj.openConnection(); - con.setRequestMethod("GET"); - con.setConnectTimeout(timeout); - con.connect(); - int code = con.getResponseCode(); - if (code == 200) { - result = true; - } - } catch (Exception e2) {} - return result; - } - } - - private static boolean hasValidNetworkInterface() throws SocketException{ - final Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); - while (interfaces.hasMoreElements()) { - final NetworkInterface interf = interfaces.nextElement(); - if (interf.isUp() && !interf.isLoopback()) { - return true; - } - } - return false; - } - -} -- cgit