[596] | 1 | package net.oni2.aeinstaller.backend.oni;
|
---|
| 2 |
|
---|
| 3 | import java.io.File;
|
---|
[597] | 4 | import java.io.FileFilter;
|
---|
[624] | 5 | import java.io.FileInputStream;
|
---|
[600] | 6 | import java.io.FileNotFoundException;
|
---|
[624] | 7 | import java.io.FileOutputStream;
|
---|
[596] | 8 | import java.io.FilenameFilter;
|
---|
| 9 | import java.io.IOException;
|
---|
[631] | 10 | import java.io.InputStream;
|
---|
[600] | 11 | import java.io.PrintWriter;
|
---|
| 12 | import java.text.SimpleDateFormat;
|
---|
| 13 | import java.util.Date;
|
---|
[608] | 14 | import java.util.HashMap;
|
---|
[624] | 15 | import java.util.HashSet;
|
---|
[598] | 16 | import java.util.List;
|
---|
[596] | 17 | import java.util.Scanner;
|
---|
[606] | 18 | import java.util.TreeMap;
|
---|
[598] | 19 | import java.util.TreeSet;
|
---|
| 20 | import java.util.Vector;
|
---|
[596] | 21 |
|
---|
[631] | 22 | import net.oni2.aeinstaller.AEInstaller2;
|
---|
[596] | 23 | import net.oni2.aeinstaller.backend.Paths;
|
---|
[597] | 24 | import net.oni2.aeinstaller.backend.Settings;
|
---|
| 25 | import net.oni2.aeinstaller.backend.Settings.Platform;
|
---|
[648] | 26 | import net.oni2.aeinstaller.backend.packages.EBSLInstallType;
|
---|
| 27 | import net.oni2.aeinstaller.backend.packages.Package;
|
---|
| 28 | import net.oni2.aeinstaller.backend.packages.PackageManager;
|
---|
[596] | 29 |
|
---|
| 30 | import org.apache.commons.io.FileUtils;
|
---|
[654] | 31 | import org.javabuilders.swing.SwingJavaBuilder;
|
---|
[596] | 32 |
|
---|
[624] | 33 | import com.thoughtworks.xstream.XStream;
|
---|
| 34 | import com.thoughtworks.xstream.io.xml.StaxDriver;
|
---|
| 35 |
|
---|
[596] | 36 | /**
|
---|
| 37 | * @author Christian Illy
|
---|
| 38 | */
|
---|
| 39 | public class Installer {
|
---|
[608] | 40 | private static FileFilter dirFileFilter = new FileFilter() {
|
---|
| 41 | @Override
|
---|
| 42 | public boolean accept(File pathname) {
|
---|
| 43 | return pathname.isDirectory();
|
---|
| 44 | }
|
---|
| 45 | };
|
---|
| 46 |
|
---|
[596] | 47 | /**
|
---|
| 48 | * @return Is Edition Core initialized
|
---|
| 49 | */
|
---|
| 50 | public static boolean isEditionInitialized() {
|
---|
[597] | 51 | return Paths.getVanillaOnisPath().exists();
|
---|
[596] | 52 | }
|
---|
| 53 |
|
---|
| 54 | private static void createEmptyPath(File path) throws IOException {
|
---|
| 55 | if (path.exists())
|
---|
| 56 | FileUtils.deleteDirectory(path);
|
---|
| 57 | path.mkdirs();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[602] | 60 | /**
|
---|
[604] | 61 | * @return list of currently installed mods
|
---|
| 62 | */
|
---|
| 63 | public static Vector<Integer> getInstalledMods() {
|
---|
| 64 | File installCfg = new File(Paths.getEditionGDF(), "installed_mods.xml");
|
---|
[648] | 65 | return PackageManager.getInstance().loadModSelection(installCfg);
|
---|
[604] | 66 | }
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
[624] | 69 | * @return Currently installed tools
|
---|
| 70 | */
|
---|
| 71 | @SuppressWarnings("unchecked")
|
---|
| 72 | public static TreeSet<Integer> getInstalledTools() {
|
---|
| 73 | File installCfg = new File(Paths.getInstallerPath(),
|
---|
| 74 | "installed_tools.xml");
|
---|
| 75 | TreeSet<Integer> res = new TreeSet<Integer>();
|
---|
| 76 | try {
|
---|
| 77 | if (installCfg.exists()) {
|
---|
| 78 | FileInputStream fis = new FileInputStream(installCfg);
|
---|
| 79 | XStream xs = new XStream(new StaxDriver());
|
---|
| 80 | Object obj = xs.fromXML(fis);
|
---|
| 81 | if (obj instanceof TreeSet<?>)
|
---|
| 82 | res = (TreeSet<Integer>) obj;
|
---|
| 83 | fis.close();
|
---|
| 84 | }
|
---|
| 85 | } catch (FileNotFoundException e) {
|
---|
| 86 | e.printStackTrace();
|
---|
| 87 | } catch (IOException e) {
|
---|
| 88 | e.printStackTrace();
|
---|
| 89 | }
|
---|
| 90 | return res;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | private static void writeInstalledTools(TreeSet<Integer> tools) {
|
---|
| 94 | File installCfg = new File(Paths.getInstallerPath(),
|
---|
| 95 | "installed_tools.xml");
|
---|
| 96 | try {
|
---|
| 97 | FileOutputStream fos = new FileOutputStream(installCfg);
|
---|
| 98 | XStream xs = new XStream(new StaxDriver());
|
---|
| 99 | xs.toXML(tools, fos);
|
---|
| 100 | fos.close();
|
---|
| 101 | } catch (FileNotFoundException e) {
|
---|
| 102 | e.printStackTrace();
|
---|
| 103 | } catch (IOException e) {
|
---|
| 104 | e.printStackTrace();
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | /**
|
---|
[604] | 109 | * @param tools
|
---|
| 110 | * Tools to install
|
---|
| 111 | */
|
---|
[648] | 112 | public static void installTools(TreeSet<Package> tools) {
|
---|
[624] | 113 | TreeSet<Integer> installed = getInstalledTools();
|
---|
[648] | 114 | for (Package m : tools) {
|
---|
[604] | 115 | File plain = new File(m.getLocalPath(), "plain");
|
---|
| 116 | if (plain.exists()) {
|
---|
| 117 | if (m.hasSeparatePlatformDirs()) {
|
---|
| 118 | File plainCommon = new File(plain, "common");
|
---|
| 119 | File plainMac = new File(plain, "mac_only");
|
---|
| 120 | File plainWin = new File(plain, "win_only");
|
---|
| 121 | if (plainCommon.exists())
|
---|
| 122 | copyToolsFiles(plainCommon);
|
---|
| 123 | if (Settings.getPlatform() == Platform.MACOS
|
---|
| 124 | && plainMac.exists())
|
---|
| 125 | copyToolsFiles(plainMac);
|
---|
| 126 | else if (plainWin.exists())
|
---|
| 127 | copyToolsFiles(plainWin);
|
---|
| 128 | } else {
|
---|
| 129 | copyToolsFiles(plain);
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
[624] | 132 | installed.add(m.getPackageNumber());
|
---|
[604] | 133 | }
|
---|
[624] | 134 | writeInstalledTools(installed);
|
---|
[604] | 135 | }
|
---|
| 136 |
|
---|
| 137 | /**
|
---|
| 138 | * @param tools
|
---|
| 139 | * Tools to uninstall
|
---|
| 140 | */
|
---|
[648] | 141 | public static void uninstallTools(TreeSet<Package> tools) {
|
---|
[624] | 142 | TreeSet<Integer> installed = getInstalledTools();
|
---|
[648] | 143 | for (Package m : tools) {
|
---|
[624] | 144 | if (installed.contains(m.getPackageNumber())) {
|
---|
| 145 | File plain = new File(m.getLocalPath(), "plain");
|
---|
| 146 | if (plain.exists()) {
|
---|
| 147 | if (m.hasSeparatePlatformDirs()) {
|
---|
| 148 | File plainCommon = new File(plain, "common");
|
---|
| 149 | File plainMac = new File(plain, "mac_only");
|
---|
| 150 | File plainWin = new File(plain, "win_only");
|
---|
| 151 | if (plainCommon.exists())
|
---|
| 152 | removeToolsFiles(plainCommon,
|
---|
| 153 | Paths.getEditionBasePath());
|
---|
| 154 | if (Settings.getPlatform() == Platform.MACOS
|
---|
| 155 | && plainMac.exists())
|
---|
| 156 | removeToolsFiles(plainMac,
|
---|
| 157 | Paths.getEditionBasePath());
|
---|
| 158 | else if (plainWin.exists())
|
---|
| 159 | removeToolsFiles(plainWin,
|
---|
| 160 | Paths.getEditionBasePath());
|
---|
| 161 | } else {
|
---|
| 162 | removeToolsFiles(plain, Paths.getEditionBasePath());
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | installed.remove(m.getPackageNumber());
|
---|
| 167 | }
|
---|
| 168 | writeInstalledTools(installed);
|
---|
[604] | 169 | }
|
---|
| 170 |
|
---|
| 171 | private static void copyToolsFiles(File srcFolder) {
|
---|
| 172 | for (File f : srcFolder.listFiles()) {
|
---|
| 173 | try {
|
---|
| 174 | if (f.isDirectory())
|
---|
| 175 | FileUtils.copyDirectoryToDirectory(f,
|
---|
| 176 | Paths.getEditionBasePath());
|
---|
| 177 | else
|
---|
| 178 | FileUtils
|
---|
| 179 | .copyFileToDirectory(f, Paths.getEditionBasePath());
|
---|
| 180 | } catch (IOException e) {
|
---|
| 181 | e.printStackTrace();
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
[608] | 185 |
|
---|
[624] | 186 | private static void removeToolsFiles(File srcFolder, File target) {
|
---|
| 187 | for (File f : srcFolder.listFiles()) {
|
---|
| 188 | if (f.isDirectory())
|
---|
| 189 | removeToolsFiles(f, new File(target, f.getName()));
|
---|
| 190 | else {
|
---|
| 191 | File targetFile = new File(target, f.getName());
|
---|
| 192 | if (targetFile.exists())
|
---|
| 193 | targetFile.delete();
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | if (target.list().length == 0)
|
---|
| 197 | target.delete();
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[604] | 200 | /**
|
---|
[602] | 201 | * Install the given set of mods
|
---|
| 202 | *
|
---|
| 203 | * @param mods
|
---|
| 204 | * Mods to install
|
---|
| 205 | * @param listener
|
---|
| 206 | * Listener for install progress updates
|
---|
| 207 | */
|
---|
[648] | 208 | public static void install(TreeSet<Package> mods,
|
---|
[600] | 209 | InstallProgressListener listener) {
|
---|
[604] | 210 | try {
|
---|
| 211 | createEmptyPath(Paths.getEditionGDF());
|
---|
| 212 | } catch (IOException e) {
|
---|
| 213 | e.printStackTrace();
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[653] | 216 | File logFile = new File(Paths.getInstallerPath(), "Installation.log");
|
---|
| 217 | PrintWriter log = null;
|
---|
| 218 | try {
|
---|
| 219 | log = new PrintWriter(logFile);
|
---|
| 220 | } catch (FileNotFoundException e) {
|
---|
| 221 | e.printStackTrace();
|
---|
| 222 | }
|
---|
| 223 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
---|
| 224 | Date start = new Date();
|
---|
| 225 | log.println("Installation of mods started at " + sdf.format(start));
|
---|
| 226 |
|
---|
| 227 | log.println();
|
---|
[654] | 228 | log.println("AEI2 version: " + SwingJavaBuilder.getConfig().getResource("appversion"));
|
---|
[653] | 229 | log.println("Installed tools:");
|
---|
| 230 | for (Package t : PackageManager.getInstance().getInstalledTools()) {
|
---|
| 231 | log.println(String.format(" - %s (%s)", t.getName(), t.getVersion()));
|
---|
| 232 | }
|
---|
| 233 | log.println("Installing mods:");
|
---|
| 234 | for (Package m : mods) {
|
---|
| 235 | log.println(String.format(" - %s (%s)", m.getName(), m.getVersion()));
|
---|
| 236 | }
|
---|
| 237 | log.println();
|
---|
| 238 |
|
---|
[604] | 239 | File installCfg = new File(Paths.getEditionGDF(), "installed_mods.xml");
|
---|
[648] | 240 | PackageManager.getInstance().saveModSelection(installCfg, mods);
|
---|
[604] | 241 |
|
---|
[653] | 242 | TreeSet<Integer> unlockLevels = new TreeSet<Integer>();
|
---|
[624] | 243 |
|
---|
[608] | 244 | Vector<File> foldersOni = new Vector<File>();
|
---|
| 245 | foldersOni.add(Paths.getVanillaOnisPath());
|
---|
[598] | 246 |
|
---|
[648] | 247 | for (Package m : mods) {
|
---|
[624] | 248 | for (int lev : m.getUnlockLevels())
|
---|
| 249 | unlockLevels.add(lev);
|
---|
| 250 |
|
---|
[598] | 251 | File oni = new File(m.getLocalPath(), "oni");
|
---|
| 252 | if (oni.exists()) {
|
---|
| 253 | if (m.hasSeparatePlatformDirs()) {
|
---|
| 254 | File oniCommon = new File(oni, "common");
|
---|
| 255 | File oniMac = new File(oni, "mac_only");
|
---|
| 256 | File oniWin = new File(oni, "win_only");
|
---|
| 257 | if (oniCommon.exists())
|
---|
[608] | 258 | foldersOni.add(oniCommon);
|
---|
[598] | 259 | if (Settings.getPlatform() == Platform.MACOS
|
---|
| 260 | && oniMac.exists())
|
---|
[608] | 261 | foldersOni.add(oniMac);
|
---|
[598] | 262 | else if (oniWin.exists())
|
---|
[608] | 263 | foldersOni.add(oniWin);
|
---|
[598] | 264 | } else {
|
---|
[608] | 265 | foldersOni.add(oni);
|
---|
[598] | 266 | }
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
[657] | 269 |
|
---|
[653] | 270 | combineBinaryFiles(foldersOni, listener, log);
|
---|
| 271 | combineBSLFolders(mods, listener, log);
|
---|
[624] | 272 |
|
---|
[653] | 273 | copyVideos(log);
|
---|
[625] | 274 |
|
---|
[624] | 275 | if (unlockLevels.size() > 0) {
|
---|
[653] | 276 | unlockLevels(unlockLevels, log);
|
---|
[624] | 277 | }
|
---|
[653] | 278 |
|
---|
[655] | 279 | log.println();
|
---|
[653] | 280 | Date end = new Date();
|
---|
| 281 | log.println("Initialization ended at " + sdf.format(end));
|
---|
| 282 | log.println("Process took "
|
---|
| 283 | + ((end.getTime() - start.getTime()) / 1000) + " seconds");
|
---|
| 284 | log.close();
|
---|
[608] | 285 | }
|
---|
[598] | 286 |
|
---|
[648] | 287 | private static void combineBSLFolders(TreeSet<Package> mods,
|
---|
[653] | 288 | InstallProgressListener listener, PrintWriter log) {
|
---|
[608] | 289 | listener.installProgressUpdate(95, 100, "Installing BSL files");
|
---|
[653] | 290 | log.println("Installing BSL files");
|
---|
[598] | 291 |
|
---|
[648] | 292 | HashMap<EBSLInstallType, Vector<Package>> modsToInclude = new HashMap<EBSLInstallType, Vector<Package>>();
|
---|
| 293 | modsToInclude.put(EBSLInstallType.NORMAL, new Vector<Package>());
|
---|
| 294 | modsToInclude.put(EBSLInstallType.ADDON, new Vector<Package>());
|
---|
[608] | 295 |
|
---|
[648] | 296 | for (Package m : mods.descendingSet()) {
|
---|
[608] | 297 | File bsl = new File(m.getLocalPath(), "bsl");
|
---|
| 298 | if (bsl.exists()) {
|
---|
| 299 | if (m.hasSeparatePlatformDirs()) {
|
---|
| 300 | File bslCommon = new File(bsl, "common");
|
---|
| 301 | File bslMac = new File(bsl, "mac_only");
|
---|
| 302 | File bslWin = new File(bsl, "win_only");
|
---|
| 303 | if ((Settings.getPlatform() == Platform.MACOS && bslMac
|
---|
| 304 | .exists())
|
---|
| 305 | || ((Settings.getPlatform() == Platform.WIN || Settings
|
---|
| 306 | .getPlatform() == Platform.LINUX) && bslWin
|
---|
| 307 | .exists()) || bslCommon.exists()) {
|
---|
| 308 | modsToInclude.get(m.getBSLInstallType()).add(m);
|
---|
| 309 | }
|
---|
| 310 | } else {
|
---|
| 311 | modsToInclude.get(m.getBSLInstallType()).add(m);
|
---|
| 312 | }
|
---|
| 313 | }
|
---|
| 314 | }
|
---|
| 315 |
|
---|
[648] | 316 | for (Package m : modsToInclude.get(EBSLInstallType.NORMAL)) {
|
---|
[608] | 317 | copyBSL(m, false);
|
---|
| 318 | }
|
---|
[648] | 319 | Vector<Package> addons = modsToInclude.get(EBSLInstallType.ADDON);
|
---|
[610] | 320 | for (int i = addons.size() - 1; i >= 0; i--) {
|
---|
| 321 | copyBSL(addons.get(i), true);
|
---|
[608] | 322 | }
|
---|
[598] | 323 | }
|
---|
| 324 |
|
---|
[648] | 325 | private static void copyBSL(Package sourceMod, boolean addon) {
|
---|
[608] | 326 | File targetBaseFolder = new File(Paths.getEditionGDF(), "IGMD");
|
---|
| 327 | if (!targetBaseFolder.exists())
|
---|
| 328 | targetBaseFolder.mkdir();
|
---|
| 329 |
|
---|
| 330 | Vector<File> sources = new Vector<File>();
|
---|
| 331 | File bsl = new File(sourceMod.getLocalPath(), "bsl");
|
---|
| 332 | if (sourceMod.hasSeparatePlatformDirs()) {
|
---|
| 333 | File bslCommon = new File(bsl, "common");
|
---|
| 334 | File bslMac = new File(bsl, "mac_only");
|
---|
| 335 | File bslWin = new File(bsl, "win_only");
|
---|
| 336 | if (Settings.getPlatform() == Platform.MACOS && bslMac.exists()) {
|
---|
| 337 | for (File f : bslMac.listFiles(dirFileFilter)) {
|
---|
| 338 | File targetBSL = new File(targetBaseFolder, f.getName());
|
---|
| 339 | if (addon || !targetBSL.exists())
|
---|
| 340 | sources.add(f);
|
---|
| 341 | }
|
---|
| 342 | }
|
---|
| 343 | if ((Settings.getPlatform() == Platform.WIN || Settings
|
---|
| 344 | .getPlatform() == Platform.LINUX) && bslWin.exists()) {
|
---|
| 345 | for (File f : bslWin.listFiles(dirFileFilter)) {
|
---|
| 346 | File targetBSL = new File(targetBaseFolder, f.getName());
|
---|
| 347 | if (addon || !targetBSL.exists())
|
---|
| 348 | sources.add(f);
|
---|
| 349 | }
|
---|
| 350 | }
|
---|
| 351 | if (bslCommon.exists()) {
|
---|
| 352 | for (File f : bslCommon.listFiles(dirFileFilter)) {
|
---|
| 353 | File targetBSL = new File(targetBaseFolder, f.getName());
|
---|
| 354 | if (addon || !targetBSL.exists())
|
---|
| 355 | sources.add(f);
|
---|
| 356 | }
|
---|
| 357 | }
|
---|
| 358 | } else {
|
---|
| 359 | for (File f : bsl.listFiles(dirFileFilter)) {
|
---|
| 360 | File targetBSL = new File(targetBaseFolder, f.getName());
|
---|
| 361 | if (addon || !targetBSL.exists())
|
---|
| 362 | sources.add(f);
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | System.out.println("For mod: " + sourceMod.getName()
|
---|
| 367 | + " install BSL folders: " + sources.toString());
|
---|
| 368 | for (File f : sources) {
|
---|
| 369 | File targetPath = new File(targetBaseFolder, f.getName());
|
---|
| 370 | if (!targetPath.exists())
|
---|
| 371 | targetPath.mkdir();
|
---|
| 372 | for (File fbsl : f.listFiles()) {
|
---|
| 373 | File targetFile = new File(targetPath, fbsl.getName());
|
---|
[610] | 374 | if (addon || !targetFile.exists()) {
|
---|
[608] | 375 | try {
|
---|
| 376 | FileUtils.copyFile(fbsl, targetFile);
|
---|
| 377 | } catch (IOException e) {
|
---|
| 378 | e.printStackTrace();
|
---|
| 379 | }
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[600] | 385 | private static void combineBinaryFiles(List<File> srcFoldersFiles,
|
---|
[653] | 386 | InstallProgressListener listener, PrintWriter log) {
|
---|
[606] | 387 | TreeMap<String, Vector<File>> levels = new TreeMap<String, Vector<File>>();
|
---|
[598] | 388 |
|
---|
[604] | 389 | for (File path : srcFoldersFiles) {
|
---|
| 390 | for (File levelF : path.listFiles()) {
|
---|
| 391 | String fn = levelF.getName().toLowerCase();
|
---|
| 392 | String levelN = null;
|
---|
| 393 | if (levelF.isDirectory()) {
|
---|
| 394 | levelN = fn;
|
---|
| 395 | } else if (fn.endsWith(".dat")) {
|
---|
| 396 | levelN = fn.substring(0, fn.lastIndexOf('.'));
|
---|
[598] | 397 | }
|
---|
[604] | 398 | if (levelN != null) {
|
---|
| 399 | if (!levels.containsKey(levelN))
|
---|
| 400 | levels.put(levelN, new Vector<File>());
|
---|
| 401 | levels.get(levelN).add(levelF);
|
---|
| 402 | }
|
---|
[598] | 403 | }
|
---|
[604] | 404 | }
|
---|
[598] | 405 |
|
---|
[604] | 406 | int totalSteps = 0;
|
---|
| 407 | int stepsDone = 0;
|
---|
[600] | 408 |
|
---|
[604] | 409 | for (@SuppressWarnings("unused")
|
---|
| 410 | String s : levels.keySet())
|
---|
| 411 | totalSteps++;
|
---|
[608] | 412 | totalSteps++;
|
---|
[600] | 413 |
|
---|
[604] | 414 | log.println("Importing levels");
|
---|
| 415 | for (String l : levels.keySet()) {
|
---|
| 416 | log.println("\tLevel " + l);
|
---|
[600] | 417 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
[604] | 418 | "Installing level " + l);
|
---|
| 419 | for (File f : levels.get(l)) {
|
---|
| 420 | log.println("\t\t\t" + f.getPath());
|
---|
| 421 | }
|
---|
[600] | 422 |
|
---|
[604] | 423 | Vector<String> res = OniSplit.packLevel(levels.get(l), new File(
|
---|
[619] | 424 | Paths.getEditionGDF(), sanitizeLevelName(l) + ".dat"));
|
---|
[604] | 425 | if (res != null && res.size() > 0) {
|
---|
| 426 | for (String s : res)
|
---|
| 427 | log.println("\t\t" + s);
|
---|
[598] | 428 | }
|
---|
[602] | 429 |
|
---|
[604] | 430 | log.println();
|
---|
[608] | 431 | stepsDone++;
|
---|
[598] | 432 | }
|
---|
| 433 | }
|
---|
| 434 |
|
---|
[653] | 435 | private static void copyVideos(PrintWriter log) {
|
---|
[631] | 436 | if (Settings.getInstance().get("copyintro", false)) {
|
---|
| 437 | File src = new File(Paths.getVanillaGDF(), "intro.bik");
|
---|
[653] | 438 | log.println("Copying intro");
|
---|
[631] | 439 | if (src.exists()) {
|
---|
| 440 | try {
|
---|
| 441 | FileUtils.copyFileToDirectory(src, Paths.getEditionGDF());
|
---|
| 442 | } catch (IOException e) {
|
---|
| 443 | e.printStackTrace();
|
---|
| 444 | }
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
| 447 | if (Settings.getInstance().get("copyoutro", true)) {
|
---|
| 448 | File src = new File(Paths.getVanillaGDF(), "outro.bik");
|
---|
[653] | 449 | log.println("Copying outro");
|
---|
[631] | 450 | if (src.exists()) {
|
---|
| 451 | try {
|
---|
| 452 | FileUtils.copyFileToDirectory(src, Paths.getEditionGDF());
|
---|
| 453 | } catch (IOException e) {
|
---|
| 454 | e.printStackTrace();
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
| 457 | }
|
---|
| 458 | }
|
---|
| 459 |
|
---|
[653] | 460 | private static void unlockLevels(TreeSet<Integer> unlockLevels,
|
---|
| 461 | PrintWriter log) {
|
---|
[631] | 462 | File dat = new File(Paths.getEditionBasePath(), "persist.dat");
|
---|
[653] | 463 | log.println("Unlocking levels: " + unlockLevels.toString());
|
---|
[631] | 464 | if (!dat.exists()) {
|
---|
[653] | 465 | InputStream is = AEInstaller2.class
|
---|
| 466 | .getResourceAsStream("/net/oni2/aeinstaller/resources/persist.dat");
|
---|
[631] | 467 | try {
|
---|
| 468 | FileUtils.copyInputStreamToFile(is, dat);
|
---|
| 469 | } catch (IOException e) {
|
---|
| 470 | // TODO Auto-generated catch block
|
---|
| 471 | e.printStackTrace();
|
---|
| 472 | }
|
---|
| 473 | }
|
---|
| 474 | PersistDat save = new PersistDat(dat);
|
---|
| 475 | HashSet<Integer> currentlyUnlocked = save.getUnlockedLevels();
|
---|
| 476 | currentlyUnlocked.addAll(unlockLevels);
|
---|
| 477 | save.setUnlockedLevels(currentlyUnlocked);
|
---|
| 478 | save.close();
|
---|
| 479 | }
|
---|
| 480 |
|
---|
[596] | 481 | /**
|
---|
| 482 | * Initializes the Edition core
|
---|
[600] | 483 | *
|
---|
| 484 | * @param listener
|
---|
| 485 | * Listener for status updates
|
---|
[596] | 486 | */
|
---|
[600] | 487 | public static void initializeEdition(InstallProgressListener listener) {
|
---|
[596] | 488 | File init = new File(Paths.getTempPath(), "init");
|
---|
[600] | 489 |
|
---|
| 490 | int totalSteps = 0;
|
---|
| 491 | int stepsDone = 0;
|
---|
| 492 |
|
---|
| 493 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
---|
| 494 |
|
---|
| 495 | for (@SuppressWarnings("unused")
|
---|
| 496 | File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() {
|
---|
| 497 | @Override
|
---|
| 498 | public boolean accept(File dir, String name) {
|
---|
| 499 | return name.endsWith(".dat");
|
---|
| 500 | }
|
---|
| 501 | })) {
|
---|
| 502 | totalSteps++;
|
---|
| 503 | }
|
---|
| 504 | totalSteps = totalSteps * 2 + 2;
|
---|
| 505 |
|
---|
[596] | 506 | try {
|
---|
[600] | 507 | File logFile = new File(Paths.getInstallerPath(),
|
---|
| 508 | "Initialization.log");
|
---|
| 509 | PrintWriter log = new PrintWriter(logFile);
|
---|
| 510 |
|
---|
| 511 | Date start = new Date();
|
---|
| 512 | log.println("Initialization of Edition core started at "
|
---|
| 513 | + sdf.format(start));
|
---|
| 514 | log.println("Cleaning directories");
|
---|
| 515 |
|
---|
| 516 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
| 517 | "Cleaning up directories");
|
---|
[596] | 518 | createEmptyPath(Paths.getVanillaOnisPath());
|
---|
| 519 | createEmptyPath(init);
|
---|
[597] | 520 | File level0Folder = new File(init, "level0_Final");
|
---|
| 521 | createEmptyPath(level0Folder);
|
---|
[596] | 522 |
|
---|
[600] | 523 | stepsDone++;
|
---|
| 524 |
|
---|
| 525 | log.println("Exporting levels and moving files to level0");
|
---|
| 526 |
|
---|
[596] | 527 | for (File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() {
|
---|
| 528 | @Override
|
---|
| 529 | public boolean accept(File dir, String name) {
|
---|
| 530 | return name.endsWith(".dat");
|
---|
| 531 | }
|
---|
| 532 | })) {
|
---|
| 533 | String levelName = f.getName().substring(0,
|
---|
| 534 | f.getName().indexOf('.'));
|
---|
| 535 | Scanner fi = new Scanner(levelName);
|
---|
[597] | 536 | int levelNumber = Integer.parseInt(fi.findInLine("[0-9]+"));
|
---|
[596] | 537 |
|
---|
[600] | 538 | log.println("\t" + levelName + ":");
|
---|
| 539 | log.println("\t\tExporting");
|
---|
| 540 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
| 541 | "Exporting vanilla level " + levelNumber);
|
---|
| 542 |
|
---|
[597] | 543 | // Edition/GameDataFolder/level*_Final/
|
---|
| 544 | File tempLevelFolder = new File(init, levelName);
|
---|
| 545 |
|
---|
| 546 | // Export Vanilla-Level-Dat -> Temp/Level
|
---|
[600] | 547 | Vector<String> res = OniSplit.export(tempLevelFolder, f);
|
---|
| 548 | if (res != null && res.size() > 0) {
|
---|
| 549 | for (String s : res)
|
---|
| 550 | log.println("\t\t\t" + s);
|
---|
| 551 | }
|
---|
[597] | 552 |
|
---|
[600] | 553 | log.println("\t\tMoving files");
|
---|
[597] | 554 | handleFileGlobalisation(tempLevelFolder, level0Folder,
|
---|
[600] | 555 | levelNumber);
|
---|
| 556 | stepsDone++;
|
---|
| 557 | log.println();
|
---|
[596] | 558 | }
|
---|
| 559 |
|
---|
[600] | 560 | log.println("Reimporting levels");
|
---|
| 561 |
|
---|
[597] | 562 | for (File f : init.listFiles()) {
|
---|
| 563 | String levelName = f.getName();
|
---|
| 564 |
|
---|
[600] | 565 | log.println("\t" + levelName);
|
---|
| 566 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
| 567 | "Creating globalized " + levelName);
|
---|
[597] | 568 |
|
---|
[598] | 569 | Vector<File> folders = new Vector<File>();
|
---|
| 570 | folders.add(f);
|
---|
| 571 |
|
---|
[600] | 572 | Vector<String> res = OniSplit.importLevel(folders, new File(
|
---|
| 573 | Paths.getVanillaOnisPath(), levelName + ".dat"));
|
---|
| 574 | if (res != null && res.size() > 0) {
|
---|
| 575 | for (String s : res)
|
---|
| 576 | log.println("\t\t" + s);
|
---|
| 577 | }
|
---|
| 578 |
|
---|
| 579 | log.println();
|
---|
| 580 | stepsDone++;
|
---|
[597] | 581 | }
|
---|
| 582 |
|
---|
[600] | 583 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
| 584 | "Copying basic files");
|
---|
[597] | 585 | // Copy Oni-configs
|
---|
| 586 | File persistVanilla = new File(Paths.getOniBasePath(),
|
---|
| 587 | "persist.dat");
|
---|
| 588 | File persistEdition = new File(Paths.getEditionBasePath(),
|
---|
| 589 | "persist.dat");
|
---|
| 590 | File keyConfVanilla = new File(Paths.getOniBasePath(),
|
---|
| 591 | "key_config.txt");
|
---|
| 592 | File keyConfEdition = new File(Paths.getEditionBasePath(),
|
---|
| 593 | "key_config.txt");
|
---|
| 594 | if (persistVanilla.exists() && !persistEdition.exists())
|
---|
| 595 | FileUtils.copyFile(persistVanilla, persistEdition);
|
---|
| 596 | if (keyConfVanilla.exists() && !keyConfEdition.exists())
|
---|
| 597 | FileUtils.copyFile(keyConfVanilla, keyConfEdition);
|
---|
| 598 |
|
---|
[603] | 599 | FileUtils.deleteDirectory(init);
|
---|
[604] | 600 |
|
---|
[600] | 601 | Date end = new Date();
|
---|
| 602 | log.println("Initialization ended at " + sdf.format(end));
|
---|
| 603 | log.println("Process took "
|
---|
| 604 | + ((end.getTime() - start.getTime()) / 1000) + " seconds");
|
---|
| 605 | log.close();
|
---|
[596] | 606 | } catch (IOException e) {
|
---|
| 607 | e.printStackTrace();
|
---|
| 608 | }
|
---|
| 609 | }
|
---|
[597] | 610 |
|
---|
| 611 | private static void moveFileToTargetOrDelete(File source, File target) {
|
---|
| 612 | if (source.equals(target))
|
---|
| 613 | return;
|
---|
| 614 | if (!target.exists()) {
|
---|
| 615 | if (!source.renameTo(target)) {
|
---|
| 616 | System.err.println("File " + source.getPath() + " not moved!");
|
---|
| 617 | }
|
---|
| 618 | } else if (!source.delete()) {
|
---|
| 619 | System.err.println("File " + source.getPath() + " not deleted!");
|
---|
| 620 | }
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | private static void handleFileGlobalisation(File tempFolder,
|
---|
[600] | 624 | File level0Folder, int levelNumber) {
|
---|
[597] | 625 | // Move AKEV and related files to subfolder so they're not globalized:
|
---|
| 626 | if (levelNumber != 0) {
|
---|
| 627 | File akevFolder = new File(tempFolder, "AKEV");
|
---|
| 628 | akevFolder.mkdir();
|
---|
| 629 | OniSplit.move(akevFolder, tempFolder.getPath() + "/AKEV*.oni",
|
---|
| 630 | "overwrite");
|
---|
| 631 | }
|
---|
| 632 |
|
---|
| 633 | for (File f : tempFolder.listFiles(new FileFilter() {
|
---|
| 634 | @Override
|
---|
| 635 | public boolean accept(File pathname) {
|
---|
| 636 | return pathname.isFile();
|
---|
| 637 | }
|
---|
| 638 | })) {
|
---|
| 639 | // Move matching files to subfolder NoGlobal:
|
---|
| 640 | if (f.getName().startsWith("TXMPfail")
|
---|
| 641 | || f.getName().startsWith("TXMPlevel")
|
---|
| 642 | || (f.getName().startsWith("TXMP") && f.getName().contains(
|
---|
| 643 | "intro"))
|
---|
| 644 | || f.getName().startsWith("TXMB")
|
---|
| 645 | || f.getName().equals("M3GMpowerup_lsi.oni")
|
---|
| 646 | || f.getName().equals("TXMPlsi_icon.oni")
|
---|
| 647 | || (f.getName().startsWith("TXMB") && f.getName().contains(
|
---|
| 648 | "splash_screen.oni"))) {
|
---|
| 649 | File noGlobal = new File(tempFolder, "NoGlobal");
|
---|
| 650 | noGlobal.mkdir();
|
---|
| 651 | File noGlobalFile = new File(noGlobal, f.getName());
|
---|
| 652 | moveFileToTargetOrDelete(f, noGlobalFile);
|
---|
| 653 | }
|
---|
| 654 | // Move matching files to level0_Animations/level0_TRAC
|
---|
| 655 | else if (f.getName().startsWith("TRAC")) {
|
---|
| 656 | File level0File = new File(level0Folder, f.getName());
|
---|
| 657 | moveFileToTargetOrDelete(f, level0File);
|
---|
| 658 | }
|
---|
| 659 | // Move matching files to level0_Animations/level0_TRAM
|
---|
| 660 | else if (f.getName().startsWith("TRAM")) {
|
---|
| 661 | File level0File = new File(level0Folder, f.getName());
|
---|
| 662 | moveFileToTargetOrDelete(f, level0File);
|
---|
| 663 | }
|
---|
| 664 | // Move matching files to level0_Textures
|
---|
| 665 | else if (f.getName().startsWith("ONSK")
|
---|
| 666 | || f.getName().startsWith("TXMP")) {
|
---|
| 667 | File level0File = new File(level0Folder, f.getName());
|
---|
[598] | 668 | moveFileToTargetOrDelete(f, level0File);
|
---|
[597] | 669 | }
|
---|
| 670 | // Move matching files to *VANILLA*/level0_Characters
|
---|
| 671 | else if (f.getName().startsWith("ONCC")
|
---|
| 672 | || f.getName().startsWith("TRBS")
|
---|
| 673 | || f.getName().startsWith("ONCV")
|
---|
| 674 | || f.getName().startsWith("ONVL")
|
---|
| 675 | || f.getName().startsWith("TRMA")
|
---|
| 676 | || f.getName().startsWith("TRSC")
|
---|
| 677 | || f.getName().startsWith("TRAS")) {
|
---|
[598] | 678 | File level0File = new File(level0Folder, f.getName());
|
---|
| 679 | moveFileToTargetOrDelete(f, level0File);
|
---|
[597] | 680 | }
|
---|
| 681 | // Move matching files to level0_Sounds
|
---|
| 682 | else if (f.getName().startsWith("OSBD")
|
---|
| 683 | || f.getName().startsWith("SNDD")) {
|
---|
| 684 | File level0File = new File(level0Folder, f.getName());
|
---|
| 685 | moveFileToTargetOrDelete(f, level0File);
|
---|
| 686 | }
|
---|
| 687 | // Move matching files to level0_Particles
|
---|
| 688 | else if (f.getName().startsWith("BINA3")
|
---|
| 689 | || f.getName().startsWith("M3GMdebris")
|
---|
| 690 | || f.getName().equals("M3GMtoxic_bubble.oni")
|
---|
| 691 | || f.getName().startsWith("M3GMelec")
|
---|
| 692 | || f.getName().startsWith("M3GMrat")
|
---|
| 693 | || f.getName().startsWith("M3GMjet")
|
---|
| 694 | || f.getName().startsWith("M3GMbomb_")
|
---|
| 695 | || f.getName().equals("M3GMbarab_swave.oni")
|
---|
| 696 | || f.getName().equals("M3GMbloodyfoot.oni")) {
|
---|
| 697 | File level0File = new File(level0Folder, f.getName());
|
---|
| 698 | moveFileToTargetOrDelete(f, level0File);
|
---|
| 699 | }
|
---|
| 700 | // Move matching files to Archive (aka delete them)
|
---|
| 701 | else if (f.getName().startsWith("AGDB")
|
---|
| 702 | || f.getName().startsWith("TRCM")) {
|
---|
| 703 | f.delete();
|
---|
| 704 | }
|
---|
[599] | 705 | // Move matching files to /level0_Final/
|
---|
[597] | 706 | else if (f.getName().startsWith("ONWC")) {
|
---|
[598] | 707 | File level0File = new File(level0Folder, f.getName());
|
---|
| 708 | moveFileToTargetOrDelete(f, level0File);
|
---|
[597] | 709 | }
|
---|
| 710 | }
|
---|
| 711 | }
|
---|
[603] | 712 |
|
---|
[619] | 713 | private static String sanitizeLevelName(String ln) {
|
---|
| 714 | int ind = ln.indexOf("_");
|
---|
| 715 | String res = ln.substring(0, ind + 1);
|
---|
| 716 | res += ln.substring(ind + 1, ind + 2).toUpperCase();
|
---|
| 717 | res += ln.substring(ind + 2);
|
---|
| 718 | return res;
|
---|
| 719 | }
|
---|
| 720 |
|
---|
[603] | 721 | /**
|
---|
[604] | 722 | * Verify that the Edition is within a subfolder to vanilla Oni
|
---|
| 723 | * (..../Oni/Edition/AEInstaller)
|
---|
| 724 | *
|
---|
[603] | 725 | * @return true if GDF can be found in the parent's parent-path
|
---|
| 726 | */
|
---|
| 727 | public static boolean verifyRunningDirectory() {
|
---|
[604] | 728 | return Paths.getVanillaGDF().exists()
|
---|
| 729 | && Paths.getVanillaGDF().isDirectory();
|
---|
[603] | 730 | }
|
---|
[596] | 731 | }
|
---|