public Splash()
        {
            AddProcessor(typeof(ANWI.Messaging.Updater.CheckResult),
                         ProcessUpdateStatus);
            AddProcessor(typeof(ANWI.Messaging.Updater.Chunk),
                         ProcessUpdateChunk);

            this.DataContext = this;
            InitializeComponent();

            Task t = new Task(() => {
                try {
                    MessageRouter.Instance.Connect(MessageRouter.Service.Update);
                    MessageRouter.Instance.Send(
                        MessageRouter.Service.Update,
                        new ANWI.Messaging.Updater.Check()
                    {
                        checksums = MD5List.GetDirectoryChecksum(".")
                    },
                        this);
                } catch (Exception e) {
                    this.Dispatcher.Invoke(() => {
                        Text_Message.Text       = "Failed to Connect to Server.";
                        Text_Message.Foreground = Brushes.Red;
                    });
                    Thread.Sleep(2000);
                    Process.GetCurrentProcess().Kill();
                }
            });

            t.Start();
        }
Example #2
0
        private IMessagePayload ProcessCheckUpdate(IMessagePayload p)
        {
            Check check = p as Check;

            if (Configuration.updateDir == null)
            {
                return(new CheckResult()
                {
                    updateNeeded = false
                });
            }

            Dictionary <string, string> localChecksums
                = MD5List.GetDirectoryChecksum(Configuration.updateDir);

            List <string> differences
                = GetFileDifferences(localChecksums, check.checksums);

            if (differences.Count == 0)
            {
                logger.Info($"Client {GetLogIdentifier()} is up to date");

                return(new CheckResult()
                {
                    updateNeeded = false
                });
            }
            else
            {
                string differenceString = "";
                foreach (string file in differences)
                {
                    differenceString += $"{file} ";
                }

                logger.Info(
                    $"Client {GetLogIdentifier()} has the following files " +
                    "out of date: " + differenceString);

                // Package up the files that don't match for the client
                // to request in chunks
                zipStream = new MemoryStream();
                using (ZipArchive archive
                           = new ZipArchive(zipStream, ZipArchiveMode.Create, true)) {
                    foreach (string file in differences)
                    {
                        archive.CreateEntryFromFile(
                            Path.Combine(Configuration.updateDir, file),
                            file);
                    }

                    archive.Dispose();
                }

                zipStream.Position = 0;

                return(new CheckResult()
                {
                    updateNeeded = true,
                    updateSize = zipStream.Length
                });
            }
        }