Ejemplo n.º 1
0
        protected override void _Unir(string fichero, string dirDest)
        {
            OnProgress (0, 1);
            long total = new FileInfo (fichero).Length;
            CamouflageMetaInfo info = CamouflageMetaInfo.LoadFromFile (fichero);

            if (info == null) {
                throw new Exception ();
            }

            long pos = 0;
            long largoPiel = info.Archivos[0].Tamano;
            string destino = dirDest + Path.DirectorySeparatorChar + fichero;

            int leidos = 0;
            byte[] buffer = new byte[Consts.BUFFER_LENGTH];
            FileStream inStream = File.OpenRead (fichero);

            if (true) {
                // Este código extrae la piel
                destino = dirDest + Path.DirectorySeparatorChar + info.Archivos[0].Nombre;
                Stream os = UtilidadesFicheros.CreateWriter (destino);
                Stream sls = new SizeLimiterStream (inStream, largoPiel);
                while ((leidos = sls.Read (buffer, 0, buffer.Length)) > 0)
                {
                    os.Write (buffer, 0, leidos);
                    pos += leidos;
                    OnProgress (pos, total);
                }
                os.Close ();

                // Permisos y tiempos de acceso
                if (26 != inStream.Read (buffer, 0, 26))
                {
                    throw new IOException ("Unexpected end of file");
                }
                pos += 26;

            }
            byte[] lc = new byte[4];
            byte[] chunk = new byte[1024 * 1024];
            Aleatorizador aleat = new Aleatorizador ();
            for (int i = 1; i < info.Archivos.Length; i++) {
                destino = dirDest + Path.DirectorySeparatorChar + info.Archivos[i].Nombre;
                Stream os = UtilidadesFicheros.CreateWriter (destino);
                int largoChunk = 0;
                do {
                    if (4 != inStream.Read (lc, 0, 4)) {
                        throw new IOException ("Unexpected end of file");
                    }
                    largoChunk = UtArrays.LeerInt32 (lc, 0);
                    pos += 4;
                    if (largoChunk > 0) {
                        aleat.Reset ();
                        leidos = inStream.Read (chunk, 0, largoChunk);
                        if (leidos != largoChunk) {
                            throw new IOException ("Unexpected end of file");
                        }
                        pos += largoChunk;
                        aleat.Desencriptar (chunk, 0, leidos);
                        os.Write (chunk, 0, leidos);
                    }
                    OnProgress (pos, total);
                } while (largoChunk > 0);
                os.Close ();

                // Permisos y tiempos de acceso
                if (26 != inStream.Read (buffer, 0, 26)) {
                    throw new IOException ("Unexpected end of file");
                }
                pos += 26;
            }
            inStream.Close ();
            OnProgress (total, total);

            //byte[] perm = UtilidadesFicheros.LeerSeek (fichero, pos, 26);
                //info.Archivos[0].Permisos = UtArrays.LeerInt16 (perm, 0);
                //info.Archivos[0].Creado = UtArrays.LeerDateTime (perm, 2);
                //info.Archivos[0].Accedido = UtArrays.LeerDateTime (perm, 10);
                //info.Archivos[0].Modificado = UtArrays.LeerDateTime (perm, 18);

                //FileInfo fi = new FileInfo (destino);
                /*
                Debería funcionar pero el programa falla

                fi.CreationTime = info.Archivos[0].Creado;
                fi.LastAccessTime = info.Archivos[0].Accedido;
                fi.LastWriteTime = info.Archivos[0].Modificado;
                */
                //fi.Attributes = (FileAttributes) info.Archivos[0].Permisos;
        }
Ejemplo n.º 2
0
        public void Unir(FileInfo fichero, DirectoryInfo dirDest)
        {
            DalleStream dstream = new DalleStream (fichero);

            byte[] buffer = new byte[Consts.BUFFER_LENGTH];
            OnProgress (0, dstream.Length);
            Stream gzipStream = new GZipStream (dstream, CompressionMode.Decompress);

            TarInputStream tarStream = new TarInputStream (gzipStream);

            TarEntry tarEntry = null;

            OnProgress (0, 1);

            while ((tarEntry = tarStream.GetNextEntry ()) != null) {
                // Tamaño de la cabecera de la entrada.
                // Nota: TarInputStream ignora sileciosamente algunas entradas,
                // por lo que el progreso no será totalmente preciso.
                if (tarEntry.IsDirectory) {
                    continue;
                }
                Stream entrada = new SizeLimiterStream (tarStream, tarEntry.Size);
                Stream salida = UtilidadesFicheros.CreateWriter (dirDest.FullName + Path.DirectorySeparatorChar + tarEntry.Name);

                int leidos = 0;

                while ((leidos = entrada.Read (buffer, 0, buffer.Length)) > 0) {
                    salida.Write (buffer, 0, leidos);
                    OnProgress (dstream.Position, dstream.Length+1); // +1 para evitar llegar al 100% antes de tiempo
                }
                salida.Close ();

            }
            tarStream.Close ();
            OnProgress (1, 1);
        }
Ejemplo n.º 3
0
        protected override void _Unir(string fichero, string dirDest)
        {
            if (!File.Exists (fichero)) {
                return;
            }
            FileInfo fi = new FileInfo (fichero);
            long datosTotales = fi.Length;
            long uncompressedSize = 0;
            FileStream input = File.OpenRead (fichero);
            Stream input2 = input;

            if (fichero.ToLower ().EndsWith (".bz2") || fichero.ToLower ().EndsWith (".tbz2") || fichero.ToLower ().EndsWith (".tbz"))
            {
                // No hay forma de saber el tamaño descomprimido de un bz2 de forma inmediata
                input2 = new BZip2InputStream (input);
            }
            else if (fichero.ToLower ().EndsWith (".gz") || fichero.ToLower ().EndsWith (".tgz"))
            {
                uncompressedSize = Dalle.Formatos.GZip.GZip.GetUncompressedSize (input);
                input2 = new GZipStream (input, CompressionMode.Decompress);
            }
            else if (fichero.ToLower ().EndsWith (".tar.lzma") || fichero.ToLower ().EndsWith ("tlz"))
            {
                input2 = new LZMAInputStream (input);
                uncompressedSize = ((LZMAInputStream)input2).UncompressedSize;
            }
            TarInputStream tarInput = new TarInputStream (input2);

            TarEntry tarEntry = null;
            byte[] buffer = new byte[Consts.BUFFER_LENGTH];
            OnProgress (0, 1);
            long transferidos = 0;
            while ((tarEntry = tarInput.GetNextEntry ()) != null)
            {
                // Tamaño de la cabecera de la entrada.
                // Nota: TarInputStream ignora sileciosamente algunas entradas,
                // por lo que el progreso no será totalmente preciso.
                transferidos += 512;
                if (tarEntry.IsDirectory)
                {
                    continue;
                }
                Stream entrada = new SizeLimiterStream (tarInput, tarEntry.Size);
                Stream salida = UtilidadesFicheros.CreateWriter (dirDest + Path.DirectorySeparatorChar + tarEntry.Name);

                int leidos = 0;

                while ((leidos = entrada.Read (buffer, 0, buffer.Length)) > 0)
                {
                    salida.Write (buffer, 0, leidos);
                    transferidos += leidos;
                    if (uncompressedSize > 0)
                    {
                        OnProgress (transferidos, uncompressedSize);
                    }
                    else {
                        OnProgress (input.Position, datosTotales);
                    }
                }
                salida.Close ();
                transferidos += 512 - (tarEntry.Size % 512);
            }
            tarInput.Close ();
            OnProgress (1, 1);
        }