/// <summary> /// Backup the installation /// </summary> /// <param name="request"> /// The request. /// </param> public void Backup(UpdateRequest request) { var backupPath = request.Parameters.BackupPath; if (Directory.Exists(backupPath)) { IOUtils.DeleteDirectory(backupPath); } if (Directory.Exists(request.Parameters.PackageLocation)) { Directory.CreateDirectory(request.Parameters.BackupPath); var files = Directory.GetFiles(request.Parameters.PackageLocation); var targetUpdatePath = request.Parameters.TargetUpdatePath; foreach (var f in files) { // Only backup files that are affected by the update package var fileName = Path.GetFileName(f); var affectFile = Path.Combine(targetUpdatePath, fileName); if (File.Exists(affectFile)) { var backupFile = Path.Combine(backupPath, fileName); File.Copy(f, backupFile); } } } }
/// <summary> /// Initializes a new instance of the <see cref="LiveUpdateClientForm"/> class. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="client"> /// The client. /// </param> /// <param name="logo"> /// The logo. /// </param> public LiveUpdateClientForm(UpdateRequest request, LiveUpdateClient client, Image logo) { this.InitializeComponent(); this._request = request; this._client = client; this.lblProduct.Text = this.lblProduct.Text.Replace("%PRODUCT_NAME%", request.ProductName); this.txtCurrentVersion.Text = request.FromVersion.VersionNumber.ToString(); this.txtNewVersion.Text = request.ToVersion.VersionNumber.ToString(); this.imgLogo.Image = logo; }
/// <summary> /// Apply the update using the downloaded resource /// </summary> /// <param name="request"> /// The request. /// </param> public void RunUpdate(UpdateRequest request) { ProgressDialog.ExecuteTask( null, "Live Update", "Downloading update package into local drive...", "RunLiveUpdate", ProgressBarStyle.Marquee, this.Logger, // Run the actual update callback => { callback.Begin(); this.Logger.InfoFormat( "Upgrading {0} from {1} to {2}...", request.ProductName, request.FromVersion.VersionNumber, request.ToVersion.VersionNumber); callback.Text = "Downloading data package..."; this.Logger.Info("Download version package for " + request.ToVersion.VersionNumber); this._versionRetriever.DownloadPackage(request, request.Parameters.PackageLocation); callback.Text = "Backing up current version..."; this.Logger.Info("Backup current version " + request.FromVersion.VersionNumber); this.Backup(request); callback.Text = "Cleaning up old backups..."; this.Logger.Info("Cleanup old version backups"); this.CleanBackup(); // Clean old backups callback.Text = "Installing update..."; ProcessStartInfo runnerProcessInfo = LiveUpdateRunner.GetUpdateRunnerProcessInfo(request.Parameters); // Prepare update runner process var runnerProcess = Process.Start(runnerProcessInfo); runnerProcess.WaitForExit(); }, request.Parameters.NotifyMsg); }
/// <summary> /// The check for update. /// </summary> /// <returns> /// The <see cref="UpdateRequest"/>. /// </returns> public UpdateRequest CheckForUpdate() { UpdateRequest result = null; var curVersion = this.GetCurrentVersion(); var latestVersion = this.GetLatestVersion(); if (latestVersion != null && latestVersion.VersionNumber != null && latestVersion.VersionNumber > curVersion.VersionNumber) { result = new UpdateRequest(AppUtil.ProductName, curVersion, latestVersion); } return result; }
/// <summary> /// The download package. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="targetLocation"> /// The target location. /// </param> public void DownloadPackage(UpdateRequest request, string targetLocation) { bool isX64 = IntPtr.Size == 8; var pkgLocation = isX64 ? request.ToVersion.X64Package : request.ToVersion.X86Package; // Determine the processor architecture Directory.CreateDirectory(targetLocation); var targetFile = Path.Combine(targetLocation, Guid.NewGuid() + ".zipTmp"); using (var client = new WebClient()) { client.DownloadFile(pkgLocation, targetFile); } try { using (var zip = ZipFile.Read(targetFile)) { zip.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently; foreach (var f in zip) { f.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently; f.Extract(targetLocation); } } } finally { File.Delete(targetFile); } }