Esempio n. 1
0
  private ObjectFile getDataStore(ObjectFileType filetype) throws Error {
    ObjectFile dataStore = dataStoreMap.get(filetype);
    if (dataStore != null) {
      return dataStore;
    }
    if (mapFile == null) {
      throw new Error("Mapfile not set.");
    }

    try {
      // extract unit file:
      try {
        LadikMpq editor = MpqEditorFactory.getEditor();
        File w3u = editor.extractFile(mapFile, "war3map." + filetype.getExt());
        dataStore = new ObjectFile(w3u, filetype);
      } catch (Error e) {
        dataStore = new ObjectFile(filetype);
      }
      dataStoreMap.put(filetype, dataStore);

      // clean datastore, remove all objects created by wurst
      deleteWurstObjects(dataStore);
    } catch (Exception e) {
      WLogger.severe(e);
      throw new Error(e);
    }

    return dataStore;
  }
Esempio n. 2
0
  private void writebackObjectFile(ObjectFile dataStore, ObjectFileType fileType) throws Error {
    File w3u = new File("./temp/new_war3map." + fileType.getExt());
    if (w3u.exists()) {
      w3u.delete();
    }
    dataStore.writeTo(w3u);

    try {
      Files.write(
          dataStore.exportToWurst(),
          new File("./temp/exportedObjects_" + fileType.getExt() + ".wurst"),
          Charsets.UTF_8);
    } catch (IOException e1) {
      WLogger.severe(e1);
    }

    try {
      LadikMpq editor = MpqEditorFactory.getEditor();
      String filenameInMpq = "war3map." + fileType.getExt();
      editor.deleteFile(mapFile, filenameInMpq);
      int tries = 1;
      while (tries < 20) {
        editor.insertFile(mapFile, filenameInMpq, w3u);

        File extr;
        try {
          extr = editor.extractFile(mapFile, filenameInMpq);
        } catch (Error e) {
          extr = null;
        }
        if (extr != null && extr.exists()) {
          break;
        }
        System.gc();
        tries++;
      }
      if (tries >= 20) {
        JOptionPane.showMessageDialog(null, "Could not insert " + fileType.getExt());
      }
    } catch (Exception e) {
      WLogger.severe(e);
      throw new Error(e);
    }
  }