Changeset 749 for java/installer2/src/net/oni2/aeinstaller/backend/oni
- Timestamp:
- Mar 26, 2013, 6:26:41 PM (12 years ago)
- Location:
- java/installer2/src/net/oni2/aeinstaller/backend/oni/management
- Files:
-
- 4 added
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
java/installer2/src/net/oni2/aeinstaller/backend/oni/management/InstallProgressListener.java
r722 r749 1 package net.oni2.aeinstaller.backend.oni ;1 package net.oni2.aeinstaller.backend.oni.management; 2 2 3 3 /** -
java/installer2/src/net/oni2/aeinstaller/backend/oni/management/Installer.java
r744 r749 1 package net.oni2.aeinstaller.backend.oni ;1 package net.oni2.aeinstaller.backend.oni.management; 2 2 3 3 import java.io.File; 4 4 import java.io.FileFilter; 5 import java.io.FileInputStream;6 5 import java.io.FileNotFoundException; 7 import java.io.FileOutputStream;8 6 import java.io.FilenameFilter; 9 7 import java.io.IOException; … … 15 13 import java.util.HashSet; 16 14 import java.util.List; 17 import java.util.Scanner;18 15 import java.util.TreeMap; 19 16 import java.util.TreeSet; … … 25 22 import net.oni2.aeinstaller.backend.CaseInsensitiveFile; 26 23 import net.oni2.aeinstaller.backend.Paths; 24 import net.oni2.aeinstaller.backend.oni.OniSplit; 25 import net.oni2.aeinstaller.backend.oni.PersistDat; 26 import net.oni2.aeinstaller.backend.oni.XMLTools; 27 27 import net.oni2.aeinstaller.backend.packages.EBSLInstallType; 28 28 import net.oni2.aeinstaller.backend.packages.Package; … … 38 38 39 39 import com.paour.NaturalOrderComparator; 40 import com.thoughtworks.xstream.XStream;41 import com.thoughtworks.xstream.io.xml.StaxDriver;42 40 43 41 /** … … 53 51 54 52 /** 53 * Verify that the Edition is within a subfolder to vanilla Oni 54 * (..../Oni/Edition/AEInstaller) 55 * 56 * @return true if GDF can be found in the parent's parent-path 57 */ 58 public static boolean verifyRunningDirectory() { 59 return Paths.getVanillaGDF().exists() 60 && Paths.getVanillaGDF().isDirectory(); 61 } 62 63 /** 55 64 * @return Is Edition Core initialized 56 65 */ 57 66 public static boolean isEditionInitialized() { 58 67 return Paths.getVanillaOnisPath().exists(); 59 }60 61 private static void createEmptyPath(File path) throws IOException {62 if (path.exists())63 FileUtils.deleteDirectory(path);64 path.mkdirs();65 68 } 66 69 … … 71 74 File installCfg = new File(Paths.getEditionGDF(), "installed_mods.xml"); 72 75 return PackageManager.getInstance().loadModSelection(installCfg); 73 }74 75 /**76 * @return Currently installed tools77 */78 @SuppressWarnings("unchecked")79 public static TreeSet<Integer> getInstalledTools() {80 File installCfg = new File(Paths.getInstallerPath(),81 "installed_tools.xml");82 TreeSet<Integer> res = new TreeSet<Integer>();83 try {84 if (installCfg.exists()) {85 FileInputStream fis = new FileInputStream(installCfg);86 XStream xs = new XStream(new StaxDriver());87 Object obj = xs.fromXML(fis);88 if (obj instanceof TreeSet<?>)89 res = (TreeSet<Integer>) obj;90 fis.close();91 }92 } catch (FileNotFoundException e) {93 e.printStackTrace();94 } catch (IOException e) {95 e.printStackTrace();96 }97 return res;98 }99 100 private static void writeInstalledTools(TreeSet<Integer> tools) {101 File installCfg = new File(Paths.getInstallerPath(),102 "installed_tools.xml");103 try {104 FileOutputStream fos = new FileOutputStream(installCfg);105 XStream xs = new XStream(new StaxDriver());106 xs.toXML(tools, fos);107 fos.close();108 } catch (FileNotFoundException e) {109 e.printStackTrace();110 } catch (IOException e) {111 e.printStackTrace();112 }113 }114 115 /**116 * @param tools117 * Tools to (un)install118 * @param uninstall119 * Uninstall tools or install?120 */121 public static void installTools(TreeSet<Package> tools, boolean uninstall) {122 TreeSet<Integer> installed = getInstalledTools();123 for (Package m : tools) {124 if (!uninstall || installed.contains(m.getPackageNumber())) {125 File plain = CaseInsensitiveFile.getCaseInsensitiveFile(126 m.getLocalPath(), "plain");127 if (plain.exists()) {128 if (m.hasSeparatePlatformDirs()) {129 File plainCommon = CaseInsensitiveFile130 .getCaseInsensitiveFile(plain, "common");131 File plainMac = CaseInsensitiveFile132 .getCaseInsensitiveFile(plain, "mac_only");133 File plainWin = CaseInsensitiveFile134 .getCaseInsensitiveFile(plain, "win_only");135 if (plainCommon.exists())136 copyRemoveToolsFiles(plainCommon,137 Paths.getEditionBasePath(), uninstall);138 if (PlatformInformation.getPlatform() == Platform.MACOS139 && plainMac.exists())140 copyRemoveToolsFiles(plainMac,141 Paths.getEditionBasePath(), uninstall);142 else if (plainWin.exists())143 copyRemoveToolsFiles(plainWin,144 Paths.getEditionBasePath(), uninstall);145 } else {146 copyRemoveToolsFiles(plain, Paths.getEditionBasePath(),147 uninstall);148 }149 }150 }151 if (uninstall)152 installed.remove(m.getPackageNumber());153 else154 installed.add(m.getPackageNumber());155 }156 writeInstalledTools(installed);157 }158 159 private static void copyRemoveToolsFiles(File srcFolder, File targetFolder,160 boolean remove) {161 for (File f : srcFolder.listFiles()) {162 try {163 if (f.isDirectory())164 copyRemoveToolsFiles(f,165 CaseInsensitiveFile.getCaseInsensitiveFile(166 targetFolder, f.getName()), remove);167 else {168 File targetFile = CaseInsensitiveFile169 .getCaseInsensitiveFile(targetFolder, f.getName());170 if (remove) {171 if (targetFile.exists())172 targetFile.delete();173 } else {174 if (!targetFile.getName().equals(f.getName()))175 targetFile.delete();176 FileUtils.copyFileToDirectory(f, targetFolder);177 }178 }179 } catch (IOException e) {180 e.printStackTrace();181 }182 }183 if (remove)184 if (targetFolder.list().length == 0)185 targetFolder.delete();186 76 } 187 77 … … 197 87 InstallProgressListener listener) { 198 88 File logFile = new File(Paths.getInstallerPath(), "Installation.log"); 199 PrintWriter log = null;89 Logger log = null; 200 90 try { 201 log = new PrintWriter(logFile);91 log = new Logger(logFile); 202 92 } catch (FileNotFoundException e) { 203 93 e.printStackTrace(); … … 353 243 354 244 private static void combineBSLFolders(TreeSet<Package> mods, 355 InstallProgressListener listener, PrintWriter log) {245 InstallProgressListener listener, Logger log) { 356 246 listener.installProgressUpdate(95, 100, "Installing BSL files"); 247 log.println(); 357 248 log.println("Installing BSL files"); 358 249 … … 386 277 387 278 for (Package m : modsToInclude.get(EBSLInstallType.NORMAL)) { 388 copyBSL(m, false );279 copyBSL(m, false, log); 389 280 } 390 281 Vector<Package> addons = modsToInclude.get(EBSLInstallType.ADDON); 391 282 for (int i = addons.size() - 1; i >= 0; i--) { 392 copyBSL(addons.get(i), true );393 } 394 } 395 396 private static void copyBSL(Package sourceMod, boolean addon ) {283 copyBSL(addons.get(i), true, log); 284 } 285 } 286 287 private static void copyBSL(Package sourceMod, boolean addon, Logger log) { 397 288 File targetBaseFolder = new File(Paths.getEditionGDF(), "IGMD"); 398 289 if (!targetBaseFolder.exists()) … … 440 331 } 441 332 442 System.out.println("For mod: " + sourceMod.getName() 443 + " install BSL folders: " + sources.toString()); 333 log.println("\tMod \"" + sourceMod.getName() + "\""); 444 334 for (File f : sources) { 335 log.println("\t\t" + f.getName()); 445 336 File targetPath = new File(targetBaseFolder, f.getName()); 446 337 if (!targetPath.exists()) … … 467 358 TreeMap<String, Vector<File>> oniLevelFolders, 468 359 List<File> patchFolders, InstallProgressListener listener, 469 PrintWriter log) {360 Logger log) { 470 361 log.println(); 471 362 log.println("Applying XML patches"); … … 515 406 ApplicationInvocationResult res = OniSplit.export( 516 407 levelFolder, srcFolder, exportPatterns); 517 log AppOutput(res, log);408 log.logAppOutput(res, true); 518 409 } 519 410 } … … 540 431 ApplicationInvocationResult res = OniSplit.export( 541 432 levelFolder, srcFolder, patterns); 542 log AppOutput(res, log);433 log.logAppOutput(res, true); 543 434 } 544 435 } else { … … 563 454 ApplicationInvocationResult res = OniSplit.convertOniToXML( 564 455 levelFolderXML, files); 565 log AppOutput(res, log);456 log.logAppOutput(res, true); 566 457 567 458 // Create masterpatch file (containing calls to all individual … … 581 472 patternWildcard = patternWildcard.replace('-', '*'); 582 473 File xmlFilePath = new File(levelFolderXML, patternWildcard); 583 masterpatchWriter.println(String.format("@COMMAND patchfile -filename:\"%s\" -forceinfiles:\"%s\"", patch.getPath(), xmlFilePath.getPath())); 474 masterpatchWriter 475 .println(String 476 .format("@COMMAND patchfile -filename:\"%s\" -forceinfiles:\"%s\"", 477 patch.getPath(), xmlFilePath.getPath())); 584 478 } 585 479 masterpatchWriter.close(); 586 480 // Apply patches through masterpatch in levelFolderXML 587 481 res = XMLTools.patch(masterpatch, null); 588 log AppOutput(res, log);482 log.logAppOutput(res, false); 589 483 590 484 // Create .oni files from XML … … 592 486 files.add(new File(levelFolderXML, "*.xml")); 593 487 res = OniSplit.convertXMLtoOni(levelFolder, files); 594 log AppOutput(res, log);488 log.logAppOutput(res, true); 595 489 596 490 // Remove XML folder as import will only require .oni's … … 610 504 private static void combineBinaryFiles( 611 505 TreeMap<String, Vector<File>> oniLevelFolders, 612 InstallProgressListener listener, PrintWriter log) {506 InstallProgressListener listener, Logger log) { 613 507 long startMS = new Date().getTime(); 614 508 … … 626 520 oniLevelFolders.get(l), new File(Paths.getEditionGDF(), 627 521 sanitizeLevelName(l) + ".dat")); 628 log AppOutput(res, log);522 log.logAppOutput(res, true); 629 523 630 524 stepsDone++; … … 636 530 } 637 531 638 private static void copyVideos(PrintWriter log) { 532 private static void copyVideos(Logger log) { 533 log.println(); 639 534 if (SettingsManager.getInstance().get("copyintro", false)) { 640 535 File src = new File(Paths.getVanillaGDF(), "intro.bik"); … … 665 560 } 666 561 667 private static void unlockLevels(TreeSet<Integer> unlockLevels, 668 PrintWriter log) { 562 private static void unlockLevels(TreeSet<Integer> unlockLevels, Logger log) { 669 563 File dat = new File(Paths.getEditionBasePath(), "persist.dat"); 564 log.println(); 670 565 log.println("Unlocking levels: " + unlockLevels.toString()); 671 566 if (!dat.exists()) { … … 685 580 } 686 581 687 /**688 * Initializes the Edition core689 *690 * @param listener691 * Listener for status updates692 */693 public static void initializeEdition(InstallProgressListener listener) {694 File init = new File(Paths.getTempPath(), "init");695 696 int totalSteps = 0;697 int stepsDone = 0;698 699 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");700 701 TreeSet<File> levelFiles = new TreeSet<File>(702 new NaturalOrderComparator());703 704 for (File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() {705 @Override706 public boolean accept(File dir, String name) {707 return name.endsWith(".dat");708 }709 })) {710 totalSteps++;711 levelFiles.add(f);712 }713 totalSteps = totalSteps * 2 + 2;714 715 try {716 File logFile = new File(Paths.getInstallerPath(),717 "Initialization.log");718 PrintWriter log = new PrintWriter(logFile);719 720 Date start = new Date();721 log.println("Initialization of Edition core started at "722 + sdf.format(start));723 log.println("Cleaning directories");724 725 listener.installProgressUpdate(stepsDone, totalSteps,726 "Cleaning up directories");727 createEmptyPath(Paths.getVanillaOnisPath());728 createEmptyPath(init);729 File level0Folder = new File(init, "level0_Final");730 createEmptyPath(level0Folder);731 732 stepsDone++;733 734 log.println("Exporting levels and moving files to level0");735 736 for (File f : levelFiles) {737 String levelName = f.getName().substring(0,738 f.getName().indexOf('.'));739 Scanner fi = new Scanner(levelName);740 int levelNumber = Integer.parseInt(fi.findInLine("[0-9]+"));741 742 log.println("\t" + levelName + ":");743 log.println("\t\tExporting");744 listener.installProgressUpdate(stepsDone, totalSteps,745 "Exporting vanilla level " + levelNumber);746 747 // Edition/GameDataFolder/level*_Final/748 File tempLevelFolder = new File(init, levelName);749 750 // Export Vanilla-Level-Dat -> Temp/Level751 ApplicationInvocationResult res = OniSplit.export(752 tempLevelFolder, f);753 logAppOutput(res, log);754 755 log.println("\t\tMoving files");756 handleFileGlobalisation(tempLevelFolder, level0Folder,757 levelNumber);758 stepsDone++;759 log.println();760 }761 762 log.println("Reimporting levels");763 TreeSet<File> initFolders = new TreeSet<File>(764 new NaturalOrderComparator());765 for (File f : init.listFiles()) {766 initFolders.add(f);767 }768 769 for (File f : initFolders) {770 String levelName = f.getName();771 772 log.println("\t" + levelName);773 listener.installProgressUpdate(stepsDone, totalSteps,774 "Creating globalized " + levelName);775 776 Vector<File> folders = new Vector<File>();777 folders.add(f);778 779 ApplicationInvocationResult res = OniSplit780 .importLevel(folders,781 new File(Paths.getVanillaOnisPath(), levelName782 + ".dat"));783 logAppOutput(res, log);784 785 log.println();786 stepsDone++;787 }788 789 listener.installProgressUpdate(stepsDone, totalSteps,790 "Copying basic files");791 // Copy Oni-configs792 File persistVanilla = new File(Paths.getOniBasePath(),793 "persist.dat");794 File persistEdition = new File(Paths.getEditionBasePath(),795 "persist.dat");796 File keyConfVanilla = new File(Paths.getOniBasePath(),797 "key_config.txt");798 File keyConfEdition = new File(Paths.getEditionBasePath(),799 "key_config.txt");800 if (persistVanilla.exists() && !persistEdition.exists())801 FileUtils.copyFile(persistVanilla, persistEdition);802 if (keyConfVanilla.exists() && !keyConfEdition.exists())803 FileUtils.copyFile(keyConfVanilla, keyConfEdition);804 805 FileUtils.deleteDirectory(init);806 807 Date end = new Date();808 log.println("Initialization ended at " + sdf.format(end));809 log.println("Process took "810 + ((end.getTime() - start.getTime()) / 1000) + " seconds");811 log.close();812 } catch (IOException e) {813 e.printStackTrace();814 }815 }816 817 private static void moveFileToTargetOrDelete(File source, File target) {818 if (source.equals(target))819 return;820 if (!target.exists()) {821 if (!source.renameTo(target)) {822 System.err.println("File " + source.getPath() + " not moved!");823 }824 } else if (!source.delete()) {825 System.err.println("File " + source.getPath() + " not deleted!");826 }827 }828 829 private static void handleFileGlobalisation(File tempFolder,830 File level0Folder, int levelNumber) {831 // Move AKEV and related files to subfolder so they're not globalized:832 if (levelNumber != 0) {833 File akevFolder = new File(tempFolder, "AKEV");834 akevFolder.mkdir();835 OniSplit.move(akevFolder, tempFolder.getPath() + "/AKEV*.oni",836 "overwrite");837 }838 839 for (File f : tempFolder.listFiles(new FileFilter() {840 @Override841 public boolean accept(File pathname) {842 return pathname.isFile();843 }844 })) {845 // Move matching files to subfolder NoGlobal:846 if (f.getName().startsWith("TXMPfail")847 || f.getName().startsWith("TXMPlevel")848 || (f.getName().startsWith("TXMP") && f.getName().contains(849 "intro"))850 || f.getName().startsWith("TXMB")851 || f.getName().equals("M3GMpowerup_lsi.oni")852 || f.getName().equals("TXMPlsi_icon.oni")853 || (f.getName().startsWith("TXMB") && f.getName().contains(854 "splash_screen.oni"))) {855 File noGlobal = new File(tempFolder, "NoGlobal");856 noGlobal.mkdir();857 File noGlobalFile = new File(noGlobal, f.getName());858 moveFileToTargetOrDelete(f, noGlobalFile);859 }860 // Move matching files to level0_Animations/level0_TRAC861 else if (f.getName().startsWith("TRAC")) {862 File level0File = new File(level0Folder, f.getName());863 moveFileToTargetOrDelete(f, level0File);864 }865 // Move matching files to level0_Animations/level0_TRAM866 else if (f.getName().startsWith("TRAM")) {867 File level0File = new File(level0Folder, f.getName());868 moveFileToTargetOrDelete(f, level0File);869 }870 // Move matching files to level0_Textures871 else if (f.getName().startsWith("ONSK")872 || f.getName().startsWith("TXMP")) {873 File level0File = new File(level0Folder, f.getName());874 moveFileToTargetOrDelete(f, level0File);875 }876 // Move matching files to *VANILLA*/level0_Characters877 else if (f.getName().startsWith("ONCC")878 || f.getName().startsWith("TRBS")879 || f.getName().startsWith("ONCV")880 || f.getName().startsWith("ONVL")881 || f.getName().startsWith("TRMA")882 || f.getName().startsWith("TRSC")883 || f.getName().startsWith("TRAS")) {884 File level0File = new File(level0Folder, f.getName());885 moveFileToTargetOrDelete(f, level0File);886 }887 // Move matching files to level0_Sounds888 else if (f.getName().startsWith("OSBD")889 || f.getName().startsWith("SNDD")) {890 File level0File = new File(level0Folder, f.getName());891 moveFileToTargetOrDelete(f, level0File);892 }893 // Move matching files to level0_Particles894 else if (f.getName().startsWith("BINA3")895 || f.getName().startsWith("M3GMdebris")896 || f.getName().equals("M3GMtoxic_bubble.oni")897 || f.getName().startsWith("M3GMelec")898 || f.getName().startsWith("M3GMrat")899 || f.getName().startsWith("M3GMjet")900 || f.getName().startsWith("M3GMbomb_")901 || f.getName().equals("M3GMbarab_swave.oni")902 || f.getName().equals("M3GMbloodyfoot.oni")) {903 File level0File = new File(level0Folder, f.getName());904 moveFileToTargetOrDelete(f, level0File);905 }906 // Move matching files to Archive (aka delete them)907 else if (f.getName().startsWith("AGDB")908 || f.getName().startsWith("TRCM")) {909 f.delete();910 }911 // Move matching files to /level0_Final/912 else if (f.getName().startsWith("ONWC")) {913 File level0File = new File(level0Folder, f.getName());914 moveFileToTargetOrDelete(f, level0File);915 }916 }917 }918 919 582 private static String sanitizeLevelName(String ln) { 920 583 int ind = ln.indexOf("_"); … … 925 588 } 926 589 927 /**928 * Verify that the Edition is within a subfolder to vanilla Oni929 * (..../Oni/Edition/AEInstaller)930 *931 * @return true if GDF can be found in the parent's parent-path932 */933 public static boolean verifyRunningDirectory() {934 return Paths.getVanillaGDF().exists()935 && Paths.getVanillaGDF().isDirectory();936 }937 938 private static void logAppOutput(ApplicationInvocationResult result,939 PrintWriter log) {940 if (result != null) {941 log.println("\t\t\tCalled:");942 for (String s : result.cmdLine)943 log.println("\t\t\t\t" + s);944 log.println("\t\t\tReturned: " + result.errorCode);945 for (String s : result.output)946 log.println("\t\t\t\t" + s);947 log.println("\t\t\tDuration: " + result.time + " ms");948 log.println();949 }950 }951 590 }
Note:
See TracChangeset
for help on using the changeset viewer.