package info.ajaxplorer.client.util;

import java.io.File;
import java.io.IOException;

public class RdiffProcessor {

	private String rdiffPath = "G:\\PROGRAMS\\rdiff\\rdiff.exe";
	
	public static boolean rdiffEnabled(){
		return true;
	}
	
	public RdiffProcessor(){
		
	}
	
	public void signature(File source, File signature){
		try {
			String[] command = {rdiffPath, "signature", "\""+source.getCanonicalPath()+"\"", "\""+signature.getCanonicalPath()+"\""};
			Process p = Runtime.getRuntime().exec(command);
			int exitValue = p.waitFor();
			//System.out.println("Process exitValue: " + exitValue);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public void delta(File signature, File source, File delta){
		try {
			String[] cmd = {
					rdiffPath, 
					"delta", 
					"\""+signature.getCanonicalPath()+"\"",
					"\""+source.getCanonicalPath()+"\"",
					"\""+delta.getCanonicalPath()+"\""
				};
			Process p = Runtime.getRuntime().exec(cmd);
			int exitValue = p.waitFor();
			//System.out.println("Process exitValue: " + exitValue);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public void patch(File source, File delta, File target){
		try {
			String[] cmd = {
					rdiffPath, 
					"patch", 
					"\""+source.getCanonicalPath()+"\"",
					"\""+delta.getCanonicalPath()+"\"",
					"\""+target.getCanonicalPath()+"\""
				};
			Process p = Runtime.getRuntime().exec(cmd);
			int exitValue = p.waitFor();
			//System.out.println("Process exitValue: " + exitValue);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
}

@@ -33,16 +33,48 @@
 til;%0D%0A%0D%0A
+import java.io.BufferedReader;%0D%0A
 import j
@@ -115,16 +115,51 @@
 eption;%0D
+%0Aimport java.io.InputStreamReader;%0D
 %0A%0D%0Apubli
@@ -215,43 +215,47 @@
 Path
- = %22G:%5C%5CPROGRAMS%5C%5Crdiff%5C%5Crdiff.exe%22
+;%0D%0A%09private boolean testEnabled = false
 ;%0D%0A%09
@@ -268,15 +268,8 @@
 lic 
-static 
 bool
@@ -303,11 +303,18 @@
 rn t
-rue
+estEnabled
 ;%0D%0A%09
@@ -346,18 +346,657 @@
 sor(
-)%7B%0D%0A%09%09%0D%0A%09%7D
+String path)%7B%0D%0A%09%09rdiffPath = path;%0D%0A%09%09try%7B%0D%0A%09%09%09testEnabled = testCommand();%0D%0A%09%09%7Dcatch(Exception e)%7B%0D%0A%09%09%09testEnabled = false;%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%09%0D%0A%09protected boolean testCommand() throws IOException, InterruptedException%7B%0D%0A%09%09%0D%0A%09%09String line;%0D%0A%09%09StringBuilder sb = new StringBuilder();%0D%0A%09%09Process p = Runtime.getRuntime().exec(rdiffPath);%0D%0A%09%09BufferedReader bri = new BufferedReader(new InputStreamReader(p.getErrorStream()));%0D%0A%09%09while ((line = bri.readLine()) != null) %7B%0D%0A%09%09%09sb.append(line);%0D%0A%09%09%7D%0D%0A%09%09bri.close();%0D%0A%09%09p.waitFor();%0D%0A%09%09String s = sb.toString();%0D%0A%09%09return (s.indexOf(%22signature%22) %3E -1 && s.indexOf(%22patch%22) %3E -1 && s.indexOf(%22delta%22) %3E -1);%0D%0A%09%7D%0D%0A%09
 %0D%0A%09%0D

Change rdiff proc initialisation