public TextWriter GetTextWriter() { if (pw == null) { HashAlgorithm digest; try { digest = HashAlgorithm.Create("MD5"); } catch (TargetException e) { throw new IOException("No MD5 implementation", e); } dos = new DigestOutputStream(new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write), digest); pw = new TrapCloseTextWriter(this, dos); // Write the headers.... String version = compatibleVersion ?? typeof(OutputFile).Assembly.GetName().Version.ToString(); pw.WriteLine("/* " + CSharpCCGlobals.GetIdString(toolName, Path.GetFileName(file)) + " Version " + version + " */"); if (options != null) { pw.WriteLine("/* CSharpCCOptions:" + Options.GetOptionsString(options) + " */"); } } return(pw); }
private void CheckVersion(string file, String versionId) { String firstLine = "/* " + CSharpCCGlobals.GetIdString(ToolName, Path.GetFileName(file)) + " Version "; try { StreamReader reader = new StreamReader(file); String line; while ((line = reader.ReadLine()) != null) { if (line.StartsWith(firstLine)) { String version = firstLine.Replace(".* Version ", "").Replace(" \\*/", ""); if (version != versionId) { CSharpCCErrors.Warning(Path.GetFileName(file) + ": File is obsolete. Please rename or delete this file so" + " that a new one can be generated for you."); } return; } } // If no version line is found, do not output the warning. } catch (FileNotFoundException) { // This should never happen CSharpCCErrors.SemanticError("Could not open file " + Path.GetFileName(file) + " for writing."); throw new InvalidOperationException(); } catch (IOException) { } }