Exemplo n.º 1
0
 public void Close()
 {
     if (_isDouble4CJob)
     {
         FileStream1.Close();
         FileStream2.Close();
     }
     else
     {
         FileStream1.Close();
     }
 }
Exemplo n.º 2
0
        public long Seek(long offset, SeekOrigin origin)
        {
            try
            {
                switch (origin)
                {
                case SeekOrigin.Begin:
                {
                    _curPos = offset;
                    break;
                }

                case SeekOrigin.Current:
                {
                    _curPos += offset;
                    break;
                }

                case SeekOrigin.End:
                {
                    _curPos -= offset;
                    break;
                }
                }
                if (_isDouble4CJob)
                {
                    long maxstep1 = 0;
                    long maxstep2 = 0;
                    long maxStep  = GetMaxStep(ref maxstep1, ref maxstep2);
                    if (_curPos > HEADERSIZE)
                    {
                        bool bReadFile1 = ((_curPos - HEADERSIZE) % maxStep) < maxstep1;
                        int  stepNum    = (int)((_curPos - HEADERSIZE) / maxStep);
                        if (bReadFile1)
                        {
                            FileStream1.Seek((long)stepNum * (long)maxstep1 + (long)(_curPos - HEADERSIZE) % stepNum + HEADERSIZE, SeekOrigin.Begin);
                            FileStream2.Seek((long)stepNum * (long)maxstep2 + HEADERSIZE, SeekOrigin.Begin);
                        }
                        else
                        {
                            FileStream1.Seek((long)(stepNum + 1) * (long)maxstep1 + HEADERSIZE, SeekOrigin.Begin);
                            FileStream2.Seek((long)stepNum * (long)maxstep2 + ((long)(_curPos - HEADERSIZE) % stepNum - maxstep1) + HEADERSIZE, SeekOrigin.Begin);
                        }
                    }
                    else
                    {
                        FileStream1.Seek(_curPos, SeekOrigin.Begin);
                        FileStream2.Seek(HEADERSIZE, SeekOrigin.Begin);
                    }
                }
                else
                {
                    FileStream1.Seek(_curPos, origin);
                }
                return(_curPos);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(_curPos);
            }
        }
Exemplo n.º 3
0
        public int Read(byte[] array, int offset, int count)
        {
            int ret = 0;

            if (_isDouble4CJob)
            {
                long maxstep1    = 0;
                long maxstep2    = 0;
                long maxStep     = GetMaxStep(ref maxstep1, ref maxstep2);
                int  readedCount = 0;
                int  suboffset   = 0;
                int  allcount    = count;
                while (allcount > readedCount)
                {
                    if (_curPos == 0 && count >= HEADERSIZE)
                    {
                        ReadHeader(array);
                        _curPos     += HEADERSIZE;
                        count       -= HEADERSIZE;
                        readedCount += HEADERSIZE;
                        suboffset   += HEADERSIZE;
                        FileStream1.Seek(HEADERSIZE, SeekOrigin.Begin);
                    }
                    int  len        = 0;
                    bool bReadFile1 = ((_curPos - HEADERSIZE) % maxStep) < maxstep1;
                    if (bReadFile1)
                    {
                        int readlen = (int)Math.Min(maxstep1 - (_curPos - HEADERSIZE) % maxStep, allcount - readedCount);
                        len = FileStream1.Read(array, suboffset, readlen);
                        LogWriter.SaveOptionLog(string.Format("FileStream1.Read pos={0},readlen={1},retlen={2}", FileStream1.Position, readlen, len));
                        if (len != readlen && FileStream1.Position != FileStream1.Length)
                        {
                            MessageBox.Show("Read file error!!");
                        }
                    }
                    else
                    {
                        int readlen =
                            (int)
                            Math.Min(maxstep2 - ((_curPos - HEADERSIZE) % maxStep - maxstep1), allcount - readedCount);
                        len = FileStream2.Read(array, suboffset, readlen);
                        LogWriter.SaveOptionLog(string.Format("FileStream2.Read pos={0},readlen={1},retlen={2}", FileStream2.Position, readlen, len));
                        if (len != readlen && FileStream1.Position != FileStream1.Length)
                        {
                            MessageBox.Show("Read file error!!");
                        }
                    }
                    if (len > 0)
                    {
                        readedCount += len;
                        suboffset   += len;
                        _curPos     += len;
                    }
                    if (fileStream1.Position == fileStream1.Length ||
                        fileStream2.Position == fileStream2.Length)
                    {
                        break;
                    }
                    //bReadFile1 = !bReadFile1;
                }
                ret = readedCount;
            }
            else
            {
                ret = FileStream1.Read(array, offset, count);
                LogWriter.SaveOptionLog(string.Format("FileStream1.Read pos={0},readlen={1},retlen={2}", FileStream1.Position, count, ret));
                if (ret != count && FileStream1.Position != FileStream1.Length)
                {
                    MessageBox.Show("Read file error!!");
                }
            }
            return(ret);
        }