Ejemplo n.º 1
0
        } /* FileCopyStats */



        private void  BuildFileListView()
        {
            filesTotal  = 0;
            filesCopied = 0;
            bytesTotal  = 0;
            bytesCopied = 0;

            FileListView.Items.Clear();


            foreach (SipperFileControlBlock fcb  in  filesToCopy)
            {
                string        fileName = fcb.FileName;
                ListViewItem  lvi      = new ListViewItem(fileName);
                FileCopyStats fcs      = new FileCopyStats(fcb, lvi);
                fileCopyStatsList.Add(fcs);
                FileListView.Items.Add(lvi);
                filesTotal++;
                bytesTotal += fcb.FileSizeInBytes;
            }
        } /* BuildFileListView */
Ejemplo n.º 2
0
        } /* BuildFileListView */

        private void  CopyFileList()
        {
            int readBlockSizeMax = 100 * 1024;
            int readBlockSize    = readBlockSizeMax;
            int readErrorsInARow = 0;

            downLoadingRunning = true;

            byte[] buff = new byte[readBlockSizeMax];
            foreach (FileCopyStats fcs in  fileCopyStatsList)
            {
                SipperFileControlBlock fcb = fcs.Fcb;

                SipperDiskFile s = disk.OpenSipperDiskFile(fcb.FcbIndex);
                if (s == null)
                {
                    return;
                }

                fcs.Size = s.Length;

                string destFileName = OSservices.AddSlash(destDir) + fcs.FileName;
                destFileName = destFileName.Trim('\0') + ".spr";

                FileStream destFile = null;
                try
                {
                    destFile = new FileStream(destFileName, FileMode.Create, FileAccess.Write, FileShare.None);
                }
                catch (Exception e)
                {
                    MessageBox.Show("Error opening File[" + destFileName + "] occurred." + "\n\n" + e.ToString(),
                                    "CopyFileList",
                                    MessageBoxButtons.OK
                                    );
                    // We will try continuing on to the next file to download.
                    continue;
                }

                currentFCS = fcs;

                bool eof            = false;
                long nextReadOffset = 0;
                long bytesToSkipped = 0;

                while ((!downLoadingTerminate) && (!eof))
                {
                    int bytesRead = 0;
                    try
                    {
                        if (nextReadOffset != s.Position)
                        {
                            s.Seek(nextReadOffset, SeekOrigin.Begin);
                        }

                        bytesRead      = s.Read(buff, 0, readBlockSize);
                        nextReadOffset = s.Position;
                        if (bytesRead == 0)
                        {
                            eof = true;
                        }
                        else
                        {
                            // Since we did not have an error;  we might as well set the
                            // readBlockSize to its max
                            readBlockSize    = buff.Length;
                            readErrorsInARow = 0;
                            bytesToSkipped   = 0;
                        }
                    }
                    catch (Exception e)
                    {
                        DialogResult dr = MessageBox.Show("Disk Error Occurred trying to read SIPPER disk" + "\n\n" +
                                                          "Do you want to keep on reading?" + "\n\n" +
                                                          e.ToString(),
                                                          "CopyFileList",
                                                          MessageBoxButtons.YesNo
                                                          );
                        if (dr == DialogResult.No)
                        {
                            eof = true;
                            break;
                        }
                        else
                        {
                            readErrorsInARow++;
                            readBlockSize = 4096;
                            if (readErrorsInARow < 5)
                            {
                                bytesToSkipped = 4 * 1024;
                            }

                            else if (readErrorsInARow < 10)
                            {
                                bytesToSkipped = 20 * 1024;
                            }

                            else if (readErrorsInARow < 15)
                            {
                                bytesToSkipped = 100 * 1024;
                            }

                            else if (readErrorsInARow < 20)
                            {
                                bytesToSkipped = 1024 * 1024;
                            }

                            else
                            {
                                bytesToSkipped = 10 * 1024 * 1024;
                            }
                        }
                        nextReadOffset += bytesToSkipped;
                    }


                    if (!eof)
                    {
                        try { destFile.Write(buff, 0, bytesRead); }
                        catch (Exception e)
                        {
                            downLoadingTerminate = true;
                            MessageBox.Show(e.ToString(), "Error saving Sipper File[" + fcs.FileName + "]", MessageBoxButtons.OK);
                            break;
                        }

                        fcs.AddToCopied(bytesRead);
                        fcs.AddToSkipped(bytesToSkipped);
                        bytesCopied += bytesRead;
                    }
                }

                s.Close();
                s.Dispose();
                s = null;

                destFile.Close();
                destFile.Dispose();
                destFile = null;

                if (fcs.Copied >= fcs.Size)
                {
                    fcb.DownLoaded = true;
                }

                if (downLoadingTerminate)
                {
                    break;
                }

                filesCopied++;
            }

            downLoadingRunning = false;
            closeForm          = true;
        } /* CopyFileList */