日期:2014-05-20  浏览次数:20883 次

C# 自动更新程序

        private void FrmUpdate_Load(object sender, System.EventArgs e)
{
            this.btnNext.PerformClick();
            //this.Visible = false;
panel2.Visible = false;
btnFinish.Visible = false;
string localXmlFile = Application.StartupPath + "\\UpdateList.xml";
string serverXmlFile = string.Empty;


try
{
//从本地读取更新配置文件信息
updaterXmlFiles = new XmlFiles(localXmlFile );
}
catch
{
MessageBox.Show("配置文件出错!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.Close();
return;
}
//获取服务器地址
updateUrl = updaterXmlFiles.GetNodeValue("//Url");

AppUpdater appUpdater = new AppUpdater();
appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml";

//与服务器连接,下载更新配置文件
try
{
tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\"+ "_"+ updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value+"_"+"y"+"_"+"x"+"_"+"m"+"_"+"\\";
appUpdater.DownAutoUpdateFile(tempUpdatePath);
}
catch
{
MessageBox.Show("与服务器连接失败,操作超时!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
return;

}

//获取更新文件列表
Hashtable htUpdateFile = new Hashtable();
             
serverXmlFile = tempUpdatePath + "\\UpdateList.xml";
if(!File.Exists(serverXmlFile))
{
return;
}

availableUpdate = appUpdater.CheckForUpdate(serverXmlFile,localXmlFile,out htUpdateFile);
if (availableUpdate > 0)
{
for(int i=0;i<htUpdateFile.Count;i++)
{
string [] fileArray =(string []) htUpdateFile[i];
lvUpdateList.Items.Add(new ListViewItem(fileArray));
}
               
            
}
    else
btnNext.Enabled = false;
                          
                
}

private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Close();
Application.ExitThread();
Application.Exit();
}
        
        private void btnNext_Click(object sender, System.EventArgs e)
        {
            
            if (availableUpdate > 0)
            {
                Thread threadDown = new Thread(new ThreadStart(DownUpdateFile));
                threadDown.IsBackground = true;
                threadDown.Start();
            }
            else
            {
                if (MessageBox.Show("没有可用更新", "更新提示", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
                {
                    this.Close();
                    Application.ExitThread();
                    Application.Exit();
                }
                
            }


        }


为什么测试的时候能够连接到服务器 但是一直是没有可用更新呢?


建立ftp服务器 用的是迷你ftp
------解决方案--------------------
那就开始Debug了,关键点设断点,看看是哪里出问题了。