<commit_before>/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */

/*
  Part of the happiNES-dev project - http://github.com/cacciatc/happiNES-dev

  Copyright (c) 2011 <NAME>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package happiNESdev.app.debug;

import processing.app.Base;
import processing.app.Preferences;
import processing.app.Sketch;
import processing.app.SketchCode;
import processing.app.debug.MessageConsumer;
import processing.app.debug.MessageSiphon;
import processing.app.debug.RunnerException;
import processing.core.*;

import java.io.*;
import java.util.*;
import java.util.zip.*;

import java.nio.*;

public class Emulator implements MessageConsumer {
  static final String BUGS_URL =
    "http://github.com/cacciatc/happiNES-dev";
  static final String SUPER_BADNESS =
    "Compiler error, please submit this code to " + BUGS_URL;

  String romPath;
  String buildPath;
  Sketch sketch;
  
  Process process;
  boolean forcedStop;
  
  boolean verbose;
  boolean firstErrorFound;
  boolean secondErrorFound;

  RunnerException exception;

  public Emulator() { }

  /**
   * Emulate with vNES applet.
   *
   * @param romPath Where the rom lives!
   * @param primaryClassName the name of the combined sketch file w/ extension
   * @return true if successful.
   * @throws RunnerException Only if there's a problem. Only then.
   */
  public boolean emulate(Sketch sketch,String buildPath,String romPath, boolean verbose) 
  throws RunnerException {
    this.romPath = romPath;
    this.buildPath = buildPath;
    this.verbose = verbose;
    this.sketch = sketch;

    forcedStop = false;
    // create a custom html harness
    String harnessPath = pullAndUpdateHarness(romPath);
    
    // run vNES
    execAsynchronously(getCommandEmulatorString(harnessPath));
   
    return true;
  }
  
  public String pullAndUpdateHarness(String romPath)
  throws RunnerException{
	  // copy the base-harness into build directory
	  String baseHarnessPath = Base.getEmulatorPath() + File.separator + "base-harness.html";
	  String harnessPath = "test." + "happiNES-dev" + ".html";
	  File harnessFile = new File(buildPath, harnessPath);
	  try{
		  // hack due to classpath tom-foolery in the applet
		  Base.copyDir(new File(Base.getEmulatorPath(),""),new File(buildPath,""));
	  }
	  catch (IOException e) {
	    	e.printStackTrace();
	    	throw new RunnerException("Problem moving " + harnessPath + " to the build folder");
	  }
	  // should just modify the base harness, but for now will rewrite it....string manip is a pain in java.
	  try{ 
		  PrintWriter pwr = new PrintWriter(new FileWriter(harnessFile.getAbsolutePath()));
		  pwr.println("<html>");
		  pwr.println("<applet code=\"vNES.class\" archive=\"vNES-213.jar\" width=\"512\" height=\"480\">");<commit_msg>removed dependency on appletviewer for now.<commit_after>/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */

/*
  Part of the happiNES-dev project - http://github.com/cacciatc/happiNES-dev

  Copyright (c) 2011 <NAME>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package happiNESdev.app.debug;

import processing.app.Base;
import processing.app.Preferences;
import processing.app.Sketch;
import processing.app.SketchCode;
import processing.app.debug.MessageConsumer;
import processing.app.debug.MessageSiphon;
import processing.app.debug.RunnerException;
import processing.core.*;

import java.io.*;
import java.util.*;
import java.util.zip.*;

import java.net.MalformedURLException;
import java.net.URL;
import java.nio.*;

public class Emulator implements MessageConsumer {
  static final String BUGS_URL =
    "http://github.com/cacciatc/happiNES-dev";
  static final String SUPER_BADNESS =
    "Compiler error, please submit this code to " + BUGS_URL;

  String romPath;
  String buildPath;
  Sketch sketch;
  
  Process process;
  boolean forcedStop;
  
  boolean verbose;
  boolean firstErrorFound;
  boolean secondErrorFound;

  RunnerException exception;

  public Emulator() { }

  /**
   * Emulate with vNES applet.
   *
   * @param romPath Where the rom lives!
   * @param primaryClassName the name of the combined sketch file w/ extension
   * @return true if successful.
   * @throws RunnerException Only if there's a problem. Only then.
   */
  public boolean emulate(Sketch sketch,String buildPath,String romPath, boolean verbose) 
  throws RunnerException {
    this.romPath = romPath;
    this.buildPath = buildPath;
    this.verbose = verbose;
    this.sketch = sketch;

    forcedStop = false;
    // create a custom html harness
    String harnessPath = pullAndUpdateHarness(romPath);
    
    // run vNES
    //execAsynchronously(getCommandEmulatorString(harnessPath));
    Base.openURL(harnessPath);
   
    return true;
  }
  
  public String pullAndUpdateHarness(String romPath)
  throws RunnerException{
	  // copy the base-harness into build directory
	  String baseHarnessPath = Base.getEmulatorPath() + File.separator + "base-harness.html";
	  String harnessPath = "test." + "happiNES-dev" + ".html";
	  File harnessFile = new File(buildPath, harnessPath);
	  try{
		  // hack due to classpath tom-foolery in the applet
		  Base.copyDir(new File(Base.getEmulatorPath(),""),new File(buildPath,""));
	  }
	  catch (IOException e) {
	    	e.printStackTrace();
	    	throw new RunnerException("Problem moving " + harnessPath + " to the build folder");
	  }
	  // should just modify the base harness, but for now will rewrite it....string manip is a pain in java.
	  try{ 
		  PrintWriter pwr = new PrintWriter(new FileWriter(harnessFile.getAbsolutePath()));
		  pwr.println("<html>");
		  pwr.println("<applet code=\"vNES.class\" archive=\"vNES-213.jar\" width=\"512\" height=\"480\">");
{'fraction_non_alphanumeric': 0.09493401447424436, 'fraction_numerical': 0.00823045267489712, 'mean_word_length': 3.6892880904856953, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '516896', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2022, 'n_words': 703}