Beispiel #1
0
        internal bool BeginDownloadManifest()
        {
            try
            {
                if ((DownloaderState)this.downloadState.Current != DownloaderState.Idle)
                {
                    EventLogger.Instance.Add("Cannot download manifest. Downloader state isn't idle.");
                    return(false);
                }
                this.downloadState.Current = DownloaderState.DownloadingManifest;
                EventLogger.Instance.Add("Downloading manifest...");

                ServiceIo.CleanDownloadFolder();

                DownloadInfo inf = new DownloadInfo();
                inf.Manifest   = null;
                inf.DownloadId = (Int32)Downloadables.UpdateManifest;

                this.webClient.DownloadFileAsync(
                    this.updateManifestUri,
                    ServiceIo.GetManifestFilePath(),
                    inf);

                return(true);
            }
            catch (Exception ex)
            {
                this.downloadState.Current = DownloaderState.Idle;
                EventLogger.Instance.Add(ex.Message);
            }

            return(false);
        }
 public bool ReloadSettings()
 {
     try
     {
         return(ServiceIo.LoadSettings());
     }
     catch (Exception ex)
     {
         EventLogger.Instance.Add(ex.Message);
     }
     return(false);
 }
Beispiel #3
0
        private UpdateManifestInfo GetNewVersionInfo()
        {
            try
            {
                object tmpCurr = this.state.Current;
                this.state.Current = UpdaterStatus.CheckingVersion;

                UpdateManifestInfo info = GetManifestInfo();
                if (info == null)
                {
                    EventLogger.Instance.Add("Cannot get manifest file info. Version comparison failed.");
                }
                else
                {
                    System.Reflection.AssemblyName asm = ServiceIo.GetUpdateAssembly();

                    if (asm == null)
                    {
                        EventLogger.Instance.Add("Cannot get update application assembly. Version comparison failed.");
                    }
                    else
                    {
                        Version currentVersion = asm.Version;
                        Version latestVersion  = new Version(info.UpdateVersion);

                        if (latestVersion > currentVersion)
                        {
                            this.IsNewVersionAvailable = true;
                            RaiseNewVersionExists(info);
                            return(info);
                        }
                        else
                        {
                            this.IsNewVersionAvailable = false;
                        }
                    }
                }
                this.state.Current = tmpCurr;
            }
            catch (Exception ex)
            {
                //this.state.Current = UpdaterStatus.Idle;
                EventLogger.Instance.Add(ex.Message);
            }

            return(null);
        }
Beispiel #4
0
        private void OnPackageDownloadComplete(DownloadInfo downloadInfo)
        {
            try
            {
                if (ServiceIo.ExtractDownloadedPackage(downloadInfo.Manifest))
                {
                    ServiceIo.Cleanup(downloadInfo.Manifest);
                    this.state.Current = UpdaterStatus.PackageDownloadCompleted;

                    this.IsDownloadComplete = true;
                    RaiseNewVersionDownloaded(downloadInfo);
                    return;
                }
            }
            catch (Exception ex)
            {
                EventLogger.Instance.Add(ex.Message);
            }

            this.state.Current = UpdaterStatus.Idle;
        }
Beispiel #5
0
        public void Start()
        {
            try
            {
                ServiceIo.LoadSettings();

                SetupDownloader();
                if (this.updaterThread == null)
                {
                    SetupThread();
                }

                if (!this.updaterThread.IsAlive)
                {
                    this.updaterThread.Start();
                }
            }
            catch (Exception ex)
            {
                EventLogger.Instance.Add(ex.Message);
            }
        }
Beispiel #6
0
        internal bool BeginDownloadPackage(UpdateManifestInfo manifest)
        {
            try
            {
                if ((DownloaderState)this.downloadState.Current == DownloaderState.DownloadingManifest ||
                    (DownloaderState)this.downloadState.Current == DownloaderState.DownloadingPackage)
                {
                    EventLogger.Instance.Add("Cannot download package. Downloader is already downloading.");
                    return(false);
                }

                if (manifest == null)
                {
                    return(false);
                }
                EventLogger.Instance.Add("Downloading package...");

                this.downloadState.Current = DownloaderState.DownloadingPackage;

                DownloadInfo inf = new DownloadInfo();
                inf.Manifest   = manifest;
                inf.DownloadId = (Int32)Downloadables.UpdatePackage;

                this.webClient.DownloadFileAsync(
                    new Uri(manifest.UpdatePackageUri),
                    ServiceIo.GetPackageFilePath(inf.Manifest),
                    inf);

                return(true);
            }
            catch (Exception ex)
            {
                this.downloadState.Current = DownloaderState.Idle;
                EventLogger.Instance.Add(ex.Message);
            }

            return(false);
        }
Beispiel #7
0
 // Loads downloaded manifest file
 private UpdateManifestInfo GetManifestInfo()
 {
     return(ServiceIo.LoadManifestFile());
 }
Beispiel #8
0
        // closes app, overwrites downloaded files and returns
        private bool ApplyDownloadedUpdate()
        {
            try
            {
                if (!this.IsNewVersionAvailable)
                {
                    return(false);
                }
                this.state.Current = UpdaterStatus.ApplyingUpdates;

                string processName = ServiceIo.GetUpdateAppProcessName();
                EventLogger.Instance.Add("Closing process: " + processName);

                // Ensure app is closed
                if (WindowsProcessController.IsProcessAlive(processName))
                {
                    System.Threading.Thread.Sleep(1000);

                    if (WindowsProcessController.IsProcessAlive(processName))
                    {
                        WindowsProcessController.KillProcess(processName);
                        System.Threading.Thread.Sleep(1000);
                    }
                }

                if (WindowsProcessController.IsProcessAlive(processName))
                {
                    EventLogger.Instance.Add("Failed to stop process. Updates weren't applied");
                    return(false);
                }

                // Backup before overwriting files
                EventLogger.Instance.Add("Backing up files.");
                if (!ServiceIo.BackupStartupDirectory())
                {
                    return(false);
                }

                // Restore backup if overwrite failed
                EventLogger.Instance.Add("Copying new files");
                if (!ServiceIo.OverwriteDownloadedFiles())
                {
                    EventLogger.Instance.Add("Overwrite failed, restoring backup");
                    ServiceIo.RestoreStartupDirectory();
                }

                // Clean up
                EventLogger.Instance.Add("Cleaning up.");
                ServiceIo.CleanupBackups();

                // Update state
                this.IsDownloadComplete    = false;
                this.IsNewVersionAvailable = false;
                this.state.Current         = UpdaterStatus.Idle;

                // Restarting app
                WindowsProcessController.Execute(ServiceIo.GetUpdateAppPath());

                return(true);
            }
            catch (Exception ex)
            {
                this.state.Current = UpdaterStatus.Idle;
                EventLogger.Instance.Add(ex.Message);
            }

            return(false);
        }