Changeset 600 for AE/installer2/src/net/oni2/aeinstaller/backend/oni
- Timestamp:
- Jan 10, 2013, 12:12:01 AM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller/backend/oni
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/backend/oni/Installer.java
r599 r600 3 3 import java.io.File; 4 4 import java.io.FileFilter; 5 import java.io.FileNotFoundException; 5 6 import java.io.FilenameFilter; 6 7 import java.io.IOException; 8 import java.io.PrintWriter; 9 import java.text.SimpleDateFormat; 10 import java.util.Date; 7 11 import java.util.HashMap; 8 12 import java.util.List; … … 35 39 } 36 40 37 public static void install(TreeSet<Mod> mods) { 41 public static void install(TreeSet<Mod> mods, 42 InstallProgressListener listener) { 43 38 44 Vector<File> folders = new Vector<File>(); 39 45 folders.add(Paths.getVanillaOnisPath()); … … 59 65 } 60 66 61 for (File f : Paths.getModsPath().listFiles()) {62 63 64 65 }66 combineBinaryFiles(folders );67 // for (File f : Paths.getModsPath().listFiles()) { 68 // File oni = new File(f, "oni"); 69 // if (oni.exists()) 70 // folders.add(oni); 71 // } 72 combineBinaryFiles(folders, listener); 67 73 68 74 // TODO: bsl() 69 75 } 70 76 71 private static void combineBinaryFiles(List<File> srcFolders) { 77 private static void combineBinaryFiles(List<File> srcFoldersFiles, 78 InstallProgressListener listener) { 72 79 try { 80 HashMap<String, Vector<File>> levels = new HashMap<String, Vector<File>>(); 81 82 for (File path : srcFoldersFiles) { 83 for (File levelF : path.listFiles()) { 84 String fn = levelF.getName().toLowerCase(); 85 String levelN = null; 86 if (levelF.isDirectory()) { 87 levelN = fn; 88 } else if (fn.endsWith(".dat")) { 89 levelN = fn.substring(0, fn.lastIndexOf('.')); 90 } 91 if (levelN != null) { 92 if (!levels.containsKey(levelN)) 93 levels.put(levelN, new Vector<File>()); 94 levels.get(levelN).add(levelF); 95 } 96 } 97 } 98 99 int totalSteps = 0; 100 int stepsDone = 0; 101 102 for (@SuppressWarnings("unused") 103 String s : levels.keySet()) 104 totalSteps++; 105 106 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 107 108 File logFile = new File(Paths.getInstallerPath(), 109 "Installation.log"); 110 PrintWriter log = null; 111 try { 112 log = new PrintWriter(logFile); 113 } catch (FileNotFoundException e) { 114 e.printStackTrace(); 115 } 116 117 Date start = new Date(); 118 log.println("Installation of mods started at " + sdf.format(start)); 119 120 log.println("Cleaning directories"); 121 listener.installProgressUpdate(stepsDone, totalSteps, 122 "Cleaning up directories"); 123 73 124 createEmptyPath(Paths.getEditionGDF()); 74 HashMap<String, Vector<File>> levels = new HashMap<String, Vector<File>>(); 75 76 for (File path : srcFolders) { 77 for (File levelF : path.listFiles()) { 78 if (!levels.containsKey(levelF.getName().toLowerCase())) 79 levels.put(levelF.getName().toLowerCase(), 80 new Vector<File>()); 81 levels.get(levelF.getName().toLowerCase()).add(levelF); 82 } 83 } 84 125 126 log.println("Importing levels"); 85 127 for (String l : levels.keySet()) { 86 System.out.println("Level " + l);128 log.println("\tLevel " + l); 87 129 for (File f : levels.get(l)) { 88 System.out.println(" " + f.getPath()); 89 90 } 91 92 OniSplit.importLevel(levels.get(l), 130 log.println("\t\t\t" + f.getPath()); 131 } 132 133 Vector<String> res = OniSplit.packLevel(levels.get(l), 93 134 new File(Paths.getEditionGDF(), l + ".dat")); 94 95 System.out.println(); 96 } 135 if (res != null && res.size() > 0) { 136 for (String s : res) 137 log.println("\t\t" + s); 138 } 139 140 log.println(); 141 } 142 143 Date end = new Date(); 144 log.println("Initialization ended at " + sdf.format(end)); 145 log.println("Process took " 146 + ((end.getTime() - start.getTime()) / 1000) + " seconds"); 147 log.close(); 97 148 } catch (IOException e) { 98 149 // TODO Auto-generated catch block … … 103 154 /** 104 155 * Initializes the Edition core 156 * 157 * @param listener 158 * Listener for status updates 105 159 */ 106 public static void initializeEdition( ) {160 public static void initializeEdition(InstallProgressListener listener) { 107 161 File init = new File(Paths.getTempPath(), "init"); 162 163 int totalSteps = 0; 164 int stepsDone = 0; 165 166 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 167 168 for (@SuppressWarnings("unused") 169 File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() { 170 @Override 171 public boolean accept(File dir, String name) { 172 return name.endsWith(".dat"); 173 } 174 })) { 175 totalSteps++; 176 } 177 totalSteps = totalSteps * 2 + 2; 178 108 179 try { 180 File logFile = new File(Paths.getInstallerPath(), 181 "Initialization.log"); 182 PrintWriter log = new PrintWriter(logFile); 183 184 Date start = new Date(); 185 log.println("Initialization of Edition core started at " 186 + sdf.format(start)); 187 log.println("Cleaning directories"); 188 189 listener.installProgressUpdate(stepsDone, totalSteps, 190 "Cleaning up directories"); 109 191 createEmptyPath(Paths.getVanillaOnisPath()); 110 192 createEmptyPath(init); 111 193 File level0Folder = new File(init, "level0_Final"); 112 194 createEmptyPath(level0Folder); 113 File level0FolderVanilla = new File(Paths.getVanillaOnisPath(), 114 "level0_Final");115 createEmptyPath(level0FolderVanilla); 116 createEmptyPath(new File(level0FolderVanilla, "characters"));195 196 stepsDone++; 197 198 log.println("Exporting levels and moving files to level0"); 117 199 118 200 for (File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() { … … 127 209 int levelNumber = Integer.parseInt(fi.findInLine("[0-9]+")); 128 210 211 log.println("\t" + levelName + ":"); 212 log.println("\t\tExporting"); 213 listener.installProgressUpdate(stepsDone, totalSteps, 214 "Exporting vanilla level " + levelNumber); 215 129 216 // Edition/GameDataFolder/level*_Final/ 130 217 File tempLevelFolder = new File(init, levelName); 131 218 132 219 // Export Vanilla-Level-Dat -> Temp/Level 133 OniSplit.export(tempLevelFolder, f); 134 220 Vector<String> res = OniSplit.export(tempLevelFolder, f); 221 if (res != null && res.size() > 0) { 222 for (String s : res) 223 log.println("\t\t\t" + s); 224 } 225 226 log.println("\t\tMoving files"); 135 227 handleFileGlobalisation(tempLevelFolder, level0Folder, 136 level0FolderVanilla, levelNumber); 137 } 228 levelNumber); 229 stepsDone++; 230 log.println(); 231 } 232 233 log.println("Reimporting levels"); 138 234 139 235 for (File f : init.listFiles()) { 140 236 String levelName = f.getName(); 141 237 142 // Edition/AEInstaller/vanilla/level*_Final/ 143 File vanillaFolder = new File(Paths.getVanillaOnisPath(), 144 levelName); 145 vanillaFolder.mkdirs(); 238 log.println("\t" + levelName); 239 listener.installProgressUpdate(stepsDone, totalSteps, 240 "Creating globalized " + levelName); 146 241 147 242 Vector<File> folders = new Vector<File>(); 148 243 folders.add(f); 149 244 150 OniSplit.importLevel(folders, new File(vanillaFolder, levelName 151 + ".oni")); 152 } 153 245 Vector<String> res = OniSplit.importLevel(folders, new File( 246 Paths.getVanillaOnisPath(), levelName + ".dat")); 247 if (res != null && res.size() > 0) { 248 for (String s : res) 249 log.println("\t\t" + s); 250 } 251 252 log.println(); 253 stepsDone++; 254 } 255 256 listener.installProgressUpdate(stepsDone, totalSteps, 257 "Copying basic files"); 154 258 // Copy Oni-configs 155 259 File persistVanilla = new File(Paths.getOniBasePath(), … … 167 271 168 272 // TODO: FileUtils.deleteDirectory(init); 273 Date end = new Date(); 274 log.println("Initialization ended at " + sdf.format(end)); 275 log.println("Process took " 276 + ((end.getTime() - start.getTime()) / 1000) + " seconds"); 277 log.close(); 169 278 } catch (IOException e) { 170 279 e.printStackTrace(); … … 185 294 186 295 private static void handleFileGlobalisation(File tempFolder, 187 File level0Folder, File level0FolderVanilla,int levelNumber) {296 File level0Folder, int levelNumber) { 188 297 // Move AKEV and related files to subfolder so they're not globalized: 189 298 if (levelNumber != 0) { -
AE/installer2/src/net/oni2/aeinstaller/backend/oni/OniSplit.java
r598 r600 8 8 9 9 import net.oni2.aeinstaller.backend.Paths; 10 import net.oni2.aeinstaller.backend.QuickAppExecution; 10 11 import net.oni2.aeinstaller.backend.Settings; 11 12 import net.oni2.aeinstaller.backend.Settings.Architecture; 12 13 import net.oni2.aeinstaller.backend.Settings.Platform; 13 14 import net.oni2.aeinstaller.backend.WinRegistry; 14 import net.oni2.aeinstaller.backend.app_launcher.QuickAppExecution;15 15 16 16 /** … … 83 83 * @param input 84 84 * Dat file 85 */ 86 public static void export(File targetFolder, File input) { 85 * @return OniSplit output 86 */ 87 public static Vector<String> export(File targetFolder, File input) { 87 88 if (!targetFolder.exists()) 88 89 targetFolder.mkdir(); … … 92 93 cmdLine.add(targetFolder.getPath()); 93 94 cmdLine.add(input.getPath()); 94 // System.out.println(cmdLine.toString()); 95 Vector<String> res = null; 96 try { 97 res = QuickAppExecution.execute(cmdLine); 98 } catch (IOException e) { 99 // TODO Auto-generated catch block 100 e.printStackTrace(); 101 } 102 if (res != null) { 103 // check for errors 104 System.out.println(res.toString()); 105 } 95 Vector<String> res = null; 96 try { 97 res = QuickAppExecution.execute(cmdLine); 98 } catch (IOException e) { 99 // TODO Auto-generated catch block 100 e.printStackTrace(); 101 } 102 return res; 106 103 } 107 104 … … 113 110 * @param targetFile 114 111 * Target .dat-file 115 */ 116 public static void importLevel(Vector<File> sourceFolders, File targetFile) { 112 * @return OniSplit output 113 */ 114 public static Vector<String> importLevel(Vector<File> sourceFolders, File targetFile) { 117 115 Vector<String> cmdLine = getProgramInvocation(); 118 116 cmdLine.add(getImportParam()); … … 120 118 cmdLine.add(f.getPath()); 121 119 cmdLine.add(targetFile.getPath()); 122 // System.out.println(cmdLine.toString()); 123 Vector<String> res = null; 124 try { 125 res = QuickAppExecution.execute(cmdLine); 126 } catch (IOException e) { 127 // TODO Auto-generated catch block 128 e.printStackTrace(); 129 } 130 if (res != null) { 131 // check for errors 132 System.out.println(res.toString()); 133 } 120 Vector<String> res = null; 121 try { 122 res = QuickAppExecution.execute(cmdLine); 123 } catch (IOException e) { 124 // TODO Auto-generated catch block 125 e.printStackTrace(); 126 } 127 return res; 128 } 129 130 /** 131 * Pack a level to a .dat-file. More powerful variant which allows 132 * specifying single .oni/.dat files 133 * 134 * @param sourceFoldersFiles 135 * Folders (for recursive .oni import) or files (.dat and single 136 * .oni) to import 137 * @param targetFile 138 * Target .dat-file 139 * @return OniSplit output 140 */ 141 public static Vector<String> packLevel(Vector<File> sourceFoldersFiles, 142 File targetFile) { 143 Vector<String> cmdLine = getProgramInvocation(); 144 cmdLine.add(getPackParam()); 145 cmdLine.add(getPackTypeParam()); 146 cmdLine.add("-out"); 147 cmdLine.add(targetFile.getPath()); 148 for (File f : sourceFoldersFiles) 149 cmdLine.add(f.getPath()); 150 Vector<String> res = null; 151 try { 152 res = QuickAppExecution.execute(cmdLine); 153 } catch (IOException e) { 154 // TODO Auto-generated catch block 155 e.printStackTrace(); 156 } 157 return res; 134 158 } 135 159 … … 144 168 * @param moveParameter 145 169 * e.g. overwrite, delete 146 */ 147 public static void move(File targetFolder, String input, 170 * @return OniSplit output 171 */ 172 public static Vector<String> move(File targetFolder, String input, 148 173 String moveParameter) { 149 174 if (!targetFolder.exists()) … … 162 187 e.printStackTrace(); 163 188 } 164 if (res != null && res.size() > 0) { 165 // TODO: errors 166 System.out.println(res.toString()); 167 } 189 return res; 168 190 } 169 191 … … 175 197 } 176 198 199 private static String getPackParam() { 200 return "pack"; 201 } 202 203 private static String getPackTypeParam() { 204 if (Settings.getPlatform() == Platform.MACOS) 205 return "-type:macintel"; 206 else 207 return "-type:pc"; 208 } 209 177 210 private static Vector<String> getProgramInvocation() { 178 211 Vector<String> res = new Vector<String>(); 179 212 if (Settings.getPlatform() != Platform.WIN) 180 213 res.add("mono"); 181 res.add(new File(Paths.getInstallerPath(), "Onisplit.exe").getPath()); 214 res.add(new File(new File(Paths.getEditionBasePath(), "Tools"), 215 "Onisplit.exe").getPath()); 182 216 return res; 183 217 }
Note:
See TracChangeset
for help on using the changeset viewer.