private void CheckForEdits(CheckSumValidator original) { foreach (string s in original._files.Keys) { byte[] currentHash; if (_files.TryGetValue(s, out currentHash)) { byte[] originalHash = original._files[s]; if (currentHash.Length != originalHash.Length) { throw new InvalidOperationException("File has been edited and left in the ''Generated Files'' folder. Please move it from this folder to prevent these changes from being lost. File: " + s); } for (int i = 0; i < originalHash.Length; i++) { if (!originalHash[i].Equals(currentHash[i])) { throw new InvalidOperationException("File has been edited and left in the ''Generated Files'' folder. Please move it from this folder to prevent these changes from being lost. File: " + s); } } } } foreach (string s in _files.Keys) { if (!original._files.ContainsKey(s)) { throw new InvalidOperationException("File has been added to the ''Generated Files'' folder manually. Please move it from this folder to prevent this file from being lost. File: " + s); } } }
public static bool ValidateCheckSum(string path) { CheckSumValidator current = new CheckSumValidator(path); CheckSumValidator original = GetInfo(path); if (original == null) { //There is no pre-computed check-sum. return true; } current.CheckForEdits(original); return true; }