Changeset 634 for AE/installer2/src/net/oni2/aeinstaller/backend/depot
- Timestamp:
- Jan 19, 2013, 12:58:17 PM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller/backend/depot
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/backend/depot/DepotManager.java
r633 r634 1 1 package net.oni2.aeinstaller.backend.depot; 2 2 3 import java.io.BufferedReader; 3 4 import java.io.FileInputStream; 4 5 import java.io.FileNotFoundException; 5 6 import java.io.FileOutputStream; 6 7 import java.io.IOException; 8 import java.io.InputStreamReader; 7 9 import java.io.UnsupportedEncodingException; 8 10 import java.net.UnknownHostException; 11 import java.util.Enumeration; 9 12 import java.util.HashMap; 10 13 import java.util.HashSet; 11 14 import java.util.Vector; 12 15 import java.util.zip.ZipEntry; 16 import java.util.zip.ZipFile; 17 18 import net.oni2.aeinstaller.backend.Paths; 13 19 import net.oni2.aeinstaller.backend.Settings; 14 20 import net.oni2.aeinstaller.backend.Settings.Platform; … … 21 27 import net.oni2.aeinstaller.backend.depot.model.TaxonomyVocabulary; 22 28 import net.oni2.aeinstaller.backend.mods.ECompatiblePlatform; 23 import net.oni2.aeinstaller.backend.network. DrupalJSONQuery;29 import net.oni2.aeinstaller.backend.network.FileDownloader; 24 30 25 31 import org.apache.http.HttpResponse; … … 64 70 * @param forceRefreshAll 65 71 * Force refreshing all data, even if it seems to be cached 66 * @param listener 67 * Listener for update status 68 */ 69 public void updateInformation(boolean forceRefreshAll, 70 DepotCacheUpdateProgressListener listener) { 72 */ 73 public void updateInformation(boolean forceRefreshAll) { 71 74 taxonomyTerms.clear(); 72 75 taxonomyVocabulary.clear(); … … 77 80 78 81 try { 79 JSONArray ja; 80 JSONObject jo; 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); 82 java.io.File zipName = new java.io.File(Paths.getDownloadPath(), 83 "jsoncache.zip"); 84 FileDownloader fd = new FileDownloader(DepotConfig.getDepotUrl() 85 + "jsoncache/jsoncache.zip", zipName); 86 fd.start(); 87 while (fd.getState() != net.oni2.aeinstaller.backend.network.FileDownloader.EState.FINISHED) { 88 Thread.sleep(50); 88 89 } 89 90 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"); 104 String type = jo.getString("type"); 105 106 Node n = null; 107 if (type.equalsIgnoreCase(DepotConfig.getNodeType_Mod())) 108 n = new NodeMod(jo); 109 else 110 n = new Node(jo); 111 112 nodes.put(nid, n); 113 if (!nodesByType.containsKey(type)) 114 nodesByType.put(type, new HashMap<Integer, Node>()); 115 nodesByType.get(type).put(nid, n); 116 } 117 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"); 124 125 File f = new File(jo); 126 files.put(fid, f); 91 ZipFile zf = null; 92 try { 93 zf = new ZipFile(zipName); 94 for (Enumeration<? extends ZipEntry> e = zf.entries(); e 95 .hasMoreElements();) { 96 ZipEntry ze = e.nextElement(); 97 if (!ze.isDirectory()) { 98 BufferedReader input = new BufferedReader( 99 new InputStreamReader(zf.getInputStream(ze))); 100 StringBuffer json = new StringBuffer(); 101 102 char data[] = new char[1024]; 103 int dataRead; 104 while ((dataRead = input.read(data, 0, 1024)) != -1) { 105 json.append(data, 0, dataRead); 106 } 107 108 if (ze.getName().toLowerCase().contains("vocabulary")) 109 initVocabulary(new JSONArray(json.toString())); 110 if (ze.getName().toLowerCase().contains("terms")) 111 initTerms(new JSONArray(json.toString())); 112 if (ze.getName().toLowerCase().contains("nodes")) 113 initNodes(new JSONArray(json.toString())); 114 if (ze.getName().toLowerCase().contains("files")) 115 initFiles(new JSONArray(json.toString())); 116 } 117 } 118 } finally { 119 if (zf != null) 120 zf.close(); 121 zipName.delete(); 127 122 } 128 123 … … 135 130 } catch (JSONException e) { 136 131 e.printStackTrace(); 137 } catch (Exception e) { 138 System.err.println(e.getMessage()); 139 e.printStackTrace(); 132 } catch (IOException e1) { 133 e1.printStackTrace(); 134 } catch (InterruptedException e) { 135 e.printStackTrace(); 136 } 137 } 138 139 private void initFiles(JSONArray ja) throws JSONException { 140 JSONObject jo; 141 142 for (int i = 0; i < ja.length(); i++) { 143 jo = ja.getJSONObject(i); 144 145 int fid = jo.getInt("fid"); 146 147 File f = new File(jo); 148 files.put(fid, f); 149 } 150 } 151 152 private void initNodes(JSONArray ja) throws JSONException { 153 JSONObject jo; 154 155 for (int i = 0; i < ja.length(); i++) { 156 jo = ja.getJSONObject(i); 157 158 int nid = jo.getInt("nid"); 159 String type = jo.getString("type"); 160 161 Node n = null; 162 if (type.equalsIgnoreCase(DepotConfig.getNodeType_Mod())) 163 n = new NodeMod(jo); 164 else 165 n = new Node(jo); 166 167 nodes.put(nid, n); 168 if (!nodesByType.containsKey(type)) 169 nodesByType.put(type, new HashMap<Integer, Node>()); 170 nodesByType.get(type).put(nid, n); 171 } 172 } 173 174 private void initTerms(JSONArray ja) throws JSONException { 175 JSONObject jo; 176 177 for (int i = 0; i < ja.length(); i++) { 178 jo = ja.getJSONObject(i); 179 TaxonomyTerm tt = new TaxonomyTerm(jo); 180 taxonomyTerms.put(tt.getTid(), tt); 181 } 182 } 183 184 private void initVocabulary(JSONArray ja) throws JSONException { 185 JSONObject jo; 186 187 for (int i = 0; i < ja.length(); i++) { 188 jo = ja.getJSONObject(i); 189 TaxonomyVocabulary tv = new TaxonomyVocabulary(jo); 190 taxonomyVocabulary.put(tv.getVid(), tv); 140 191 } 141 192 }
Note:
See TracChangeset
for help on using the changeset viewer.