コード例 #1
0
ファイル: Form1.cs プロジェクト: vpuhoff/PatchGenSharp
        Dictionary <string, FileStateInfo> GetFileStates(string path)
        {
            Dictionary <string, FileStateInfo> dir = new Dictionary <string, FileStateInfo>();
            var allfiles = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);

            foreach (var file in allfiles)
            {
                FileStateInfo fs = new FileStateInfo();
                fs.path      = file;
                fs.shortpath = file.Replace(path, "");
                dir.Add(fs.shortpath, fs);
            }
            ;
            return(dir);
        }
コード例 #2
0
 public void CompareFile(FileStateInfo sample)
 {
     using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read))
         using (BufferedStream bs = new BufferedStream(fs, chunksize))
         {
             len = fs.Length;
             SampleFileStateInfo = sample;
             if (len < chunksize)
             {
                 chunkcount = 1;
             }
             else
             {
                 double chkcnt = len / chunksize;
                 chkcnt     = Math.Ceiling(chkcnt);
                 chunkcount = (int)chkcnt + 1;
             }
             byte[] buffer = new byte[chunksize];
             int    bytesRead;
             int    num = 0;
             reading = true;
             Thread t = new Thread(GetHashesAsync);
             t.Start();
             while ((bytesRead = bs.Read(buffer, 0, chunksize)) != 0) //reading only 50mb chunks at a time
             {
                 var   stream = new BinaryReader(new MemoryStream(buffer));
                 Chunk chk    = new Chunk();
                 chk.startposition = num * chunksize;
                 chk.len           = bytesRead;
                 chk.data          = new byte[bytesRead];
                 Buffer.BlockCopy(buffer, 0, chk.data, 0, bytesRead);
                 chk.num = num;
                 if (chk.data == null)
                 {
                     //MessageBox.Show("ERROR DATA IS NULL");
                 }
                 tmpchunks.Push(chk);
                 num++;
                 RepProgress(num, chunkcount);
                 GC.Collect();
             }
             reading = false;
             do
             {
                 Thread.Sleep(100);
             } while (tmpchunks.Count > 0 | GettingHashes);
         }
 }
コード例 #3
0
ファイル: Data.cs プロジェクト: jorik041/PatchGen
 public void CompareFile(FileStateInfo sample)
 {
     using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read))
     using (BufferedStream bs = new BufferedStream(fs, chunksize))
     {
         len = fs.Length;
         SampleFileStateInfo = sample;
         if (len < chunksize)
         {
             chunkcount = 1;
         }
         else
         {
             double chkcnt = len / chunksize;
             chkcnt = Math.Ceiling(chkcnt);
             chunkcount = (int)chkcnt + 1;
         }
         byte[] buffer = new byte[chunksize];
         int bytesRead;
         int num = 0;
         reading = true;
         Thread t = new Thread(GetHashesAsync);
         t.Start();
         while ((bytesRead = bs.Read(buffer, 0, chunksize)) != 0) //reading only 50mb chunks at a time
         {
             var stream = new BinaryReader(new MemoryStream(buffer));
             Chunk chk = new Chunk();
             chk.startposition = num * chunksize;
             chk.len = bytesRead;
             chk.data = new byte[bytesRead];
             Buffer.BlockCopy(buffer, 0, chk.data, 0, bytesRead);
             chk.num = num;
             if (chk.data == null)
             {
                 //MessageBox.Show("ERROR DATA IS NULL");
             }
             tmpchunks.Push(chk);
             num++;
             RepProgress(num, chunkcount);
             GC.Collect();
         }
         reading = false;
         do
         {
             Thread.Sleep(100);
         } while (tmpchunks.Count > 0 | GettingHashes);
     }
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: jorik041/PatchGen
 Dictionary<string, FileStateInfo> GetFileStates(string path)
 {
     Dictionary<string, FileStateInfo> dir = new Dictionary<string, FileStateInfo>();
     var allfiles = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories );
     foreach (var file in allfiles)
     {
         FileStateInfo fs = new FileStateInfo();
         fs.path = file;
         fs.shortpath = file.Replace(path, "");
         dir.Add(fs.shortpath, fs);
     };
     return dir;
 }