示例#1
0
        private void WorkThread()
        {
            try
            {
                string        root1 = AppDomain.CurrentDomain.BaseDirectory;
                DirectoryInfo di1   = new DirectoryInfo(root1);
                DirectoryInfo di2   = di1.Parent.Parent;
                string        root  = di2.FullName;
                //Directory.SetCurrentDirectory(root);
                bool update = false;
                int  i      = 0;
                foreach (var item in arrUpdate)
                {
                    //判断是否是目录
                    string ext = Path.GetExtension(item.ToString());
                    if (string.IsNullOrEmpty(ext))
                    {
                        if (!Directory.Exists(root + item.ToString()))
                        {
                            Directory.CreateDirectory(root + item.ToString());
                            this.Invoke((EventHandler) delegate
                            {
                                listBoxTip.Items.Add(item.ToString());
                            });
                        }
                    }
                    else
                    {
                        string path = Path.GetDirectoryName(item.ToString()) + "\\";
                        string name = Path.GetFileName(item.ToString());
                        if (File.Exists(path + item.ToString()))
                        {
                            File.Delete(path + item.ToString());
                        }
                        bool ret = ftp.Download(root, item.ToString());
                        if (ret)
                        {
                            this.Invoke((EventHandler) delegate
                            {
                                listBoxTip.Items.Add(item.ToString());
                            });
                        }
                        else
                        {
                            LogClass.WriteLogFile("download file error:" + item.ToString());
                        }
                    }
                    i++;
                    this.Invoke((EventHandler) delegate
                    {
                        progressBar1.Value = i;
                    });
                    listBoxTip.TopIndex = listBoxTip.Items.Count - 1;
                }
                this.Invoke((EventHandler) delegate
                {
                    MessageBox.Show("更新完成");
                    if (File.Exists(root1 + "UpdateVersion.xml"))
                    {
                        File.Delete(root1 + "UpdateVersion.xml");
                    }
                    Thread.Sleep(100);
                    File.Move(root1 + updateFile, root1 + "UpdateVersion.xml");


                    if (File.Exists(root1 + "BackUp/UpdateVersion.xml"))
                    {
                        File.Delete(root1 + "BackUp/UpdateVersion.xml");
                    }
                    File.Copy(root1 + "UpdateVersion.xml", root1 + "BackUp/UpdateVersion.xml");
                    if (isStartAfterUpdate == "1")
                    {
                        Process.Start(root1 + updateProcessPath);
                    }

                    this.Close();
                });
            }
            catch (Exception e)
            {
                LogClass.WriteLogFile("thread error:" + e.Message);
            }
        }
示例#2
0
        private ArrayList ParseVersionFile(string file)
        {
            ArrayList arr  = new ArrayList();
            string    root = AppDomain.CurrentDomain.BaseDirectory;
            //string root = Environment.CurrentDirectory.ToString();
            DirectoryInfo di1 = new DirectoryInfo(root);
            DirectoryInfo di2 = di1.Parent.Parent;

            root = di2.FullName;
            try
            {
                verStdModle = ReadConfig(file);

                //判断文件主版本是否已经改变,需要更新
                if (verStdModle.Version != verModle.Version)
                {
                    foreach (var item in verStdModle.fileDic)
                    {
                        if (verStdModle.PubNumber == item.Value.pubnumber)
                        {
                            if (verModle.fileDic.ContainsKey(item.Key.ToString()))
                            {
                                if (verModle.fileDic[item.Key.ToString()].version != item.Value.version.ToString())
                                {
                                    arr.Add(item.Key.ToString());
                                }
                            }
                            else
                            {
                                arr.Add(item.Key.ToString());
                            }
                        }
                        else
                        {
                            //发布计数不相等,需要删除这个文件
                            string ext = Path.GetExtension(root + item.Key.ToString());
                            if (string.IsNullOrEmpty(ext))
                            {
                                if (Directory.Exists(root + item.Key.ToString()))
                                {
                                    DirectoryInfo di = new DirectoryInfo(root + item.Key.ToString());
                                    if (di.GetFiles().Length > 0)
                                    {
                                        //di.Delete(true);
                                    }
                                    else
                                    {
                                        //Directory.Delete(root + item.Key.ToString());
                                    }
                                }
                            }
                            else
                            {
                                if (File.Exists(root + item.Key.ToString()))
                                {
                                    //File.Delete(root + item.Key.ToString());
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogClass.WriteLogFile("ParseVersionFile error :" + e.Message);
            }
            return(arr);
        }