Exemple #1
0
  private static <T extends W3OBase<?>> T loadW3OFile(
      final Class<T> cls,
      final MPQArchive map,
      final String archivedFile,
      final File file,
      final WTSFile wts)
      throws Exception {
    T w3o;
    if (map.hasFile(archivedFile)) {
      Log.info("Found " + archivedFile);
      map.extractFile(archivedFile, file);

      w3o = cls.getConstructor(String.class, WTSFile.class).newInstance(file.getPath(), wts);
    } else {
      w3o = cls.getConstructor(WTSFile.class).newInstance(wts);
    }
    return w3o;
  }
Exemple #2
0
  private ObjectDataExtractor(final String odeFolderPath, final String mapPath) throws Exception {
    Log.entry(odeFolderPath, mapPath);
    final MPQArchive map = new MPQArchive(mapPath);

    final File odeFolder = new File(odeFolderPath);
    final File jFile = new File(odeFolder, FILE_NAME_SCRIPT);
    final File wtsFile = new File(odeFolder, FILE_NAME_WTS);
    final File w3uFile = new File(odeFolder, FILE_NAME_W3U);
    final File w3tFile = new File(odeFolder, FILE_NAME_W3T);
    final File w3bFile = new File(odeFolder, FILE_NAME_W3B);

    map.extractFile(FILE_NAME_SCRIPT, jFile);
    map.extractFile(FILE_NAME_WTS, wtsFile);

    Log.info("Loading JASS into memory");
    String scriptContent = readFileToString(jFile.getPath(), StandardCharsets.UTF_8);
    Log.info("Loading WTS from file");
    final WTSFile wts = new WTSFile(wtsFile.getPath());

    final List<Extractor<?, ?>> extractors = new LinkedList<Extractor<?, ?>>();

    // -------------------------------------------------------
    // Unit Data Extractor
    extractors.add(
        new UnitDataExtractor(
            odeFolder, loadW3OFile(W3UFile.class, map, FILE_NAME_W3U, w3uFile, wts)));

    // -------------------------------------------------------
    // Item Data Extractor
    extractors.add(
        new ItemDataExtractor(
            odeFolder, loadW3OFile(W3TFile.class, map, FILE_NAME_W3T, w3tFile, wts)));

    // -------------------------------------------------------
    // Destructable Data Extractor
    extractors.add(
        new DestructableDataExtractor(
            odeFolder, loadW3OFile(W3BFile.class, map, FILE_NAME_W3B, w3bFile, wts)));

    for (final Extractor<?, ?> extractor : extractors) {
      scriptContent = extractor.processScript(scriptContent);
    }

    Log.info("Writing new script file to disk");
    final FileWriter fw = new FileWriter(jFile);
    fw.write(scriptContent);
    fw.close();

    Log.info("Replacing script file in map");
    final MPQFile file = new MPQFile(map, FILE_NAME_SCRIPT, MPQFileOpenScope.MPQ);
    file.removeFromArchive();
    file.close();

    final MPQCompressionFlags compr = new MPQCompressionFlags();
    compr.setCompression(Compression.BZIP2);

    map.addFile(jFile.getAbsolutePath(), FILE_NAME_SCRIPT, MPQFileFlags.fromInteger(0x200), compr);
    map.compactArchive((String) null);
    map.close();

    Log.exit();
  }