using PWAppUpdater.FTP; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; namespace PWAppUpdater { class Updater { public static void Update(string installPath, ProgressBar progress, Label stepInfo, string tempPath = "") { try { progress.PerformStep(); stepInfo.Text = "Creating temp directories..."; stepInfo.Update(); if (tempPath == "") { tempPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); tempPath = Path.Combine(tempPath, "PWAPP\\Temp"); } progress.PerformStep(); if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } progress.PerformStep(); stepInfo.Text = "Downloading update..."; stepInfo.Update(); FTP.FTPManager ftpManager = new FTPManager("ftp://waws-prod-blu-109.ftp.azurewebsites.windows.net/", "patientweb\\$patientweb", "vHBnkgxPDS4Q410eehaFlXb8DH67QW50m9Rsxf1omXyYWRDgYioWJL63Tagp"); ftpManager.DownloadFile("pwapp/current/Release.zip", tempPath + "\\Release.zip"); progress.PerformStep(); stepInfo.Text = "Removing old installation..."; stepInfo.Update(); progress.PerformStep(); stepInfo.Text = "Creating new install directory..."; stepInfo.Update(); Directory.CreateDirectory(installPath); progress.PerformStep(); stepInfo.Text = "Unpacking update..."; stepInfo.Update(); Zip.ZipManager.UnZip(tempPath + "\\Release.zip", installPath, true); progress.PerformStep(); stepInfo.Text = "Cleaning up installation..."; stepInfo.Update(); Directory.Delete(tempPath, true); progress.PerformStep(); stepInfo.Text = "Complete!"; stepInfo.Update(); } catch (UnauthorizedAccessException) { MessageBox.Show("Updater does not have sufficent permissions to perform update. Please run with administrator privilages to continue."); throw new NoAuthException(); } } } class NoAuthException : Exception { } class CouldNotFindInstallPathException : Exception { } }