package edu.oregonstate.cope.eclipse.installer;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public abstract class InstallerOperation {

	protected Path workspaceDirectory;
	protected Path permanentDirectory;

	public InstallerOperation(Path workspaceDirectory, Path permanentDirectory) {
		this.permanentDirectory = permanentDirectory;
		this.workspaceDirectory = workspaceDirectory;
	}

	public void perform() throws IOException {
		String fileName = getFileName();
		File workspaceFile = workspaceDirectory.resolve(fileName).toFile();
		File permanentFile = permanentDirectory.resolve(fileName).toFile();

		if (workspaceFile.exists() && permanentFile.exists()) {
			// System.out.println(this.getClass() + " both files exist");
			doBothFilesExists();
		}

		else if (!workspaceFile.exists() && permanentFile.exists()) {
			// System.out.println(this.getClass() + " only permanent");
			doOnlyPermanentFileExists(workspaceFile, permanentFile);
		}

		else if (workspaceFile.exists() && !permanentFile.exists()) {
			// System.out.println(this.getClass() + " only workspace");
			doOnlyWorkspaceFileExists(workspaceFile, permanentFile);
		}

		else if (!workspaceFile.exists() && !permanentFile.exists()) {
			// System.out.println(this.getClass() + " neither files exist");
			doNoFileExists(workspaceFile, permanentFile);
		}
	}

	protected void doOnlyWorkspaceFileExists(File workspaceFile, File permanentFile) throws IOException {
		Files.copy(workspaceFile.toPath(), permanentFile.toPath());
	}

	protected void doOnlyPermanentFileExists(File workspaceFile, File permanentFile) throws IOException {
		Files.copy(permanentFile.toPath(), workspaceFile.toPath());
	}

	protected void doBothFilesExists() {
	}

	protected abstract void doNoFileExists(File workspaceFile, File permanentFile) throws IOException;
	
	protected abstract String getFileName();

	protected void writeContentsToFile(Path filePath, String fileContents) throws IOException {
		Files.write(filePath, fileContents.getBytes(), StandardOpenOption.CREATE);
	}
}
@@ -188,16 +188,76 @@
 ption;%0A%0A
+import edu.oregonstate.cope.clientRecorder.RecorderFacade;%0A%0A
 public a
@@ -363,16 +363,58 @@
 rectory;
+%0A%09protected RecorderFacade recorderFacade;
 %0A%0A%09publi
@@ -486,16 +486,16 @@
 tory) %7B%0A
-
 %09%09this.p
@@ -580,24 +580,266 @@
 irectory;%0A%09%7D
+%0A%09%0A%09public void init(RecorderFacade recorderFacade, Path permanentDiretory, Path workspaceDirectory)%7B%0A%09%09this.recorderFacade = recorderFacade;%0A%09%09%0A%09%09this.permanentDirectory = permanentDiretory;%0A%09%09this.workspaceDirectory = workspaceDirectory;%0A%09%7D
 %0A%0A%09public vo

Add init method This is required for those challenged call sites who require a 0 arg constructor. And to pass in things that would otherwise require IDE specific knowledge to get.