Index: /trunk/gsinstaller/gsinstall.cpp
===================================================================
--- /trunk/gsinstaller/gsinstall.cpp	(revision 1637)
+++ /trunk/gsinstaller/gsinstall.cpp	(revision 1638)
@@ -350,9 +350,8 @@
     }
 
-  // open the log for writing
+  // set the log for writing
   FilePath *logPath = new FilePath(this->destinationPath->pathString(), "install.log");
-  this->openLog(logPath->pathString(), true);
-  delete logPath;
-}
+  this->setLogFile(logPath->pathString());
+  delete logPath;}
 
 bool GSInstall::setUninstall()
@@ -394,5 +393,6 @@
   // will in fact be the temporary directory as outlined above)
   FilePath *logPath = new FilePath(this->sourcePath->pathString(), "install.log");
-  this->openLog(logPath->pathString(), false);
+  this->setLogFile(logPath->pathString());
+  this->readLog();
   delete logPath;
   
@@ -951,5 +951,5 @@
 	      // will be deleted, it must be closed; copying may also fail, so it's
 	      // safer to close it before doing either.
-	      install.closeLog();
+	      install.recordLog();
 
 	      // if the install is empty, terminate all final items (currently the
@@ -999,9 +999,6 @@
 		install.updateSetupExe();
 
-		// the log will need reopening (probably failed initially)
-		install.reopenLog();
-
 		// close log
-		install.closeLog();
+		install.recordLog();
 
 		// do further actions
Index: /trunk/gsinstaller/unInstall.cpp
===================================================================
--- /trunk/gsinstaller/unInstall.cpp	(revision 1637)
+++ /trunk/gsinstaller/unInstall.cpp	(revision 1638)
@@ -5,298 +5,257 @@
 #include "File.h"
 
-bool installManager::openLog(string filename, bool write)
+bool installManager::ensureLog()
 {
-  string command;
-  stringArray params;
-
-  // close the log if already open
-  if (this->logfile.rdbuf()->is_open())
-    {
-      this->closeLog();
-    }
-
-  // note the new file details and do an open
-  this->logfileName = filename;
-  this->logfile.open(filename.c_str(), ios::out | ios::in);
-	
+	HANDLE fHandle;
+
+	fHandle = CreateFile(this->logfileName.c_str(), GENERIC_READ | GENERIC_WRITE,
+						 FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
+						 FILE_ATTRIBUTE_NORMAL, NULL);
+	if (fHandle == INVALID_HANDLE_VALUE)
+	{
+  		fHandle = CreateFile(this->logfileName.c_str(), GENERIC_READ | GENERIC_WRITE,
+                         FILE_SHARE_WRITE, NULL, CREATE_NEW,
+		                     FILE_ATTRIBUTE_NORMAL, NULL);
+		if (fHandle != INVALID_HANDLE_VALUE)
+		{	
+			CloseHandle(fHandle);
+			return true;
+		}
+		return false;
+    }
+	else
+	{	CloseHandle(fHandle);
+	}
+	return true;
+}
+
+bool installManager::setLogFile(string filename)
+{	this->logfileName = filename;
+	this->setModule("default");
+	return true;
+}
+
+bool installManager::readLog()
+{	string command;
+	stringArray params;
+
+  // open the log file 
+	this->logfile.open(this->logfileName.c_str(), ios::in);
+
+	// Get the commands into this object from the existing log file
+	while ((command = this->readCommand(params)) != "")
+  	{	if (command[0] == '[' && command[command.length()-1] == ']')
+  		{ this->setModule(command.substr(1, command.length() - 2));
+		}
+    	else
+    	{	unInstallCommand action(command, params);
+    		this->storeCommand(action);
+    	}
+	}
+	this->changed = false;
+
+	// close the logfile
+	this->logfile.close();
+  
+  // set to the default module
+  this->setModule("default");
+  return true;
+}
+
+void installManager::setModule(string moduleName)
+{	this->currentModule = moduleName;
+}
+
+bool installManager::storeCommand(unInstallCommand &command)
+{ this->modules[this->currentModule].push_back(command);
+	this->changed = true; // set the "changed" flag
+	return true;
+}
+
+bool installManager::writeCommand(unInstallCommand &command)
+{ if (!this->writeString(command.command))
+	{ return false;
+  }
+	for (unsigned int p = 0; p < command.parameters.size(); p ++)
+  {	if (!this->writeSeparator())
+  	{ return false;
+    }
+    if (!this->writeString(command.parameters[p]))
+    { return false;
+    }
+  }
+  if (!this->writeString("\n"))
+  { return false;
+  }
+  return true;
+}
+
+bool installManager::writeString(char *buffer)
+{ string s(buffer);
+	return this->writeString(s);
+}
+
+bool installManager::writeString(string str)
+{ bool quote;
+
+	// TODO: check for space characters in str and quote if necessary
+	quote = str.find_first_of(' ') < str.length();
+
+	if (quote)
+  {	this->logfile << "\"";
+  }
+	this->logfile << str;
+  if (quote)
+  {	this->logfile << "\"";
+  }
+  return true;
+}
+
+bool installManager::writeSeparator()
+{	this->logfile << " ";
+	return true;
+}
+
+string installManager::readString()
+{	string reply = "";
+	char c;
+
+  if (this->logfile.eof())
+	{	return reply;
+  }
+
+  this->logfile >> c;
+  while (c <= ' ' && !this->logfile.eof())
+  {	this->logfile.get();
+  }
+
+  if (this->logfile.eof())
+  { return reply;
+  }
+
+  if (c == '\"')
+  { do
+  	{	c = this->logfile.get();
+    	if (c != '\"')
+      { reply += c;
+      }
+    }
+    while (c != '\"' && !this->logfile.eof());
+  }
+  else
+  { while (c > ' ')
+    { reply += c;
+    	if (this->logfile.eof())
+      {	break;
+      }
+    	c = this->logfile.get();
+    }
+    if (!this->logfile.eof())
+    {	this->logfile.putback(c);
+    }
+    //this->logfile >> reply;
+  }
+  return reply;
+}
+
+string installManager::readCommand(stringArray &array)
+{	string reply = "";
+  char c;
+
+  array.clear();
+
+  if (this->logfile.eof())
+  {	return reply;
+  }
+
+	reply = this->readString();
+  if (reply == "")
+  { return reply;
+  }
+
+  while(!this->logfile.eof() &&
+  			(c = this->logfile.get()) != '\n')
+  {	this->logfile.putback(c);
+   	array.add(this->readString());
+  }
+  if (!this->logfile.eof())
+  { this->logfile.putback(c);
+  }
+
+  return reply;
+}
+
+string installManager::popCommand(stringArray &array)
+{ string command;
+
+  if (this->modules[this->currentModule].size() == 0)
+  { command = "";
+  }
+  else
+  { unsigned int last;
+
+	  last = this->modules[this->currentModule].size() - 1;
+  	command = this->modules[this->currentModule][last].commandName();
+  	array		= this->modules[this->currentModule][last].parameterList();
+    this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last);
+  }
+  return command;
+}
+
+bool installManager::recordLog()
+{ 
+	// just return if there are no changes to record
+	if (this->changed == false)
+	{	return true;
+	}
+
   // if the file didn't open, then this is almost certainly being compiled
   // with Microsoft Visual C++ which has a library which fails to open the
   // file if it doesn't already exist.  Do a createfile and hope for success.
   // TODO: add proper error handling here
-  if (!this->logfile.rdbuf()->is_open() && write == true)
-    {
-      HANDLE fHandle;
-      fHandle = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE,
-			   FILE_SHARE_WRITE, NULL, CREATE_NEW,
-			   FILE_ATTRIBUTE_NORMAL, NULL);
-      if (fHandle)
-	{
-	  CloseHandle(fHandle);
-	}
-      this->logfile.open(filename.c_str(), ios::out | ios::in);
-    }
-
-  // if we aren't seeking write access, then get the commands into this
-  // object
-  if (write == false)
-    {
-      while ((command = this->readCommand(params)) != "")
-	{
-	  if (command[0] == '[' && command[command.length()-1] == ']')
-	    {
-	      this->setModule(command.substr(1, command.length() - 2));
-	    }
-	  else
-	    {	
-	      unInstallCommand action(command, params);
-	      this->storeCommand(action);
-	    }
-	}
-    }
-
-  // set to the default module
-  this->setModule("default");
-  return true;
-}
-
-bool installManager::reopenLog()
-{
-  if (this->logfile.rdbuf()->is_open())
-    {
-      this->logfile.close();
-    }
-  else
-    {
-      this->logfile.close();
-    }
-  
-  this->logfile.open(this->logfileName.c_str(), ios::out | ios::in);
-  return true;
-}
-
-void installManager::setModule(string moduleName)
-{
-  this->currentModule = moduleName;
-}
-
-bool installManager::storeCommand(unInstallCommand &command)
-{
-  this->modules[this->currentModule].push_back(command);
-  return true;
-}
-
-bool installManager::writeCommand(unInstallCommand &command)
-{
-  if (!this->writeString(command.command))
-    {
-      return false;
-    }
-  for (unsigned int p = 0; p < command.parameters.size(); p ++)
-    {
-      if (!this->writeSeparator())
-  	{
-	  return false;
-	}
-      if (!this->writeString(command.parameters[p]))
-	{
-	  return false;
-	}
-    }
-  if (!this->writeString("\n"))
-    {
-      return false;
-    }
-  return true;
-}
-
-bool installManager::writeString(char *buffer)
-{
-  string s(buffer);
-  return this->writeString(s);
-}
-
-bool installManager::writeString(string str)
-{
-  bool quote;
-
-  // TODO: check for space characters in str and quote if necessary
-  quote = str.find_first_of(' ') < str.length();
-
-  if (quote)
-    {
-      this->logfile << string("\"");
-    }
-  this->logfile << str;
-
-  if (quote)
-    {
-      this->logfile << string("\"");
-    }
-  return true;
-}
-
-bool installManager::writeSeparator()
-{
-  this->logfile << string(" ");
-  return true;
-}
-
-string installManager::readString()
-{
-  string reply = "";
-  char c;
-
-  if (this->logfile.eof())
-    {
-      return reply;
-    }
-
-  this->logfile >> c;
-  while (c <= ' ' && !this->logfile.eof())
-    {
-      this->logfile.get();
-    }
-  
-  if (this->logfile.eof())
-    {
-      return reply;
-    }
-  
-  if (c == '\"')
-    {
-      do
-  	{
-	  c = this->logfile.get();
-	  if (c != '\"')
-	    {
-	      reply += c;
-	    }
-	}
-      while (c != '\"' && !this->logfile.eof());
-    }
-  else
-    {
-      while (c > ' ')
-	{
-	  reply += c;
-	  if (this->logfile.eof())
-	    {
-	      break;
-	    }
-	  c = this->logfile.get();
-	}
-      if (!this->logfile.eof())
-	{
-	  this->logfile.putback(c);
-	}
-      //this->logfile >> reply;
-    }
-  return reply;
-}
-
-string installManager::readCommand(stringArray &array)
-{
-  string reply = "";
-  char c;
-  
-  array.clear();
-  
-  if (this->logfile.eof())
-    {
-      return reply;
-    }
-  
-  reply = this->readString();
-  if (reply == "")
-    {
-      return reply;
-    }
-  
-  while(!this->logfile.eof() &&
-	(c = this->logfile.get()) != '\n')
-    {
-      this->logfile.putback(c);
-      array.add(this->readString());
-    }
-  if (!this->logfile.eof())
-    {
-      this->logfile.putback(c);
-    }
-  
-  return reply;
-}
-
-string installManager::popCommand(stringArray &array)
-{
-  string command;
-  
-  if (this->modules[this->currentModule].size() == 0)
-    {
-      command = "";
-    }
-  else
-    {
-      unsigned int last;
-      
-      last = this->modules[this->currentModule].size() - 1;
-      command = this->modules[this->currentModule][last].commandName();
-      array = this->modules[this->currentModule][last].parameterList();
-      this->modules[this->currentModule].erase(this->modules[this->currentModule].begin() + last);
-    }
-  return command;
-}
-
-bool installManager::closeLog()
-{
-  if (this->logfile.rdbuf()->is_open() == false)
-    {
-      return false;
-    }
-
-  unInstallCommandMap::iterator here = this->modules.begin();
-  unInstallCommandMap::iterator end = this->modules.end();
-  
+	this->ensureLog();
+	this->logfile.open(this->logfileName.c_str(), ios::out);
+	
+	unInstallCommandMap::iterator here = this->modules.begin();
+	unInstallCommandMap::iterator end  = this->modules.end();
+
+	while (here != end)
+	{	
+		this->writeString("[" + (*here).first + "]\n");
+	
+  		unInstallCommandList::iterator	ahere = (*here).second.begin();
+		unInstallCommandList::iterator  aend  = (*here).second.end();
+
+		while (ahere != aend)
+		{	this->writeCommand(*ahere);
+    		ahere ++;
+		}
+  		here ++;
+	}
+	this->logfile.close();
+
+	this->changed = false;
+
+	return true;
+}
+
+bool installManager::isEmpty()
+{ unInstallCommandMap::iterator here = this->modules.begin();
+	unInstallCommandMap::iterator end  = this->modules.end();
+
   while (here != end)
-    {
-      this->writeString("[" + (*here).first + "]\n");
-      
-      unInstallCommandList::iterator ahere = (*here).second.begin();
-      unInstallCommandList::iterator aend  = (*here).second.end();
-      while (ahere != aend)
-	{
-	  this->writeCommand(*ahere);
-	  ahere ++;
-	}
-      here ++;
-    }
-  this->logfile.close();
-  return true;
-}
-
-bool installManager::isEmpty()
-{
-  unInstallCommandMap::iterator here = this->modules.begin();
-  unInstallCommandMap::iterator end = this->modules.end();
-
-  while (here != end)
-    {
-      this->writeString("[" + (*here).first + "]\n");
-
-      unInstallCommandList::iterator ahere = (*here).second.begin();
-      unInstallCommandList::iterator aend = (*here).second.end();
-      if (ahere != aend)
-	{
-	  return false;
-	}
-      here ++;
-    }
+  {	this->writeString("[" + (*here).first + "]\n");
+
+  	unInstallCommandList::iterator	ahere = (*here).second.begin();
+    unInstallCommandList::iterator  aend  = (*here).second.end();
+    if (ahere != aend)
+    {	return false;
+    }
+  	here ++;
+  }
   return true;
 }
 
 installManager::~installManager()
-{
-  if (this->logfile.rdbuf()->is_open())
-    {
-      this->closeLog();
-    }
-}
+{	this->recordLog();
+}
Index: /trunk/gsinstaller/unInstall.h
===================================================================
--- /trunk/gsinstaller/unInstall.h	(revision 1637)
+++ /trunk/gsinstaller/unInstall.h	(revision 1638)
@@ -55,4 +55,5 @@
   string currentModule;
   unInstallCommandMap modules;
+  bool	changed;
 
   bool writeString(string str);
@@ -63,8 +64,9 @@
   string readCommand(stringArray &params);
 public:
-  installManager() { };
-  bool openLog(string filename, bool write);
-  bool closeLog();
-  bool reopenLog();
+  installManager() { this->changed = false; }
+  bool setLogFile(string filename);
+  bool ensureLog();
+  bool readLog();
+  bool recordLog();
   void setModule(string moduleName);
   bool storeCommand(unInstallCommand &command);
