示例#1
0
        private void Update()
        {
            try
            {
                XmlDocument XMLDoc = new XmlDocument();
                XMLDoc.Load("http://mariaradio.sektor.hu/?version=" + VERSION);
                XmlElement doc = XMLDoc.DocumentElement;

                bool updatable = false;
                List<UFile> files = new List<UFile>();
                int totalFileSize = 0;

                foreach (XmlElement el in doc.ChildNodes)
                {
                    if (el.Name == "updateavailable" && el.InnerText == "true")
                    {
                        updatable = true;
                    }

                    if (el.Name == "files" && el.HasChildNodes)
                    {
                        foreach (XmlElement fe in el.ChildNodes)
                        {
                            UFile file = new UFile(fe.InnerText, int.Parse(fe.Attributes["size"].Value));
                            totalFileSize += int.Parse(fe.Attributes["size"].Value);
                            files.Add(file);
                        }
                    }
                }

                if (updatable)
                {
                    Invoke(new SetTotalProgressMaxDelegate(SetTotalProgressMax), totalFileSize * 2);

                    string dir = Path.GetTempPath() + "\\Maria_Radio\\";

                    if (!File.Exists(dir) || (File.GetAttributes(dir) & FileAttributes.Directory) != FileAttributes.Directory)
                    {
                        Directory.CreateDirectory(dir);
                    }

                    foreach (UFile file in files)
                    {
                        Invoke(new SetFileNameDelegate(SetFileName), file.fileName);
                        Invoke(new SetProgressMaxDelegate(SetProgressMax), file.fileSize);

                        currFileSize = file.fileSize;

                        WebClient webClient = new WebClient();
                        webClient.DownloadFileCompleted += Completed;
                        webClient.DownloadProgressChanged += OnDownload;
                        webClient.DownloadFileAsync(new Uri(file.filePath), dir + file.fileName);
                        evt.WaitOne();
                    }

                    foreach (UFile file in files)
                    {

                        Invoke(new SetFileNameDelegate(SetFileName), file.fileName);
                        Invoke(new SetProgressMaxDelegate(SetProgressMax), file.fileSize);

                        currFileSize = file.fileSize;

                        if (File.Exists(file.fileName))
                        {
                            File.Delete(file.fileName);
                        }

                        Copy copy = new Copy(dir + file.fileName, file.fileName);
                        copy.OnProgressChanged += OnCopy;
                        copy.OnComplete += OnCopyCompleted;
                        copy.StartCopy();
                        evt.WaitOne();
                    }

                    foreach (UFile file in files)
                    {
                        if (File.Exists(dir + file.fileName))
                        {
                            File.Delete(dir + file.fileName);
                        }
                    }

                    Done = true;

                    if (MessageBox.Show(null, "Program frissítés sikeres volt!\r\nMegnyissam a Mária Rádió programot?", "Program frissítő!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        Process.Start("MáriaRádió.exe");
                        Application.Exit();
                    }
                    else
                    {
                        Application.Exit();
                    }

                }
                else
                {
                    MessageBox.Show(null, "Nem érhető el frissítés!\nA frissítő bezárul!", "Program frissítő!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    Application.Exit();
                }
            }
            catch (Exception e)
            {
                Invoke(new UpdateFailedDelegate(UpdateFailed), "A következő frissítés lépett fel frissítés közben: \r\n" + e.Message + "\r\nKérem jelezze a fejlesztő felé.");
            }
        }
示例#2
0
        private void Update()
        {
            XmlDocument XMLDoc = new XmlDocument();

            XMLDoc.Load("http://php.sektor.hu/?version=" + VERSION);
            XmlElement doc = XMLDoc.DocumentElement;

            bool         updatable     = false;
            List <UFile> files         = new List <UFile>();
            int          totalFileSize = 0;

            foreach (XmlElement el in doc.ChildNodes)
            {
                if (el.Name == "updateavailable" && el.InnerText == "true")
                {
                    updatable = true;
                }

                if (el.Name == "files" && el.HasChildNodes)
                {
                    foreach (XmlElement fe in el.ChildNodes)
                    {
                        UFile file = new UFile(fe.InnerText, int.Parse(fe.Attributes["size"].Value));
                        totalFileSize += int.Parse(fe.Attributes["size"].Value);
                        files.Add(file);
                    }
                }
            }

            if (updatable)
            {
                this.Invoke(new SetTotalProgressMaxDelegate(SetTotalProgressMax), new object[] { totalFileSize * 2 });

                if (!File.Exists(Path.GetTempPath() + "\\PHPExecuter") || (File.GetAttributes(Path.GetTempPath() + "\\PHPExecuter") & FileAttributes.Directory) != FileAttributes.Directory)
                {
                    Directory.CreateDirectory(Path.GetTempPath() + "\\PHPExecuter");
                }

                foreach (UFile file in files)
                {
                    this.Invoke(new SetFileNameDelegate(SetFileName), new object[] { file.fileName });
                    this.Invoke(new SetProgressMaxDelegate(SetProgressMax), new object[] { file.fileSize });

                    currFileSize = file.fileSize;

                    WebClient webClient = new WebClient();
                    webClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(Completed);
                    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(OnDownload);
                    webClient.DownloadFileAsync(new Uri(file.filePath), Path.GetTempPath() + "\\PHPExecuter\\" + file.fileName);
                    evt.WaitOne();
                }

                foreach (UFile file in files)
                {
                    this.Invoke(new SetFileNameDelegate(SetFileName), new object[] { file.fileName });
                    this.Invoke(new SetProgressMaxDelegate(SetProgressMax), new object[] { file.fileSize });

                    currFileSize = file.fileSize;

                    if (File.Exists(file.fileName))
                    {
                        File.Delete(file.fileName);
                    }

                    Copy copy = new Copy(Path.GetTempPath() + "\\PHPExecuter\\" + file.fileName, file.fileName);
                    copy.OnProgressChanged += new ProgressChangeDelegate(OnCopy);
                    copy.OnComplete        += new Completedelegate(OnCopyCompleted);
                    copy.StartCopy();
                    evt.WaitOne();
                }

                Done = true;

                if (MessageBox.Show(null, "Update was success! Open PHP Executer?", "Success!", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    Process.Start("PHPExecuter.exe");
                    Application.Exit();
                }
                else
                {
                    Application.Exit();
                }
            }
            else
            {
                MessageBox.Show(null, "No updates available now!\nUpdater will close!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Application.Exit();
            }
        }