<commit_before>package com.nincraft.modpackdownloader.util;

import com.google.common.base.Strings;
import com.nincraft.modpackdownloader.container.DownloadableFile;
import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;
import lombok.val;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

@Log4j2
@UtilityClass
public final class FileSystemHelper {

	private static Reference reference = Reference.getInstance();

	public static void createFolder(final String folder) {
		if (folder != null) {
			final File dir = new File(folder);
			if (!dir.exists()) {
				dir.mkdirs();
			}
		}
	}

	public static void moveFromLocalRepo(final DownloadableFile downloadableFile, final String fileName, boolean downloadToLocalRepo, String modFolder) {
		val newProjectName = getProjectNameOrDefault(downloadableFile.getName());
		String folder = downloadableFile.getFolder();
		if (Strings.isNullOrEmpty(folder)) {
			folder = modFolder;
		}
		try {
			File downloadedFile = getDownloadedFile(fileName, folder);
			if (downloadToLocalRepo) {
				FileUtils.copyFileToDirectory(getLocalFile(fileName, newProjectName), new File(folder));
			} else if (!downloadedFile.exists()) {
				FileUtils.moveFileToDirectory(getLocalFile(fileName, newProjectName), new File(folder), true);
			}
			if (!Strings.isNullOrEmpty(downloadableFile.getRename())) {
				downloadedFile.renameTo(new File(downloadedFile.getParent() + File.separator + downloadableFile.getRename()));
			}
		} catch (final IOException e) {
			log.error(String.format("Could not copy %s from local repo.", newProjectName), e);
		}
	}

	public static boolean isInLocalRepo(final String projectName, final String fileName) {
		return getLocalFile(fileName, getProjectNameOrDefault(projectName)).exists();
	}

	public static File getDownloadedFile(final String fileName, String modFolder) {
		return getDownloadedFile(fileName, null, modFolder);
	}

	private static String getProjectNameOrDefault(final String projectName) {
		return projectName != null ? projectName : "thirdParty";
	}

	public static File getLocalFile(DownloadableFile downloadableFile) {
		return getLocalFile(downloadableFile.getFileName(), downloadableFile.getName());
	}

	private static File getLocalFile(final String fileName, final String newProjectName) {
		return new File(reference.getUserhome() + newProjectName + File.separator + fileName);
	}

	private static File getDownloadedFile(String fileName, String folder, String modFolder) {
		if (folder != null) {
			createFolder(folder);
			return new File(folder + File.separator + fileName);
		} else if (modFolder != null) {
			createFolder(modFolder);
			return new File(modFolder + File.separator + fileName);
		} else {<commit_msg>Fix log message<commit_after>package com.nincraft.modpackdownloader.util;

import com.google.common.base.Strings;
import com.nincraft.modpackdownloader.container.DownloadableFile;
import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;
import lombok.val;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

@Log4j2
@UtilityClass
public final class FileSystemHelper {

	private static Reference reference = Reference.getInstance();

	public static void createFolder(final String folder) {
		if (folder != null) {
			final File dir = new File(folder);
			if (!dir.exists()) {
				dir.mkdirs();
			}
		}
	}

	public static void moveFromLocalRepo(final DownloadableFile downloadableFile, final String fileName, boolean downloadToLocalRepo, String modFolder) {
		val newProjectName = getProjectNameOrDefault(downloadableFile.getName());
		String folder = downloadableFile.getFolder();
		if (Strings.isNullOrEmpty(folder)) {
			folder = modFolder;
		}
		try {
			File downloadedFile = getDownloadedFile(fileName, folder);
			if (downloadToLocalRepo) {
				FileUtils.copyFileToDirectory(getLocalFile(fileName, newProjectName), new File(folder));
			} else if (!downloadedFile.exists()) {
				FileUtils.moveFileToDirectory(getLocalFile(fileName, newProjectName), new File(folder), true);
			}
			if (!Strings.isNullOrEmpty(downloadableFile.getRename())) {
				downloadedFile.renameTo(new File(downloadedFile.getParent() + File.separator + downloadableFile.getRename()));
			}
		} catch (final IOException e) {
			log.error("Could not copy {} from local repo.", newProjectName, e);
		}
	}

	public static boolean isInLocalRepo(final String projectName, final String fileName) {
		return getLocalFile(fileName, getProjectNameOrDefault(projectName)).exists();
	}

	public static File getDownloadedFile(final String fileName, String modFolder) {
		return getDownloadedFile(fileName, null, modFolder);
	}

	private static String getProjectNameOrDefault(final String projectName) {
		return projectName != null ? projectName : "thirdParty";
	}

	public static File getLocalFile(DownloadableFile downloadableFile) {
		return getLocalFile(downloadableFile.getFileName(), downloadableFile.getName());
	}

	private static File getLocalFile(final String fileName, final String newProjectName) {
		return new File(reference.getUserhome() + newProjectName + File.separator + fileName);
	}

	private static File getDownloadedFile(String fileName, String folder, String modFolder) {
		if (folder != null) {
			createFolder(folder);
			return new File(folder + File.separator + fileName);
		} else if (modFolder != null) {
			createFolder(modFolder);
			return new File(modFolder + File.separator + fileName);
		} else {
{'fraction_non_alphanumeric': 0.10175629187036031, 'fraction_numerical': 0.001810610175629187, 'mean_word_length': 5.498823529411765, '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': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2278208', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1599, 'n_words': 389}