Exemplo n.º 1
0
        public override void Delete_file(string TargetFPath, ref CFileItem refFI)
        {
            if (TargetFPath[TargetFPath.Length - 1] != '\\') //非根目录
            {
                TargetFPath += "\\";
            }
            DirectoryInfo di = new DirectoryInfo(TargetFPath);

            foreach (FileInfo f in di.GetFiles("*.rsvdata"))
            {
                Console.Write(f.Name);
                f.Delete();
            }
            base.Delete_file(TargetFPath, ref refFI);
        }
Exemplo n.º 2
0
        public override void Copy_file(string TargetFPath, ref CFileItem refFI)
        {
            Console.WriteLine("call the CMediumTMethod\n");
            int nFileIndex      = 0;
            int nFileTimesIndex = 0;

            for (nFileTimesIndex = 0; nFileTimesIndex < ucFileTimes; nFileTimesIndex++)
            {
                for (nFileIndex = 0; nFileIndex < refFI.FList.Count; nFileIndex++)
                {
                    if (bDisk_PowerOff)
                    {
                        return;
                    }
                    refFI.uWhichFile = nFileIndex;
                    CopySingleFile(ref refFI, nFileIndex, TargetFPath, nFileTimesIndex);
                }
            }
        }
Exemplo n.º 3
0
        public override void Compare_file(string TargetFPath, ref CFileItem refFI)
        {
            byte[] cmp_buf   = new byte[1024];
            byte[] ffile_buf = new byte[1024];
            int    ncmpIndex = 0;

            for (ncmpIndex = 0; ncmpIndex < 1024; ncmpIndex++)
            {
                cmp_buf[ncmpIndex] = 0xAA;
            }
            DirectoryInfo di = new DirectoryInfo(TargetFPath);

            if (refCMPSeniorSetting.bNeedCmp)
            {
                refCMPSeniorSetting.bNeedCmp = false;
                foreach (FileInfo fi in di.GetFiles("*.rsvdata"))
                {
                    string     strPath        = fi.FullName;
                    FileStream fs             = new FileStream(strPath, FileMode.Open, FileAccess.Read);
                    int        nCMPKSizeIndex = 0;
                    for (nCMPKSizeIndex = 0; nCMPKSizeIndex < (int)1024 * 1024; nCMPKSizeIndex++)
                    {
                        fs.Seek(nCMPKSizeIndex * 1024, SeekOrigin.Begin);
                        fs.Read(ffile_buf, 0, 1024);
                        string outputS;
                        string outputD;

                        outputS = System.Text.Encoding.ASCII.GetString(ffile_buf);
                        outputD = System.Text.Encoding.ASCII.GetString(cmp_buf);
                        if (outputD != outputS)
                        {
                            ucFileFailCMP_Senior++;
                            break;
                        }
                    }
                    fs.Close();
                }
            }

            base.Compare_file(TargetFPath, ref refFI);
        }
Exemplo n.º 4
0
 public virtual void Compare_file(string TargetFPath, ref CFileItem refFI)
 {
 }
Exemplo n.º 5
0
 public override void Copy_file(string TargetFPath, ref CFileItem refFI)
 {
     base.Copy_file(TargetFPath, ref refFI);
 }
Exemplo n.º 6
0
        public override void Compare_file(string TargetFPath, ref CFileItem refFI)
        {
            if (TargetFPath[TargetFPath.Length - 1] != '\\') //非根目录
            {
                TargetFPath += "\\";
            }
            DirectoryInfo diInfo         = new DirectoryInfo(TargetFPath);
            int           nListPos_Start = 0;
            int           nListPos_End   = 0;

            FileInfo[]      fileInfo = diInfo.GetFiles("*.dsttesttmp");
            List <FileInfo> fileList = new List <FileInfo>();

            foreach (FileInfo f in fileInfo)
            {
                fileList.Add(f);
            }
            fileList.Sort(new FileComparer());
            int  nFileIndex_Innder = 0;
            int  nFileIndex_Dst    = 0;
            bool bneedcmp          = false;

            ucFileLostNum = ucCycleFileNum - fileList.Count;

            for (nFileIndex_Innder = 0; nFileIndex_Innder < refFI.FList.Count; nFileIndex_Innder++)
            {
                string fromFile       = refFI.FList[nFileIndex_Innder];
                string strDstFullName = "";
                for (nFileIndex_Dst = 0; nFileIndex_Dst < fileList.Count; nFileIndex_Dst++)
                {
                    string strDstName_inner = fileList[nFileIndex_Dst].Name;
                    bneedcmp = IsNeedCompare(ref fromFile, ref strDstName_inner);
                    if (bneedcmp)
                    {
                        strDstFullName = fileList[nFileIndex_Dst].FullName;
                        FileStream fsource = new FileStream(fromFile, FileMode.Open);
                        FileStream fDst = new FileStream(strDstFullName, FileMode.Open);
                        long       nSrcLength, nDstLength;
                        byte[]     buf_src        = new byte[1024];
                        byte[]     buf_dst        = new byte[1024];
                        int        nCompareLength = 0;

                        //Compare the file in this area!!!Tomorrow finish
                        if (strDstName_inner == refFI.strWhichFileName)
                        {
                            //compare the last 1024 byte
                            if (!refCMPSetting.bEnableAll)
                            {
                                if (fDst.Length <= refCMPSetting.ulCmpSize)
                                {
                                    fsource.Seek(0, SeekOrigin.Begin);
                                    fDst.Seek(0, SeekOrigin.Begin);
                                    nCompareLength = (int)fDst.Length;
                                }
                                else
                                {
                                    fsource.Seek(refCMPSetting.ulCmpSize, SeekOrigin.Begin);
                                    fDst.Seek(refCMPSetting.ulCmpSize, SeekOrigin.Begin);
                                    nCompareLength = (int)refCMPSetting.ulCmpSize;
                                }
                                byte[] bytesrc = new byte[nCompareLength];
                                byte[] bytedst = new byte[nCompareLength];
                                fsource.Read(bytesrc, 0, nCompareLength);
                                fDst.Read(bytedst, 0, nCompareLength);
                                string outputS_inner;
                                string outputD_inner;
                                outputS_inner = System.Text.Encoding.ASCII.GetString(bytesrc);
                                outputD_inner = System.Text.Encoding.ASCII.GetString(bytedst);
                                fsource.Close();
                                fDst.Close();
                                if (outputS_inner != outputD_inner)
                                {
                                    this.ucFileFailCMP++;
                                }
                            }
                            else
                            {
                                long   nleft = fDst.Length;
                                byte[] bytesrc;
                                byte[] bytedst;
                                long   nCMPSize = 0;
                                while (nleft >= 0)
                                {
                                    fDst.Seek(fDst.Length - nleft, SeekOrigin.Begin);
                                    fsource.Seek(fDst.Length - nleft, SeekOrigin.Begin);

                                    if (nleft >= 1024)
                                    {
                                        nCMPSize = 1024;
                                    }
                                    else
                                    {
                                        nCMPSize = nleft;
                                    }
                                    bytesrc = new byte[nCMPSize];
                                    bytedst = new  byte[nCMPSize];
                                    fsource.Read(bytesrc, 0, (int)nCMPSize);
                                    fDst.Read(bytedst, 0, (int)nCMPSize);
                                    string outputS;
                                    string outputD;
                                    outputS = System.Text.Encoding.ASCII.GetString(bytesrc);
                                    outputD = System.Text.Encoding.ASCII.GetString(bytedst);
                                    if (outputS != outputD)
                                    {
                                        Console.Write("compare file failed\n");
                                        this.ucFileFailCMP++;
                                        break;
                                        //return false;
                                    }
                                    nleft = nleft - nCMPSize;
                                }
                                fDst.Close();
                                fsource.Close();
                            }
                        }
                        else
                        {
                            //compare the file or the last 1024 byte
                            if (fsource.Length != fDst.Length)
                            {
                                Console.Write("compare file failed\n");
                                //return false;
                                this.ucFileFailCMP++;
                            }
                            else if (refCMPSetting.bEnableAll)
                            {
                                byte[] bufSrc    = new byte[1024];
                                byte[] bufDst    = new byte[1024];
                                long   nCMPTimes = fsource.Length / 1024;
                                int    nIndex    = 0;
                                for (nIndex = 0; nIndex < (int)nCMPTimes; nIndex++)
                                {
                                    fsource.Seek(nIndex * 1024, SeekOrigin.Begin);
                                    fDst.Seek(nIndex * 1024, SeekOrigin.Begin);
                                    fDst.Read(bufDst, 0, 1024);
                                    fsource.Read(bufSrc, 0, 1024);
                                    string outputS;
                                    string outputD;
                                    outputS = System.Text.Encoding.ASCII.GetString(bufSrc);
                                    outputD = System.Text.Encoding.ASCII.GetString(bufDst);
                                    if (outputS != outputD)
                                    {
                                        Console.Write("compare file failed\n");
                                        this.ucFileFailCMP++;
                                        break;
                                        //return false;
                                    }
                                }
                            }
                            else
                            {
                                fsource.Seek(refCMPSetting.ulCmpSize, SeekOrigin.Begin);
                                fDst.Seek(refCMPSetting.ulCmpSize, SeekOrigin.Begin);

                                byte[] bufSrc = new byte[refCMPSetting.ulCmpSize];
                                byte[] bufDst = new byte[refCMPSetting.ulCmpSize];
                                fsource.Read(bufSrc, 0, (int)refCMPSetting.ulCmpSize);
                                fDst.Read(bufDst, 0, (int)refCMPSetting.ulCmpSize);
                                string outputS;
                                string outputD;
                                outputS = System.Text.Encoding.ASCII.GetString(bufSrc);
                                outputD = System.Text.Encoding.ASCII.GetString(bufDst);
                                if (outputS != outputD)
                                {
                                    Console.Write("compare file failed\n");
                                    this.ucFileFailCMP++;
                                    //return false;
                                }
                            }
                        }

                        fsource.Close();
                        fDst.Close();
                        fileList.RemoveAt(nFileIndex_Dst);
                        nFileIndex_Dst--;
                    }
                }
            }
        }
Exemplo n.º 7
0
        protected void CopySingleFile(ref CFileItem refFI, int nIndex, string TargetFPath, int nHowManyTimes)//string fromFile, string toFile, int lengthEachTime)
        {
            string     fromFile       = refFI.FList[nIndex];
            string     strDstFileName = GetDstFileName(ref fromFile, nHowManyTimes);
            string     toFile         = TargetFPath + "\\" + strDstFileName;
            long       lengthToCopy;
            int        lengthEachTime = 1024;
            FileStream fileToCopy     = null;
            FileStream copyToFile     = null;

            try
            {
                fileToCopy = new FileStream(fromFile, FileMode.Open, FileAccess.Read);
                copyToFile = new FileStream(toFile, FileMode.Append, FileAccess.Write);
                ucRealFileNum++;
                ucCycleFileNum++;
                refFI.strWhichFileName = strDstFileName;
                if (lengthEachTime < fileToCopy.Length)//如果分段拷贝,即每次拷贝内容小于文件总长度
                {
                    byte[] buffer = new byte[lengthEachTime];
                    long   copied = 0;
                    while (copied <= (fileToCopy.Length - (long)lengthEachTime))//拷贝主体部分
                    {
                        lengthToCopy = fileToCopy.Read(buffer, 0, lengthEachTime);
                        fileToCopy.Flush();
                        copyToFile.Write(buffer, 0, lengthEachTime);
                        copyToFile.Flush();
                        copyToFile.Position = fileToCopy.Position;
                        copied += lengthToCopy;
                        refFI.uFileSeekPointer = copied;
                    }
                    int left = (int)(fileToCopy.Length - copied);//拷贝剩余部分
                    lengthToCopy = fileToCopy.Read(buffer, 0, left);
                    fileToCopy.Flush();
                    copyToFile.Write(buffer, 0, left);
                    copyToFile.Flush();
                    refFI.uFileSeekPointer = fileToCopy.Length;
                }
                else//如果整体拷贝,即每次拷贝内容大于文件总长度
                {
                    byte[] buffer = new byte[fileToCopy.Length];
                    fileToCopy.Read(buffer, 0, (int)fileToCopy.Length);
                    fileToCopy.Flush();
                    copyToFile.Write(buffer, 0, (int)fileToCopy.Length);
                    copyToFile.Flush();
                    refFI.uFileSeekPointer = fileToCopy.Length;
                }
                fileToCopy.Dispose();
                copyToFile.Dispose();
                fileToCopy.Close();
                copyToFile.Close();
            }
            catch (IOException e)
            {
                return;
            }
            catch (Exception ex)
            {
                if (fileToCopy != null)
                {
                    fileToCopy.Dispose();
                    fileToCopy.Close();
                }
                if (copyToFile != null)
                {
                    copyToFile.Dispose();
                    copyToFile.Close();
                }
                return;
            }
            finally
            {
                if (fileToCopy != null)
                {
                    fileToCopy.Dispose();
                }
                if (copyToFile != null)
                {
                    copyToFile.Dispose();
                }
            }
        }
Exemplo n.º 8
0
 public virtual void Delete_file(string TargetFPath, ref CFileItem refFI)
 {
 }