Ejemplo n.º 1
0
        public UploadData getFile(SerializedVersion serV)
        {
            FBVersion  ver   = FBVersion.deserialize(serV.encodedVersion);
            PhysicFile found = null;

            if (ver.fileList.Count != 1)
            {
                return(null);
            }

            foreach (FBFile file in ver.fileList)
            {
                found = findPhysicFile(file);
                if (found == null)
                {
                    return(null);
                }
            }

            FileStream fStream = new FileStream(found.getRealFileInfo().FullName,
                                                FileMode.Open, FileAccess.Read);
            String token   = Server.GetUniqueKey(20);
            var    secDown = new SecureDownloader(this, token, null, null, fStream);

            return(new UploadData(UsefullMethods.GetLocalIPAddress(), secDown.port,
                                  token));
        }
Ejemplo n.º 2
0
        private UploadData resetInternals(FBVersion newVersion, FBVersion current)
        {
            FBVersion diff = newVersion - current;

            newVersion.setAbsoluteNameToFile();
            if (diff.root != null) diff.setAbsoluteNameToFile();
            current.setAbsoluteNameToFile();

            List<Instruction> instrucionList = new List<Instruction>();

            try { File.Delete(user.rootDirectory.FullName + @"\tmp.zip"); }
            catch { }

            ZipArchive zip = ZipFile.Open(user.rootDirectory.FullName + @"\tmp.zip", ZipArchiveMode.Update);

            if (diff.fileList != null)
                foreach (FBAbstractElement to in diff.fileList)
                {
                    bool found = false;
                    foreach (FBAbstractElement from in current.fileList)
                    {
                        if (from.Equals(to))
                        {
                            found = true;
                            instrucionList.Add(new Instruction(InstructionType.COPY, from.Name, to.Name));
                            break;
                        }
                    }

                    if (!found)
                    {
                        foreach (PhysicFile ph in realFiles.list)
                        {
                            if (ph.getFBFile().Equals(to))
                            {
                                if (zip.GetEntry(ph.getRealFileInfo().Name) == null)
                                {
                                    zip.CreateEntryFromFile(ph.getRealFileInfo().FullName, ph.getRealFileInfo().Name, CompressionLevel.Optimal);
                                }
                                instrucionList.Add(new Instruction(InstructionType.NEW, ph.getRealFileInfo().Name, to.Name));
                            }
                        }
                    }
                }

            diff = current - newVersion;

            if (diff.fileList != null)
            {
                //diff.setAbsoluteNameToFile();
                foreach (FBAbstractElement toDelete in diff.fileList)
                {
                    instrucionList.Add(new Instruction(InstructionType.DELETE, toDelete.Name, ""));
                }
            }
            Stream FilesStream = File.OpenWrite(this.user.rootDirectory + @"\instructions.bin");
            BinaryFormatter serializer = new BinaryFormatter();
            serializer.Serialize(FilesStream, instrucionList);
            FilesStream.Close();

            zip.CreateEntryFromFile(this.user.rootDirectory + @"\instructions.bin", "instructions.bin", CompressionLevel.Optimal);
            File.Delete(this.user.rootDirectory + @"\instructions.bin");
            zip.Dispose();
            FilesStream = new FileStream(user.rootDirectory.FullName + @"\tmp.zip", FileMode.Open, FileAccess.Read);

            string token = Server.GetUniqueKey(20);
            SecureDownloader sr = new SecureDownloader(this, token,
                this.ManageCompleteUpload, this.ManageFailedUpload, FilesStream);
            UInt16 port = sr.port;

            return new UploadData(UsefullMethods.GetLocalIPAddress(), port, token);
        }
Ejemplo n.º 3
0
        private UploadData resetInternals(FBVersion newVersion, FBVersion current)
        {
            FBVersion diff = newVersion - current;

            newVersion.setAbsoluteNameToFile();
            if (diff.root != null)
            {
                diff.setAbsoluteNameToFile();
            }
            current.setAbsoluteNameToFile();

            List <Instruction> instrucionList = new List <Instruction>();

            try { File.Delete(user.rootDirectory.FullName + @"\tmp.zip"); }
            catch { }

            ZipArchive zip = ZipFile.Open(user.rootDirectory.FullName + @"\tmp.zip", ZipArchiveMode.Update);

            if (diff.fileList != null)
            {
                foreach (FBAbstractElement to in diff.fileList)
                {
                    bool found = false;
                    foreach (FBAbstractElement from in current.fileList)
                    {
                        if (from.Equals(to))
                        {
                            found = true;
                            instrucionList.Add(new Instruction(InstructionType.COPY, from.Name, to.Name));
                            break;
                        }
                    }

                    if (!found)
                    {
                        foreach (PhysicFile ph in realFiles.list)
                        {
                            if (ph.getFBFile().Equals(to))
                            {
                                if (zip.GetEntry(ph.getRealFileInfo().Name) == null)
                                {
                                    zip.CreateEntryFromFile(ph.getRealFileInfo().FullName, ph.getRealFileInfo().Name, CompressionLevel.Optimal);
                                }
                                instrucionList.Add(new Instruction(InstructionType.NEW, ph.getRealFileInfo().Name, to.Name));
                            }
                        }
                    }
                }
            }

            diff = current - newVersion;

            if (diff.fileList != null)
            {
                //diff.setAbsoluteNameToFile();
                foreach (FBAbstractElement toDelete in diff.fileList)
                {
                    instrucionList.Add(new Instruction(InstructionType.DELETE, toDelete.Name, ""));
                }
            }
            Stream          FilesStream = File.OpenWrite(this.user.rootDirectory + @"\instructions.bin");
            BinaryFormatter serializer  = new BinaryFormatter();

            serializer.Serialize(FilesStream, instrucionList);
            FilesStream.Close();

            zip.CreateEntryFromFile(this.user.rootDirectory + @"\instructions.bin", "instructions.bin", CompressionLevel.Optimal);
            File.Delete(this.user.rootDirectory + @"\instructions.bin");
            zip.Dispose();
            FilesStream = new FileStream(user.rootDirectory.FullName + @"\tmp.zip", FileMode.Open, FileAccess.Read);

            string           token = Server.GetUniqueKey(20);
            SecureDownloader sr    = new SecureDownloader(this, token,
                                                          this.ManageCompleteUpload, this.ManageFailedUpload, FilesStream);
            UInt16 port = sr.port;

            return(new UploadData(UsefullMethods.GetLocalIPAddress(), port, token));
        }
Ejemplo n.º 4
0
        public UploadData getFile(SerializedVersion serV)
        {
            FBVersion ver = FBVersion.deserialize(serV.encodedVersion);
            PhysicFile found = null;

            if (ver.fileList.Count != 1)
                return null;

            foreach(FBFile file in ver.fileList)
            {
                found = findPhysicFile(file);
                if (found == null)
                    return null;
            }

            FileStream fStream = new FileStream(found.getRealFileInfo().FullName,
                FileMode.Open, FileAccess.Read);
            String token = Server.GetUniqueKey(20);
            var secDown = new SecureDownloader(this, token, null, null, fStream);

            return new UploadData(UsefullMethods.GetLocalIPAddress(), secDown.port,
                token);
        }