<commit_before>package immibis.bon.mcp;

import immibis.bon.IProgressListener;
import immibis.bon.Mapping;
import immibis.bon.NameSet;
import immibis.bon.NameSet.Side;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class MappingLoader_MCP {
	
	public static class CantLoadMCPMappingException extends Exception {
		private static final long serialVersionUID = 1;
		
		public CantLoadMCPMappingException(String reason) {
			super(reason);
		}
	}
	
	
	
	@SuppressWarnings("unused")
	private final Side side;
	@SuppressWarnings("unused")
	private final String mcVer;
	private final File mcpDir;
	private final int[] sideNumbers;
	private final File srgFile, excFile;
	
	// forward: obf -> searge -> mcp
	// reverse: mcp -> searge -> obf
	private Mapping forwardSRG, reverseSRG, forwardCSV, reverseCSV;
	
	
	private Map<String, String> srgMethodDescriptors = new HashMap<>(); // SRG name -> SRG descriptor
	private Map<String, Set<String>> srgMethodOwners = new HashMap<>(); // SRG name -> SRG owners
	private Map<String, Set<String>> srgFieldOwners = new HashMap<>(); // SRG name -> SRG owners
	
	private ExcFile excFileData;
	
	public MappingLoader_MCP(String mcVer, Side side, File mcpDir, IProgressListener progress) throws IOException, CantLoadMCPMappingException {
		this.mcVer = mcVer;
		this.mcpDir = mcpDir;
		this.side = side;
		
		switch(side) {
		case UNIVERSAL:
			sideNumbers = new int[] {2, 0};
			if(new File(mcpDir, "conf/packaged.srg").exists()) {
				srgFile = new File(mcpDir, "conf/packaged.srg");
				excFile = new File(mcpDir, "conf/packaged.exc");
			} else {
				srgFile = new File(mcpDir, "conf/joined.srg");
				excFile = new File(mcpDir, "conf/joined.exc");
			}
			break;
			
		case CLIENT:
			sideNumbers = new int[] {0};
			srgFile = new File(mcpDir, "conf/client.srg");
			
			if(new File(mcpDir, "conf/joined.exc").exists())
				excFile = new File(mcpDir, "conf/joined.exc");
			else
				excFile = new File(mcpDir, "conf/client.exc");
			
			break;
			
		case SERVER:
			sideNumbers = new int[] {1};
			srgFile = new File(mcpDir, "conf/server.srg");
			
			if(new File(mcpDir, "conf/joined.exc").exists())
				excFile = new File(mcpDir, "conf/joined.exc");
			else<commit_msg>Apparently there's also things marked as side 1.<commit_after>package immibis.bon.mcp;

import immibis.bon.IProgressListener;
import immibis.bon.Mapping;
import immibis.bon.NameSet;
import immibis.bon.NameSet.Side;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class MappingLoader_MCP {
	
	public static class CantLoadMCPMappingException extends Exception {
		private static final long serialVersionUID = 1;
		
		public CantLoadMCPMappingException(String reason) {
			super(reason);
		}
	}
	
	
	
	@SuppressWarnings("unused")
	private final Side side;
	@SuppressWarnings("unused")
	private final String mcVer;
	private final File mcpDir;
	private final int[] sideNumbers;
	private final File srgFile, excFile;
	
	// forward: obf -> searge -> mcp
	// reverse: mcp -> searge -> obf
	private Mapping forwardSRG, reverseSRG, forwardCSV, reverseCSV;
	
	
	private Map<String, String> srgMethodDescriptors = new HashMap<>(); // SRG name -> SRG descriptor
	private Map<String, Set<String>> srgMethodOwners = new HashMap<>(); // SRG name -> SRG owners
	private Map<String, Set<String>> srgFieldOwners = new HashMap<>(); // SRG name -> SRG owners
	
	private ExcFile excFileData;
	
	public MappingLoader_MCP(String mcVer, Side side, File mcpDir, IProgressListener progress) throws IOException, CantLoadMCPMappingException {
		this.mcVer = mcVer;
		this.mcpDir = mcpDir;
		this.side = side;
		
		switch(side) {
		case UNIVERSAL:
			sideNumbers = new int[] {2, 1, 0};
			if(new File(mcpDir, "conf/packaged.srg").exists()) {
				srgFile = new File(mcpDir, "conf/packaged.srg");
				excFile = new File(mcpDir, "conf/packaged.exc");
			} else {
				srgFile = new File(mcpDir, "conf/joined.srg");
				excFile = new File(mcpDir, "conf/joined.exc");
			}
			break;
			
		case CLIENT:
			sideNumbers = new int[] {0};
			srgFile = new File(mcpDir, "conf/client.srg");
			
			if(new File(mcpDir, "conf/joined.exc").exists())
				excFile = new File(mcpDir, "conf/joined.exc");
			else
				excFile = new File(mcpDir, "conf/client.exc");
			
			break;
			
		case SERVER:
			sideNumbers = new int[] {1};
			srgFile = new File(mcpDir, "conf/server.srg");
			
			if(new File(mcpDir, "conf/joined.exc").exists())
				excFile = new File(mcpDir, "conf/joined.exc");
			else
{'fraction_non_alphanumeric': 0.1260905691732447, 'fraction_numerical': 0.0024927295388450354, 'mean_word_length': 3.9741735537190084, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 33, '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': '1352245', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1656, 'n_words': 417}