Example #1
0
        static bool CheckUpdate()
        {
            string currentDirectory = Environment.CurrentDirectory;
            String TempFilePath = "temp";
            String UpdateListFile = "UpdateList.xml";

            if (ConfigurationManager.AppSettings["update_file"] != null)
            {
                UpdateListFile = ConfigurationManager.AppSettings["update_file"];
            }

            if (ConfigurationManager.AppSettings["TempFilePath"] != null)
            {
                TempFilePath = ConfigurationManager.AppSettings["TempFilePath"];
            }

            string localXmlFile = currentDirectory + "\\" + UpdateListFile;
            string serverXmlFile = string.Empty;
            AutoUpdater.XmlFiles updaterXmlFiles;
            try
            {
                //从本地读取更新配置文件信息
                updaterXmlFiles = new AutoUpdater.XmlFiles(localXmlFile);
            }
            catch
            {
                System.Console.WriteLine("读配置文件出错 " + UpdateListFile);
                return false;
            }

            AutoUpdater.AppUpdater update_check = new AutoUpdater.AppUpdater();
            String app_id = updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value;
            String app_version = updaterXmlFiles.GetNodeValue("//Application//Version");
            update_check.UpdaterUrl = String.Format("{0:s}{1:s}?client_id={2:s}&app_id={3:s}&app_ver={4:s}",updaterXmlFiles.GetNodeValue("//Url"),UpdateListFile,mAppCode,app_id,app_version);
            String tempUpdatePath = currentDirectory + "\\" + TempFilePath;
            try
            {
                update_check.DownAutoUpdateFile(tempUpdatePath);
            }
            catch
            {
                System.Console.WriteLine("与服务器连接失败,操作超时!");
                return false;

            }
            //获取更新文件列表
            Hashtable htUpdateFile = new Hashtable();

            serverXmlFile = tempUpdatePath + "\\UpdateList.xml";
            if (!File.Exists(serverXmlFile))
            {
                System.Console.WriteLine("不能够下载服务器文件");
                return false;
            }
            int availableUpdate = update_check.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile);
            if (availableUpdate > 0) return true;

            return false;
        }
Example #2
0
        static bool CheckUpdate()
        {
            string currentDirectory = Environment.CurrentDirectory;
            String TempFilePath     = "temp";
            String UpdateListFile   = "UpdateList.xml";

            if (ConfigurationManager.AppSettings["update_file"] != null)
            {
                UpdateListFile = ConfigurationManager.AppSettings["update_file"];
            }

            if (ConfigurationManager.AppSettings["TempFilePath"] != null)
            {
                TempFilePath = ConfigurationManager.AppSettings["TempFilePath"];
            }

            string localXmlFile  = currentDirectory + "\\" + UpdateListFile;
            string serverXmlFile = string.Empty;

            AutoUpdater.XmlFiles updaterXmlFiles;
            try
            {
                //从本地读取更新配置文件信息
                updaterXmlFiles = new AutoUpdater.XmlFiles(localXmlFile);
            }
            catch
            {
                System.Console.WriteLine("读配置文件出错 " + UpdateListFile);
                return(false);
            }

            AutoUpdater.AppUpdater update_check = new AutoUpdater.AppUpdater();
            String app_id      = updaterXmlFiles.FindNode("//Application").Attributes["applicationId"].Value;
            String app_version = updaterXmlFiles.GetNodeValue("//Application//Version");

            update_check.UpdaterUrl = String.Format("{0:s}{1:s}?client_id={2:s}&app_id={3:s}&app_ver={4:s}", updaterXmlFiles.GetNodeValue("//Url"), UpdateListFile, mAppCode, app_id, app_version);
            String tempUpdatePath = currentDirectory + "\\" + TempFilePath;

            try
            {
                update_check.DownAutoUpdateFile(tempUpdatePath);
            }
            catch
            {
                System.Console.WriteLine("与服务器连接失败,操作超时!");
                return(false);
            }
            //获取更新文件列表
            Hashtable htUpdateFile = new Hashtable();

            serverXmlFile = tempUpdatePath + "\\UpdateList.xml";
            if (!File.Exists(serverXmlFile))
            {
                System.Console.WriteLine("不能够下载服务器文件");
                return(false);
            }
            int availableUpdate = update_check.CheckForUpdate(serverXmlFile, localXmlFile, out htUpdateFile);

            if (availableUpdate > 0)
            {
                return(true);
            }

            return(false);
        }