Пример #1
0
 public ItemProgressChangedEventArgs(int percent, UpdateFile updateFile)
     : base(percent, updateFile)
 {
     UpdateFile = updateFile;
 }
Пример #2
0
 private void OnItemDownloadProgressChanged(int percent, UpdateFile updateFile)
 {
     if (ItemDownloadProgressChanged != null)
     {
         this.ItemDownloadProgressChanged(this, new ItemProgressChangedEventArgs(percent, updateFile));
     }
 }
Пример #3
0
        /// <summary>
        /// 检查更新文件
        /// </summary>
        /// <param name="serverXmlFile"></param>
        /// <param name="localXmlFile"></param>
        /// <param name="updateFileList"></param>
        /// <returns></returns>
        internal int CheckForUpdate(out Hashtable updateFileList)
        {
            updateFileList = new Hashtable();
            string localXmlFile = Application.StartupPath + "\\" + UpdateConfigName;
            //加载本地升级配置文件
            XmlFiles updaterXmlFiles;
            try { updaterXmlFiles = new XmlFiles(localXmlFile); }
            catch { throw new Exception("配置文件出错"); }
            //与服务器连接,下载更新配置文件
            string downLoadPath = string.Empty;
            try
            {
                downLoadPath = tempUpdatePath;
                this.DownAutoUpdateFile(tempUpdatePath);
            }
            catch { throw new Exception("与服务器连接失败"); }
            string serverXmlFile = Path.Combine(downLoadPath, UpdateConfigName);
            XmlFiles serverXmlFiles = new XmlFiles(serverXmlFile);
            XmlFiles localXmlFiles = new XmlFiles(localXmlFile);
            XmlNodeList newNodeList = serverXmlFiles.GetNodeList("AutoUpdater/Files");
            XmlNodeList oldNodeList = localXmlFiles.GetNodeList("AutoUpdater/Files");
            int k = 0;
            for (int i = 0; i < newNodeList.Count; i++)
            {
                UpdateFile upateFile = new UpdateFile();
                string newFileName = newNodeList.Item(i).Attributes["FileName"].Value.Trim();
                string newVer = newNodeList.Item(i).Attributes["Version"].Value.Trim();
                string newSavePath = newNodeList.Item(i).Attributes["SavePath"].Value.Trim();
                string newUpdatePath = newNodeList.Item(i).Attributes["UpdatePath"].Value.Trim();
                long newFileSize = Convert.ToInt64(newNodeList.Item(i).Attributes["FileSize"].Value.Trim());
                ArrayList oldFileAl = new ArrayList();
                for (int j = 0; j < oldNodeList.Count; j++)
                {
                    string oldFileName = oldNodeList.Item(j).Attributes["FileName"].Value.Trim();
                    string oldVer = oldNodeList.Item(j).Attributes["Version"].Value.Trim();
                    oldFileAl.Add(oldFileName);
                    oldFileAl.Add(oldVer);
                }
                int pos = oldFileAl.IndexOf(newFileName);
                if (pos == -1)
                {
                    upateFile.FileName = newFileName;
                    upateFile.Version = newVer;
                    //upateFile.SavePath = newSavePath;
                    //upateFile.UpdatePath = newUpdatePath;
                    upateFile.FileSize = newFileSize;
                    updateFileList.Add(k, upateFile);
                    k++;
                }
                else if (pos > -1 && newVer.CompareTo(oldFileAl[pos + 1].ToString()) > 0)
                {
                    upateFile.FileName = newFileName;
                    upateFile.Version = newVer;
                    //upateFile.SavePath = newSavePath;
                    //upateFile.UpdatePath = newUpdatePath;
                    upateFile.FileSize = newFileSize;
                    updateFileList.Add(k, upateFile);
                    k++;
                }

            }
            return k;
        }