Changeset 604 for AE/installer2/src/net/oni2/aeinstaller/backend/oni
- Timestamp:
- Jan 12, 2013, 11:48:33 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/backend/oni/Installer.java
r603 r604 19 19 import net.oni2.aeinstaller.backend.Settings.Platform; 20 20 import net.oni2.aeinstaller.backend.mods.Mod; 21 import net.oni2.aeinstaller.backend.mods.ModManager; 21 22 22 23 import org.apache.commons.io.FileUtils; … … 39 40 } 40 41 42 /** 43 * @return list of currently installed mods 44 */ 45 public static Vector<Integer> getInstalledMods() { 46 File installCfg = new File(Paths.getEditionGDF(), "installed_mods.xml"); 47 return ModManager.getInstance().loadModSelection(installCfg); 48 } 49 50 /** 51 * @param tools 52 * Tools to install 53 */ 54 public static void installTools(TreeSet<Mod> tools) { 55 for (Mod m : tools) { 56 File plain = new File(m.getLocalPath(), "plain"); 57 if (plain.exists()) { 58 if (m.hasSeparatePlatformDirs()) { 59 File plainCommon = new File(plain, "common"); 60 File plainMac = new File(plain, "mac_only"); 61 File plainWin = new File(plain, "win_only"); 62 if (plainCommon.exists()) 63 copyToolsFiles(plainCommon); 64 if (Settings.getPlatform() == Platform.MACOS 65 && plainMac.exists()) 66 copyToolsFiles(plainMac); 67 else if (plainWin.exists()) 68 copyToolsFiles(plainWin); 69 } else { 70 copyToolsFiles(plain); 71 } 72 } 73 } 74 } 75 76 /** 77 * @param tools 78 * Tools to uninstall 79 */ 80 public static void uninstallTools(TreeSet<Mod> tools) { 81 // TODO: implement this! 82 } 83 84 private static void copyToolsFiles(File srcFolder) { 85 for (File f : srcFolder.listFiles()) { 86 try { 87 if (f.isDirectory()) 88 FileUtils.copyDirectoryToDirectory(f, 89 Paths.getEditionBasePath()); 90 else 91 FileUtils 92 .copyFileToDirectory(f, Paths.getEditionBasePath()); 93 } catch (IOException e) { 94 // TODO Auto-generated catch block 95 e.printStackTrace(); 96 } 97 } 98 } 41 99 /** 42 100 * Install the given set of mods … … 49 107 public static void install(TreeSet<Mod> mods, 50 108 InstallProgressListener listener) { 109 try { 110 createEmptyPath(Paths.getEditionGDF()); 111 } catch (IOException e) { 112 e.printStackTrace(); 113 } 114 115 File installCfg = new File(Paths.getEditionGDF(), "installed_mods.xml"); 116 ModManager.getInstance().saveModSelection(installCfg, mods); 117 51 118 Vector<File> folders = new Vector<File>(); 52 119 folders.add(Paths.getVanillaOnisPath()); … … 79 146 private static void combineBinaryFiles(List<File> srcFoldersFiles, 80 147 InstallProgressListener listener) { 148 HashMap<String, Vector<File>> levels = new HashMap<String, Vector<File>>(); 149 150 for (File path : srcFoldersFiles) { 151 for (File levelF : path.listFiles()) { 152 String fn = levelF.getName().toLowerCase(); 153 String levelN = null; 154 if (levelF.isDirectory()) { 155 levelN = fn; 156 } else if (fn.endsWith(".dat")) { 157 levelN = fn.substring(0, fn.lastIndexOf('.')); 158 } 159 if (levelN != null) { 160 if (!levels.containsKey(levelN)) 161 levels.put(levelN, new Vector<File>()); 162 levels.get(levelN).add(levelF); 163 } 164 } 165 } 166 167 int totalSteps = 0; 168 int stepsDone = 0; 169 170 for (@SuppressWarnings("unused") 171 String s : levels.keySet()) 172 totalSteps++; 173 174 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 175 176 File logFile = new File(Paths.getInstallerPath(), "Installation.log"); 177 PrintWriter log = null; 81 178 try { 82 HashMap<String, Vector<File>> levels = new HashMap<String, Vector<File>>(); 83 84 for (File path : srcFoldersFiles) { 85 for (File levelF : path.listFiles()) { 86 String fn = levelF.getName().toLowerCase(); 87 String levelN = null; 88 if (levelF.isDirectory()) { 89 levelN = fn; 90 } else if (fn.endsWith(".dat")) { 91 levelN = fn.substring(0, fn.lastIndexOf('.')); 92 } 93 if (levelN != null) { 94 if (!levels.containsKey(levelN)) 95 levels.put(levelN, new Vector<File>()); 96 levels.get(levelN).add(levelF); 97 } 98 } 99 } 100 101 int totalSteps = 0; 102 int stepsDone = 0; 103 104 for (@SuppressWarnings("unused") 105 String s : levels.keySet()) 106 totalSteps++; 107 108 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 109 110 File logFile = new File(Paths.getInstallerPath(), 111 "Installation.log"); 112 PrintWriter log = null; 113 try { 114 log = new PrintWriter(logFile); 115 } catch (FileNotFoundException e) { 116 e.printStackTrace(); 117 } 118 119 Date start = new Date(); 120 log.println("Installation of mods started at " + sdf.format(start)); 121 122 log.println("Cleaning directories"); 179 log = new PrintWriter(logFile); 180 } catch (FileNotFoundException e) { 181 e.printStackTrace(); 182 } 183 184 Date start = new Date(); 185 log.println("Installation of mods started at " + sdf.format(start)); 186 187 log.println("Importing levels"); 188 for (String l : levels.keySet()) { 189 log.println("\tLevel " + l); 123 190 listener.installProgressUpdate(stepsDone, totalSteps, 124 "Cleaning up directories"); 125 126 createEmptyPath(Paths.getEditionGDF()); 127 128 log.println("Importing levels"); 129 for (String l : levels.keySet()) { 130 log.println("\tLevel " + l); 131 for (File f : levels.get(l)) { 132 log.println("\t\t\t" + f.getPath()); 133 } 134 135 Vector<String> res = OniSplit.packLevel(levels.get(l), 136 new File(Paths.getEditionGDF(), l + ".dat")); 137 if (res != null && res.size() > 0) { 138 for (String s : res) 139 log.println("\t\t" + s); 140 } 141 142 log.println(); 143 } 144 145 Date end = new Date(); 146 log.println("Initialization ended at " + sdf.format(end)); 147 log.println("Process took " 148 + ((end.getTime() - start.getTime()) / 1000) + " seconds"); 149 log.close(); 150 } catch (IOException e) { 151 // TODO Auto-generated catch block 152 e.printStackTrace(); 153 } 191 "Installing level " + l); 192 for (File f : levels.get(l)) { 193 log.println("\t\t\t" + f.getPath()); 194 } 195 196 Vector<String> res = OniSplit.packLevel(levels.get(l), new File( 197 Paths.getEditionGDF(), l + ".dat")); 198 if (res != null && res.size() > 0) { 199 for (String s : res) 200 log.println("\t\t" + s); 201 } 202 203 log.println(); 204 } 205 206 Date end = new Date(); 207 log.println("Initialization ended at " + sdf.format(end)); 208 log.println("Process took " 209 + ((end.getTime() - start.getTime()) / 1000) + " seconds"); 210 log.close(); 154 211 } 155 212 … … 273 330 274 331 FileUtils.deleteDirectory(init); 275 332 276 333 Date end = new Date(); 277 334 log.println("Initialization ended at " + sdf.format(end)); … … 387 444 388 445 /** 389 * Verify that the Edition is within a subfolder to vanilla Oni (..../Oni/Edition/AEInstaller) 446 * Verify that the Edition is within a subfolder to vanilla Oni 447 * (..../Oni/Edition/AEInstaller) 448 * 390 449 * @return true if GDF can be found in the parent's parent-path 391 450 */ 392 451 public static boolean verifyRunningDirectory() { 393 return Paths.getVanillaGDF().exists() && Paths.getVanillaGDF().isDirectory(); 452 return Paths.getVanillaGDF().exists() 453 && Paths.getVanillaGDF().isDirectory(); 394 454 } 395 455 }
Note:
See TracChangeset
for help on using the changeset viewer.