Skip to content

Commit

Permalink
Looked better using commons. Closes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Apr 10, 2015
1 parent 71ceda1 commit b79de78
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/main/java/vic/mod/integratedcircuits/IntegratedCircuits.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package vic.mod.integratedcircuits;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.logging.log4j.Logger;

import vic.mod.integratedcircuits.compat.BPRedstoneProvider;
Expand Down Expand Up @@ -171,14 +170,27 @@ public void postInit(FMLPostInitializationEvent event)
@Override
public void run()
{
//I would have done it with commons, but it doesn't let me. So this is pretty much copied from AW
//https://github.com/RiskyKen/Armourers-Workshop
try {
HttpClient client = HttpClientBuilder.create().build();
HttpUriRequest request = new HttpGet(new URL("http://bit.ly/1GIaUA6").toURI());
request.setHeader("Referer", "http://" + Constants.MOD_VERSION);
request.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0");
String newestVersion = client.execute(request, new BasicResponseHandler());
String location = "http://bit.ly/1GIaUA6";
HttpURLConnection conn = null;
while(location != null && !location.isEmpty()) {
URL url = new URL(location);
if(conn != null) conn.disconnect();

conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0");
conn.setRequestProperty("Referer", "http://" + Constants.MOD_VERSION);
conn.connect();
location = conn.getHeaderField("Location");
}

if(conn == null) throw new NullPointerException();
String newestVersion = new BufferedReader(new InputStreamReader(conn.getInputStream(), Charset.forName("UTF-8"))).readLine();
// TODO version checker? I don't really like them but we have the information now...
logger.info("Your version: {}, Newest version: {}", Constants.MOD_VERSION, newestVersion);
conn.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit b79de78

Please sign in to comment.