Ignore:
Timestamp:
Jan 15, 2013, 9:02:01 PM (12 years ago)
Author:
alloc
Message:

AEI2:

  • Added offline detection (should run without internet connection)
  • Update check (manual/on startup), not actually updating yet
Location:
AE/installer2/src/net/oni2/aeinstaller/backend/depot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • AE/installer2/src/net/oni2/aeinstaller/backend/depot/DepotConfig.java

    r604 r621  
    11package net.oni2.aeinstaller.backend.depot;
     2
     3import net.oni2.aeinstaller.backend.Settings;
    24
    35/**
     
    7678                return 8000;
    7779        }
     80
     81        /**
     82         * @return URL of Depot
     83         */
     84        public static String getDepotUrl() {
     85                return Settings.getInstance().get("depot_url", "http://mods.oni2.net/");
     86        }
     87
     88        /**
     89         * @return URL of Depot API
     90         */
     91        public static String getDepotApiUrl() {
     92                return Settings.getInstance().get("depot_api_url",
     93                                "http://mods.oni2.net/?q=api/");
     94        }
    7895}
  • AE/installer2/src/net/oni2/aeinstaller/backend/depot/DepotManager.java

    r605 r621  
    55import java.io.FileOutputStream;
    66import java.io.IOException;
     7import java.io.UnsupportedEncodingException;
     8import java.net.UnknownHostException;
    79import java.util.HashMap;
    810import java.util.HashSet;
     
    2123import net.oni2.aeinstaller.backend.network.DrupalJSONQuery;
    2224
     25import org.apache.http.HttpResponse;
     26import org.apache.http.client.methods.HttpGet;
     27import org.apache.http.client.methods.HttpRequestBase;
     28import org.apache.http.impl.client.DefaultHttpClient;
    2329import org.json.JSONArray;
    2430import org.json.JSONException;
     
    221227
    222228        /**
     229         * @return Can we connect to the Depot?
     230         */
     231        public boolean checkConnection() {
     232                HttpRequestBase httpQuery = null;
     233
     234                try {
     235                        DefaultHttpClient httpclient = new DefaultHttpClient();
     236                        httpQuery = new HttpGet(DepotConfig.getDepotUrl());
     237
     238                        HttpResponse response = httpclient.execute(httpQuery);
     239
     240                        int code = response.getStatusLine().getStatusCode();
     241
     242                        return (code >= 200) && (code <= 299);
     243                } catch (UnknownHostException e) {
     244                } catch (UnsupportedEncodingException e) {
     245                        e.printStackTrace();
     246                } catch (IOException e) {
     247                        e.printStackTrace();
     248                } finally {
     249                        if (httpQuery != null)
     250                                httpQuery.releaseConnection();
     251                }
     252                return false;
     253        }
     254
     255        /**
    223256         * @return All TaxVocabs
    224257         */
Note: See TracChangeset for help on using the changeset viewer.