[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 | }
|
---|
[653] | 269 | combineBinaryFiles(foldersOni, listener, log);
|
---|
| 270 | combineBSLFolders(mods, listener, log);
|
---|
[624] | 271 |
|
---|
[653] | 272 | copyVideos(log);
|
---|
[625] | 273 |
|
---|
[624] | 274 | if (unlockLevels.size() > 0) {
|
---|
[653] | 275 | unlockLevels(unlockLevels, log);
|
---|
[624] | 276 | }
|
---|
[653] | 277 |
|
---|
[655] | 278 | log.println();
|
---|
[653] | 279 | Date end = new Date();
|
---|
| 280 | log.println("Initialization ended at " + sdf.format(end));
|
---|
| 281 | log.println("Process took "
|
---|
| 282 | + ((end.getTime() - start.getTime()) / 1000) + " seconds");
|
---|
| 283 | log.close();
|
---|
[608] | 284 | }
|
---|
[598] | 285 |
|
---|
[648] | 286 | private static void combineBSLFolders(TreeSet<Package> mods,
|
---|
[653] | 287 | InstallProgressListener listener, PrintWriter log) {
|
---|
[608] | 288 | listener.installProgressUpdate(95, 100, "Installing BSL files");
|
---|
[653] | 289 | log.println("Installing BSL files");
|
---|
[598] | 290 |
|
---|
[648] | 291 | HashMap<EBSLInstallType, Vector<Package>> modsToInclude = new HashMap<EBSLInstallType, Vector<Package>>();
|
---|
| 292 | modsToInclude.put(EBSLInstallType.NORMAL, new Vector<Package>());
|
---|
| 293 | modsToInclude.put(EBSLInstallType.ADDON, new Vector<Package>());
|
---|
[608] | 294 |
|
---|
[648] | 295 | for (Package m : mods.descendingSet()) {
|
---|
[608] | 296 | File bsl = new File(m.getLocalPath(), "bsl");
|
---|
| 297 | if (bsl.exists()) {
|
---|
| 298 | if (m.hasSeparatePlatformDirs()) {
|
---|
| 299 | File bslCommon = new File(bsl, "common");
|
---|
| 300 | File bslMac = new File(bsl, "mac_only");
|
---|
| 301 | File bslWin = new File(bsl, "win_only");
|
---|
| 302 | if ((Settings.getPlatform() == Platform.MACOS && bslMac
|
---|
| 303 | .exists())
|
---|
| 304 | || ((Settings.getPlatform() == Platform.WIN || Settings
|
---|
| 305 | .getPlatform() == Platform.LINUX) && bslWin
|
---|
| 306 | .exists()) || bslCommon.exists()) {
|
---|
| 307 | modsToInclude.get(m.getBSLInstallType()).add(m);
|
---|
| 308 | }
|
---|
| 309 | } else {
|
---|
| 310 | modsToInclude.get(m.getBSLInstallType()).add(m);
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | }
|
---|
| 314 |
|
---|
[648] | 315 | for (Package m : modsToInclude.get(EBSLInstallType.NORMAL)) {
|
---|
[608] | 316 | copyBSL(m, false);
|
---|
| 317 | }
|
---|
[648] | 318 | Vector<Package> addons = modsToInclude.get(EBSLInstallType.ADDON);
|
---|
[610] | 319 | for (int i = addons.size() - 1; i >= 0; i--) {
|
---|
| 320 | copyBSL(addons.get(i), true);
|
---|
[608] | 321 | }
|
---|
[598] | 322 | }
|
---|
| 323 |
|
---|
[648] | 324 | private static void copyBSL(Package sourceMod, boolean addon) {
|
---|
[608] | 325 | File targetBaseFolder = new File(Paths.getEditionGDF(), "IGMD");
|
---|
| 326 | if (!targetBaseFolder.exists())
|
---|
| 327 | targetBaseFolder.mkdir();
|
---|
| 328 |
|
---|
| 329 | Vector<File> sources = new Vector<File>();
|
---|
| 330 | File bsl = new File(sourceMod.getLocalPath(), "bsl");
|
---|
| 331 | if (sourceMod.hasSeparatePlatformDirs()) {
|
---|
| 332 | File bslCommon = new File(bsl, "common");
|
---|
| 333 | File bslMac = new File(bsl, "mac_only");
|
---|
| 334 | File bslWin = new File(bsl, "win_only");
|
---|
| 335 | if (Settings.getPlatform() == Platform.MACOS && bslMac.exists()) {
|
---|
| 336 | for (File f : bslMac.listFiles(dirFileFilter)) {
|
---|
| 337 | File targetBSL = new File(targetBaseFolder, f.getName());
|
---|
| 338 | if (addon || !targetBSL.exists())
|
---|
| 339 | sources.add(f);
|
---|
| 340 | }
|
---|
| 341 | }
|
---|
| 342 | if ((Settings.getPlatform() == Platform.WIN || Settings
|
---|
| 343 | .getPlatform() == Platform.LINUX) && bslWin.exists()) {
|
---|
| 344 | for (File f : bslWin.listFiles(dirFileFilter)) {
|
---|
| 345 | File targetBSL = new File(targetBaseFolder, f.getName());
|
---|
| 346 | if (addon || !targetBSL.exists())
|
---|
| 347 | sources.add(f);
|
---|
| 348 | }
|
---|
| 349 | }
|
---|
| 350 | if (bslCommon.exists()) {
|
---|
| 351 | for (File f : bslCommon.listFiles(dirFileFilter)) {
|
---|
| 352 | File targetBSL = new File(targetBaseFolder, f.getName());
|
---|
| 353 | if (addon || !targetBSL.exists())
|
---|
| 354 | sources.add(f);
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 | } else {
|
---|
| 358 | for (File f : bsl.listFiles(dirFileFilter)) {
|
---|
| 359 | File targetBSL = new File(targetBaseFolder, f.getName());
|
---|
| 360 | if (addon || !targetBSL.exists())
|
---|
| 361 | sources.add(f);
|
---|
| 362 | }
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | System.out.println("For mod: " + sourceMod.getName()
|
---|
| 366 | + " install BSL folders: " + sources.toString());
|
---|
| 367 | for (File f : sources) {
|
---|
| 368 | File targetPath = new File(targetBaseFolder, f.getName());
|
---|
| 369 | if (!targetPath.exists())
|
---|
| 370 | targetPath.mkdir();
|
---|
| 371 | for (File fbsl : f.listFiles()) {
|
---|
| 372 | File targetFile = new File(targetPath, fbsl.getName());
|
---|
[610] | 373 | if (addon || !targetFile.exists()) {
|
---|
[608] | 374 | try {
|
---|
| 375 | FileUtils.copyFile(fbsl, targetFile);
|
---|
| 376 | } catch (IOException e) {
|
---|
| 377 | e.printStackTrace();
|
---|
| 378 | }
|
---|
| 379 | }
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
| 383 |
|
---|
[600] | 384 | private static void combineBinaryFiles(List<File> srcFoldersFiles,
|
---|
[653] | 385 | InstallProgressListener listener, PrintWriter log) {
|
---|
[606] | 386 | TreeMap<String, Vector<File>> levels = new TreeMap<String, Vector<File>>();
|
---|
[598] | 387 |
|
---|
[604] | 388 | for (File path : srcFoldersFiles) {
|
---|
| 389 | for (File levelF : path.listFiles()) {
|
---|
| 390 | String fn = levelF.getName().toLowerCase();
|
---|
| 391 | String levelN = null;
|
---|
| 392 | if (levelF.isDirectory()) {
|
---|
| 393 | levelN = fn;
|
---|
| 394 | } else if (fn.endsWith(".dat")) {
|
---|
| 395 | levelN = fn.substring(0, fn.lastIndexOf('.'));
|
---|
[598] | 396 | }
|
---|
[604] | 397 | if (levelN != null) {
|
---|
| 398 | if (!levels.containsKey(levelN))
|
---|
| 399 | levels.put(levelN, new Vector<File>());
|
---|
| 400 | levels.get(levelN).add(levelF);
|
---|
| 401 | }
|
---|
[598] | 402 | }
|
---|
[604] | 403 | }
|
---|
[598] | 404 |
|
---|
[604] | 405 | int totalSteps = 0;
|
---|
| 406 | int stepsDone = 0;
|
---|
[600] | 407 |
|
---|
[604] | 408 | for (@SuppressWarnings("unused")
|
---|
| 409 | String s : levels.keySet())
|
---|
| 410 | totalSteps++;
|
---|
[608] | 411 | totalSteps++;
|
---|
[600] | 412 |
|
---|
[604] | 413 | log.println("Importing levels");
|
---|
| 414 | for (String l : levels.keySet()) {
|
---|
| 415 | log.println("\tLevel " + l);
|
---|
[600] | 416 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
[604] | 417 | "Installing level " + l);
|
---|
| 418 | for (File f : levels.get(l)) {
|
---|
| 419 | log.println("\t\t\t" + f.getPath());
|
---|
| 420 | }
|
---|
[600] | 421 |
|
---|
[604] | 422 | Vector<String> res = OniSplit.packLevel(levels.get(l), new File(
|
---|
[619] | 423 | Paths.getEditionGDF(), sanitizeLevelName(l) + ".dat"));
|
---|
[604] | 424 | if (res != null && res.size() > 0) {
|
---|
| 425 | for (String s : res)
|
---|
| 426 | log.println("\t\t" + s);
|
---|
[598] | 427 | }
|
---|
[602] | 428 |
|
---|
[604] | 429 | log.println();
|
---|
[608] | 430 | stepsDone++;
|
---|
[598] | 431 | }
|
---|
| 432 | }
|
---|
| 433 |
|
---|
[653] | 434 | private static void copyVideos(PrintWriter log) {
|
---|
[631] | 435 | if (Settings.getInstance().get("copyintro", false)) {
|
---|
| 436 | File src = new File(Paths.getVanillaGDF(), "intro.bik");
|
---|
[653] | 437 | log.println("Copying intro");
|
---|
[631] | 438 | if (src.exists()) {
|
---|
| 439 | try {
|
---|
| 440 | FileUtils.copyFileToDirectory(src, Paths.getEditionGDF());
|
---|
| 441 | } catch (IOException e) {
|
---|
| 442 | e.printStackTrace();
|
---|
| 443 | }
|
---|
| 444 | }
|
---|
| 445 | }
|
---|
| 446 | if (Settings.getInstance().get("copyoutro", true)) {
|
---|
| 447 | File src = new File(Paths.getVanillaGDF(), "outro.bik");
|
---|
[653] | 448 | log.println("Copying outro");
|
---|
[631] | 449 | if (src.exists()) {
|
---|
| 450 | try {
|
---|
| 451 | FileUtils.copyFileToDirectory(src, Paths.getEditionGDF());
|
---|
| 452 | } catch (IOException e) {
|
---|
| 453 | e.printStackTrace();
|
---|
| 454 | }
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
| 457 | }
|
---|
| 458 |
|
---|
[653] | 459 | private static void unlockLevels(TreeSet<Integer> unlockLevels,
|
---|
| 460 | PrintWriter log) {
|
---|
[631] | 461 | File dat = new File(Paths.getEditionBasePath(), "persist.dat");
|
---|
[653] | 462 | log.println("Unlocking levels: " + unlockLevels.toString());
|
---|
[631] | 463 | if (!dat.exists()) {
|
---|
[653] | 464 | InputStream is = AEInstaller2.class
|
---|
| 465 | .getResourceAsStream("/net/oni2/aeinstaller/resources/persist.dat");
|
---|
[631] | 466 | try {
|
---|
| 467 | FileUtils.copyInputStreamToFile(is, dat);
|
---|
| 468 | } catch (IOException e) {
|
---|
| 469 | // TODO Auto-generated catch block
|
---|
| 470 | e.printStackTrace();
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 | PersistDat save = new PersistDat(dat);
|
---|
| 474 | HashSet<Integer> currentlyUnlocked = save.getUnlockedLevels();
|
---|
| 475 | currentlyUnlocked.addAll(unlockLevels);
|
---|
| 476 | save.setUnlockedLevels(currentlyUnlocked);
|
---|
| 477 | save.close();
|
---|
| 478 | }
|
---|
| 479 |
|
---|
[596] | 480 | /**
|
---|
| 481 | * Initializes the Edition core
|
---|
[600] | 482 | *
|
---|
| 483 | * @param listener
|
---|
| 484 | * Listener for status updates
|
---|
[596] | 485 | */
|
---|
[600] | 486 | public static void initializeEdition(InstallProgressListener listener) {
|
---|
[596] | 487 | File init = new File(Paths.getTempPath(), "init");
|
---|
[600] | 488 |
|
---|
| 489 | int totalSteps = 0;
|
---|
| 490 | int stepsDone = 0;
|
---|
| 491 |
|
---|
| 492 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
---|
| 493 |
|
---|
| 494 | for (@SuppressWarnings("unused")
|
---|
| 495 | File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() {
|
---|
| 496 | @Override
|
---|
| 497 | public boolean accept(File dir, String name) {
|
---|
| 498 | return name.endsWith(".dat");
|
---|
| 499 | }
|
---|
| 500 | })) {
|
---|
| 501 | totalSteps++;
|
---|
| 502 | }
|
---|
| 503 | totalSteps = totalSteps * 2 + 2;
|
---|
| 504 |
|
---|
[596] | 505 | try {
|
---|
[600] | 506 | File logFile = new File(Paths.getInstallerPath(),
|
---|
| 507 | "Initialization.log");
|
---|
| 508 | PrintWriter log = new PrintWriter(logFile);
|
---|
| 509 |
|
---|
| 510 | Date start = new Date();
|
---|
| 511 | log.println("Initialization of Edition core started at "
|
---|
| 512 | + sdf.format(start));
|
---|
| 513 | log.println("Cleaning directories");
|
---|
| 514 |
|
---|
| 515 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
| 516 | "Cleaning up directories");
|
---|
[596] | 517 | createEmptyPath(Paths.getVanillaOnisPath());
|
---|
| 518 | createEmptyPath(init);
|
---|
[597] | 519 | File level0Folder = new File(init, "level0_Final");
|
---|
| 520 | createEmptyPath(level0Folder);
|
---|
[596] | 521 |
|
---|
[600] | 522 | stepsDone++;
|
---|
| 523 |
|
---|
| 524 | log.println("Exporting levels and moving files to level0");
|
---|
| 525 |
|
---|
[596] | 526 | for (File f : Paths.getVanillaGDF().listFiles(new FilenameFilter() {
|
---|
| 527 | @Override
|
---|
| 528 | public boolean accept(File dir, String name) {
|
---|
| 529 | return name.endsWith(".dat");
|
---|
| 530 | }
|
---|
| 531 | })) {
|
---|
| 532 | String levelName = f.getName().substring(0,
|
---|
| 533 | f.getName().indexOf('.'));
|
---|
| 534 | Scanner fi = new Scanner(levelName);
|
---|
[597] | 535 | int levelNumber = Integer.parseInt(fi.findInLine("[0-9]+"));
|
---|
[596] | 536 |
|
---|
[600] | 537 | log.println("\t" + levelName + ":");
|
---|
| 538 | log.println("\t\tExporting");
|
---|
| 539 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
| 540 | "Exporting vanilla level " + levelNumber);
|
---|
| 541 |
|
---|
[597] | 542 | // Edition/GameDataFolder/level*_Final/
|
---|
| 543 | File tempLevelFolder = new File(init, levelName);
|
---|
| 544 |
|
---|
| 545 | // Export Vanilla-Level-Dat -> Temp/Level
|
---|
[600] | 546 | Vector<String> res = OniSplit.export(tempLevelFolder, f);
|
---|
| 547 | if (res != null && res.size() > 0) {
|
---|
| 548 | for (String s : res)
|
---|
| 549 | log.println("\t\t\t" + s);
|
---|
| 550 | }
|
---|
[597] | 551 |
|
---|
[600] | 552 | log.println("\t\tMoving files");
|
---|
[597] | 553 | handleFileGlobalisation(tempLevelFolder, level0Folder,
|
---|
[600] | 554 | levelNumber);
|
---|
| 555 | stepsDone++;
|
---|
| 556 | log.println();
|
---|
[596] | 557 | }
|
---|
| 558 |
|
---|
[600] | 559 | log.println("Reimporting levels");
|
---|
| 560 |
|
---|
[597] | 561 | for (File f : init.listFiles()) {
|
---|
| 562 | String levelName = f.getName();
|
---|
| 563 |
|
---|
[600] | 564 | log.println("\t" + levelName);
|
---|
| 565 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
| 566 | "Creating globalized " + levelName);
|
---|
[597] | 567 |
|
---|
[598] | 568 | Vector<File> folders = new Vector<File>();
|
---|
| 569 | folders.add(f);
|
---|
| 570 |
|
---|
[600] | 571 | Vector<String> res = OniSplit.importLevel(folders, new File(
|
---|
| 572 | Paths.getVanillaOnisPath(), levelName + ".dat"));
|
---|
| 573 | if (res != null && res.size() > 0) {
|
---|
| 574 | for (String s : res)
|
---|
| 575 | log.println("\t\t" + s);
|
---|
| 576 | }
|
---|
| 577 |
|
---|
| 578 | log.println();
|
---|
| 579 | stepsDone++;
|
---|
[597] | 580 | }
|
---|
| 581 |
|
---|
[600] | 582 | listener.installProgressUpdate(stepsDone, totalSteps,
|
---|
| 583 | "Copying basic files");
|
---|
[597] | 584 | // Copy Oni-configs
|
---|
| 585 | File persistVanilla = new File(Paths.getOniBasePath(),
|
---|
| 586 | "persist.dat");
|
---|
| 587 | File persistEdition = new File(Paths.getEditionBasePath(),
|
---|
| 588 | "persist.dat");
|
---|
| 589 | File keyConfVanilla = new File(Paths.getOniBasePath(),
|
---|
| 590 | "key_config.txt");
|
---|
| 591 | File keyConfEdition = new File(Paths.getEditionBasePath(),
|
---|
| 592 | "key_config.txt");
|
---|
| 593 | if (persistVanilla.exists() && !persistEdition.exists())
|
---|
| 594 | FileUtils.copyFile(persistVanilla, persistEdition);
|
---|
| 595 | if (keyConfVanilla.exists() && !keyConfEdition.exists())
|
---|
| 596 | FileUtils.copyFile(keyConfVanilla, keyConfEdition);
|
---|
| 597 |
|
---|
[603] | 598 | FileUtils.deleteDirectory(init);
|
---|
[604] | 599 |
|
---|
[600] | 600 | Date end = new Date();
|
---|
| 601 | log.println("Initialization ended at " + sdf.format(end));
|
---|
| 602 | log.println("Process took "
|
---|
| 603 | + ((end.getTime() - start.getTime()) / 1000) + " seconds");
|
---|
| 604 | log.close();
|
---|
[596] | 605 | } catch (IOException e) {
|
---|
| 606 | e.printStackTrace();
|
---|
| 607 | }
|
---|
| 608 | }
|
---|
[597] | 609 |
|
---|
| 610 | private static void moveFileToTargetOrDelete(File source, File target) {
|
---|
| 611 | if (source.equals(target))
|
---|
| 612 | return;
|
---|
| 613 | if (!target.exists()) {
|
---|
| 614 | if (!source.renameTo(target)) {
|
---|
| 615 | System.err.println("File " + source.getPath() + " not moved!");
|
---|
| 616 | }
|
---|
| 617 | } else if (!source.delete()) {
|
---|
| 618 | System.err.println("File " + source.getPath() + " not deleted!");
|
---|
| 619 | }
|
---|
| 620 | }
|
---|
| 621 |
|
---|
| 622 | private static void handleFileGlobalisation(File tempFolder,
|
---|
[600] | 623 | File level0Folder, int levelNumber) {
|
---|
[597] | 624 | // Move AKEV and related files to subfolder so they're not globalized:
|
---|
| 625 | if (levelNumber != 0) {
|
---|
| 626 | File akevFolder = new File(tempFolder, "AKEV");
|
---|
| 627 | akevFolder.mkdir();
|
---|
| 628 | OniSplit.move(akevFolder, tempFolder.getPath() + "/AKEV*.oni",
|
---|
| 629 | "overwrite");
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 | for (File f : tempFolder.listFiles(new FileFilter() {
|
---|
| 633 | @Override
|
---|
| 634 | public boolean accept(File pathname) {
|
---|
| 635 | return pathname.isFile();
|
---|
| 636 | }
|
---|
| 637 | })) {
|
---|
| 638 | // Move matching files to subfolder NoGlobal:
|
---|
| 639 | if (f.getName().startsWith("TXMPfail")
|
---|
| 640 | || f.getName().startsWith("TXMPlevel")
|
---|
| 641 | || (f.getName().startsWith("TXMP") && f.getName().contains(
|
---|
| 642 | "intro"))
|
---|
| 643 | || f.getName().startsWith("TXMB")
|
---|
| 644 | || f.getName().equals("M3GMpowerup_lsi.oni")
|
---|
| 645 | || f.getName().equals("TXMPlsi_icon.oni")
|
---|
| 646 | || (f.getName().startsWith("TXMB") && f.getName().contains(
|
---|
| 647 | "splash_screen.oni"))) {
|
---|
| 648 | File noGlobal = new File(tempFolder, "NoGlobal");
|
---|
| 649 | noGlobal.mkdir();
|
---|
| 650 | File noGlobalFile = new File(noGlobal, f.getName());
|
---|
| 651 | moveFileToTargetOrDelete(f, noGlobalFile);
|
---|
| 652 | }
|
---|
| 653 | // Move matching files to level0_Animations/level0_TRAC
|
---|
| 654 | else if (f.getName().startsWith("TRAC")) {
|
---|
| 655 | File level0File = new File(level0Folder, f.getName());
|
---|
| 656 | moveFileToTargetOrDelete(f, level0File);
|
---|
| 657 | }
|
---|
| 658 | // Move matching files to level0_Animations/level0_TRAM
|
---|
| 659 | else if (f.getName().startsWith("TRAM")) {
|
---|
| 660 | File level0File = new File(level0Folder, f.getName());
|
---|
| 661 | moveFileToTargetOrDelete(f, level0File);
|
---|
| 662 | }
|
---|
| 663 | // Move matching files to level0_Textures
|
---|
| 664 | else if (f.getName().startsWith("ONSK")
|
---|
| 665 | || f.getName().startsWith("TXMP")) {
|
---|
| 666 | File level0File = new File(level0Folder, f.getName());
|
---|
[598] | 667 | moveFileToTargetOrDelete(f, level0File);
|
---|
[597] | 668 | }
|
---|
| 669 | // Move matching files to *VANILLA*/level0_Characters
|
---|
| 670 | else if (f.getName().startsWith("ONCC")
|
---|
| 671 | || f.getName().startsWith("TRBS")
|
---|
| 672 | || f.getName().startsWith("ONCV")
|
---|
| 673 | || f.getName().startsWith("ONVL")
|
---|
| 674 | || f.getName().startsWith("TRMA")
|
---|
| 675 | || f.getName().startsWith("TRSC")
|
---|
| 676 | || f.getName().startsWith("TRAS")) {
|
---|
[598] | 677 | File level0File = new File(level0Folder, f.getName());
|
---|
| 678 | moveFileToTargetOrDelete(f, level0File);
|
---|
[597] | 679 | }
|
---|
| 680 | // Move matching files to level0_Sounds
|
---|
| 681 | else if (f.getName().startsWith("OSBD")
|
---|
| 682 | || f.getName().startsWith("SNDD")) {
|
---|
| 683 | File level0File = new File(level0Folder, f.getName());
|
---|
| 684 | moveFileToTargetOrDelete(f, level0File);
|
---|
| 685 | }
|
---|
| 686 | // Move matching files to level0_Particles
|
---|
| 687 | else if (f.getName().startsWith("BINA3")
|
---|
| 688 | || f.getName().startsWith("M3GMdebris")
|
---|
| 689 | || f.getName().equals("M3GMtoxic_bubble.oni")
|
---|
| 690 | || f.getName().startsWith("M3GMelec")
|
---|
| 691 | || f.getName().startsWith("M3GMrat")
|
---|
| 692 | || f.getName().startsWith("M3GMjet")
|
---|
| 693 | || f.getName().startsWith("M3GMbomb_")
|
---|
| 694 | || f.getName().equals("M3GMbarab_swave.oni")
|
---|
| 695 | || f.getName().equals("M3GMbloodyfoot.oni")) {
|
---|
| 696 | File level0File = new File(level0Folder, f.getName());
|
---|
| 697 | moveFileToTargetOrDelete(f, level0File);
|
---|
| 698 | }
|
---|
| 699 | // Move matching files to Archive (aka delete them)
|
---|
| 700 | else if (f.getName().startsWith("AGDB")
|
---|
| 701 | || f.getName().startsWith("TRCM")) {
|
---|
| 702 | f.delete();
|
---|
| 703 | }
|
---|
[599] | 704 | // Move matching files to /level0_Final/
|
---|
[597] | 705 | else if (f.getName().startsWith("ONWC")) {
|
---|
[598] | 706 | File level0File = new File(level0Folder, f.getName());
|
---|
| 707 | moveFileToTargetOrDelete(f, level0File);
|
---|
[597] | 708 | }
|
---|
| 709 | }
|
---|
| 710 | }
|
---|
[603] | 711 |
|
---|
[619] | 712 | private static String sanitizeLevelName(String ln) {
|
---|
| 713 | int ind = ln.indexOf("_");
|
---|
| 714 | String res = ln.substring(0, ind + 1);
|
---|
| 715 | res += ln.substring(ind + 1, ind + 2).toUpperCase();
|
---|
| 716 | res += ln.substring(ind + 2);
|
---|
| 717 | return res;
|
---|
| 718 | }
|
---|
| 719 |
|
---|
[603] | 720 | /**
|
---|
[604] | 721 | * Verify that the Edition is within a subfolder to vanilla Oni
|
---|
| 722 | * (..../Oni/Edition/AEInstaller)
|
---|
| 723 | *
|
---|
[603] | 724 | * @return true if GDF can be found in the parent's parent-path
|
---|
| 725 | */
|
---|
| 726 | public static boolean verifyRunningDirectory() {
|
---|
[604] | 727 | return Paths.getVanillaGDF().exists()
|
---|
| 728 | && Paths.getVanillaGDF().isDirectory();
|
---|
[603] | 729 | }
|
---|
[596] | 730 | }
|
---|