Fix for Bug 157687 Assertion failed applying patch
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java
index 740ce77..0e05fae 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java
@@ -79,7 +79,10 @@
 		
 		addPage(fPatchWizardPage= new InputPatchPage(this));
 		addPage(new PatchTargetPage(this));
-		addPage(new PreviewPatchPage2(this));
+		if (System.getProperty("oldPatch") != null) //$NON-NLS-1$
+			addPage(new PreviewPatchPage(this));
+		else
+			addPage(new PreviewPatchPage2(this));
 	}
 	
 	/* (non-Javadoc)
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatcherCompareEditorInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatcherCompareEditorInput.java
index 00b17cc..a8d53b5 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatcherCompareEditorInput.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatcherCompareEditorInput.java
@@ -330,17 +330,26 @@
 						Object obj = iter.next();
 						if (obj instanceof Diff) {
 							Diff diff = (Diff) obj;
-							IFile tempFile = projects[i].getFile(new Path(diff.getLabel(diff)));
+							IPath filePath = new Path(diff.getLabel(diff));
+							IFile tempFile = projects[i].getFile(filePath);
 							byte[] bytes = quickPatch(tempFile, patcher, diff);
 							int differencer = Differencer.CHANGE;
 							if (failedHunks.size() != 0) {
 								differencer += Differencer.CONFLICTING;
 							}
-							if (!tempFile.exists())
-								tempFile = null;
 							
-							ResourceNode tempNode = new ResourceNode(tempFile);
-							PatchedFileNode patchedNode = new PatchedFileNode(bytes, tempNode.getType(), tempFile.getProjectRelativePath().toString());
+							ITypedElement tempNode;
+							PatchedFileNode patchedNode;
+							
+							if (tempFile != null && tempFile.exists()){
+								tempNode = new ResourceNode(tempFile);
+								patchedNode = new PatchedFileNode(bytes, tempNode.getType(), tempFile.getProjectRelativePath().toString());
+							}
+							else{ 
+								tempNode = new PatchedFileNode(new byte[0], filePath.getFileExtension(), PatchMessages.PatcherCompareEditorInput_FileNotFound);
+								patchedNode = new PatchedFileNode(bytes, tempNode.getType(), ""); //$NON-NLS-1$
+							}
+						
 							MyDiffNode allFile = new MyDiffNode(projectNode, differencer, tempNode, tempNode, patchedNode, diff);
 							//Add individual hunks to each Diff node
 							Hunk[] hunks = diff.getHunks();
@@ -414,7 +423,7 @@
 					ITypedElement tempNode;
 					PatchedFileNode patchedNode;
 					
-					if (tempFile != null){
+					if (tempFile != null && tempFile.exists()){
 						tempNode = new ResourceNode(tempFile);
 						patchedNode = new PatchedFileNode(bytes, tempNode.getType(), tempFile.getProjectRelativePath().toString());
 					}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java
index 740ce77..0e05fae 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatchWizard.java
@@ -79,7 +79,10 @@
 		
 		addPage(fPatchWizardPage= new InputPatchPage(this));
 		addPage(new PatchTargetPage(this));
-		addPage(new PreviewPatchPage2(this));
+		if (System.getProperty("oldPatch") != null) //$NON-NLS-1$
+			addPage(new PreviewPatchPage(this));
+		else
+			addPage(new PreviewPatchPage2(this));
 	}
 	
 	/* (non-Javadoc)
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatcherCompareEditorInput.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatcherCompareEditorInput.java
index 00b17cc..a8d53b5 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatcherCompareEditorInput.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PatcherCompareEditorInput.java
@@ -330,17 +330,26 @@
 						Object obj = iter.next();
 						if (obj instanceof Diff) {
 							Diff diff = (Diff) obj;
-							IFile tempFile = projects[i].getFile(new Path(diff.getLabel(diff)));
+							IPath filePath = new Path(diff.getLabel(diff));
+							IFile tempFile = projects[i].getFile(filePath);
 							byte[] bytes = quickPatch(tempFile, patcher, diff);
 							int differencer = Differencer.CHANGE;
 							if (failedHunks.size() != 0) {
 								differencer += Differencer.CONFLICTING;
 							}
-							if (!tempFile.exists())
-								tempFile = null;
 							
-							ResourceNode tempNode = new ResourceNode(tempFile);
-							PatchedFileNode patchedNode = new PatchedFileNode(bytes, tempNode.getType(), tempFile.getProjectRelativePath().toString());
+							ITypedElement tempNode;
+							PatchedFileNode patchedNode;
+							
+							if (tempFile != null && tempFile.exists()){
+								tempNode = new ResourceNode(tempFile);
+								patchedNode = new PatchedFileNode(bytes, tempNode.getType(), tempFile.getProjectRelativePath().toString());
+							}
+							else{ 
+								tempNode = new PatchedFileNode(new byte[0], filePath.getFileExtension(), PatchMessages.PatcherCompareEditorInput_FileNotFound);
+								patchedNode = new PatchedFileNode(bytes, tempNode.getType(), ""); //$NON-NLS-1$
+							}
+						
 							MyDiffNode allFile = new MyDiffNode(projectNode, differencer, tempNode, tempNode, patchedNode, diff);
 							//Add individual hunks to each Diff node
 							Hunk[] hunks = diff.getHunks();
@@ -414,7 +423,7 @@
 					ITypedElement tempNode;
 					PatchedFileNode patchedNode;
 					
-					if (tempFile != null){
+					if (tempFile != null && tempFile.exists()){
 						tempNode = new ResourceNode(tempFile);
 						patchedNode = new PatchedFileNode(bytes, tempNode.getType(), tempFile.getProjectRelativePath().toString());
 					}