public UpdateForm(string tempPath, ReleaseList localRelease, ReleaseList remoteRelease)
 {
     InitializeComponent();
     this.tempPath = tempPath;
     this.localRelease = localRelease;
     this.remoteRelease = remoteRelease;
 }
Beispiel #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //未捕获异常处理
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);//处理未捕获的异常
            Application.ThreadException += Application_ThreadException; ;//处理UI线程异常
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;//处理非UI线程异常

            //获取本地relealist文件信息
            string localXmlPath = string.Format("{0}\\{1}", Application.StartupPath, ReleaseConfigFileName);
            localRelease = new ReleaseList(localXmlPath);
            tempPath = Application.StartupPath + "\\~temp\\cache\\";

            try
            {
                //下载服务器上的relealist文件
                DownloadTool.DownloadFile(tempPath, localRelease.ReleaseUrl, ReleaseConfigFileName);
            }
            catch (WebException ex)
            {
                AppTool.DeleteTempFolder(tempPath);
                Application.Exit();
                AppTool.Start(localRelease.ApplicationStart);
                return;
            }
            catch
            {
                AppTool.DeleteTempFolder(tempPath);
                MessageBox.Show("下载更新文件失败,请检查网络和文件夹权限");
                Application.Exit();
                return;
            }

            //把relealist.xml文件下载到本地后,从本地读取
            remoteRelease = new ReleaseList(tempPath + ReleaseConfigFileName);

            //比较本机文件和服务器上的XML文件
            if (localRelease.Compare(remoteRelease) != 0)
            {
                //if (CheckProcessing() != DialogResult.OK)
                //{
                //    AppTool.DeleteTempFolder(tempPath);
                //    Application.Exit();
                //    return;
                //}

                UpdateForm form = new UpdateForm(tempPath, localRelease, remoteRelease);
                Application.Run(form);
            }
            else
            {
                AppTool.DeleteTempFolder(tempPath);
                Application.Exit();
                AppTool.Start(localRelease.ApplicationStart);
            }
        }
 /// <summary>
 /// 版本号比较,并输出总文件大小
 /// </summary>
 /// <param name="otherList"></param>
 /// <param name="fileSize"></param>
 /// <returns></returns>
 public ReleaseFile[] GetDifferences(ReleaseList otherList, out int fileSize)
 {
     fileSize = 0;
     if (otherList == null || Compare(otherList) == 0)
         return null;
     var ht = new Hashtable();
     foreach (ReleaseFile file in files)
     {
         ht.Add(file.FileName, file.ReleaseDate);
     }
     var diffrences = new List<ReleaseFile>();
     foreach (ReleaseFile file in otherList.files)
     {
         //如果本地的XML文件中不包括服务器上要升级的文件或者服务器的文件的发布日期大于本地XML文件的发布日期,开始升级
         if (!ht.ContainsKey(file.FileName) ||
             DateTime.Parse(file.ReleaseDate) > DateTime.Parse(ht[file.FileName].ToString()))
         {
             diffrences.Add(file);
             fileSize += file.FileSize;
         }
     }
     return diffrences.ToArray();
 }
 //版本号比较
 public int Compare(ReleaseList otherList)
 {
     if (otherList == null)
         throw new ArgumentNullException("otherList");
     int diff = Compare(otherList.ReleaseVersion);
     if (diff != 0)
         return diff;
     return (releaseDate == otherList.ReleaseDate)
             ? 0
             : (DateTime.Parse(releaseDate) > DateTime.Parse(otherList.ReleaseDate) ? 1 : -1);
 }