/// <summary> /// Return file crc of the specified file /// </summary> public static string GetFileCRC(string filename) { if (!FileEx.Exists(filename)) { return(""); } Fesersoft.Hashing.crc32 crc32 = new Fesersoft.Hashing.crc32(); using (FileStreamEx stmcheck = FileEx.OpenRead(filename)) { uint crchash = (uint)crc32.CRC(stmcheck); stmcheck.Close(); return(ConvertToHex(crchash)); } }
public static string GetFileMD5(string filename) { if (!FileEx.Exists(filename)) { return(""); } MD5CryptoServiceProvider csp = new MD5CryptoServiceProvider(); using (FileStreamEx stmcheck = FileEx.OpenRead(filename)) { byte[] hash = csp.ComputeHash(stmcheck); stmcheck.Close(); return(BitConverter.ToString(hash).Replace("-", "").ToLower()); } }
/// <summary> /// Copy directory or file, take full path of source and dest as parameter. /// </summary> public static void CopyFile(string source, string dest, FileCancelDelegate cancel) { using (FileStreamEx srcStream = FileEx.OpenRead(source)) { byte[] buffer = new byte[Math.Min(1024 * 1024 * 32, srcStream.Length)]; //32MB int readCount; ushort completePercent = 0; long completeCount = 0; using (FileStreamEx destStream = FileEx.Create(dest)) { while ((readCount = srcStream.Read(buffer, 0, buffer.Length)) > 0 && !IsCancelTriggered(cancel, completePercent)) { completeCount += readCount; destStream.Write(buffer, 0, readCount); completePercent = srcStream.Length == 0 ? (ushort)100 : (ushort)((float)completeCount / (float)srcStream.Length * 100.0); } destStream.Flush(); destStream.Close(); } srcStream.Close(); } }