Esempio n. 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (!textBox1.Text.EndsWith("\\"))
            {
                textBox1.AppendText("\\");
            }
            label3.Text = "Collecting file information...";
            label3.Refresh();
            Application.DoEvents();
            List <FileCandidate> fc = new List <FileCandidate>();
            var files = Directory.GetFiles(textBox1.Text, "*.*", SearchOption.AllDirectories);
            int ctor  = 0;

            foreach (var f in files)
            {
                ctor++;
                fc.Add(new FileCandidate(f));
            }
            var privkey = File.ReadAllText(textBox3.Text);

            label3.Text = "Writing file information...(" + ctor.ToString() + " files)";
            label3.Refresh();
            Application.DoEvents();
            MemoryStream writes = new MemoryStream();

            KrileArchive.Compress(writes, textBox1.Text, fc);
            writes.Seek(0, SeekOrigin.Begin);
            using (var fs = new FileStream(textBox2.Text, FileMode.Create, FileAccess.Write))
            {
                using (var gz = new GZipStream(fs, CompressionMode.Compress))
                {
                    KASignature.Signature(writes, gz, privkey);
                }
            }
            using (var fs = new FileStream(textBox2.Text, FileMode.Open, FileAccess.Read))
                using (var gz = new GZipStream(fs, CompressionMode.Decompress))
                {
                    MemoryStream verified = new MemoryStream();
                    if (!KASignature.Verify(gz, verified, privkey))
                    {
                        throw new SecurityException("Patch-pack verification failed.");
                    }
                    verified.Seek(0, SeekOrigin.Begin);
                    Directory.CreateDirectory(textBox2.Text + "__");
                    KrileArchive.Extract(verified, textBox2.Text + "__");
                }
            label3.Text = "Completed!";
            label3.Refresh();
            Application.DoEvents();
        }
Esempio n. 2
0
        public void SequenceApplyPatches(IEnumerable <string> uris)
        {
            SetCancellableInvoke(false);
            WriteLine("Starting patch...");
            var pubkey = File.ReadAllText(Path.Combine(Application.StartupPath, publicKeyFile));

            foreach (var uri in uris)
            {
                WriteLine("Downloading patch-pack " + uri + "...");
                var dlstream = DownloadStream(new Uri(uri));
                if (dlstream == null)
                {
                    throw new Exception("File download error: " + uri);
                }
                string dest = null;
                while (dest == null || Directory.Exists(dest) || File.Exists(dest))
                {
                    dest = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                }
                Directory.CreateDirectory(dest);
                try
                {
                    using (var gz = new GZipStream(dlstream, CompressionMode.Decompress))
                    {
                        WriteLine("Verifying patch-pack...");
                        MemoryStream verified = new MemoryStream();
                        if (!KASignature.Verify(gz, verified, pubkey))
                        {
                            throw new SecurityException("Patch-pack verification failed.");
                        }
                        WriteLine("Extracting patch-pack...");
                        verified.Seek(0, SeekOrigin.Begin);
                        KrileArchive.Extract(verified, dest);
                        WriteLine("Updating files...");
                        MoveDirectory(dest, Application.StartupPath, true);
                        WriteLine("Complete.");
                    }
                }
                finally
                {
                    WriteLine("Removing temporally files...");
                    Directory.Delete(dest, true);
                }
            }
            WriteLine("All Done!");
        }