<commit_before>package mork.gui;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 * Tries to find the first address book of the current user on the local machine
 * and suggest the absolute path to the address book mork file.
 * 
 * @author mhaller
 */
class ProfileLocator {

	public String locateFirstThunderbirdAddressbookPath() {
		// 1. Use environment variable "APPDATA"/Thunderbird/
		String appData = System.getenv().get("APPDATA");
		if (appData == null)
		{
		   return null;
		}
		File appDataFolder = new File(appData);
		if (!appDataFolder.exists()) {
			return null;
		}
		if (!appDataFolder.isDirectory()) {
			return null;
		}
		File thunderbird = new File(appDataFolder, "Thunderbird");
		if (!thunderbird.exists()) {
			return null;
		}
		if (!thunderbird.isDirectory()) {
			return null;
		}
		File profiles = new File(thunderbird, "profiles.ini");
		if (!profiles.exists()) {
			return null;
		}
		if (!profiles.isFile()) {
			return null;
		}
		if (!profiles.canRead()) {
			return null;
		}
		Properties props = new Properties();
		try {
			props.load(new FileInputStream(profiles));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (!props.containsKey("Path")) {
			return null;
		}
		String path = (String) props.getProperty("Path");
		File firstProfileFolder = new File(thunderbird, path);
		if (!firstProfileFolder.exists()) {
			return null;
		}
		if (!firstProfileFolder.isDirectory()) {
			return null;
		}
		return firstProfileFolder.getAbsolutePath();
	}<commit_msg>make it work on linux systems<commit_after>package mork.gui;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 * Tries to find the first address book of the current user on the local machine
 * and suggest the absolute path to the address book mork file.
 * 
 * @author mhaller
 */
class ProfileLocator
{

   private File getThunderbirdDir()
   {
      // 1. Try environment variable "APPDATA"/Thunderbird/
      String appData = System.getenv().get("APPDATA");
      if (appData != null && new File(appData).exists())
      {
         File appDataFolder = new File(appData);
         if (appDataFolder.isDirectory())
         {
            File thunderbird = new File(appDataFolder, "Thunderbird");
            if (thunderbird.exists() && thunderbird.isDirectory() )
            {
               return thunderbird;
            }
         }
      }
      
      // 2. Try "<user.home>/.mozilla-thunderbird
      File userhome = new File(System.getProperty("user.home"));
      File thunderbird = new File(userhome, ".mozilla-thunderbird");
      if (thunderbird.exists() && thunderbird.isDirectory())
      {
         return thunderbird;
      }
      
      return null;
   }

   public String locateFirstThunderbirdAddressbookPath()
   {
      File thunderbird = getThunderbirdDir();
      if (thunderbird == null)
      {
         return null;
      }
      File profiles = new File(thunderbird, "profiles.ini");
      if (!profiles.exists())
      {
         return null;
      }
      if (!profiles.isFile())
      {
         return null;
      }
      if (!profiles.canRead())
      {
         return null;
      }
      Properties props = new Properties();
      try
      {
         props.load(new FileInputStream(profiles));
      }
      catch (FileNotFoundException e)
      {
         e.printStackTrace();
      }
      catch (IOException e)
      {
         e.printStackTrace();
      }
      if (!props.containsKey("Path"))
      {
         return null;
      }
      String path = (String) props.getProperty("Path");
      File firstProfileFolder = new File(thunderbird, path);
      if (!firstProfileFolder.exists())
      {
         return null;
      }
      if (!firstProfileFolder.isDirectory())
      {
         return null;
      }
      return firstProfileFolder.getAbsolutePath();
   }
{'fraction_non_alphanumeric': 0.11779081133919844, 'fraction_numerical': 0.0007331378299120235, 'mean_word_length': 2.5715532286212914, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4658256', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1194, 'n_words': 302}