// Path: src/main/java/de/hartz/vpn/helper/OutputStreamHandler.java
// public class OutputStreamHandler extends Thread {
//     private InputStream inputStream;
//     private Logger listener;
//     private StringBuilder output = new StringBuilder();
// 
//     public OutputStreamHandler(InputStream inputStream) {
//         this.inputStream = inputStream;
//     }
// 
//     public OutputStreamHandler(InputStream inputStream, Logger listener) {
//         this.listener = listener;
//         this.inputStream = inputStream;
//     }
// 
//     public void run() {
//         try (Scanner br = new Scanner(new InputStreamReader(inputStream))) {
//             String line;
//             while (br.hasNextLine()) {
//                 line = br.nextLine();
//                 output.append(line).append(System.getProperty("line.separator"));
//                 if (listener != null)
//                     listener.addLogLine(line);
//             }
//         }
//     }
// 
//     public StringBuilder getOutput() {
//         /*
//         TODO: Check if this works always.
//         try {
//             inputStream.close();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }*/
//         return output;
//     }
// }


import de.hartz.vpn.helper.OutputStreamHandler;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
package de.hartz.vpn.utilities;



/**
 * Created by kaiha on 31.08.2017.
 */
public final class OpenVPNUtilities {

    //TODO: If possible get rid off..
    // @Windows
    public static String openVPNBinPath;

    /**
     * TODO: TIDY UP!!!! MODULARIZE.
     * TODO: Get working under linux?! And maybe same concept to find openssl?
     * Finds the installation path of openvpn through the environment variables.
     * @return The installation path or null if not found.
     */
    public static String getOpenVPNInstallationPath() {
        if (GeneralUtilities.isWindows()) {
            String findValue = "OpenVPN";

            // After installations getenv() returns old values, missing openvpn...
            // HACK AROUND THIS;
            // https://stackoverflow.com/questions/10434065/how-to-retrieve-the-modified-value-of-an-environment-variable-which-is-modified
            ProcessBuilder pb = new ProcessBuilder( "cmd.exe");
            pb.redirectErrorStream(true);
            Process process = null;
            try {
                process = pb.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
// Path: src/main/java/de/hartz/vpn/helper/OutputStreamHandler.java
// public class OutputStreamHandler extends Thread {
//     private InputStream inputStream;
//     private Logger listener;
//     private StringBuilder output = new StringBuilder();
// 
//     public OutputStreamHandler(InputStream inputStream) {
//         this.inputStream = inputStream;
//     }
// 
//     public OutputStreamHandler(InputStream inputStream, Logger listener) {
//         this.listener = listener;
//         this.inputStream = inputStream;
//     }
// 
//     public void run() {
//         try (Scanner br = new Scanner(new InputStreamReader(inputStream))) {
//             String line;
//             while (br.hasNextLine()) {
//                 line = br.nextLine();
//                 output.append(line).append(System.getProperty("line.separator"));
//                 if (listener != null)
//                     listener.addLogLine(line);
//             }
//         }
//     }
// 
//     public StringBuilder getOutput() {
//         /*
//         TODO: Check if this works always.
//         try {
//             inputStream.close();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }*/
//         return output;
//     }
// }


// Path: src/main/java/de/hartz/vpn/utilities/OpenVPNUtilities.java
import de.hartz.vpn.helper.OutputStreamHandler;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

package de.hartz.vpn.utilities;



/**
 * Created by kaiha on 31.08.2017.
 */
public final class OpenVPNUtilities {

    //TODO: If possible get rid off..
    // @Windows
    public static String openVPNBinPath;

    /**
     * TODO: TIDY UP!!!! MODULARIZE.
     * TODO: Get working under linux?! And maybe same concept to find openssl?
     * Finds the installation path of openvpn through the environment variables.
     * @return The installation path or null if not found.
     */
    public static String getOpenVPNInstallationPath() {
        if (GeneralUtilities.isWindows()) {
            String findValue = "OpenVPN";

            // After installations getenv() returns old values, missing openvpn...
            // HACK AROUND THIS;
            // https://stackoverflow.com/questions/10434065/how-to-retrieve-the-modified-value-of-an-environment-variable-which-is-modified
            ProcessBuilder pb = new ProcessBuilder( "cmd.exe");
            pb.redirectErrorStream(true);
            Process process = null;
            try {
                process = pb.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
            OutputStreamHandler outputHandler = new OutputStreamHandler(process.getInputStream());