/// <summary>
        
/// 检测网络更新
        
/// </summary>

        private void InstallUpdateSyncWithInfo()
        
{
            UpdateCheckInfo info 
= null;


            
if (ApplicationDeployment.IsNetworkDeployed)
            
{
                ApplicationDeployment ad 
= ApplicationDeployment.CurrentDeployment;

                
try
                
{
                    info 
= ad.CheckForDetailedUpdate();

                }

                
catch (DeploymentDownloadException dde)
                
{
                    MessageBox.Show(
"软件升级发现异常. \n\n请检测网络情况后重新升经. 错误原因为:" + dde.Message, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    
return;
                }

                
catch (InvalidDeploymentException ide)
                
{
                    MessageBox.Show(
"网络中无法检测到可更新的部署文件,请与软件开发商联系. 错误原因: " + ide.Message, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    
return;
                }

                
catch (InvalidOperationException ioe)
                
{
                    MessageBox.Show(
"软件无法更新. 请与软件开发商联系. 错误原因: " + ioe.Message, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    
return;
                }


                
if (info.UpdateAvailable)
                
{
                    Boolean doUpdate 
= true;

                    
if (!info.IsUpdateRequired)
                    
{
                        DialogResult dr 
= MessageBox.Show("检测到新版本,版本号为:" + info.AvailableVersion.ToString() + ",是否现在升级?""升级检测", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        
if (!(DialogResult.OK == dr))
                        
{
                            doUpdate 
= false;
                        }

                    }


                    
if (doUpdate)
                    
{
                        
try
                        
{
                            ad.Update();
                            MessageBox.Show(
"升级完毕,请重启软件以使用新版本.""升级检测", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Application.Restart();
                        }

                        
catch (DeploymentDownloadException dde)
                        
{
                            MessageBox.Show(
"软件升级发现异常. \n\n请检测网络情况后重新升经. 错误原因为: " + dde, "升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            
return;
                        }

                    }

                }

                
else
                
{
                    MessageBox.Show(
"您现在使用的已经是最新版本软件!""升级检测", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }

            
else
            
{
                MessageBox.Show(
"不是网络部署软件,无法更新""升级检测", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


        }
posted on 2006-11-23 11:01  forrestsun  阅读(603)  评论(0编辑  收藏  举报