Exemplo n.º 1
0
        public void SaveFile(int IndexInZip)
        {
            ZipEntry zipe     = zip[IndexInZip];
            string   txtTmp   = "";
            string   key      = "";
            string   filePath = System.Windows.Forms.Application.StartupPath + "../../../data/";
            int      i        = 1;

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            filePath = filePath + zipe.Name;
            List <decimal> columnValues = new List <decimal>();
            FileStream     fs           = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
            Stream         s            = zip.GetInputStream(zipe);

            if (s != null)
            {
                StreamReader sr = new StreamReader(s);
                StreamWriter sw = new StreamWriter(fs);

                sw.AutoFlush = true;
                string txt;
                while ((txt = sr.ReadLine()) != null)
                {
                    txtTmp = txtTmp + txt + "\r\n";
                    sb.AppendLine(txt);
                    ReturnProgress();
                }
                sw.Write(txtTmp);
                sw.Close();
                s.Close();
            }
        }
Exemplo n.º 2
0
        public static bool DownloadFileFromZipURL(string ZipURL, string FilePathInZip, string LocalPath)
        {
            if (!isURLValid(ZipURL))
            {
                return(false);
            }

            bool          ret  = false;
            RemoteZipFile file = new RemoteZipFile();

            if (file.Load(ZipURL))
            {
                try
                {
                    IEnumerator enumerator = file.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        ZipEntry current = (ZipEntry)enumerator.Current;
                        if (current.Name == FilePathInZip)
                        {
                            FileStream output = new FileStream(LocalPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                            CopyStream(file.GetInputStream(current), output);
                            output.Close();
                            ret = true;
                        }
                    }
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                catch (Exception) { }
            }
            return(ret);
        }
Exemplo n.º 3
0
        public static void catchemall(string url, string remotepath, string localpath)
        {
            /* Checking if local file exists */
            if (File.Exists(localpath))
            {
                File.Delete(localpath);
            }

            /* creating local file */
            File.Create(localpath).Dispose();

            RemoteZipFile zip = new RemoteZipFile();

            if (zip.Load(url) == false)
            {
                Console.WriteLine("ERROR: Wasn't able to map the remote zip");
                Environment.Exit(1);
            }
            Console.WriteLine("Loaded URL: " + url);

            int itemscount = 0;

            foreach (ZipEntry zipe in zip)
            {
                //Console.WriteLine(zipe.ToString()); <- this prints all zip files (could be helpful for a --list argument)

                if (zipe.ToString() == remotepath)
                {
                    Console.WriteLine("Found remote file: " + zipe.ToString());
                    break;
                }

                itemscount++;
            }

            ZipEntry zipee = zip[itemscount];

            Stream os = File.Open(localpath, FileMode.Open);
            Stream s  = zip.GetInputStream(zipee);

            byte[] bb = new byte[65536];

            try
            {
                while (true)
                {
                    int r = s.Read(bb, 0, bb.Length);
                    if (r <= 0)
                    {
                        break;
                    }
                    os.Write(bb, 0, r);
                }
            }
            catch (Exception ee)
            {
                Console.WriteLine("Unknown error: " + ee);
            }

            os.Close();
            s.Close();
        }