<commit_before>package net.hearthstats;

import net.hearthstats.config.Environment;
import net.hearthstats.config.OS;
import net.hearthstats.log.Log;
import net.hearthstats.updater.api.GitHubReleases;
import net.hearthstats.updater.api.model.Release;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import java.io.File;
import java.net.URI;


public final class Updater {
	private Updater() {} // never instantiated

  public static final String MANUAL_DOWNLOAD_URL = "http://hearthstats.net/uploader";

  private final static Logger debugLog = LoggerFactory.getLogger(Updater.class);

  private static Release cachedlatestRelease;


  public static Release getLatestRelease() {
    if (cachedlatestRelease == null) {
      try {
        debugLog.debug("Loading latest release information from GitHub");
        if (Config.os == OS.OSX) {
          cachedlatestRelease = GitHubReleases.getLatestReleaseForOSX();
        } else if (Config.os == OS.WINDOWS) {
          cachedlatestRelease = GitHubReleases.getLatestReleaseForWindows();
        }
        if (cachedlatestRelease == null) {
          Log.warn("Unable to check latest release of HearthStats Uploader");
        }
      } catch (Exception e) {
        Log.warn("Unable to check latest release of HearthStats Uploader due to error: " + e.getMessage(), e);
      }
    }
    return cachedlatestRelease;
  }


  public static void run(Environment environment, Release release) {
    Log.info("Extracting and running updater ...");

    String errorMessage = null;
    try {
      errorMessage = environment.performApplicationUpdate(release);
    } catch (Exception e) {
      debugLog.warn("Unable to run updater", e);
      if (errorMessage == null) {
        errorMessage = e.getMessage();
      }
    }

    if (errorMessage == null) {
      // There was no error, so the updater should be running now
      System.exit(0);

    } else {
      // There was an error
      Main.showMessageDialog(null, errorMessage + "\n\nYou will now be taken to the download page.");
      try {
        Desktop.getDesktop().browse(new URI(MANUAL_DOWNLOAD_URL));
      } catch (Exception e) {
        Main.showErrorDialog("Error launching browser with URL " + MANUAL_DOWNLOAD_URL, e);
      }
      Log.warn("Updater Error: " + errorMessage);
    }


  }


  public static void cleanUp() {
		removeFile(Config.getExtractionFolder() + "/updater.jar");
		removeFile(Config.getExtractionFolder() + "/update.zip");
	}


	private static void removeFile(String path) {
		File file = new File(path);
		if (file.isFile()) {
			file.delete();
		}
	}

}<commit_msg>Update files downloaded by the updater are now deleted on startup.<commit_after>package net.hearthstats;

import net.hearthstats.config.Environment;
import net.hearthstats.config.OS;
import net.hearthstats.log.Log;
import net.hearthstats.updater.api.GitHubReleases;
import net.hearthstats.updater.api.model.Release;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import java.io.File;
import java.io.FileFilter;
import java.net.URI;


public final class Updater {
	private Updater() {} // never instantiated

  public static final String MANUAL_DOWNLOAD_URL = "http://hearthstats.net/uploader";

  private final static Logger debugLog = LoggerFactory.getLogger(Updater.class);

  private static Release cachedlatestRelease;


  public static Release getLatestRelease() {
    if (cachedlatestRelease == null) {
      try {
        debugLog.debug("Loading latest release information from GitHub");
        if (Config.os == OS.OSX) {
          cachedlatestRelease = GitHubReleases.getLatestReleaseForOSX();
        } else if (Config.os == OS.WINDOWS) {
          cachedlatestRelease = GitHubReleases.getLatestReleaseForWindows();
        }
        if (cachedlatestRelease == null) {
          Log.warn("Unable to check latest release of HearthStats Uploader");
        }
      } catch (Exception e) {
        Log.warn("Unable to check latest release of HearthStats Uploader due to error: " + e.getMessage(), e);
      }
    }
    return cachedlatestRelease;
  }


  public static void run(Environment environment, Release release) {
    Log.info("Extracting and running updater ...");

    String errorMessage = null;
    try {
      errorMessage = environment.performApplicationUpdate(release);
    } catch (Exception e) {
      debugLog.warn("Unable to run updater", e);
      if (errorMessage == null) {
        errorMessage = e.getMessage();
      }
    }

    if (errorMessage == null) {
      // There was no error, so the updater should be running now
      System.exit(0);

    } else {
      // There was an error
      Main.showMessageDialog(null, errorMessage + "\n\nYou will now be taken to the download page.");
      try {
        Desktop.getDesktop().browse(new URI(MANUAL_DOWNLOAD_URL));
      } catch (Exception e) {
        Main.showErrorDialog("Error launching browser with URL " + MANUAL_DOWNLOAD_URL, e);
      }
      Log.warn("Updater Error: " + errorMessage);
    }


  }


  public static void cleanUp() {
    removeFile(Config.getExtractionFolder(), "updater.jar");
    removeFile(Config.getExtractionFolder(), "update-*.zip");
	}


  /**
   * Deletes a file or files in the given path.
   * @param path The path where the file or files are located.
   * @param filename The file or files to delete. Accepts wildcards * and ?.
   */
	private static void removeFile(String path, String filename) {
    debugLog.debug("Deleting {}/{}", path, filename);
    File dir = new File(path);
    FileFilter fileFilter = new WildcardFileFilter(filename);
    File[] files = dir.listFiles(fileFilter);
    for (File file : files) {
      debugLog.info("Deleting file {}", file.getAbsolutePath());
      file.delete();
    }
	}

}
{'fraction_non_alphanumeric': 0.10940433521078682, 'fraction_numerical': 0.0010240655401945725, 'mean_word_length': 3.170818505338078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '821393', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1694, 'n_words': 456}