Index: src/winhugs/installer/FileCode.cpp
===================================================================
RCS file: /cvs/hugs98/src/winhugs/installer/FileCode.cpp,v
retrieving revision 1.1
diff -u -r1.1 FileCode.cpp
--- src/winhugs/installer/FileCode.cpp	6 Oct 2005 11:18:43 -0000	1.1
+++ src/winhugs/installer/FileCode.cpp	12 Oct 2005 09:52:09 -0000
@@ -1,5 +1,14 @@
 #include "Header.h"
 
+struct FolderItem
+{
+	char* Folder;
+	FolderItem* Next;
+};
+
+FolderItem* CreatedFolders = NULL;
+
+
 bool Exists(char* File)
 {
 	return (GetFileAttributes(File) != 0xffffffff);
@@ -60,7 +69,27 @@
 		if (!Res) return false;
 	}
 
-	return (CreateDirectory(File, NULL) != 0);
+	bool Res = (CreateDirectory(File, NULL) != 0);
+	if (Res)
+	{
+		FolderItem* tmp = CreatedFolders;
+		CreatedFolders = new FolderItem;
+		CreatedFolders->Folder = strdup(File);
+		CreatedFolders->Next = tmp;
+	}
+	return Res;
+}
+
+void DeleteFolders()
+{
+	while (CreatedFolders != NULL)
+	{
+		RemoveDirectory(CreatedFolders->Folder);
+		free(CreatedFolders->Folder);
+		FolderItem* i = CreatedFolders;
+		CreatedFolders = CreatedFolders->Next;
+		delete i;
+	}
 }
 
 void FileSize(__int64 Size, char* Buffer)
Index: src/winhugs/installer/FileCode.h
===================================================================
RCS file: /cvs/hugs98/src/winhugs/installer/FileCode.h,v
retrieving revision 1.1
diff -u -r1.1 FileCode.h
--- src/winhugs/installer/FileCode.h	6 Oct 2005 11:18:43 -0000	1.1
+++ src/winhugs/installer/FileCode.h	12 Oct 2005 09:49:23 -0000
@@ -5,6 +5,7 @@
 bool CanReadWrite(char* File);
 void NormalPath(char* File);
 bool EnsureFolder(char* File);
+void DeleteFolders();
 void FileSize(__int64 Size, char* Buffer);
 
 const int MaxFileSizeBuf = 10;
Index: src/winhugs/installer/StartCode.cpp
===================================================================
RCS file: /cvs/hugs98/src/winhugs/installer/StartCode.cpp,v
retrieving revision 1.1
diff -u -r1.1 StartCode.cpp
--- src/winhugs/installer/StartCode.cpp	6 Oct 2005 11:18:43 -0000	1.1
+++ src/winhugs/installer/StartCode.cpp	12 Oct 2005 09:56:32 -0000
@@ -20,6 +20,7 @@
 // GLOBAL STATE
 HINSTANCE hInst;
 bool InDoEvents = false;
+bool CancelInstall = false;
 BlueZip zip;
 
 int TotalCompSize;
@@ -209,8 +210,13 @@
 
 	//now you have access to at least the file Str
 	//extract all the files
-	for (zList* i = zip.Files; i != NULL; i = i->next)
+	zList* i;
+	for (i = zip.Files; i != NULL; i = i->next)
 	{
+		DoEvents();
+		if (CancelInstall)
+			break;
+
 		Done += i->CompressedSize();
 
 		strcpy(BufPos, i->FileName);
@@ -252,6 +258,36 @@
 		}
 		SendDlgItemMessage(hDlg, prgBar, PBM_SETPOS, Done / PrgFactor, 0);
 	}
+
+	if (CancelInstall)
+	{
+		DoEvents();
+
+		// first delete all the created files
+		for (zList* j = zip.Files; j != i; j = j->next)
+		{
+			Done -= j->CompressedSize();
+
+			strcpy(BufPos, j->FileName);
+			char LastChar = BufPos[strlen(BufPos)-1];
+			bool IsFolder = ((LastChar == '\\') || (LastChar == '/'));
+			NormalPath(BufPos);
+
+			if (!IsFolder)
+				DeleteFile(InstallTo);
+
+			SendDlgItemMessage(hDlg, prgBar, PBM_SETPOS, Done / PrgFactor, 0);
+		}
+
+		//now delete all the directories
+		DeleteFolders();
+
+		InfoBox("Installation rolled back, " ProgramName " has not been installed yet");
+		return false;
+	}
+
+	EnableWindow(GetDlgItem(hDlg, IDCANCEL), FALSE);
+
 	SetDlgItemText(hDlg, lblInstallFile, "Finalising...");
 
 	//now InstallTo is the install directory, plus a \\ character
@@ -290,7 +326,7 @@
 {
 	int Show[] = {txtEdit, cmdBrowse, lblWelcome, 0};
 	int Hide[] = {prgBar, lblInstallTo, lblInstallFile, 0};
-	int Enable[] = {chkExecute, chkShortcutDesktop, chkShortcutStart, IDOK, IDCANCEL, 0};
+	int Enable[] = {chkExecute, chkShortcutDesktop, chkShortcutStart, IDOK, 0};
 
 	int i;
 	for (i = 0; Show[i] != 0; i++)
@@ -317,7 +353,14 @@
 
 	ShowProgress(hDlg, true);
 
-	return DoInstall(Buffer, IsDlgButtonChecked(hDlg, chkExecute) == BST_CHECKED, hDlg);
+	bool Res = DoInstall(Buffer, IsDlgButtonChecked(hDlg, chkExecute) == BST_CHECKED, hDlg);
+	if (!Res)
+	{
+		//Rollback some variables that may have got modified
+		CancelInstall = false;
+		EnableWindow(GetDlgItem(hDlg, IDCANCEL), TRUE);
+	}
+	return Res;
 }
 
 int CALLBACK DlgFunc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
@@ -343,6 +386,12 @@
 		case IDCANCEL:
 			if (!InDoEvents)
 				EndDialog(hDlg, 0);
+			else
+			{
+				CancelInstall = true;
+				SetDlgItemText(hDlg, lblInstallFile, "Cancelling...");
+				EnableWindow(GetDlgItem(hDlg, IDCANCEL), FALSE);
+			}
 			break;
 
 		case IDOK:
