Server/MainForm.cs
changeset 88 4f09ae97cdcc
parent 79 76564df23849
child 90 aa157e129c42
     1.1 --- a/Server/MainForm.cs	Mon Jan 12 08:33:53 2015 +0100
     1.2 +++ b/Server/MainForm.cs	Thu Jan 15 19:18:25 2015 +0100
     1.3 @@ -13,6 +13,7 @@
     1.4  using System.ServiceModel;
     1.5  using System.Threading;
     1.6  using System.Diagnostics;
     1.7 +using System.Deployment.Application;
     1.8  //
     1.9  using SharpDisplayClient;
    1.10  using SharpDisplay;
    1.11 @@ -1316,6 +1317,81 @@
    1.12          {
    1.13              iDisplay.HideClock();
    1.14          }
    1.15 +
    1.16 +        private void buttonUpdate_Click(object sender, EventArgs e)
    1.17 +        {
    1.18 +            InstallUpdateSyncWithInfo();
    1.19 +        }
    1.20 +
    1.21 +
    1.22 +        private void InstallUpdateSyncWithInfo()
    1.23 +        {
    1.24 +            UpdateCheckInfo info = null;
    1.25 +
    1.26 +            if (ApplicationDeployment.IsNetworkDeployed)
    1.27 +            {
    1.28 +                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
    1.29 +
    1.30 +                try
    1.31 +                {
    1.32 +                    info = ad.CheckForDetailedUpdate();
    1.33 +
    1.34 +                }
    1.35 +                catch (DeploymentDownloadException dde)
    1.36 +                {
    1.37 +                    MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
    1.38 +                    return;
    1.39 +                }
    1.40 +                catch (InvalidDeploymentException ide)
    1.41 +                {
    1.42 +                    MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
    1.43 +                    return;
    1.44 +                }
    1.45 +                catch (InvalidOperationException ioe)
    1.46 +                {
    1.47 +                    MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
    1.48 +                    return;
    1.49 +                }
    1.50 +
    1.51 +                if (info.UpdateAvailable)
    1.52 +                {
    1.53 +                    Boolean doUpdate = true;
    1.54 +
    1.55 +                    if (!info.IsUpdateRequired)
    1.56 +                    {
    1.57 +                        DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
    1.58 +                        if (!(DialogResult.OK == dr))
    1.59 +                        {
    1.60 +                            doUpdate = false;
    1.61 +                        }
    1.62 +                    }
    1.63 +                    else
    1.64 +                    {
    1.65 +                        // Display a message that the app MUST reboot. Display the minimum required version.
    1.66 +                        MessageBox.Show("This application has detected a mandatory update from your current " +
    1.67 +                            "version to version " + info.MinimumRequiredVersion.ToString() +
    1.68 +                            ". The application will now install the update and restart.",
    1.69 +                            "Update Available", MessageBoxButtons.OK,
    1.70 +                            MessageBoxIcon.Information);
    1.71 +                    }
    1.72 +
    1.73 +                    if (doUpdate)
    1.74 +                    {
    1.75 +                        try
    1.76 +                        {
    1.77 +                            ad.Update();
    1.78 +                            MessageBox.Show("The application has been upgraded, and will now restart.");
    1.79 +                            Application.Restart();
    1.80 +                        }
    1.81 +                        catch (DeploymentDownloadException dde)
    1.82 +                        {
    1.83 +                            MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
    1.84 +                            return;
    1.85 +                        }
    1.86 +                    }
    1.87 +                }
    1.88 +            }
    1.89 +        }
    1.90      }
    1.91  
    1.92      /// <summary>