static int CheckFile(string filename, CommandLineOptions options, FileType fileType) { var fileContents = File.ReadAllLines(filename); if (Enumerable.SequenceEqual(options.CopyrightBanner[fileType], fileContents.Take(options.CopyrightBanner[fileType].Length))) { // This file already has the correct copyright. return 0; } else { if (options.Validate) { // Just report that the copyright does not match. Console.WriteLine("Error: Wrong copyright: {0}", options.GetRelativeName(filename)); } else { // Find any existing copyright. var existingCopyright = fileType.GetExistingCopyrightBanner(fileContents); if (options.PreviousCopyrightBanner != null && !Enumerable.SequenceEqual(existingCopyright, options.PreviousCopyrightBanner[fileType])) { // Warn if what we tried to overwrite doesn't match the expected previous (then don't actually edit anything). Console.WriteLine("Warning: Skipping {0}: doesn't match previous copyright", options.GetRelativeName(filename)); } else { // Remove the old copyright. var withoutOldCopyright = fileContents.Skip(existingCopyright.Count()); // Insert the new copyright. var withNewCopyright = options.CopyrightBanner[fileType].Concat(withoutOldCopyright); // Write out the new file. Console.WriteLine("Warning: Updating copyright: {0}", options.GetRelativeName(filename)); File.WriteAllLines(filename, withNewCopyright); } } return 1; } }