- Timestamp:
- Jan 18, 2013, 7:18:45 PM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/AEInstaller.properties
r632 r633 1 1 appname=AE Installer 2 2 appversion=0.9 12 appversion=0.92a -
AE/installer2/src/net/oni2/aeinstaller/AEInstaller2.java
r629 r633 123 123 JFrame.setDefaultLookAndFeelDecorated(true); 124 124 125 // TODO: Remove debug output126 125 System.out.println("JarPath: " + Paths.getInstallerPath()); 127 126 System.out.println("PrefsPath: " + Paths.getPrefsPath()); -
AE/installer2/src/net/oni2/aeinstaller/backend/depot/DepotManager.java
r621 r633 72 72 taxonomyVocabulary.clear(); 73 73 74 HashMap<Integer, Node> oldNodes = null;75 HashMap<Integer, File> oldFiles = null;76 77 if (forceRefreshAll) {78 oldNodes = new HashMap<Integer, Node>();79 oldFiles = new HashMap<Integer, File>();80 } else {81 oldNodes = nodes;82 oldFiles = files;83 }84 85 74 nodes = new HashMap<Integer, Node>(); 86 75 nodesByType = new HashMap<String, HashMap<Integer, Node>>(); … … 90 79 JSONArray ja; 91 80 JSONObject jo; 92 int page; 93 94 // Get taxonomy vocabulary 95 if (listener != null) 96 listener.cacheUpdateProgress("Updating taxonomy vocabulary", 0, 97 100); 98 page = 0; 99 do { 100 ja = DrupalJSONQuery.getIndex("taxonomy_vocabulary", page, 100); 101 for (int i = 0; i < ja.length(); i++) { 102 jo = ja.getJSONObject(i); 103 TaxonomyVocabulary tv = new TaxonomyVocabulary(jo); 104 taxonomyVocabulary.put(tv.getVid(), tv); 105 } 106 page++; 107 } while (ja.length() > 0); 108 109 // Get taxonomy terms 110 if (listener != null) 111 listener.cacheUpdateProgress("Updating taxonomy terms", 0, 100); 112 page = 0; 113 do { 114 ja = DrupalJSONQuery.getIndex("taxonomy_term", page, 100); 115 for (int i = 0; i < ja.length(); i++) { 116 jo = ja.getJSONObject(i); 117 TaxonomyTerm tt = new TaxonomyTerm(jo); 118 taxonomyTerms.put(tt.getTid(), tt); 119 } 120 page++; 121 } while (ja.length() > 0); 122 123 // Check nodes for new information 124 if (listener != null) 125 listener.cacheUpdateProgress("Checking for new/updated nodes", 126 1, 100); 127 HashSet<Integer> nodesToUpdate = new HashSet<Integer>(); 128 page = 0; 129 do { 130 ja = DrupalJSONQuery.getIndex("node", page, 500); 131 for (int i = 0; i < ja.length(); i++) { 132 jo = ja.getJSONObject(i); 133 int nid = jo.getInt("nid"); 134 long changedRemote = jo.getLong("changed"); 135 if (oldNodes.containsKey(nid)) { 136 if (changedRemote > oldNodes.get(nid).getChanged()) 137 nodesToUpdate.add(nid); 138 else { 139 Node n = oldNodes.get(nid); 140 nodes.put(nid, n); 141 if (!nodesByType.containsKey(n.getType())) 142 nodesByType.put(n.getType(), 143 new HashMap<Integer, Node>()); 144 nodesByType.get(n.getType()).put(nid, n); 145 } 146 } else { 147 nodesToUpdate.add(nid); 148 } 149 } 150 page++; 151 } while (ja.length() > 0); 152 153 // Check files for new stuff 154 if (listener != null) 155 listener.cacheUpdateProgress("Checking for new/updated files", 156 2, 100); 157 HashSet<Integer> filesToUpdate = new HashSet<Integer>(); 158 page = 0; 159 do { 160 ja = DrupalJSONQuery.getIndex("file", page, 500); 161 for (int i = 0; i < ja.length(); i++) { 162 jo = ja.getJSONObject(i); 163 int fid = jo.getInt("fid"); 164 long changedRemote = jo.getLong("timestamp"); 165 if (oldFiles.containsKey(fid)) { 166 if (changedRemote > oldFiles.get(fid).getTimestamp()) 167 filesToUpdate.add(fid); 168 else 169 files.put(fid, oldFiles.get(fid)); 170 } else { 171 filesToUpdate.add(fid); 172 } 173 } 174 page++; 175 } while (ja.length() > 0); 176 177 int total = nodesToUpdate.size() + filesToUpdate.size() + 3; 178 int step = 3; 179 // Update nodes with new information 180 for (int nid : nodesToUpdate) { 181 if (listener != null) 182 listener.cacheUpdateProgress("Updating nodes", step++, 183 total); 184 185 ja = DrupalJSONQuery.getItem("node", nid, ""); 186 jo = ja.getJSONObject(0); 81 82 ja = DrupalJSONQuery 83 .executeQuery("http://mods.oni2.net/jsoncache/vocabulary.json"); 84 for (int i = 0; i < ja.length(); i++) { 85 jo = ja.getJSONObject(i); 86 TaxonomyVocabulary tv = new TaxonomyVocabulary(jo); 87 taxonomyVocabulary.put(tv.getVid(), tv); 88 } 89 90 ja = DrupalJSONQuery 91 .executeQuery("http://mods.oni2.net/jsoncache/terms.json"); 92 for (int i = 0; i < ja.length(); i++) { 93 jo = ja.getJSONObject(i); 94 TaxonomyTerm tt = new TaxonomyTerm(jo); 95 taxonomyTerms.put(tt.getTid(), tt); 96 } 97 98 ja = DrupalJSONQuery 99 .executeQuery("http://mods.oni2.net/jsoncache/nodes.json"); 100 for (int i = 0; i < ja.length(); i++) { 101 jo = ja.getJSONObject(i); 102 103 int nid = jo.getInt("nid"); 187 104 String type = jo.getString("type"); 188 105 … … 199 116 } 200 117 201 // Update new files 202 for (int fid : filesToUpdate) { 203 if (listener != null) 204 listener.cacheUpdateProgress("Updating files", step++, 205 total); 206 207 ja = DrupalJSONQuery.getItem("file", fid, "&file_contents=0"); 208 jo = ja.getJSONObject(0); 118 ja = DrupalJSONQuery 119 .executeQuery("http://mods.oni2.net/jsoncache/files.json"); 120 for (int i = 0; i < ja.length(); i++) { 121 jo = ja.getJSONObject(i); 122 123 int fid = jo.getInt("fid"); 209 124 210 125 File f = new File(jo); -
AE/installer2/src/net/oni2/aeinstaller/backend/network/DrupalJSONQuery.java
r621 r633 5 5 import java.io.InputStreamReader; 6 6 import java.io.UnsupportedEncodingException; 7 import java.util.ArrayList;8 import java.util.HashMap;9 import java.util.List;10 11 import net.oni2.aeinstaller.backend.depot.DepotConfig;12 7 13 8 import org.apache.http.HttpEntity; 14 9 import org.apache.http.HttpResponse; 15 import org.apache.http.NameValuePair;16 import org.apache.http.client.entity.UrlEncodedFormEntity;17 10 import org.apache.http.client.methods.HttpGet; 18 import org.apache.http.client.methods.HttpPost;19 11 import org.apache.http.client.methods.HttpRequestBase; 20 12 import org.apache.http.impl.client.DefaultHttpClient; 21 import org.apache.http.message.BasicNameValuePair;22 13 import org.apache.http.util.EntityUtils; 23 14 import org.json.JSONArray; … … 31 22 32 23 /** 33 * Execute an REST action through a HTTP POST query24 * Get the JSON array found at the given url 34 25 * 35 * @param resource 36 * Resource to run on 37 * @param action 38 * Action to call 39 * @param postData 40 * Fieldname / value pairs to include in POST data 41 * @return JSON structure of item 26 * @param url 27 * URL to look at for the JSON data 28 * @return JSON array of data 42 29 * @throws Exception 43 * on HTTP error30 * On HTTP status code <200 / >299 44 31 */ 45 public static JSONArray postAction(String resource, String action, 46 HashMap<String, String> postData) throws Exception { 47 try { 48 List<NameValuePair> nvps = new ArrayList<NameValuePair>(); 49 for (String key : postData.keySet()) { 50 nvps.add(new BasicNameValuePair(key, postData.get(key))); 51 } 52 HttpEntity data = new UrlEncodedFormEntity(nvps); 53 return executeQuery(DepotConfig.getDepotApiUrl() + resource + "/" + action 54 + ".json", data); 55 } catch (UnsupportedEncodingException e) { 56 e.printStackTrace(); 57 } 58 return null; 59 } 60 61 /** 62 * Execute an REST references query through a HTTP GET query 63 * 64 * @param resource 65 * Resource to run on 66 * @param index 67 * Index of item to get the references from 68 * @param refName 69 * Name of references type 70 * @return JSON structure of item 71 * @throws Exception 72 * on HTTP error 73 */ 74 public static JSONArray getReferences(String resource, int index, 75 String refName) throws Exception { 76 return executeQuery( 77 DepotConfig.getDepotApiUrl() + resource + "/" + Integer.toString(index) + "/" 78 + refName + ".json", null); 79 } 80 81 /** 82 * Execute an REST item query through a HTTP GET query 83 * 84 * @param resource 85 * Resource to run on 86 * @param index 87 * Index of item to get 88 * @param parameters 89 * Parameters to pass (must start with ampersand "&") 90 * @return JSON structure of item 91 * @throws Exception 92 * on HTTP error 93 */ 94 public static JSONArray getItem(String resource, int index, 95 String parameters) throws Exception { 96 return executeQuery( 97 DepotConfig.getDepotApiUrl() + resource + "/" + Integer.toString(index) 98 + ".json" + parameters, null); 99 } 100 101 /** 102 * Execute an REST index query through a HTTP GET query 103 * 104 * @param resource 105 * Resource to run on 106 * @param page 107 * Number of page to get (for limited results, e.g. nodes), -1 to 108 * ignore 109 * @param pagesize 110 * Maximum number of elements to return 111 * @return JSON structure of item 112 * @throws Exception 113 * on HTTP error 114 */ 115 public static JSONArray getIndex(String resource, int page, int pagesize) 116 throws Exception { 117 String pageN = ""; 118 if (page >= 0) 119 pageN = "&page=" + Integer.toString(page); 120 String pagesizeN = ""; 121 if (pagesize >= 0) 122 pagesizeN = "&pagesize=" + Integer.toString(pagesize); 123 return executeQuery(DepotConfig.getDepotApiUrl() + resource + ".json" + pageN 124 + pagesizeN, null); 125 } 126 127 private static JSONArray executeQuery(String url, HttpEntity postData) 128 throws Exception { 32 public static JSONArray executeQuery(String url) throws Exception { 129 33 BufferedReader input = null; 130 34 HttpRequestBase httpQuery = null; … … 132 36 try { 133 37 DefaultHttpClient httpclient = new DefaultHttpClient(); 134 if (postData == null) { 135 httpQuery = new HttpGet(url); 136 } else { 137 httpQuery = new HttpPost(url); 138 ((HttpPost) httpQuery).setEntity(postData); 139 } 38 httpQuery = new HttpGet(url); 140 39 141 40 HttpResponse response = httpclient.execute(httpQuery); -
AE/installer2/src/net/oni2/aeinstaller/gui/MainWin.java
r632 r633 181 181 } 182 182 } 183 183 184 ModManager.getInstance().init(); 184 185 tblMods.reloadData();
Note:
See TracChangeset
for help on using the changeset viewer.