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); }
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); } }
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; }