Changeset 698 for AE/installer2/src/net
- Timestamp:
- Mar 13, 2013, 8:00:39 PM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/AEInstaller.properties
r673 r698 1 1 appname=AE Installer 2 2 appversion=0.99 r2 appversion=0.99s -
AE/installer2/src/net/oni2/aeinstaller/backend/oni/Installer.java
r664 r698 19 19 import java.util.TreeSet; 20 20 import java.util.Vector; 21 import java.util.regex.Pattern; 21 22 22 23 import net.oni2.aeinstaller.AEInstaller2; … … 29 30 30 31 import org.apache.commons.io.FileUtils; 32 import org.apache.commons.io.filefilter.RegexFileFilter; 33 import org.apache.commons.io.filefilter.TrueFileFilter; 31 34 import org.javabuilders.swing.SwingJavaBuilder; 32 35 … … 260 263 FileUtils.deleteDirectory(f); 261 264 } catch (IOException e) { 262 // TODO Auto-generated catch block263 265 e.printStackTrace(); 264 266 } … … 274 276 Vector<File> foldersOni = new Vector<File>(); 275 277 foldersOni.add(Paths.getVanillaOnisPath()); 278 279 Vector<File> foldersPatches = new Vector<File>(); 276 280 277 281 for (Package m : mods) { … … 296 300 } 297 301 } 298 } 299 300 combineBinaryFiles(foldersOni, listener, log); 302 303 File patches = new File(m.getLocalPath(), "patches"); 304 if (patches.exists()) { 305 if (m.hasSeparatePlatformDirs()) { 306 File patchesCommon = new File(patches, "common"); 307 File patchesMac = new File(patches, "mac_only"); 308 File patchesWin = new File(patches, "win_only"); 309 if (patchesCommon.exists()) 310 foldersPatches.add(patchesCommon); 311 if (Settings.getPlatform() == Platform.MACOS 312 && patchesMac.exists()) 313 foldersPatches.add(patchesMac); 314 else if (patchesWin.exists()) 315 foldersPatches.add(patchesWin); 316 } else { 317 foldersPatches.add(patches); 318 } 319 } 320 } 321 322 TreeMap<String, Vector<File>> levels = new TreeMap<String, Vector<File>>(); 323 for (File path : foldersOni) { 324 for (File levelF : path.listFiles()) { 325 String fn = levelF.getName().toLowerCase(); 326 String levelN = null; 327 if (levelF.isDirectory()) { 328 levelN = fn; 329 } else if (fn.endsWith(".dat")) { 330 levelN = fn.substring(0, fn.lastIndexOf('.')).toLowerCase(); 331 } 332 if (levelN != null) { 333 if (!levels.containsKey(levelN)) 334 levels.put(levelN, new Vector<File>()); 335 levels.get(levelN).add(levelF); 336 } 337 } 338 } 339 340 applyPatches(levels, foldersPatches, listener, log); 341 342 combineBinaryFiles(levels, listener, log); 301 343 combineBSLFolders(mods, listener, log); 302 344 … … 417 459 } 418 460 419 private static void combineBinaryFiles(List<File> srcFoldersFiles, 461 private static void applyPatches( 462 TreeMap<String, Vector<File>> oniLevelFolders, 463 List<File> patchFolders, InstallProgressListener listener, 464 PrintWriter log) { 465 // TODO: REMOVE 466 long startMS = new Date().getTime(); 467 // TODO: Implement this 468 String tmpFolderName = "installrun_temp-" 469 + new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss") 470 .format(new Date()); 471 File tmpFolder = new File(Paths.getTempPath(), tmpFolderName); 472 473 HashMap<String, Vector<File>> patches = new HashMap<String, Vector<File>>(); 474 for (File patchFolder : patchFolders) { 475 for (File levelFolder : patchFolder.listFiles(dirFileFilter)) { 476 String lvlName = levelFolder.getName().toLowerCase(); 477 for (File f : FileUtils.listFiles(levelFolder, 478 new String[] { "oni-patch" }, true)) { 479 if (!patches.containsKey(lvlName)) 480 patches.put(lvlName, new Vector<File>()); 481 patches.get(lvlName).add(f); 482 } 483 } 484 } 485 486 for (String level : patches.keySet()) { 487 File levelFolder = new File(tmpFolder, level); 488 levelFolder.mkdir(); 489 490 // Get files to be patched from vanilla.dat / packages 491 for (File patch : patches.get(level)) { 492 String patternWildcard = patch.getName(); 493 patternWildcard = patternWildcard.substring(0, 494 patternWildcard.indexOf(".oni-patch")); 495 patternWildcard = patternWildcard.replace('-', '*'); 496 final Pattern patternRegex = Pattern.compile( 497 patternWildcard.replaceAll("\\*", ".\\*"), 498 Pattern.CASE_INSENSITIVE); 499 500 for (File srcFolder : oniLevelFolders.get(level)) { 501 if (srcFolder.isFile()) { 502 // Extract from .dat 503 OniSplit.export(levelFolder, srcFolder, patternWildcard); 504 } else { 505 // Copy from folder with overwrite 506 for (File f : FileUtils.listFiles(srcFolder, 507 new RegexFileFilter(patternRegex), 508 TrueFileFilter.TRUE)) { 509 try { 510 FileUtils.copyFileToDirectory(f, levelFolder); 511 } catch (IOException e) { 512 e.printStackTrace(); 513 } 514 } 515 } 516 } 517 } 518 519 // Extract files to XML 520 File levelFolderXML = new File(levelFolder, "xml"); 521 Vector<File> files = new Vector<File>(); 522 files.add(new File(levelFolder, "*.oni")); 523 OniSplit.convertOniToXML(levelFolderXML, files); 524 525 // Apply patches in levelFolderXML 526 for (File patch : patches.get(level)) { 527 String patternWildcard = patch.getName(); 528 patternWildcard = patternWildcard.substring(0, 529 patternWildcard.indexOf(".oni-patch")); 530 patternWildcard = patternWildcard.replace('-', '*'); 531 final Pattern patternRegex = Pattern.compile( 532 patternWildcard.replaceAll("\\*", ".\\*"), 533 Pattern.CASE_INSENSITIVE); 534 535 for (File toPatch : FileUtils.listFiles(levelFolderXML, 536 new RegexFileFilter(patternRegex), null)) { 537 // Apply patch "patch" to "toPatch" 538 XMLTools.patch(patch, toPatch); 539 } 540 } 541 542 // Create .oni files from XML 543 files.clear(); 544 files.add(new File(levelFolderXML, "*.xml")); 545 OniSplit.convertXMLtoOni(levelFolder, files); 546 547 // Remove XML folder as import will only require .oni's 548 try { 549 FileUtils.deleteDirectory(levelFolderXML); 550 } catch (IOException e) { 551 e.printStackTrace(); 552 } 553 554 oniLevelFolders.get(level).add(levelFolder); 555 } 556 557 System.out.println("Took: " + (new Date().getTime() - startMS) 558 + " msec"); 559 System.exit(0); 560 } 561 562 private static void combineBinaryFiles( 563 TreeMap<String, Vector<File>> oniLevelFolders, 420 564 InstallProgressListener listener, PrintWriter log) { 421 TreeMap<String, Vector<File>> levels = new TreeMap<String, Vector<File>>();422 423 for (File path : srcFoldersFiles) {424 for (File levelF : path.listFiles()) {425 String fn = levelF.getName().toLowerCase();426 String levelN = null;427 if (levelF.isDirectory()) {428 levelN = fn;429 } else if (fn.endsWith(".dat")) {430 levelN = fn.substring(0, fn.lastIndexOf('.'));431 }432 if (levelN != null) {433 if (!levels.containsKey(levelN))434 levels.put(levelN, new Vector<File>());435 levels.get(levelN).add(levelF);436 }437 }438 }439 440 565 int totalSteps = 0; 441 566 int stepsDone = 0; 442 567 443 568 for (@SuppressWarnings("unused") 444 String s : levels.keySet())569 String s : oniLevelFolders.keySet()) 445 570 totalSteps++; 446 571 totalSteps++; 447 572 448 573 log.println("Importing levels"); 449 for (String l : levels.keySet()) {574 for (String l : oniLevelFolders.keySet()) { 450 575 log.println("\tLevel " + l); 451 576 listener.installProgressUpdate(stepsDone, totalSteps, 452 577 "Installing level " + l); 453 for (File f : levels.get(l)) {578 for (File f : oniLevelFolders.get(l)) { 454 579 log.println("\t\t\t" + f.getPath()); 455 580 } 456 581 457 Vector<String> res = OniSplit.packLevel(levels.get(l), new File( 458 Paths.getEditionGDF(), sanitizeLevelName(l) + ".dat")); 582 Vector<String> res = OniSplit.packLevel(oniLevelFolders.get(l), 583 new File(Paths.getEditionGDF(), sanitizeLevelName(l) 584 + ".dat")); 459 585 if (res != null && res.size() > 0) { 460 586 for (String s : res) … … 502 628 FileUtils.copyInputStreamToFile(is, dat); 503 629 } catch (IOException e) { 504 // TODO Auto-generated catch block505 630 e.printStackTrace(); 506 631 } -
AE/installer2/src/net/oni2/aeinstaller/backend/oni/OniSplit.java
r672 r698 33 33 */ 34 34 public static Vector<String> export(File targetFolder, File input) { 35 return export(targetFolder, input, null); 36 } 37 38 /** 39 * Export named resources from given dat-file to target folder 40 * 41 * @param targetFolder 42 * Target folder 43 * @param input 44 * Dat file 45 * @param pattern 46 * Filename pattern for files to export 47 * @return OniSplit output 48 */ 49 public static Vector<String> export(File targetFolder, File input, 50 String pattern) { 35 51 if (!targetFolder.exists()) 36 52 targetFolder.mkdir(); 37 53 38 54 Vector<String> cmdLine = getProgramInvocation(); 39 cmdLine.add("-export"); 55 if (pattern == null) 56 cmdLine.add("-export"); 57 else 58 cmdLine.add("-export:" + pattern); 40 59 cmdLine.add(targetFolder.getPath()); 41 60 cmdLine.add(input.getPath()); … … 134 153 } 135 154 155 /** 156 * Convert given .oni-files to XML and put them in target folder 157 * 158 * @param targetFolder 159 * Target folder 160 * @param inputFiles 161 * .oni files 162 * @return OniSplit output 163 */ 164 public static Vector<String> convertOniToXML(File targetFolder, 165 Vector<File> inputFiles) { 166 if (!targetFolder.exists()) 167 targetFolder.mkdirs(); 168 169 Vector<String> cmdLine = getProgramInvocation(); 170 cmdLine.add("-extract:xml"); 171 cmdLine.add(targetFolder.getPath()); 172 for (File f : inputFiles) { 173 cmdLine.add(f.getPath()); 174 } 175 Vector<String> res = null; 176 try { 177 res = AppExecution.executeAndWait(cmdLine); 178 } catch (IOException e) { 179 e.printStackTrace(); 180 } 181 return res; 182 } 183 184 /** 185 * Convert given XML-files to .oni and put them in target folder 186 * 187 * @param targetFolder 188 * Target folder 189 * @param inputFiles 190 * XML-files 191 * @return OniSplit output 192 */ 193 public static Vector<String> convertXMLtoOni(File targetFolder, 194 Vector<File> inputFiles) { 195 if (!targetFolder.exists()) 196 targetFolder.mkdirs(); 197 198 Vector<String> cmdLine = getProgramInvocation(); 199 cmdLine.add("-create"); 200 cmdLine.add(targetFolder.getPath()); 201 for (File f : inputFiles) { 202 cmdLine.add(f.getPath()); 203 } 204 Vector<String> res = null; 205 try { 206 res = AppExecution.executeAndWait(cmdLine); 207 } catch (IOException e) { 208 e.printStackTrace(); 209 } 210 return res; 211 } 212 136 213 private static String getImportParam() { 137 214 if (Settings.getPlatform() == Platform.MACOS) -
AE/installer2/src/net/oni2/aeinstaller/backend/packages/download/ModDownloader.java
r648 r698 82 82 83 83 private int getTimeElapsed() { 84 int total = (int) (new Date().getTime() - startMS) / 1000;84 int total = (int) (new Date().getTime() - startMS); 85 85 return total; 86 86 } … … 88 88 private int getDownloadSpeed() { 89 89 int elap = getTimeElapsed(); 90 intdown = downloadedComplete + downloadedCurrent;90 long down = downloadedComplete + downloadedCurrent; 91 91 if (elap > 0) 92 return down / elap;92 return (int)(down * 1000 / elap); 93 93 else 94 94 return 1; … … 106 106 downloads.get(currentDownload).getMod(), state, unpacked, 107 107 downloads.size(), downloadedComplete + downloadedCurrent, 108 totalSize, getTimeElapsed() , getTimeRemaining(),108 totalSize, getTimeElapsed() / 1000, getTimeRemaining(), 109 109 getDownloadSpeed()); 110 110 } else { 111 111 listener.updateStatus(this, null, state, unpacked, 112 112 downloads.size(), downloadedComplete + downloadedCurrent, 113 totalSize, getTimeElapsed() , getTimeRemaining(),113 totalSize, getTimeElapsed() / 1000, getTimeRemaining(), 114 114 getDownloadSpeed()); 115 115 } -
AE/installer2/src/net/oni2/aeinstaller/gui/MainWin.java
r673 r698 244 244 size += m.getZipSize(); 245 245 JCheckBox check = new JCheckBox("Mod: " + m.getName() 246 + " (" + SizeFormatter.format( size, 1) + ")");246 + " (" + SizeFormatter.format(m.getZipSize(), 1) + ")"); 247 247 check.setSelected(true); 248 248 check.addItemListener(new ItemListener() { … … 268 268 size += m.getZipSize(); 269 269 JCheckBox check = new JCheckBox("Tool: " + m.getName() 270 + " (" + SizeFormatter.format( size, 1) + ")");270 + " (" + SizeFormatter.format(m.getZipSize(), 1) + ")"); 271 271 check.setSelected(true); 272 272 check.addItemListener(new ItemListener() {
Note:
See TracChangeset
for help on using the changeset viewer.