/// <summary>
        /// Obtains the remote update file list and determines if updates are needed.
        /// </summary>
        /// <param name="callback"></param>
        public void GetUpdateFiles(Action<List<UpdateFile>, Exception> callback)
        {
            try
            {
                var worker = new BackgroundWorker();
                worker.DoWork += (sender, e) =>
                    {
                        var tempFiles = new List<UpdateFile>();
                        try
                        {
                            // Parse and validate the update list..
                            var updateList = XDocument.Load(Ashita.Properties.Resources.RemoteUpdateList);
                            if (updateList.Root == null || !updateList.Root.Elements("file").Any())
                            {
                                e.Result = tempFiles;
                                return;
                            }

                            // Process each found file in the update list..
                            foreach (var f in updateList.Root.Elements("file"))
                            {
                                // Read the remote file data..
                                var file = new UpdateFile
                                    {
                                        FileName = f.Attribute("file_name").Value,
                                        FilePath = f.Attribute("file_path").Value,
                                        FullPath = AppDomain.CurrentDomain.BaseDirectory + "//" + f.Attribute("file_path").Value,
                                        RemoteChecksum = f.Attribute("checksum").Value,
                                        LocalChecksum = String.Empty
                                    };

                                // Obtain local checksum if file exists..
                                if (File.Exists(file.FullPath))
                                {
                                    using (var stream = new BufferedStream(File.OpenRead(file.FullPath), 12000000))
                                    {
                                        var md5 = MD5.Create().ComputeHash(stream);
                                        file.LocalChecksum = String.Join("", md5.Select(x => x.ToString("x2")));
                                    }
                                }

                                if (String.Equals(file.LocalChecksum, file.RemoteChecksum))
                                    continue;

                                tempFiles.Add(file);
                            }
                        }
                        catch
                        {
                        }

                        e.Result = tempFiles.ToList();
                    };

                // Assign and invoke the worker..
                worker.RunWorkerCompleted += (sender, e) => callback((List<UpdateFile>)e.Result, null);
                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                callback(null, ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Obtains the remote update file list and determines if updates are needed.
        /// </summary>
        /// <param name="callback"></param>
        public void GetUpdateFiles(Action <List <UpdateFile>, Exception> callback)
        {
            try
            {
                var worker = new BackgroundWorker();
                worker.DoWork += (sender, e) =>
                {
                    var tempFiles = new List <UpdateFile>();
                    try
                    {
                        // Parse and validate the update list..
                        var updateList = XDocument.Load(Ashita.Properties.Resources.RemoteUpdateList);
                        if (updateList.Root == null || !updateList.Root.Elements("file").Any())
                        {
                            e.Result = tempFiles;
                            return;
                        }

                        // Process each found file in the update list..
                        foreach (var f in updateList.Root.Elements("file"))
                        {
                            // Read the remote file data..
                            var file = new UpdateFile
                            {
                                FileName       = f.Attribute("file_name").Value,
                                FilePath       = f.Attribute("file_path").Value,
                                FullPath       = AppDomain.CurrentDomain.BaseDirectory + "//" + f.Attribute("file_path").Value,
                                RemoteChecksum = f.Attribute("checksum").Value,
                                LocalChecksum  = String.Empty
                            };

                            // Obtain local checksum if file exists..
                            if (File.Exists(file.FullPath))
                            {
                                using (var stream = new BufferedStream(File.OpenRead(file.FullPath), 12000000))
                                {
                                    var md5 = MD5.Create().ComputeHash(stream);
                                    file.LocalChecksum = String.Join("", md5.Select(x => x.ToString("x2")));
                                }
                            }

                            if (String.Equals(file.LocalChecksum, file.RemoteChecksum))
                            {
                                continue;
                            }

                            tempFiles.Add(file);
                        }
                    }
                    catch
                    {
                    }

                    e.Result = tempFiles.ToList();
                };

                // Assign and invoke the worker..
                worker.RunWorkerCompleted += (sender, e) => callback((List <UpdateFile>)e.Result, null);
                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                callback(null, ex);
            }
        }