Пример #1
0
 public UpdateUI(ConfigList cfPC, ConfigList cfServer)
 {
     InitializeComponent();
     log.Info("加载UpdateUI");
     this.cfPC     = cfPC;
     this.cfServer = cfServer;
     showDiff();
     doUpdate();
 }
 public UpdateUI(ConfigList cfPC, ConfigList cfServer, int _Minimum, int _Maximum)//带参数,表示进度条的范围的最小值和最大值
 {
     InitializeComponent();
     progressBar1.Maximum = _Maximum;                        //设置范围最大值
     progressBar1.Value   = progressBar1.Minimum = _Minimum; //设置范围最小值
     this.cfPC            = cfPC;
     this.cfServer        = cfServer;
     showDiff();
 }
        public void initList()
        {
            string fileDir          = Environment.CurrentDirectory;
            string configureListDir = System.IO.Path.Combine(fileDir + "\\Server", "configureList");

            if (!System.IO.Directory.Exists(configureListDir))
            {
                System.IO.Directory.CreateDirectory(configureListDir);
            }
            DirectoryInfo fileFold = new DirectoryInfo(configureListDir);

            FileInfo[]        files   = fileFold.GetFiles(); //获取指定文件夹下的所有文件
            List <ConfigList> config2 = new List <ConfigList>();

            for (int i = 0; files != null && i < files.Length; i++)  //将文件信息添加到List里面
            {
                try
                {
                    if (files[i].Extension == ".ini")   //挑选出符合条件的信息
                    {
                        ConfigList config1 = new ConfigList(files[i].Name, files[i].LastWriteTime, false, configureListDir + "\\" + files[i].Name);
                        config1.ConfigFileMD5Code = config1.GetConfigFileMD5Code();
                        config2.Add(config1);
                    }
                    else
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
            }
            //按修改时间排序
            config2.Sort((x, y) => { return(y.ConfigFileModificationTime.CompareTo(x.ConfigFileModificationTime)); });
            bool tem_i = true;

            foreach (var tem_config in config2)
            {
                if (tem_i)
                {
                    tem_config.IsVersion = true;
                    listView.Items.Add(tem_config);
                    tem_i = false;
                    continue;
                }
                listView.Items.Add(tem_config);
            }
        }
        private void Button_Check(object sender, RoutedEventArgs e)
        {
            // 获取PC的 ini 文件
            cfPC = GetPCIni();
            int PCIniHash = 0;

            if (cfPC != null)
            {
                PCIniHash = cfPC.ConfigFileHashCode;
            }
            // 获取Server的 ini 文件
            cfServer = GetServerIni();
            int ServerIniHash = 0;

            if (cfServer != null)
            {
                ServerIniHash = cfServer.ConfigFileHashCode;
            }

            //Console.WriteLine(PCIniHash);
            //Console.WriteLine(ServerIniHash);

            // 如果文件hash码不同,进行更新
            if (PCIniHash != ServerIniHash)
            {
                UpdateUI SWSetting = new UpdateUI(cfPC, cfServer, 0, 100);
                //在父窗口中间显示
                SWSetting.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                SWSetting.Title = "软件更新";
                SWSetting.Show();
                for (int i = 0; i < 100; i++)
                {
                    SWSetting.setPos(i, 100); //设置进度条位置
                    Thread.Sleep(100);        //睡眠时间为100
                }
                SWSetting.doUpdate();
                SWSetting.Close();//关闭窗体
            }
            // 否则 不更新
            else
            {
                MessageBox.Show("当前为最新版本,无须更新");
            }
        }
        // 获取Server的 ini 文件
        private ConfigList GetServerIni()
        {
            string        fileDir          = Environment.CurrentDirectory;
            string        configureListDir = System.IO.Path.Combine(fileDir, "configureList");
            DirectoryInfo fileFold         = new DirectoryInfo(configureListDir);

            FileInfo[]        files   = fileFold.GetFiles(); //获取指定文件夹下的所有文件
            List <ConfigList> config2 = new List <ConfigList>();

            //将文件信息添加到List里面
            for (int i = 0; files != null && i < files.Length; i++)
            {
                try
                {
                    if (files[i].Extension == ".ini")   //挑选出符合条件的信息
                    {
                        ConfigList config1 = new ConfigList(files[i].Name, files[i].LastWriteTime, false, configureListDir + "\\" + files[i].Name);
                        config1.ConfigFileHashCode = config1.GetHashCode();
                        config2.Add(config1);
                    }
                    else
                    {
                        continue;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
            }
            config2.Sort((x, y) => { return(y.ConfigFileModificationTime.CompareTo(x.ConfigFileModificationTime)); });
            if (config2.Count > 0)
            {
                return(config2[0]);
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        // 获取Server的 ini 文件 通过url找
        private ConfigList GetServerIni()
        {
            string       current = System.IO.Directory.GetCurrentDirectory();
            StreamReader sr      = new StreamReader(current + @"\url.txt", Encoding.Default);
            string       line;
            string       url = "";

            while ((line = sr.ReadLine()) != null)
            {
                url = line;
                //Console.WriteLine(url);
                //Console.WriteLine(line);
            }
            //Uri uri = new Uri(url);
            //if (uri.IsFile)
            //{
            //    string urifilepath = uri.LocalPath;
            //    if(!System.IO.File.Exists(urifilepath))
            //        return null;
            //}

            string tempDir = current + @"\PC\temp";

            if (!System.IO.Directory.Exists(tempDir))
            {
                System.IO.Directory.CreateDirectory(tempDir);
            }
            ConfigureFileListPage.DeleteFolder(tempDir);
            //存在 下载下来进行比较
            WebClient webClient    = new WebClient();
            string    downloadPath = tempDir + "\\temp.ini";

            webClient.DownloadFile(url, downloadPath);
            System.IO.FileInfo f       = new System.IO.FileInfo(downloadPath);
            ConfigList         config1 = new ConfigList("temp.ini", f.LastWriteTime, false, downloadPath);

            config1.ConfigFileMD5Code = config1.GetConfigFileMD5Code();
            //删除temp文件夹
            //Directory.Delete(tempDir, true);
            return(config1);
        }
        //获取PC的 ini 文件
        private ConfigList GetPCIni()
        {
            string        fileDir  = Environment.CurrentDirectory;
            string        PCDir    = System.IO.Path.Combine(fileDir, "PC");
            DirectoryInfo fileFold = new DirectoryInfo(PCDir);

            FileInfo[] files = fileFold.GetFiles();
            for (int i = 0; files != null && i < files.Length; i++) //找出ini
            {
                if (files[i].Extension == ".ini")                   //挑选出符合条件的信息
                {
                    ConfigList config1 = new ConfigList(files[i].Name, files[i].LastWriteTime, false, PCDir + "\\" + files[i].Name);
                    config1.ConfigFileHashCode = config1.GetHashCode();
                    return(config1);
                }
                else
                {
                    continue;
                }
            }
            return(null);
        }
Пример #8
0
        private void Button_Update(object sender, RoutedEventArgs e)
        {
            log.Info("点击更新");
            // 获取PC的 ini 文件
            cfPC = GetPCIni();
            string PCIniHash = "";

            if (cfPC != null)
            {
                PCIniHash = cfPC.ConfigFileMD5Code;
            }
            // 获取Server的 ini 文件
            cfServer = GetServerIni();
            string ServerIniHash = "";

            if (cfServer != null)
            {
                ServerIniHash = cfServer.ConfigFileMD5Code;
            }

            Console.WriteLine(PCIniHash);
            Console.WriteLine(ServerIniHash);

            // 如果文件hash码不同,进行更新
            if (PCIniHash != ServerIniHash)
            {
                UpdateUI SWSetting = new UpdateUI(cfPC, cfServer);
                //在父窗口中间显示
                SWSetting.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                SWSetting.Title = "软件更新";
                SWSetting.ShowDialog();
            }
            // 否则 不更新
            else
            {
                MessageBox.Show("当前为最新版本,无须更新");
            }
        }