Example #1
0
        static void GetNewFileZip(IProgressReporterDialogue frmProgressReporter, string baseurl, string subdir, string file)
        {
            // create dest dir
            string dir = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            // get dest path
            string path = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir +
                          file;

            DownloadStream ds = new DownloadStream(baseurl);

            ZipArchive zip = new ZipArchive(ds);

            var entry = zip.GetEntry((subdir.TrimStart('\\').Replace('\\', '/') + file));

            if (entry == null)
            {
                Console.WriteLine("{0} {1}", file, baseurl);
                return;
            }

            log.InfoFormat("unzip {0}", file);

            entry.ExtractToFile(path + ".new", true);

            zip.Dispose();

            ds.Dispose();
        }
Example #2
0
        static void GetNewFileZip(IProgressReporterDialogue frmProgressReporter, string baseurl, string subdir, string file)
        {
            // create dest dir
            string dir = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir;

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            // get dest path
            string path = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir +
                          file;

            using (DownloadStream ds = new DownloadStream(baseurl))
                using (ZipArchive zip = new ZipArchive(ds))
                {
                    log.InfoFormat("zip entry get {0}", (subdir.TrimStart('/').TrimStart('\\').Replace('\\', '/') + file));

                    var entry = zip.GetEntry((subdir.TrimStart('/').TrimStart('\\').Replace('\\', '/') + file));

                    if (entry == null)
                    {
                        log.InfoFormat("zip missing entry {0} {1}", file, baseurl);
                        return;
                    }

                    ds.chunksize = (int)entry.CompressedLength;

                    log.InfoFormat("unzip {0}", file);

                    using (var fo = File.Open(path + ".new", FileMode.Create))
                    {
                        entry.Open().CopyTo(fo, 1024 * 1024);
                        fo.Flush(true);
                        fo.Dispose();
                    }

                    zip.Dispose();
                    ds.Dispose();
                }
        }