Changeset 604 for AE/installer2/src/net/oni2/aeinstaller/backend/mods
- Timestamp:
- Jan 12, 2013, 11:48:33 PM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller/backend/mods
- Files:
-
- 5 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/backend/mods/Mod.java
r603 r604 13 13 import net.oni2.aeinstaller.backend.Settings; 14 14 import net.oni2.aeinstaller.backend.Settings.Platform; 15 import net.oni2.aeinstaller.backend.depot.DepotConfig; 15 16 import net.oni2.aeinstaller.backend.depot.DepotManager; 16 17 import net.oni2.aeinstaller.backend.depot.model.NodeMod; … … 21 22 */ 22 23 public class Mod implements Comparable<Mod> { 23 // TODO: Dependencies/Conflicts24 25 24 private String name = ""; 26 25 private int packageNumber = 0; … … 76 75 public void updateLocalData() { 77 76 File config = new File(getLocalPath(), "Mod_Info.cfg"); 78 File timestamp= new File(getLocalPath(), "aei.cfg");77 File aeicfg = new File(getLocalPath(), "aei.cfg"); 79 78 if (config.exists()) { 80 79 try { … … 112 111 if (node == null) 113 112 description = sVal.replaceAll("\\\\n", "<br>"); 113 } else if (sName.equalsIgnoreCase("Depends")) { 114 String[] depsS = sVal.split(","); 115 for (String s : depsS) { 116 try { 117 int dep = Integer.parseInt(s); 118 dependencies.add(dep); 119 } catch (NumberFormatException e) { 120 System.err 121 .format("Mod %05d does contain a non-number dependency: '%s'\n", 122 packageNumber, s); 123 } 124 } 125 } else if (sName.equalsIgnoreCase("Conflicts")) { 126 String[] confS = sVal.split(","); 127 for (String s : confS) { 128 try { 129 int conf = Integer.parseInt(s); 130 conflicts.add(conf); 131 } catch (NumberFormatException e) { 132 System.err 133 .format("Mod %05d does contain a non-number dependency: '%s'\n", 134 packageNumber, s); 135 } 136 } 114 137 } 115 138 } … … 123 146 + getLocalPath().getPath()); 124 147 } 125 if ( timestamp.exists()) {148 if (aeicfg.exists()) { 126 149 try { 127 FileInputStream fstream = new FileInputStream( timestamp);150 FileInputStream fstream = new FileInputStream(aeicfg); 128 151 InputStreamReader isr = new InputStreamReader(fstream); 129 152 BufferedReader br = new BufferedReader(isr); 130 String ts = br.readLine(); 131 localTimestamp = Long.parseLong(ts); 153 String strLine; 154 while ((strLine = br.readLine()) != null) { 155 if (strLine.indexOf("->") < 1) 156 continue; 157 if (strLine.indexOf("//") >= 0) 158 strLine = strLine.substring(0, strLine.indexOf("//")); 159 String[] split = strLine.split("->", 2); 160 String sName = split[0].trim(); 161 String sVal = split[1].trim(); 162 if (sName.equalsIgnoreCase("Timestamp")) { 163 localTimestamp = Long.parseLong(sVal); 164 } 165 } 132 166 isr.close(); 133 167 } catch (FileNotFoundException e) { … … 214 248 215 249 /** 250 * @return the package number as 5 digit string 251 */ 252 public String getPackageNumberString() { 253 return String.format("%05d", packageNumber); 254 } 255 256 /** 216 257 * @return Types of mod 217 258 */ … … 266 307 */ 267 308 public boolean isMandatoryMod() { 268 return packageNumber < 10000;309 return packageNumber < DepotConfig.getMandatoryLimit(); 269 310 } 270 311 -
AE/installer2/src/net/oni2/aeinstaller/backend/mods/ModManager.java
r603 r604 3 3 import java.io.File; 4 4 import java.io.FileFilter; 5 import java.io.FileInputStream; 6 import java.io.FileNotFoundException; 7 import java.io.FileOutputStream; 8 import java.io.IOException; 5 9 import java.util.Collection; 6 10 import java.util.HashMap; … … 9 13 import java.util.Vector; 10 14 15 import com.thoughtworks.xstream.XStream; 16 import com.thoughtworks.xstream.io.xml.StaxDriver; 17 11 18 import net.oni2.aeinstaller.backend.Paths; 12 19 import net.oni2.aeinstaller.backend.depot.DepotManager; 13 20 import net.oni2.aeinstaller.backend.depot.model.NodeMod; 14 21 import net.oni2.aeinstaller.backend.depot.model.TaxonomyTerm; 22 import net.oni2.aeinstaller.backend.oni.Installer; 15 23 16 24 /** … … 18 26 */ 19 27 public class ModManager { 20 // Download mods21 // Update mods22 23 28 private static ModManager instance = new ModManager(); 24 29 … … 26 31 private HashMap<Integer, Mod> mods = new HashMap<Integer, Mod>(); 27 32 private HashMap<Integer, Mod> tools = new HashMap<Integer, Mod>(); 33 34 private Vector<Integer> currentlyInstalled = new Vector<Integer>(); 35 36 /** 37 * @param f 38 * Mod selection file 39 * @return Mod selection 40 */ 41 @SuppressWarnings("unchecked") 42 public Vector<Integer> loadModSelection(File f) { 43 Vector<Integer> res = new Vector<Integer>(); 44 try { 45 FileInputStream fis = new FileInputStream(f); 46 XStream xs = new XStream(new StaxDriver()); 47 Object obj = xs.fromXML(fis); 48 if (obj instanceof Vector<?>) 49 res = (Vector<Integer>) obj; 50 fis.close(); 51 } catch (FileNotFoundException e) { 52 e.printStackTrace(); 53 } catch (IOException e) { 54 e.printStackTrace(); 55 } 56 return res; 57 } 58 59 /** 60 * @param f 61 * Mod selection file 62 * @param mods 63 * Selected mods 64 */ 65 public void saveModSelection(File f, TreeSet<Mod> mods) { 66 try { 67 Vector<Integer> installed = new Vector<Integer>(); 68 for (Mod m : mods) { 69 installed.add(m.getPackageNumber()); 70 } 71 FileOutputStream fos = new FileOutputStream(f); 72 XStream xs = new XStream(new StaxDriver()); 73 xs.toXML(installed, fos); 74 fos.close(); 75 } catch (FileNotFoundException e) { 76 e.printStackTrace(); 77 } catch (IOException e) { 78 e.printStackTrace(); 79 } 80 } 28 81 29 82 /** … … 69 122 mods.put(m.getPackageNumber(), m); 70 123 } 71 } 72 73 public void refreshLocalMods() {74 // TODO: evtl nur private e.g. als listener für downloads?124 125 currentlyInstalled = Installer.getInstalledMods(); 126 if (currentlyInstalled == null) 127 currentlyInstalled = new Vector<Integer>(); 75 128 } 76 129 … … 108 161 * @return Mods which are always installed 109 162 */ 110 public Collection<Mod> getMandatoryMods() {111 Vector<Mod> res = new Vector<Mod>();163 public TreeSet<Mod> getMandatoryMods() { 164 TreeSet<Mod> res = new TreeSet<Mod>(); 112 165 for (Mod m : mods.values()) { 113 166 if (m.isMandatoryMod()) … … 116 169 return res; 117 170 } 118 171 119 172 /** 120 173 * @return Collection of tools … … 123 176 return tools.values(); 124 177 } 125 178 126 179 /** 127 180 * @return Tools which are always installed 128 181 */ 129 public Collection<Mod> getMandatoryTools() {130 Vector<Mod> res = new Vector<Mod>();182 public TreeSet<Mod> getMandatoryTools() { 183 TreeSet<Mod> res = new TreeSet<Mod>(); 131 184 for (Mod m : tools.values()) { 132 185 if (m.isMandatoryMod()) … … 201 254 } 202 255 256 /** 257 * @param m 258 * Mod to check 259 * @return Is mod installed? 260 */ 261 public boolean isModInstalled(Mod m) { 262 return currentlyInstalled.contains(m.getPackageNumber()); 263 } 203 264 }
Note:
See TracChangeset
for help on using the changeset viewer.