Changeset 634 for AE/installer2/src/net/oni2/aeinstaller/backend
- Timestamp:
- Jan 19, 2013, 12:58:17 PM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller/backend
- Files:
-
- 3 added
- 3 deleted
- 3 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 } -
AE/installer2/src/net/oni2/aeinstaller/backend/mods/download/ModDownload.java
r624 r634 8 8 import net.oni2.aeinstaller.backend.Paths; 9 9 import net.oni2.aeinstaller.backend.mods.Mod; 10 import net.oni2.aeinstaller.backend.mods.unpack.UnpackListener; 11 import net.oni2.aeinstaller.backend.mods.unpack.Unpacker; 10 12 import net.oni2.aeinstaller.backend.network.FileDownloadListener; 11 13 import net.oni2.aeinstaller.backend.network.FileDownloader; 12 14 import net.oni2.aeinstaller.backend.network.FileDownloader.EState; 13 import net.oni2.aeinstaller.backend.unpack.UnpackListener;14 import net.oni2.aeinstaller.backend.unpack.Unpacker;15 15 16 16 /** … … 75 75 try { 76 76 downloader = new FileDownloader(mod.getFile().getUri_full(), 77 zipFile .getPath());77 zipFile); 78 78 downloader.addListener(this); 79 79 unpacker = new Unpacker(zipFile, targetFolder, this); … … 166 166 @Override 167 167 public void statusUpdate(Unpacker source, 168 net.oni2.aeinstaller.backend. unpack.Unpacker.EState state) {168 net.oni2.aeinstaller.backend.mods.unpack.Unpacker.EState state) { 169 169 switch (state) { 170 170 case INIT: -
AE/installer2/src/net/oni2/aeinstaller/backend/network/FileDownloader.java
r619 r634 61 61 * If url could not be opened 62 62 */ 63 public FileDownloader(String url, Stringtarget) throws IOException {63 public FileDownloader(String url, File target) throws IOException { 64 64 this.url = new URL(url); 65 this.target = new File(target);65 this.target = target; 66 66 67 67 URLConnection connection = this.url.openConnection(); … … 130 130 target.delete(); 131 131 } 132 } 133 134 /** 135 * @return current state 136 */ 137 public EState getState() { 138 return state; 132 139 } 133 140
Note:
See TracChangeset
for help on using the changeset viewer.