Changeset 635
- Timestamp:
- Jan 19, 2013, 4:04:27 PM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/AEInstaller2.java
r634 r635 88 88 Settings.deserializeFromFile(); 89 89 Settings.setDebug(debug); 90 DepotManager.getInstance().loadFromFile(91 Settings.getDepotCacheFilename());92 90 93 91 SwingJavaBuilder.getConfig().addResourceBundle(imagesBundle); -
AE/installer2/src/net/oni2/aeinstaller/backend/depot/DepotManager.java
r634 r635 11 11 import java.util.Enumeration; 12 12 import java.util.HashMap; 13 import java.util.HashSet;14 13 import java.util.Vector; 15 14 import java.util.zip.ZipEntry; … … 18 17 import net.oni2.aeinstaller.backend.Paths; 19 18 import net.oni2.aeinstaller.backend.Settings; 20 import net.oni2.aeinstaller.backend.Settings.Platform;21 19 import net.oni2.aeinstaller.backend.depot.model.File; 22 20 import net.oni2.aeinstaller.backend.depot.model.Node; … … 26 24 import net.oni2.aeinstaller.backend.depot.model.TaxonomyTerm; 27 25 import net.oni2.aeinstaller.backend.depot.model.TaxonomyVocabulary; 28 import net.oni2.aeinstaller.backend.mods.ECompatiblePlatform;29 26 import net.oni2.aeinstaller.backend.network.FileDownloader; 30 27 … … 44 41 */ 45 42 public class DepotManager { 46 private static DepotManager instance = new DepotManager();43 private static DepotManager instance = loadFromFile(); 47 44 48 45 private HashMap<Integer, TaxonomyVocabulary> taxonomyVocabulary = new HashMap<Integer, TaxonomyVocabulary>(); … … 72 69 */ 73 70 public void updateInformation(boolean forceRefreshAll) { 74 taxonomyTerms.clear();75 taxonomyVocabulary.clear();76 77 nodes = new HashMap<Integer, Node>();78 nodesByType = new HashMap<String, HashMap<Integer, Node>>();79 files = new HashMap<Integer, File>();80 81 71 try { 82 72 java.io.File zipName = new java.io.File(Paths.getDownloadPath(), … … 106 96 } 107 97 108 if (ze.getName().toLowerCase().contains("vocabulary")) 98 if (ze.getName().toLowerCase().contains("vocabulary")) { 109 99 initVocabulary(new JSONArray(json.toString())); 110 if (ze.getName().toLowerCase().contains("terms")) 100 } 101 if (ze.getName().toLowerCase().contains("terms")) { 111 102 initTerms(new JSONArray(json.toString())); 112 if (ze.getName().toLowerCase().contains("nodes")) 103 } 104 if (ze.getName().toLowerCase().contains("nodes")) { 113 105 initNodes(new JSONArray(json.toString())); 114 if (ze.getName().toLowerCase().contains("files")) 106 } 107 if (ze.getName().toLowerCase().contains("files")) { 115 108 initFiles(new JSONArray(json.toString())); 109 } 116 110 } 117 111 } … … 128 122 vocabId_instmethod = getVocabulary( 129 123 DepotConfig.getVocabularyName_InstallType()).getVid(); 124 125 saveToFile(); 130 126 } catch (JSONException e) { 131 127 e.printStackTrace(); … … 138 134 139 135 private void initFiles(JSONArray ja) throws JSONException { 136 files = new HashMap<Integer, File>(); 140 137 JSONObject jo; 141 142 138 for (int i = 0; i < ja.length(); i++) { 143 139 jo = ja.getJSONObject(i); 144 145 140 int fid = jo.getInt("fid"); 146 141 … … 151 146 152 147 private void initNodes(JSONArray ja) throws JSONException { 148 nodes = new HashMap<Integer, Node>(); 149 nodesByType = new HashMap<String, HashMap<Integer, Node>>(); 153 150 JSONObject jo; 154 155 151 for (int i = 0; i < ja.length(); i++) { 156 152 jo = ja.getJSONObject(i); … … 173 169 174 170 private void initTerms(JSONArray ja) throws JSONException { 171 taxonomyTerms.clear(); 175 172 JSONObject jo; 176 177 173 for (int i = 0; i < ja.length(); i++) { 178 174 jo = ja.getJSONObject(i); … … 183 179 184 180 private void initVocabulary(JSONArray ja) throws JSONException { 181 taxonomyVocabulary.clear(); 185 182 JSONObject jo; 186 187 183 for (int i = 0; i < ja.length(); i++) { 188 184 jo = ja.getJSONObject(i); … … 218 214 return false; 219 215 } 220 221 /** 222 * @return All TaxVocabs 223 */ 224 public Vector<TaxonomyVocabulary> getVocabulary() { 225 return new Vector<TaxonomyVocabulary>(taxonomyVocabulary.values()); 226 } 227 228 /** 229 * @param id 230 * Get taxonomy vocabulary by given ID 231 * @return TaxVocab 232 */ 233 public TaxonomyVocabulary getVocabulary(int id) { 234 return taxonomyVocabulary.get(id); 235 } 236 237 /** 238 * @param name 239 * Get taxonomy vocabulary by given name 240 * @return TaxVocab 241 */ 242 public TaxonomyVocabulary getVocabulary(String name) { 216 217 private TaxonomyVocabulary getVocabulary(String name) { 243 218 for (TaxonomyVocabulary v : taxonomyVocabulary.values()) { 244 219 if (v.getName().equalsIgnoreCase(name)) … … 253 228 * @return TaxTerms 254 229 */ 255 p ublicVector<TaxonomyTerm> getTaxonomyTermsByVocabulary(int vocabId) {230 private Vector<TaxonomyTerm> getTaxonomyTermsByVocabulary(int vocabId) { 256 231 Vector<TaxonomyTerm> res = new Vector<TaxonomyTerm>(); 257 232 for (TaxonomyTerm t : taxonomyTerms.values()) { … … 263 238 264 239 /** 240 * @return All defined types 241 */ 242 public Vector<TaxonomyTerm> getTypes() { 243 return getTaxonomyTermsByVocabulary(getVocabIdType()); 244 } 245 246 /** 265 247 * @param id 266 248 * Get taxonomy term by given ID … … 269 251 public TaxonomyTerm getTaxonomyTerm(int id) { 270 252 return taxonomyTerms.get(id); 271 }272 273 /**274 * @param name275 * Get taxonomy term by given name276 * @return TaxTerm277 */278 public TaxonomyTerm getTaxonomyTerm(String name) {279 for (TaxonomyTerm t : taxonomyTerms.values()) {280 if (t.getName().equalsIgnoreCase(name))281 return t;282 }283 return null;284 253 } 285 254 … … 293 262 public Vector<Node> getNodesByType(String nodeType) { 294 263 return new Vector<Node>(nodesByType.get(nodeType).values()); 295 }296 297 /**298 * Get a node by node id299 *300 * @param id301 * Node id302 * @return Node303 */304 public Node getNodeById(int id) {305 return nodes.get(id);306 }307 308 /**309 * Get a Mod-Node by a given package number310 *311 * @param packageNumber312 * Package number to find313 * @return The Mod-Node or null314 */315 public NodeMod getNodeByPackageNumber(int packageNumber) {316 Vector<Node> files = getNodesByType(DepotConfig.getNodeType_Mod());317 for (Node n : files) {318 if (n instanceof NodeMod) {319 NodeMod nm = (NodeMod) n;320 if (nm.getPackageNumber() == packageNumber)321 return nm;322 }323 }324 return null;325 264 } 326 265 … … 345 284 346 285 /** 347 * @param node348 * Node to check validity on349 * @param platform350 * Platform to check against351 * @return True if valid on platform352 */353 public boolean isModValidOnPlatform(NodeMod node, Settings.Platform platform) {354 ECompatiblePlatform plat = node.getPlatform();355 switch (plat) {356 case BOTH:357 return true;358 case WIN:359 return (platform == Platform.WIN)360 || (platform == Platform.LINUX);361 case MACOS:362 return (platform == Platform.MACOS);363 }364 return false;365 }366 367 /**368 * Checks if the given mod-node is of the given mod-type(s)369 *370 * @param node371 * Node to check372 * @param type373 * Type(s) to check374 * @param or375 * If false check if all given types are included in node. If376 * true checks if either of the given types is included.377 * @return True if of given type(s)378 */379 public boolean isModOfType(NodeMod node, HashSet<Integer> type, boolean or) {380 boolean matching = !or;381 HashSet<TaxonomyTerm> terms = node.getTypes();382 383 for (int t : type) {384 if (or)385 matching |= terms.contains(t);386 else387 matching &= terms.contains(t);388 }389 return matching;390 }391 392 /**393 286 * @return VocabId of Platform vocabulary 394 287 */ … … 432 325 } 433 326 434 private XStream getXStream() {327 private static XStream getXStream() { 435 328 XStream xs = new XStream(new StaxDriver()); 436 329 xs.alias("Depot", DepotManager.class); … … 447 340 /** 448 341 * Save Depot cache instance to file 449 * 450 * @param f 451 * File to write to 452 */ 453 public void saveToFile(java.io.File f) { 342 */ 343 private void saveToFile() { 454 344 try { 455 FileOutputStream fos = new FileOutputStream(f); 345 FileOutputStream fos = new FileOutputStream( 346 Settings.getDepotCacheFilename()); 456 347 XStream xs = getXStream(); 457 348 xs.toXML(this, fos); … … 464 355 } 465 356 466 /** 467 * Load Depot cache instance from file 468 * 469 * @param f 470 * File to read from 471 */ 472 public void loadFromFile(java.io.File f) { 357 private static DepotManager loadFromFile() { 473 358 try { 474 FileInputStream fis = new FileInputStream(f); 359 FileInputStream fis = new FileInputStream( 360 Settings.getDepotCacheFilename()); 475 361 XStream xs = getXStream(); 476 362 Object obj = xs.fromXML(fis); 363 fis.close(); 477 364 if (obj instanceof DepotManager) 478 instance = (DepotManager) obj; 479 fis.close(); 365 return (DepotManager) obj; 480 366 } catch (FileNotFoundException e) { 481 367 } catch (IOException e) { 482 368 } 369 return new DepotManager(); 483 370 } 484 371 } -
AE/installer2/src/net/oni2/aeinstaller/backend/depot/model/NodeMod.java
r626 r635 18 18 public class NodeMod extends Node { 19 19 private Vector<NodeField_Upload> uploads = new Vector<NodeField_Upload>(); 20 private HashMap<Integer, HashSet< Integer>> taxonomyTerms = new HashMap<Integer, HashSet<Integer>>();20 private HashMap<Integer, HashSet<TaxonomyTerm>> taxonomyTerms = new HashMap<Integer, HashSet<TaxonomyTerm>>(); 21 21 private HashMap<String, String> fields = new HashMap<String, String>(); 22 22 … … 58 58 int vid = Integer 59 59 .parseInt(keyS.substring(keyS.lastIndexOf("_") + 1)); 60 HashSet< Integer> values = new HashSet<Integer>();60 HashSet<TaxonomyTerm> values = new HashSet<TaxonomyTerm>(); 61 61 if (val instanceof JSONObject) { 62 62 JSONArray ja = ((JSONObject) val).getJSONArray("und"); 63 63 for (int i = 0; i < ja.length(); i++) { 64 values.add(ja.getJSONObject(i).getInt("tid")); 64 values.add(DepotManager.getInstance().getTaxonomyTerm( 65 ja.getJSONObject(i).getInt("tid"))); 65 66 } 66 67 } … … 81 82 */ 82 83 public HashSet<TaxonomyTerm> getTypes() { 83 HashSet<TaxonomyTerm> tt = new HashSet<TaxonomyTerm>(); 84 for (int t : taxonomyTerms.get(DepotManager.getInstance() 85 .getVocabIdType())) { 86 tt.add(DepotManager.getInstance().getTaxonomyTerm(t)); 87 } 88 return tt; 84 return taxonomyTerms.get(DepotManager.getInstance().getVocabIdType()); 89 85 } 90 86 … … 93 89 */ 94 90 public TaxonomyTerm getInstallMethod() { 95 return DepotManager.getInstance().getTaxonomyTerm( 96 taxonomyTerms 97 .get(DepotManager.getInstance().getVocabIdInstMethod()) 98 .iterator().next()); 91 return taxonomyTerms 92 .get(DepotManager.getInstance().getVocabIdInstMethod()) 93 .iterator().next(); 99 94 } 100 95 … … 103 98 */ 104 99 public ECompatiblePlatform getPlatform() { 105 TaxonomyTerm term = DepotManager.getInstance().getTaxonomyTerm( 106 taxonomyTerms 107 .get(DepotManager.getInstance().getVocabIdPlatform()) 108 .iterator().next()); 100 TaxonomyTerm term = taxonomyTerms 101 .get(DepotManager.getInstance().getVocabIdPlatform()) 102 .iterator().next(); 109 103 110 104 String validPlatform = term.getName(); … … 155 149 HashSet<TaxonomyTerm> types = getTypes(); 156 150 for (String s : DepotConfig.getTaxonomyName_ModType_Tool()) { 157 TaxonomyTerm tt = DepotManager.getInstance().getTaxonomyTerm(s);158 if (types.contains(tt))159 return true;151 for (TaxonomyTerm tt : types) 152 if (tt.getName().equalsIgnoreCase(s)) 153 return true; 160 154 } 161 155 return false; -
AE/installer2/src/net/oni2/aeinstaller/backend/mods/ModManager.java
r631 r635 93 93 types.put("-Local-", localType); 94 94 95 for (TaxonomyTerm tt : DepotManager.getInstance() 96 .getTaxonomyTermsByVocabulary( 97 DepotManager.getInstance().getVocabIdType())) { 95 for (TaxonomyTerm tt : DepotManager.getInstance().getTypes()) { 98 96 types.put(tt.getName(), new Type(tt.getName(), tt)); 99 97 } -
AE/installer2/src/net/oni2/aeinstaller/gui/MainWin.java
r634 r635 159 159 private void saveLocalData() { 160 160 Settings.getInstance().serializeToFile(); 161 DepotManager.getInstance().saveToFile(Settings.getDepotCacheFilename());162 161 } 163 162
Note:
See TracChangeset
for help on using the changeset viewer.