示例#1
0
  /** Starts BSPSource */
  public void run() {
    // some benchmarking
    long startTime = System.currentTimeMillis();

    // log all config fields in debug mode
    if (config.isDebug()) {
      config.dumpToLog();
    }

    // acquire list of files
    Set<BspFileEntry> entries = config.getFileSet();

    if (entries.isEmpty()) {
      L.severe("No BSP files found");
    } else {
      for (BspFileEntry entry : entries) {
        try {
          decompile(entry);
          System.gc(); // try to free some resources
        } catch (Exception ex) {
          // likely to be a critical error, but maybe it will work
          // with other files
          L.log(Level.SEVERE, "Decompiling error", ex);
        }
      }

      // get total execution time
      double duration = (System.currentTimeMillis() - startTime) / 1000.0;
      L.log(
          Level.INFO,
          "Processed {0} file(s) in {1} seconds",
          new Object[] {entries.size(), String.format("%.4f", duration)});
    }
  }
示例#2
0
  /** Starts the decompiling process */
  private void decompile(BspFileEntry entry) {
    File bspFile = entry.getBspFile();
    File vmfFile = entry.getVmfFile();

    // load BSP
    BspFileReader reader;

    try {
      BspFile bsp = new BspFile();
      bsp.setSourceApp(config.defaultApp);
      bsp.load(bspFile);

      if (config.loadLumpFiles) {
        bsp.loadLumpFiles();
      }

      // extract embedded files
      if (config.unpackEmbedded) {
        try {
          bsp.getPakFile().extract(entry.getPakDir());
        } catch (IOException ex) {
          L.log(Level.WARNING, "Can't extract embedded files", ex);
        }
      }

      reader = new BspFileReader(bsp);
      reader.loadAll();

      L.log(Level.INFO, "Loaded {0}", bspFile);
    } catch (IOException ex) {
      L.log(Level.SEVERE, "Can't load " + bspFile, ex);
      return;
    }

    if (!config.isDebug()) {
      L.log(Level.INFO, "BSP version: {0}", reader.getBspFile().getVersion());
      L.log(Level.INFO, "Game: {0}", reader.getBspFile().getSourceApp());
    }

    // create VMF
    VmfWriter writer;

    try {
      // write to file or omit output?
      if (config.nullOutput) {
        writer = new VmfWriter(new NullOutputStream());
      } else {
        writer = new VmfWriter(vmfFile);
      }
      L.log(Level.INFO, "Opened {0}", vmfFile);
    } catch (IOException ex) {
      L.log(Level.SEVERE, "Can't write " + vmfFile, ex);
      return;
    }

    try {
      // create and configure decompiler, then start decompiling
      BspDecompiler decompiler = new BspDecompiler(reader, writer, config);
      decompiler.setComment("Decompiled by BSPSource v" + VERSION + " from " + bspFile.getName());
      decompiler.start();
    } finally {
      // "Cave Johnson, we're done here."
      IOUtils.closeQuietly(writer);
      L.log(Level.INFO, "Closed {0}", vmfFile);
      L.log(Level.INFO, "Finished {0}", bspFile);
    }
  }