package de.lazyzero.kkMulticopterFlashTool.utils;

import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class SendLogFile {
	private Desktop desktop;

	public SendLogFile() {
		if (Desktop.isDesktopSupported()) {
	        desktop = Desktop.getDesktop();
		}
		
		
	}
	
	public boolean sendMail(String version, File file)  {
		String filecontent = "";
		
		try {
			FileReader fr = new FileReader(file);
			int c;
			while((c = fr.read())!=-1) {
				filecontent=filecontent.concat(((char)c)+"");
			}
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		try {
			URI mailtoURI = new URI("mailto", "christian@chrmoll.de?SUBJECT=KKmulticopterFlashTool: "+version+"&BODY=" + filecontent, null);
			desktop.mail(mailtoURI);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
		return true;
	}
	
	public static void main (String args[]) {
		SendLogFile slf = new SendLogFile();
		slf.sendMail("0.20", new File("kkLogging.txt"));
	}
}
