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