Ejemplo n.º 1
0
 /// <summary>
 /// 根据版本信息,下载相应版本的Config.xml文件
 /// </summary>
 /// <param name="list"></param>
 protected void DownloadVersion()
 {
     try
     {
         _appUpdate.ServerVersions.Sort();
         int precent = 0;
         int count   = 0;
         int total   = _appUpdate.ServerVersions.Count;
         foreach (Version v in _appUpdate.ServerVersions)
         {
             precent++;
             string serverconfigurl = _appUpdate.LocalVersion.ServerUrl;
             serverconfigurl += serverconfigurl.EndsWith("/") ? v.ValueVersion.ToString() : "/" + v.ValueVersion;
             serverconfigurl += "/Config.xml";
             string localconfigpath = _appUpdate.LocalFileDir;
             localconfigpath += localconfigpath.EndsWith("\\") ? v.ValueVersion.ToString() : "\\" + v.ValueVersion;
             localconfigpath += "\\Config.xml";
             CreateDirtory(localconfigpath);
             _appUpdate.DownloadFile(serverconfigurl, localconfigpath);
             XmlFiles    xmlconfigfile = new XmlFiles(localconfigpath);
             XmlNodeList filenodes     = xmlconfigfile.GetNodeList("//File");
             count += filenodes == null ? 0 : filenodes.Count;
             VersionProgressChanged(precent);
         }
         VersionProgressComplete(count);
     }
     catch (Exception ex)
     {
         ShowMessage("错误:" + ex.Message);
     }
 }
Ejemplo n.º 2
0
        private string serverXmlFile = "http://update.geit.com.cn/UBoardMate/UBoardCamera/update.xml";//服务器XML文档地址(默认中文)
        //获取服务器上的版本号
        public String GetFileNameInfo()
        {
            XmlFiles    serverXmlFiles = new XmlFiles(serverXmlFile);
            XmlNodeList newNodeList    = serverXmlFiles.GetNodeList("UpdateInfo/AppVersion");

            return(newNodeList.Item(0).Value.Trim());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 检查更新文件
        /// </summary>
        /// <param name="serverXmlFile"></param>
        /// <param name="localXmlFile"></param>
        /// <param name="updateFileList"></param>
        /// <returns></returns>
        public int CheckForUpdate(string serverXmlFile, string localXmlFile, out Hashtable updateFileList)
        {
            updateFileList = new Hashtable();
            if (!File.Exists(localXmlFile) || !File.Exists(serverXmlFile))
            {
                return(-1);
            }

            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++)
            {
                string[] fileList = new string[3];

                string newFileName = newNodeList.Item(i).Attributes["Name"].Value.Trim();
                string newVer      = newNodeList.Item(i).Attributes["Ver"].Value.Trim();

                ArrayList oldFileAl = new ArrayList();
                for (int j = 0; j < oldNodeList.Count; j++)
                {
                    string oldFileName = oldNodeList.Item(j).Attributes["Name"].Value.Trim();
                    string oldVer      = oldNodeList.Item(j).Attributes["Ver"].Value.Trim();

                    oldFileAl.Add(oldFileName);
                    oldFileAl.Add(oldVer);
                }
                int pos = oldFileAl.IndexOf(newFileName);
                if (pos == -1)
                {
                    fileList[0] = newFileName;
                    fileList[1] = newVer;
                    updateFileList.Add(k, fileList);
                    k++;
                }
                else if (pos > -1 && newVer.CompareTo(oldFileAl[pos + 1].ToString()) > 0)
                {
                    fileList[0] = newFileName;
                    fileList[1] = newVer;
                    updateFileList.Add(k, fileList);
                    k++;
                }
            }
            return(k);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 下载文件列表
        /// </summary>
        protected void DownloadFiles()
        {
            try
            {
                string serverUrl = _appUpdate.LocalVersion.ServerUrl;
                serverUrl += serverUrl.EndsWith("/") ? "" : "/";
                string localDir = _appUpdate.LocalFileDir;
                localDir += localDir.EndsWith("\\") ? "" : "\\";
                foreach (Version v in _appUpdate.ServerVersions)
                {
                    string localconfigpath = localDir;
                    localconfigpath += v.ValueVersion + "\\Config.xml";
                    XmlFiles         xmlconfigfile = new XmlFiles(localconfigpath);
                    XmlNodeList      filenodes     = xmlconfigfile.GetNodeList("//File");
                    List <FileModel> fileList      = new List <FileModel>();
                    foreach (XmlNode node in filenodes)
                    {
                        FileModel model = new FileModel();
                        model.FileName     = Path.GetFileName(node.Attributes["Name"].Value);
                        model.FileUri      = serverUrl + v.ValueVersion + "/" + node.Attributes["Name"].Value;
                        model.TempPath     = localDir + v.ValueVersion + "\\" + node.Attributes["Name"].Value.Replace("/", "\\");
                        model.FileVersion  = v.StrVersion;
                        model.VersionValue = v.ValueVersion;
                        fileList.Add(model);
                    }

                    DownloadFiles(v, fileList);

                    string localVersionDir = localDir;
                    localVersionDir += localVersionDir.EndsWith("\\") ? v.ValueVersion.ToString() : "\\" + v.ValueVersion;
                    if (CheckMainAppIsRun())
                    {
                        KillMainApp();
                    }
                    CopyFile(localVersionDir, Application.StartupPath);
                    UpdateLocalXml(v.StrVersion, v.ValueVersion.ToString());
                }

                _appUpdate.StartMainAppExe(_appUpdate.LocalVersion.EntryPoint);
            }
            catch (Exception ex)
            {
                LogHelper.WriteException(ex);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 检查更新文件
        /// </summary>
        /// <param name="serverXmlFile"></param>
        /// <param name="localXmlFile"></param>
        /// <param name="updateFileList"></param>
        /// <returns></returns>
        public int CheckForUpdate()
        {
            string localXmlFile = Application.StartupPath + "\\UpdateList.xml";

            if (!File.Exists(localXmlFile))
            {
                return(-1);
            }

            XmlFiles updaterXmlFiles = new XmlFiles(localXmlFile);


            string tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\";

            this.UpdaterUrl = updaterXmlFiles.GetNodeValue("//Url") + "/UpdateList.xml";
            this.DownAutoUpdateFile(tempUpdatePath);

            string serverXmlFile = tempUpdatePath + "\\UpdateList.xml";

            if (!File.Exists(serverXmlFile))
            {
                return(-1);
            }

            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++)
            {
                string[] fileList = new string[3];

                string newFileName = newNodeList.Item(i).Attributes["Name"].Value.Trim();
                string newVer      = newNodeList.Item(i).Attributes["Ver"].Value.Trim();

                ArrayList oldFileAl = new ArrayList();
                for (int j = 0; j < oldNodeList.Count; j++)
                {
                    string oldFileName = oldNodeList.Item(j).Attributes["Name"].Value.Trim();
                    string oldVer      = oldNodeList.Item(j).Attributes["Ver"].Value.Trim();

                    oldFileAl.Add(oldFileName);
                    oldFileAl.Add(oldVer);
                }
                int pos = oldFileAl.IndexOf(newFileName);
                if (pos == -1)
                {
                    fileList[0] = newFileName;
                    fileList[1] = newVer;
                    k++;
                }
                else if (pos > -1 && newVer.CompareTo(oldFileAl[pos + 1].ToString()) > 0)
                {
                    fileList[0] = newFileName;
                    fileList[1] = newVer;
                    k++;
                }
            }
            return(k);
        }