Example #1
0
        // deprecated
        public int Partir(string fichero, string sal1, string dir, long kb, JoinInfo info)
        {
            long tamano = new FileInfo (fichero).Length;
            long tFragmento = 1024 * kb;
            long transferidos = 0;

            Stream fis = File.OpenRead (fichero);
            int leidos = 0;
            byte[] buffer = new byte[Consts.BUFFER_LENGTH];
            int contador = 0;
            do {

                string fullOutputFilename = info.Directory.FullName +
                    Path.DirectorySeparatorChar +
                    info.GetFragmentName (contador + 1);
                Stream fos = UtilidadesFicheros.CreateWriter (fullOutputFilename);
                long parcial = 0;
                while ((leidos = fis.Read (buffer, 0, (int)Math.Min (tFragmento - parcial, buffer.Length))) > 0)
                {
                    fos.Write (buffer, 0, leidos);
                    parcial += leidos;
                    transferidos += leidos;
                    OnProgress (transferidos, tamano);
                }
                fos.Close();
                contador++;
            } while (transferidos < tamano);
            fis.Close();
            info.FragmentsNumber = contador;
            return contador;
        }
Example #2
0
        protected override void _Partir(string fichero, string sal1, string dir, long kb)
        {
            JoinInfo info = new JoinInfo ();

            info.InitialFragment = 1;
            info.Digits = 3;
            info.OriginalFile = new FileInfo (fichero).Name;
            info.BaseName = info.OriginalFile;
            info.Directory = new DirectoryInfo (dir);
            // TODO Rewrite to use new generic
            int fragmentos = new ParteGenerico().Partir (fichero, sal1, dir, kb, info);

            MXSInfo mxsinfo = new MXSInfo ();
            mxsinfo.NombreOriginal = info.OriginalFile;
            mxsinfo.TamanoOriginal = new FileInfo (fichero).Length;
            mxsinfo.Fragmentos = fragmentos;

            Stream fos = UtilidadesFicheros.CreateWriter(dir+Path.DirectorySeparatorChar+fichero+".mxs");
            byte[] mxs = mxsinfo.ToByteArray();
            fos.Write(mxs, 0, mxs.Length);
            fos.Close();
        }
Example #3
0
        public static JoinInfo GetFromFile(string fichero)
        {
            JoinInfo info = new JoinInfo ();
            info.Directory = new FileInfo (fichero).Directory;
            string original = new FileInfo (fichero).Name;
            string extensionParte = original.Substring (original.LastIndexOf (".")+1);
            info.BaseName = original.Substring (0, original.LastIndexOf ('.') + 1);
            info.OriginalFile = original.Substring (0, original.LastIndexOf ('.'));

            // Soporte ultrasplit
            if (extensionParte.StartsWith ("u")) {
                info.BaseName = original.Substring (0, original.LastIndexOf ('.') + 2);
            }
            info.Digits = original.Length - info.BaseName.Length;

            if (File.Exists (info.Directory.FullName + Path.DirectorySeparatorChar + info.BaseName + UtilidadesCadenas.Format (0, info.Digits)))
            {
                info.InitialFragment = 0;
            }
            else if (File.Exists (info.Directory.FullName + Path.DirectorySeparatorChar + info.BaseName  + UtilidadesCadenas.Format (1, info.Digits)))
            {
                info.InitialFragment = 1;
            }
            else {
                return null;
            }
            int contador = 1;

            while (File.Exists (info.GetFragmentFullPath (contador)))
            {
                FileInfo fi = new FileInfo (info.GetFragmentFullPath (contador));
                info.Length += fi.Length;
                contador++;
            }
            info.FragmentsNumber = contador - 1;

            // Comprobar cutkiller
            if (info.InitialFragment == 1 && info.Digits == 3)
            {
                byte[] buffer = UtilidadesFicheros.LeerSeek (info.GetFragmentFullPath(1), 0, 8);
                string extension = UtArrays.LeerTexto (buffer, 0, 3);
                string fragmentos = UtArrays.LeerTexto (buffer, 3, 5);
                if (extension.Length > 0 && fragmentos.Length == 5)
                {
                    if (
                        Char.IsWhiteSpace (fragmentos[0]) &&
                        Char.IsWhiteSpace (fragmentos[1]) &&
                        Char.IsDigit (fragmentos[2]) &&
                        Char.IsDigit (fragmentos[3]) &&
                        Char.IsDigit (fragmentos[4]) &&
                        Int32.Parse (fragmentos.Trim ()) == info.FragmentsNumber

                    )
                    {
                        info.IsCutKiller = true;
                        info.OriginalFile = info.OriginalFile + "." + extension;
                        info.Length -= 8;
                    }
                }
            }
            info.CalculateLength();
            return info;
        }
Example #4
0
        protected override void _Partir(string fichero, string sal1, string dir, long kb)
        {
            FileInfo fi = null;
            DirectoryInfo din = null;
            DirectoryInfo dout = new DirectoryInfo (dir);

            if (File.Exists (fichero)) {
                fi = new FileInfo (fichero);
            } else if (Directory.Exists (fichero)) {
                din = new DirectoryInfo (fichero);
            } else {
                throw new Exception ("" + fichero + " not found");
            }
            List<FileInfo> files = load (fichero);

            string baseName = "";
            if (fi != null) {
                baseName = fi.Name;
            } else if (din != null) {
                baseName = din.Name;
            }

            if ((sal1 == null) || (sal1 == string.Empty)) {
                //
                if (din != null) {
                    sal1 = din.Name;
                }
                if (fi != null) {
                    sal1 = fi.Name;
                }
            }

            long totalSize = calculateTotalSize (files);
            long fragments = totalSize / (kb * 1024);
            string s = "" + fragments;
            JoinInfo info = new JoinInfo ();
            info.OriginalFile = baseName;
            info.InitialFragment = 0;
            info.Digits = Math.Max (s.Length, 3);
            info.BaseName = sal1 + ".tar.gz.";
            info.Directory = dout;
            info.Length = totalSize;

            Stream stream = new SplitStream (info, kb * 1024, info.Directory.FullName + Path.DirectorySeparatorChar + info.BaseName + "sha512sum.dalle", "SHA512");
            stream = new GZipStream (stream, CompressionMode.Compress);
            TarOutputStream taros = new TarOutputStream (stream);
            foreach (FileInfo f in files) {

                TarEntry te = TarEntry.CreateEntryFromFile (f.FullName);
                te.UserId = 0;
                te.GroupId = 0;
                te.UserName = String.Empty;
                te.GroupName = String.Empty;
                taros.PutNextEntry (te);
                FileStream fs = f.OpenRead ();
                long leidosTotales = 0;
                byte[] buffer = new byte[Consts.BUFFER_LENGTH];
                int leidos = 0;
                while ((leidos = fs.Read (buffer, 0, buffer.Length)) > 0) {
                    taros.Write (buffer, 0, leidos);
                    leidosTotales += leidos;
                    OnProgress (leidosTotales, totalSize);
                }
                taros.CloseEntry ();
                fs.Close ();
            }
            taros.Close ();
            OnProgress (totalSize, totalSize);
        }
Example #5
0
        /// <returns>El numero de fragmentos que se han creado.</returns>
        // TODO: Cambiar el orden de los parametros (String, st, long, int, int).
        protected override void _Partir(string fichero, string sal1, string dir, long kb)
        {
            if ((sal1 == null) || (sal1 == string.Empty))
            {
                sal1 = new FileInfo (fichero).Name;
            }
            JoinInfo info = new JoinInfo ();

            info.InitialFragment = 1;
            info.Digits = 3;
            info.OriginalFile = new FileInfo (fichero).Name;
            //info.BaseName = info.OriginalFile;
            info.BaseName = sal1 +".";
            info.Directory = new DirectoryInfo (dir);

            Stream stream = new SplitStream (
                info,
                kb * 1024,
                dir + Path.DirectorySeparatorChar + info.BaseName + "sha512sum",
                "SHA512");
            byte[] buffer = new byte[Consts.BUFFER_LENGTH];
            int leidos = 0;
            long transferidos = 0;
            long tamano = new FileInfo (fichero).Length;
            OnProgress (0, tamano);
            Stream fis = File.OpenRead (fichero);
            while ((leidos = fis.Read (buffer, 0, buffer.Length)) > 0) {
                stream.Write (buffer, 0, leidos);
                transferidos += leidos;
                OnProgress (transferidos, tamano);
            }
            fis.Close ();
            stream.Close ();

            //Partir (fichero, sal1, dir, kb, info);
        }
Example #6
0
 public void Unir(string fichero, string dirDest, JoinInfo info)
 {
     byte[] buffer = new byte[Consts.BUFFER_LENGTH];
     int leidos = 0;
     long transferidos = 0;
     OnProgress (0, info.Length);
     Stream fos = UtilidadesFicheros.CreateWriter (dirDest + Path.DirectorySeparatorChar + info.OriginalFile);
     Stream fis = new JoinStream (info);
     while ((leidos = fis.Read(buffer, 0, buffer.Length)) > 0) {
         transferidos += leidos;
         fos.Write (buffer, 0, leidos);
         OnProgress (transferidos, info.Length);
     }
     fis.Close ();
     fos.Close ();
 }
Example #7
0
        protected override void _Unir(string fichero, string dirDest)
        {
            FileInfo fi = new FileInfo (fichero);
            string[] partes = GetPartesNombre (fi.Name);
            JoinInfo info = new JoinInfo ();
            info.Digits = 3;
            info.InitialFragment = 1;
            info.BaseName = partes[0];
            info.OriginalFile = info.BaseName;
            info.FragmentsNumber = Int32.Parse (partes[2]);
            info.Format = info.BaseName + "{0:D3}-" + info.FragmentsNumber;
            info.Directory = fi.Directory;
            info.CalculateLength ();

            new ParteGenerico ().Unir (fichero, dirDest, info);
        }
Example #8
0
 public SplitStream(JoinInfo info, long fragmentSize)
 {
     this.info = info;
     this.fragmentSize = fragmentSize;
 }
Example #9
0
 public SplitStream(JoinInfo info, long fragmentSize, string md5File, string hashAlg)
     : this(info, fragmentSize)
 {
     this.md5File = md5File;
     this.hashAlg = hashAlg;
 }