package uk.ac.ed.inf.Metabolic.sbmlexport;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

public class LibSBMLConfigManager {
	
	private static boolean isWindows() {
		return System.getProperty("os.name").indexOf("Win") != -1;
	}

	private static String getPath() throws Exception {
		InputStream is = LibSBMLConfigManager.class.getResourceAsStream("PathToNativeSBMLLibraries.setUp");
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		String rc = br.readLine();
		return rc;
       
	}
	/**
	 * 
	 * @return true if sbml libraries loaded ok
	 * @throws Exception 
	 */
	static boolean configure () throws Exception {
		try {
		String path = getPath();
    	if(isWindows()) {
    	      System.load(path + "os/win32/sbmlj.dll");
    	      return true;
    	} else {
    		return false;
    	}
		}catch (Exception e) {
			return false;
		}
  
	}
}

@@ -108,27 +108,22 @@
 .io.File
-InputStream
+Writer
 ;%0Aimport
@@ -135,18 +135,19 @@
 .io.
-FileReader
+IOException
 ;%0Aim
@@ -209,37 +209,8 @@
 der;
-%0Aimport java.util.Properties;
 %0A%0Apu
@@ -346,16 +346,57 @@
 = -1;%0A%09%7D
+%0A%09static int i;%0A%09static boolean isLoaded;
 %0A%0A%09priva
@@ -907,16 +907,41 @@
 .dll%22);%0A
+    %09      markLoaded();%0A
     %09   
@@ -956,16 +956,23 @@
 n true;%0A
+    %09%09%0A
     %09%7D e
@@ -1050,16 +1050,290 @@
 se;%0A%09%09%7D%0A
-
   %0A%09%7D%0A
+%09private static void markLoaded() throws IOException%7B%0A%09%09FileWriter fw = new FileWriter(new File (%22./sbmlLoaded%22));%0A%09%09fw.write(%221%22);%0A%09%09fw.close();%0A%09%09%0A%09%7D%0A%09%0A%09private static boolean isLoaded() throws IOException%7B%0A%09%09File f = new File (%22./sbmlLoaded%22);%0A%09%09return f.exists();%0A%09%09%0A%09%7D%0A
 %7D%0A

load libSBML each test