Changeset 597 for AE/installer2
- Timestamp:
- Jan 3, 2013, 2:02:59 AM (12 years ago)
- Location:
- AE/installer2/src/net/oni2/aeinstaller/backend/oni
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
AE/installer2/src/net/oni2/aeinstaller/backend/oni/Installer.java
r596 r597 2 2 3 3 import java.io.File; 4 import java.io.FileFilter; 4 5 import java.io.FilenameFilter; 5 6 import java.io.IOException; … … 7 8 8 9 import net.oni2.aeinstaller.backend.Paths; 10 import net.oni2.aeinstaller.backend.Settings; 11 import net.oni2.aeinstaller.backend.Settings.Platform; 9 12 10 13 import org.apache.commons.io.FileUtils; … … 18 21 */ 19 22 public static boolean isEditionInitialized() { 20 File editionGDF = Paths.getEditionGDF(); 21 File vanillaDats = Paths.getVanillaGDF(); 22 return editionGDF.exists() && vanillaDats.exists(); 23 return Paths.getVanillaOnisPath().exists(); 23 24 } 24 25 … … 38 39 createEmptyPath(Paths.getVanillaOnisPath()); 39 40 createEmptyPath(init); 41 File level0Folder = new File(init, "level0_Final"); 42 createEmptyPath(level0Folder); 43 File level0FolderVanilla = new File(Paths.getVanillaOnisPath(), 44 "level0_Final"); 45 createEmptyPath(level0FolderVanilla); 46 createEmptyPath(new File(level0FolderVanilla, "characters")); 40 47 41 48 for (File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() { … … 47 54 String levelName = f.getName().substring(0, 48 55 f.getName().indexOf('.')); 49 int levelNumber = -1;50 51 56 Scanner fi = new Scanner(levelName); 52 fi.useDelimiter("[^\\p{Alnum}]"); 53 while (fi.hasNextInt()) { 54 levelNumber = fi.nextInt(); 55 } 56 57 OniSplit.export(new File(init, levelName), f); 58 } 59 60 // TODO: FileUtils.deleteDirectory(Paths.getEditionGDF()); 57 int levelNumber = Integer.parseInt(fi.findInLine("[0-9]+")); 58 59 // Edition/GameDataFolder/level*_Final/ 60 File tempLevelFolder = new File(init, levelName); 61 62 // Export Vanilla-Level-Dat -> Temp/Level 63 OniSplit.export(tempLevelFolder, f); 64 65 handleFileGlobalisation(tempLevelFolder, level0Folder, 66 level0FolderVanilla, levelNumber); 67 } 68 69 for (File f : init.listFiles()) { 70 String levelName = f.getName(); 71 72 // Edition/AEInstaller/vanilla/level*_Final/ 73 File vanillaFolder = new File(Paths.getVanillaOnisPath(), 74 levelName); 75 vanillaFolder.mkdirs(); 76 77 OniSplit.importLevel(f, new File(vanillaFolder, levelName 78 + ".oni")); 79 } 80 81 // Copy Oni-configs 82 File persistVanilla = new File(Paths.getOniBasePath(), 83 "persist.dat"); 84 File persistEdition = new File(Paths.getEditionBasePath(), 85 "persist.dat"); 86 File keyConfVanilla = new File(Paths.getOniBasePath(), 87 "key_config.txt"); 88 File keyConfEdition = new File(Paths.getEditionBasePath(), 89 "key_config.txt"); 90 if (persistVanilla.exists() && !persistEdition.exists()) 91 FileUtils.copyFile(persistVanilla, persistEdition); 92 if (keyConfVanilla.exists() && !keyConfEdition.exists()) 93 FileUtils.copyFile(keyConfVanilla, keyConfEdition); 94 95 if (Settings.getPlatform() == Platform.MACOS) { 96 // TODO 97 // /* On Mac only, set the current GDF to the AE GDF by writing 98 // to Oni's global preferences file (thankfully a standard OS X 99 // ".plist" XML file). 100 // Tests for presence of prefs with [ -f ] before doing anything 101 // so it doesn't create a partial prefs file -- just in case 102 // user has never 103 // run Oni before :-p */ 104 // string fullAEpath = 105 // escapePath(system_complete(".").parent_path().parent_path().string()); 106 // // get full path for Edition/ (Oni wants folder that 107 // *contains* the GDF) 108 // string prefsCommand = 109 // "[ -f ~/Library/Preferences/com.godgames.oni.plist ] && defaults write com.godgames.oni RetailInstallationPath -string '" 110 // + fullAEpath + "'"; 111 // system(prefsCommand.c_str()); 112 } 113 // TODO: FileUtils.deleteDirectory(init); 61 114 } catch (IOException e) { 62 115 e.printStackTrace(); 63 116 } 64 117 } 118 119 private static void moveFileToTargetOrDelete(File source, File target) { 120 if (source.equals(target)) 121 return; 122 if (!target.exists()) { 123 if (!source.renameTo(target)) { 124 System.err.println("File " + source.getPath() + " not moved!"); 125 } 126 } else if (!source.delete()) { 127 System.err.println("File " + source.getPath() + " not deleted!"); 128 } 129 } 130 131 private static void handleFileGlobalisation(File tempFolder, 132 File level0Folder, File level0FolderVanilla, int levelNumber) { 133 // Move AKEV and related files to subfolder so they're not globalized: 134 if (levelNumber != 0) { 135 File akevFolder = new File(tempFolder, "AKEV"); 136 akevFolder.mkdir(); 137 OniSplit.move(akevFolder, tempFolder.getPath() + "/AKEV*.oni", 138 "overwrite"); 139 } 140 141 for (File f : tempFolder.listFiles(new FileFilter() { 142 @Override 143 public boolean accept(File pathname) { 144 return pathname.isFile(); 145 } 146 })) { 147 // Move matching files to subfolder NoGlobal: 148 if (f.getName().startsWith("TXMPfail") 149 || f.getName().startsWith("TXMPlevel") 150 || (f.getName().startsWith("TXMP") && f.getName().contains( 151 "intro")) 152 || f.getName().startsWith("TXMB") 153 || f.getName().equals("M3GMpowerup_lsi.oni") 154 || f.getName().equals("TXMPlsi_icon.oni") 155 || (f.getName().startsWith("TXMB") && f.getName().contains( 156 "splash_screen.oni"))) { 157 File noGlobal = new File(tempFolder, "NoGlobal"); 158 noGlobal.mkdir(); 159 File noGlobalFile = new File(noGlobal, f.getName()); 160 moveFileToTargetOrDelete(f, noGlobalFile); 161 } 162 // Move matching files to level0_Animations/level0_TRAC 163 else if (f.getName().startsWith("TRAC")) { 164 File level0File = new File(level0Folder, f.getName()); 165 moveFileToTargetOrDelete(f, level0File); 166 } 167 // Move matching files to level0_Animations/level0_TRAM 168 else if (f.getName().startsWith("TRAM")) { 169 File level0File = new File(level0Folder, f.getName()); 170 moveFileToTargetOrDelete(f, level0File); 171 } 172 // Move matching files to level0_Textures 173 else if (f.getName().startsWith("ONSK") 174 || f.getName().startsWith("TXMP")) { 175 // TODO ? new File(tempFolder, "TexFix").mkdir(); 176 File level0File = new File(level0Folder, f.getName()); 177 // TODO: delete non-moved? 178 if (!level0File.exists()) { 179 if (!f.renameTo(level0File)) { 180 System.err.println("File " + f.getName() 181 + " not moved!"); 182 } 183 } 184 } 185 // Move matching files to *VANILLA*/level0_Characters 186 else if (f.getName().startsWith("ONCC") 187 || f.getName().startsWith("TRBS") 188 || f.getName().startsWith("ONCV") 189 || f.getName().startsWith("ONVL") 190 || f.getName().startsWith("TRMA") 191 || f.getName().startsWith("TRSC") 192 || f.getName().startsWith("TRAS")) { 193 File level0FolderCharactersVanilla = new File( 194 level0FolderVanilla, "characters"); 195 File level0FileVanilla = new File( 196 level0FolderCharactersVanilla, f.getName()); 197 moveFileToTargetOrDelete(f, level0FileVanilla); 198 } 199 // Move matching files to level0_Sounds 200 else if (f.getName().startsWith("OSBD") 201 || f.getName().startsWith("SNDD")) { 202 File level0File = new File(level0Folder, f.getName()); 203 moveFileToTargetOrDelete(f, level0File); 204 } 205 // Move matching files to level0_Particles 206 else if (f.getName().startsWith("BINA3") 207 || f.getName().startsWith("M3GMdebris") 208 || f.getName().equals("M3GMtoxic_bubble.oni") 209 || f.getName().startsWith("M3GMelec") 210 || f.getName().startsWith("M3GMrat") 211 || f.getName().startsWith("M3GMjet") 212 || f.getName().startsWith("M3GMbomb_") 213 || f.getName().equals("M3GMbarab_swave.oni") 214 || f.getName().equals("M3GMbloodyfoot.oni")) { 215 File level0File = new File(level0Folder, f.getName()); 216 moveFileToTargetOrDelete(f, level0File); 217 } 218 // Move matching files to Archive (aka delete them) 219 else if (f.getName().startsWith("AGDB") 220 || f.getName().startsWith("TRCM")) { 221 f.delete(); 222 } 223 // TODO: needed? ONWC to GDF instead? 224 // Move matching files to *VANILLADATS*/level0_Final/level0_Final/ 225 // fix for buggy ONWC overriding 226 else if (f.getName().startsWith("ONWC")) { 227 File level0FileVanilla = new File(level0FolderVanilla, 228 f.getName()); 229 moveFileToTargetOrDelete(f, level0FileVanilla); 230 } 231 } 232 } 65 233 } -
AE/installer2/src/net/oni2/aeinstaller/backend/oni/OniSplit.java
r596 r597 92 92 cmdLine.add(targetFolder.getPath()); 93 93 cmdLine.add(input.getPath()); 94 System.out.println(cmdLine.toString());94 // System.out.println(cmdLine.toString()); 95 95 Vector<String> res = null; 96 96 try { … … 101 101 } 102 102 if (res != null) { 103 // check for errors 103 104 System.out.println(res.toString()); 104 105 } 105 106 } 106 107 107 public static void importLevel() { 108 getImportParam(); 108 /** 109 * Import given folder to a .dat-file 110 * @param sourceFolder Folder containing .oni-files 111 * @param targetFile Target .dat-file 112 */ 113 public static void importLevel(File sourceFolder, File targetFile) { 114 Vector<String> cmdLine = getProgramInvocation(); 115 cmdLine.add(getImportParam()); 116 cmdLine.add(sourceFolder.getPath()); 117 cmdLine.add(targetFile.getPath()); 118 // System.out.println(cmdLine.toString()); 119 Vector<String> res = null; 120 try { 121 res = QuickAppExecution.execute(cmdLine); 122 } catch (IOException e) { 123 // TODO Auto-generated catch block 124 e.printStackTrace(); 125 } 126 if (res != null) { 127 // check for errors 128 System.out.println(res.toString()); 129 } 130 } 131 132 /** 133 * Move files from one location to another using OniSplit so relations are 134 * handled 135 * 136 * @param targetFolder 137 * Target folder for files 138 * @param input 139 * Files to move, can contain wildcards 140 * @param moveParameter 141 * e.g. overwrite, delete 142 */ 143 public static void move(File targetFolder, String input, 144 String moveParameter) { 145 if (!targetFolder.exists()) 146 targetFolder.mkdir(); 147 148 Vector<String> cmdLine = getProgramInvocation(); 149 cmdLine.add("-move" 150 + (moveParameter != null ? ":" + moveParameter : "")); 151 cmdLine.add(targetFolder.getPath()); 152 cmdLine.add(input); 153 Vector<String> res = null; 154 try { 155 res = QuickAppExecution.execute(cmdLine); 156 } catch (IOException e) { 157 // TODO Auto-generated catch block 158 e.printStackTrace(); 159 } 160 if (res != null && res.size() > 0) { 161 // TODO: errors 162 System.out.println(res.toString()); 163 } 109 164 } 110 165
Note:
See TracChangeset
for help on using the changeset viewer.