private void performUpdate(object obj)
{
string url = (string)zipFileURL;
String fullAppName = callingAssembly.GetName().CodeBase;
String appPath = Path.GetDirectoryName(fullAppName);
String updateDir = appPath + "\\" + UPDATE_FOLDER_NAME;
String updateFilename = getFilename(url);
string updateZip = updateDir + "\\" + updateFilename;
// Create directory to store update files
Directory.CreateDirectory(updateDir);
TransferManager tm = new TransferManager();
tm.AddObserver(notification);
Stream s;
tm.downloadFile(url, out s, updateZip, notification.trans);
if (s != null)
s.Close();
if (!abortUpdate)
{
using (ZipFile zip1 = ZipFile.Read(updateZip))
{
foreach (ZipEntry e in zip1)
{
e.Extract(updateDir, ExtractExistingFileAction.OverwriteSilently);
}
}
File.Delete(updateZip);
string backupDir = appPath + "\\" + BACKUP_FOLDER_NAME;
if (Directory.Exists(backupDir))
Directory.Delete(backupDir, true);
Directory.CreateDirectory(backupDir);
foreach (string filepath in Directory.GetFiles(updateDir))
{
string originalFile = appPath + "\\" + getFilenameFromPath(filepath);
if (File.Exists(originalFile))
{
string backupFilepath = backupDir + "\\" + getFilenameFromPath(filepath);
File.Move(originalFile, backupFilepath);
File.Move(filepath, originalFile);
}
}
OnUpdateDone();
}
}