Adding application update button.
authorsl
Thu, 15 Jan 2015 19:18:25 +0100
changeset 884f09ae97cdcc
parent 87 26e884e49594
child 89 0e8c077d63bf
Adding application update button.
Adding manifest to run as admin.
Disabling ClickOnce security check to run as admin.
The whole thing is not tested.
Server/MainForm.Designer.cs
Server/MainForm.cs
Server/Properties/AssemblyInfo.cs
Server/SharpDisplayManager.csproj
Server/app.manifest
     1.1 --- a/Server/MainForm.Designer.cs	Mon Jan 12 08:33:53 2015 +0100
     1.2 +++ b/Server/MainForm.Designer.cs	Thu Jan 15 19:18:25 2015 +0100
     1.3 @@ -79,6 +79,8 @@
     1.4              this.labelFontWidth = new System.Windows.Forms.Label();
     1.5              this.labelFontHeight = new System.Windows.Forms.Label();
     1.6              this.pictureBoxDemo = new System.Windows.Forms.PictureBox();
     1.7 +            this.tabPageApp = new System.Windows.Forms.TabPage();
     1.8 +            this.buttonUpdate = new System.Windows.Forms.Button();
     1.9              this.panelDisplay.SuspendLayout();
    1.10              this.tableLayoutPanel.SuspendLayout();
    1.11              this.statusStrip.SuspendLayout();
    1.12 @@ -88,6 +90,7 @@
    1.13              this.tabControl.SuspendLayout();
    1.14              this.tabPageDesign.SuspendLayout();
    1.15              ((System.ComponentModel.ISupportInitialize)(this.pictureBoxDemo)).BeginInit();
    1.16 +            this.tabPageApp.SuspendLayout();
    1.17              this.SuspendLayout();
    1.18              // 
    1.19              // panelDisplay
    1.20 @@ -485,6 +488,7 @@
    1.21              this.tabControl.Controls.Add(this.tabPageDisplay);
    1.22              this.tabControl.Controls.Add(this.tabPageClients);
    1.23              this.tabControl.Controls.Add(this.tabPageDesign);
    1.24 +            this.tabControl.Controls.Add(this.tabPageApp);
    1.25              this.tabControl.Location = new System.Drawing.Point(12, 139);
    1.26              this.tabControl.Name = "tabControl";
    1.27              this.tabControl.SelectedIndex = 0;
    1.28 @@ -633,6 +637,27 @@
    1.29              this.pictureBoxDemo.TabIndex = 21;
    1.30              this.pictureBoxDemo.TabStop = false;
    1.31              // 
    1.32 +            // tabPageApp
    1.33 +            // 
    1.34 +            this.tabPageApp.Controls.Add(this.buttonUpdate);
    1.35 +            this.tabPageApp.Location = new System.Drawing.Point(4, 22);
    1.36 +            this.tabPageApp.Name = "tabPageApp";
    1.37 +            this.tabPageApp.Padding = new System.Windows.Forms.Padding(3);
    1.38 +            this.tabPageApp.Size = new System.Drawing.Size(592, 242);
    1.39 +            this.tabPageApp.TabIndex = 4;
    1.40 +            this.tabPageApp.Text = "Application";
    1.41 +            this.tabPageApp.UseVisualStyleBackColor = true;
    1.42 +            // 
    1.43 +            // buttonUpdate
    1.44 +            // 
    1.45 +            this.buttonUpdate.Location = new System.Drawing.Point(6, 213);
    1.46 +            this.buttonUpdate.Name = "buttonUpdate";
    1.47 +            this.buttonUpdate.Size = new System.Drawing.Size(75, 23);
    1.48 +            this.buttonUpdate.TabIndex = 0;
    1.49 +            this.buttonUpdate.Text = "Update";
    1.50 +            this.buttonUpdate.UseVisualStyleBackColor = true;
    1.51 +            this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
    1.52 +            // 
    1.53              // MainForm
    1.54              // 
    1.55              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    1.56 @@ -665,6 +690,7 @@
    1.57              this.tabPageDesign.ResumeLayout(false);
    1.58              this.tabPageDesign.PerformLayout();
    1.59              ((System.ComponentModel.ISupportInitialize)(this.pictureBoxDemo)).EndInit();
    1.60 +            this.tabPageApp.ResumeLayout(false);
    1.61              this.ResumeLayout(false);
    1.62              this.PerformLayout();
    1.63  
    1.64 @@ -721,6 +747,8 @@
    1.65          private System.Windows.Forms.Label labelFontHeight;
    1.66          private System.Windows.Forms.CheckBox checkBoxInverseColors;
    1.67          private System.Windows.Forms.PictureBox pictureBoxDemo;
    1.68 +        private System.Windows.Forms.TabPage tabPageApp;
    1.69 +        private System.Windows.Forms.Button buttonUpdate;
    1.70      }
    1.71  }
    1.72  
     2.1 --- a/Server/MainForm.cs	Mon Jan 12 08:33:53 2015 +0100
     2.2 +++ b/Server/MainForm.cs	Thu Jan 15 19:18:25 2015 +0100
     2.3 @@ -13,6 +13,7 @@
     2.4  using System.ServiceModel;
     2.5  using System.Threading;
     2.6  using System.Diagnostics;
     2.7 +using System.Deployment.Application;
     2.8  //
     2.9  using SharpDisplayClient;
    2.10  using SharpDisplay;
    2.11 @@ -1316,6 +1317,81 @@
    2.12          {
    2.13              iDisplay.HideClock();
    2.14          }
    2.15 +
    2.16 +        private void buttonUpdate_Click(object sender, EventArgs e)
    2.17 +        {
    2.18 +            InstallUpdateSyncWithInfo();
    2.19 +        }
    2.20 +
    2.21 +
    2.22 +        private void InstallUpdateSyncWithInfo()
    2.23 +        {
    2.24 +            UpdateCheckInfo info = null;
    2.25 +
    2.26 +            if (ApplicationDeployment.IsNetworkDeployed)
    2.27 +            {
    2.28 +                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
    2.29 +
    2.30 +                try
    2.31 +                {
    2.32 +                    info = ad.CheckForDetailedUpdate();
    2.33 +
    2.34 +                }
    2.35 +                catch (DeploymentDownloadException dde)
    2.36 +                {
    2.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);
    2.38 +                    return;
    2.39 +                }
    2.40 +                catch (InvalidDeploymentException ide)
    2.41 +                {
    2.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);
    2.43 +                    return;
    2.44 +                }
    2.45 +                catch (InvalidOperationException ioe)
    2.46 +                {
    2.47 +                    MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
    2.48 +                    return;
    2.49 +                }
    2.50 +
    2.51 +                if (info.UpdateAvailable)
    2.52 +                {
    2.53 +                    Boolean doUpdate = true;
    2.54 +
    2.55 +                    if (!info.IsUpdateRequired)
    2.56 +                    {
    2.57 +                        DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
    2.58 +                        if (!(DialogResult.OK == dr))
    2.59 +                        {
    2.60 +                            doUpdate = false;
    2.61 +                        }
    2.62 +                    }
    2.63 +                    else
    2.64 +                    {
    2.65 +                        // Display a message that the app MUST reboot. Display the minimum required version.
    2.66 +                        MessageBox.Show("This application has detected a mandatory update from your current " +
    2.67 +                            "version to version " + info.MinimumRequiredVersion.ToString() +
    2.68 +                            ". The application will now install the update and restart.",
    2.69 +                            "Update Available", MessageBoxButtons.OK,
    2.70 +                            MessageBoxIcon.Information);
    2.71 +                    }
    2.72 +
    2.73 +                    if (doUpdate)
    2.74 +                    {
    2.75 +                        try
    2.76 +                        {
    2.77 +                            ad.Update();
    2.78 +                            MessageBox.Show("The application has been upgraded, and will now restart.");
    2.79 +                            Application.Restart();
    2.80 +                        }
    2.81 +                        catch (DeploymentDownloadException dde)
    2.82 +                        {
    2.83 +                            MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
    2.84 +                            return;
    2.85 +                        }
    2.86 +                    }
    2.87 +                }
    2.88 +            }
    2.89 +        }
    2.90      }
    2.91  
    2.92      /// <summary>
     3.1 --- a/Server/Properties/AssemblyInfo.cs	Mon Jan 12 08:33:53 2015 +0100
     3.2 +++ b/Server/Properties/AssemblyInfo.cs	Thu Jan 15 19:18:25 2015 +0100
     3.3 @@ -3,7 +3,7 @@
     3.4  using System.Runtime.InteropServices;
     3.5  using System.Resources;
     3.6  
     3.7 -// General Information about an assembly is controlled through the following 
     3.8 +// General Information about an assembly is controlled through the following
     3.9  // set of attributes. Change these attribute values to modify the information
    3.10  // associated with an assembly.
    3.11  [assembly: AssemblyTitle("Sharp Display Manager")]
    3.12 @@ -11,12 +11,12 @@
    3.13  [assembly: AssemblyConfiguration("")]
    3.14  [assembly: AssemblyCompany("Slions")]
    3.15  [assembly: AssemblyProduct("Sharp Display Manager")]
    3.16 -[assembly: AssemblyCopyright("Copyright ©  2014")]
    3.17 +[assembly: AssemblyCopyright("Copyright © 2014 Stéphane Lenclud")]
    3.18  [assembly: AssemblyTrademark("")]
    3.19  [assembly: AssemblyCulture("")]
    3.20  
    3.21 -// Setting ComVisible to false makes the types in this assembly not visible 
    3.22 -// to COM components.  If you need to access a type in this assembly from 
    3.23 +// Setting ComVisible to false makes the types in this assembly not visible
    3.24 +// to COM components.  If you need to access a type in this assembly from
    3.25  // COM, set the ComVisible attribute to true on that type.
    3.26  [assembly: ComVisible(false)]
    3.27  
    3.28 @@ -26,11 +26,11 @@
    3.29  // Version information for an assembly consists of the following four values:
    3.30  //
    3.31  //      Major Version
    3.32 -//      Minor Version 
    3.33 +//      Minor Version
    3.34  //      Build Number
    3.35  //      Revision
    3.36  //
    3.37 -// You can specify all the values or you can default the Build and Revision Numbers 
    3.38 +// You can specify all the values or you can default the Build and Revision Numbers
    3.39  // by using the '*' as shown below:
    3.40  // [assembly: AssemblyVersion("1.0.*")]
    3.41  [assembly: AssemblyVersion("1.0.0.0")]
     4.1 --- a/Server/SharpDisplayManager.csproj	Mon Jan 12 08:33:53 2015 +0100
     4.2 +++ b/Server/SharpDisplayManager.csproj	Thu Jan 15 19:18:25 2015 +0100
     4.3 @@ -17,10 +17,10 @@
     4.4      <Install>true</Install>
     4.5      <InstallFrom>Web</InstallFrom>
     4.6      <UpdateEnabled>true</UpdateEnabled>
     4.7 -    <UpdateMode>Foreground</UpdateMode>
     4.8 +    <UpdateMode>Background</UpdateMode>
     4.9      <UpdateInterval>7</UpdateInterval>
    4.10      <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    4.11 -    <UpdatePeriodically>false</UpdatePeriodically>
    4.12 +    <UpdatePeriodically>true</UpdatePeriodically>
    4.13      <UpdateRequired>false</UpdateRequired>
    4.14      <MapFileExtensions>true</MapFileExtensions>
    4.15      <InstallUrl>http://publish.slions.net/SharpDisplayManager/</InstallUrl>
    4.16 @@ -88,7 +88,7 @@
    4.17      <ManifestKeyFile>SharpDisplayManager_TemporaryKey.pfx</ManifestKeyFile>
    4.18    </PropertyGroup>
    4.19    <PropertyGroup>
    4.20 -    <GenerateManifests>true</GenerateManifests>
    4.21 +    <GenerateManifests>false</GenerateManifests>
    4.22    </PropertyGroup>
    4.23    <PropertyGroup>
    4.24      <ApplicationIcon>vfd.ico</ApplicationIcon>
    4.25 @@ -96,6 +96,12 @@
    4.26    <PropertyGroup>
    4.27      <StartupObject>SharpDisplayManager.Program</StartupObject>
    4.28    </PropertyGroup>
    4.29 +  <PropertyGroup>
    4.30 +    <ApplicationManifest>app.manifest</ApplicationManifest>
    4.31 +  </PropertyGroup>
    4.32 +  <PropertyGroup>
    4.33 +    <TargetZone>LocalIntranet</TargetZone>
    4.34 +  </PropertyGroup>
    4.35    <ItemGroup>
    4.36      <Reference Include="Microsoft.VisualBasic" />
    4.37      <Reference Include="Microsoft.VisualBasic.PowerPacks.Vs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
    4.38 @@ -146,6 +152,7 @@
    4.39        <DependentUpon>Resources.resx</DependentUpon>
    4.40        <DesignTime>True</DesignTime>
    4.41      </Compile>
    4.42 +    <None Include="app.manifest" />
    4.43      <None Include="Properties\Settings.settings">
    4.44        <Generator>SettingsSingleFileGenerator</Generator>
    4.45        <LastGenOutput>Settings.Designer.cs</LastGenOutput>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/Server/app.manifest	Thu Jan 15 19:18:25 2015 +0100
     5.3 @@ -0,0 +1,52 @@
     5.4 +<?xml version="1.0" encoding="utf-8"?>
     5.5 +<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     5.6 +  <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
     5.7 +  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
     5.8 +    <security>
     5.9 +      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    5.10 +        <!-- UAC Manifest Options
    5.11 +            If you want to change the Windows User Account Control level replace the
    5.12 +            requestedExecutionLevel node with one of the following.
    5.13 +
    5.14 +        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
    5.15 +        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
    5.16 +        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
    5.17 +
    5.18 +            Specifying requestedExecutionLevel node will disable file and registry virtualization.
    5.19 +            If you want to utilize File and Registry Virtualization for backward
    5.20 +            compatibility then delete the requestedExecutionLevel node.
    5.21 +        -->
    5.22 +        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
    5.23 +      </requestedPrivileges>
    5.24 +      <applicationRequestMinimum>
    5.25 +        <PermissionSet Unrestricted="true" ID="Custom" SameSite="site" />
    5.26 +        <defaultAssemblyRequest permissionSetReference="Custom" />
    5.27 +      </applicationRequestMinimum>
    5.28 +    </security>
    5.29 +  </trustInfo>
    5.30 +  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    5.31 +    <application>
    5.32 +      <!-- A list of all Windows versions that this application is designed to work with.
    5.33 +      Windows will automatically select the most compatible environment.-->
    5.34 +      <!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
    5.35 +      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->
    5.36 +      <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
    5.37 +      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
    5.38 +      <!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
    5.39 +      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->
    5.40 +    </application>
    5.41 +  </compatibility>
    5.42 +  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
    5.43 +  <!-- <dependency>
    5.44 +    <dependentAssembly>
    5.45 +      <assemblyIdentity
    5.46 +          type="win32"
    5.47 +          name="Microsoft.Windows.Common-Controls"
    5.48 +          version="6.0.0.0"
    5.49 +          processorArchitecture="*"
    5.50 +          publicKeyToken="6595b64144ccf1df"
    5.51 +          language="*"
    5.52 +        />
    5.53 +    </dependentAssembly>
    5.54 +  </dependency>-->
    5.55 +</asmv1:assembly>
    5.56 \ No newline at end of file