Exemple #1
0
        /// <summary>
        /// 检查新版本
        /// </summary>
        /// <param name="isApplicationStart">是否程序启动时调用</param>
        /// <exception cref="System.Net.WebException">无法找到指定资源</exception>
        /// <exception cref="System.NotSupportException">升级地址配置错误</exception>
        /// <exception cref="System.Xml.XmlException">下载的升级文件有错误</exception>
        /// <exception cref="System.ArgumentException">下载的升级文件有错误</exception>
        /// <exception cref="System.Excpetion">未知错误</exception>
        /// <returns></returns>
        public void Update(bool isApplicationStart)
        {
            //程序启动时调用则需检查是否需要提示更新
            if (isApplicationStart)
            {
                if (!config.Enabled)
                {
                    return;
                }
            }
            Dictionary <string, RemoteFile> listRemotFile = ParseRemoteXml(config.ServerUrl);

            List <DownloadFileInfo> downloadList = new List <DownloadFileInfo>();

            //某些文件不再需要了,删除
            List <LocalFile> preDeleteFile = new List <LocalFile>();

            foreach (LocalFile file in config.UpdateFileList)
            {
                if (listRemotFile.ContainsKey(file.Path))
                {
                    RemoteFile rf = listRemotFile[file.Path];
                    if (rf.LastVer != file.LastVer)
                    {
                        downloadList.Add(new DownloadFileInfo(rf.Url, file.Path, rf.LastVer, rf.Size));
                        file.LastVer = rf.LastVer;
                        file.Size    = rf.Size;

                        if (rf.NeedRestart)
                        {
                            bNeedRestart = true;
                        }
                    }

                    listRemotFile.Remove(file.Path);
                }
                else
                {
                    preDeleteFile.Add(file);
                }
            }

            foreach (RemoteFile file in listRemotFile.Values)
            {
                downloadList.Add(new DownloadFileInfo(file.Url, file.Path, file.LastVer, file.Size));
                config.UpdateFileList.Add(new LocalFile(file.Path, file.LastVer, file.Size));

                if (file.NeedRestart)
                {
                    bNeedRestart = true;
                }
            }

            if (downloadList.Count > 0)
            {
                DownloadConfirm dc = new DownloadConfirm(downloadList, isApplicationStart);

                if (this.OnShow != null)
                {
                    this.OnShow();
                }
                DialogResult result = dc.ShowDialog();

                if (DialogResult.OK == result)
                {
                    foreach (LocalFile file in preDeleteFile)
                    {
                        string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file.Path);
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }

                        config.UpdateFileList.Remove(file);
                    }

                    StartDownload(downloadList);
                }
                //不再提醒
                else if (DialogResult.Ignore == result)
                {
                    config.Enabled = false;
                    config.SaveEnabled(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FILENAME));
                }
            }
            else
            {
                if (!isApplicationStart)
                {
                    MessageBox.Show("恭喜,您的数据字典生成工具已经是最新版本!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 检查新版本
        /// </summary>
        /// <param name="isApplicationStart">是否程序启动时调用</param>
        /// <exception cref="System.Net.WebException">无法找到指定资源</exception>
        /// <exception cref="System.NotSupportException">升级地址配置错误</exception>
        /// <exception cref="System.Xml.XmlException">下载的升级文件有错误</exception>
        /// <exception cref="System.ArgumentException">下载的升级文件有错误</exception>
        /// <exception cref="System.Excpetion">未知错误</exception>
        /// <returns></returns>
        public void Update(bool isApplicationStart)
        {
            //程序启动时调用则需检查是否需要提示更新
            if (isApplicationStart)
            {
                if (!config.Enabled)
                {
                    return;
                }
            }
            Dictionary<string, RemoteFile> listRemotFile = ParseRemoteXml(config.ServerUrl);

            List<DownloadFileInfo> downloadList = new List<DownloadFileInfo>();

            //某些文件不再需要了,删除
            List<LocalFile> preDeleteFile = new List<LocalFile>();

            foreach (LocalFile file in config.UpdateFileList)
            {
                if (listRemotFile.ContainsKey(file.Path))
                {
                    RemoteFile rf = listRemotFile[file.Path];
                    if (rf.LastVer != file.LastVer)
                    {
                        downloadList.Add(new DownloadFileInfo(rf.Url, file.Path, rf.LastVer, rf.Size));
                        file.LastVer = rf.LastVer;
                        file.Size = rf.Size;

                        if (rf.NeedRestart)
                            bNeedRestart = true;
                    }

                    listRemotFile.Remove(file.Path);
                }
                else
                {
                    preDeleteFile.Add(file);
                }
            }

            foreach (RemoteFile file in listRemotFile.Values)
            {
                downloadList.Add(new DownloadFileInfo(file.Url, file.Path, file.LastVer, file.Size));
                config.UpdateFileList.Add(new LocalFile(file.Path, file.LastVer, file.Size));

                if (file.NeedRestart)
                    bNeedRestart = true;
            }

            if (downloadList.Count > 0)
            {
                DownloadConfirm dc = new DownloadConfirm(downloadList, isApplicationStart);

                if (this.OnShow != null)
                {
                    this.OnShow();
                }
                DialogResult result = dc.ShowDialog();

                if (DialogResult.OK == result)
                {
                    foreach (LocalFile file in preDeleteFile)
                    {
                        string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file.Path);
                        if (File.Exists(filePath))
                            File.Delete(filePath);

                        config.UpdateFileList.Remove(file);
                    }

                    StartDownload(downloadList);
                }
                //不再提醒
                else if (DialogResult.Ignore == result)
                {
                    config.Enabled = false;
                    config.SaveEnabled(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FILENAME));
                }
            }
            else
            {
                if (!isApplicationStart)
                {
                    MessageBox.Show("恭喜,您的数据字典生成工具已经是最新版本!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }