public void ShowNewFile(FileState fs)
 {
     dgvFiles.BeginInvoke((MethodInvoker) delegate()
     {
         lock (dgvFiles) {
             fileShowList.Add(new FileShow(fs));
             dgvFiles.DataSource = null;
             dgvFiles.DataSource = new BindingList <FileShow>(fileShowList);
             HideColumns();
         }
     });
 }
        public FileState ProvideFileState(int fileId)
        {
            FileDescription fd = FileDescriptions[fileId];

            string fullName = fd.FileName;

            if (fd.FileExtension != null && fd.FileExtension != "")
            {
                fullName += "." + fd.FileExtension;
            }
            FileStream mainFileStream = new FileStream(fd.Path + "\\" + fullName, FileMode.Open, FileAccess.ReadWrite);

            if (fd.Fts != FileTransferState.Deleted && fd.Fts != FileTransferState.Finished)
            {
                FileStream descriptorFile = new FileStream(".\\descriptors\\descriptor_" + fullName + ".desc", FileMode.Open, FileAccess.ReadWrite);
                FileState  fs             = new FileState();
                fs.FileDescription = fd;

                byte[] chunksState = new byte[Sizes.GetChunksNumber(fd.FileSize)];
                descriptorFile.Seek(0, SeekOrigin.Begin);
                int numberOfChunks = Sizes.GetChunksNumber(fd.FileSize);
                descriptorFile.Read(chunksState, 0, numberOfChunks);

                fs.ChunksState = Utils.GetBitForByte(chunksState);
                int downloaded = 0;
                foreach (bool b in fs.ChunksState)
                {
                    if (b == true)
                    {
                        downloaded++;
                    }
                }
                fs.FinishedChunksNumber = downloaded;

                fs.FileManager = new FileIOManager(mainFileStream, descriptorFile);
                return(fs);
            }
            else
            {
                FileState fs = new FileState();
                fs.FileDescription      = fd;
                fs.FinishedChunksNumber = fs.NumberOfChunks;
                fs.FileManager          = new FileIOManager(mainFileStream);
                return(fs);
            }
        }
        public void LocalFileInitTransfer(FileDescription fd)
        {
            Debug.WriteLine("LocalFileInitTransfer:" + fd.FileId);
            fd.Ftm = FileTransferMode.OnlyUpload;
            fd.Fts = FileTransferState.Finished;
            NewFileTransferManager.nftm.NewUploadFile(fd, fd.Path);
            MasterFileManager.mfm.RecordNewFile(fd);

            FileState           fs  = MasterFileManager.mfm.ProvideFileState(fd.FileId);
            ActiveFileResources afr =
                new ActiveFileResources(
                    fs,
                    new FileUploadManager(fs, false)
                    );

            FileTransferCenter.ftc.AddFile(afr);

            FrmFileTransfers.frmFileTransfers.ShowNewFile(fs);
        }
        public void NewFileStartTransfer(FileDescription fd, ChunkHash[] hashes)
        {
            Debug.WriteLine("NewFileStartTransfer:" + fd.FileId);
            fd.Ftm = FileTransferMode.DownloadAndUpload;
            fd.Fts = FileTransferState.Normal;

            NewFileTransferManager.nftm.NewDownloadFile(fd, hashes);

            MasterFileManager.mfm.RecordNewFile(fd);

            FileState fs = MasterFileManager.mfm.ProvideFileState(fd.FileId);

            ActiveFileResources afr =
                new ActiveFileResources(
                    fs,
                    new FileDownloadManager(fd.FileId, fs, false),
                    new FileUploadManager(fs, false)
                    );

            FileTransferCenter.ftc.AddFile(afr);

            FrmFileTransfers.frmFileTransfers.ShowNewFile(fs);
        }
Exemple #5
0
 public FileShow(FileState fs)
 {
     this.fs = fs;
 }
 public FileUploadManager(FileState fs, bool pausedInput)
 {
     this.fs = fs;
     paused  = pausedInput;
 }
Exemple #7
0
 public ActiveFileResources(FileState fsInput, FileDownloadManager fdmInput, FileUploadManager fumInput)
 {
     this.fs  = fsInput;
     this.fdm = fdmInput;
     this.fum = fumInput;
 }
Exemple #8
0
 public ActiveFileResources(FileState fsInput)
 {
     this.fs  = fsInput;
     this.fdm = null;
     this.fum = null;
 }