// Constructor. Creates a file with the given name and writes a standard HTML header. public HTMLFile(string filename, string title, string description, string keywords) { // This is for CJ who ended up with 17000 files plastered all over her desktop... if (GMHelper.IsDesktop(filename)) { throw new HTMLException(string.Format("A problem occurred when creating an HTML file:\r\nGEDmill will not place files onto the Desktop.")); } fLogger.WriteInfo("CHTMLFile : " + filename); if (File.Exists(filename)) { // Delete any current file File.SetAttributes(filename, FileAttributes.Normal); File.Delete(filename); } fStream = null; try { fStream = new FileStream(filename, FileMode.Create); } catch (NotSupportedException) { throw new HTMLException(string.Format("A problem occurred when creating an HTML file:\r\nThe path or filename {0} is not valid.", filename)); } if (fStream != null) { System.Text.Encoding encoding = new UTF8EncodingWithoutPreamble(); fWriter = new StreamWriter(fStream, encoding); string date; DateTime dt = DateTime.Now; date = dt.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo); fWriter.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); fWriter.WriteLine("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">"); fWriter.WriteLine(" <head>"); fWriter.WriteLine(" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + CConfig.Instance.StylesheetFilename + ".css\" />"); if (CConfig.Instance.AllowMultipleImages) // Multiple images feature is currently (10Dec08) the only thing that uses javascript { fWriter.WriteLine(" <script type=\"text/javascript\" src=\"gedmill.js\"></script>"); } fWriter.WriteLine(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + CharsetString + "\" />"); fWriter.WriteLine(" <meta http-equiv=\"imagetoolbar\" content=\"no\" />"); fWriter.WriteLine(string.Concat(" <meta name=\"Title\" content=\"", title, "\" />")); fWriter.WriteLine(string.Concat(" <meta name=\"Description\" content=\"", description, "\" />")); fWriter.WriteLine(string.Concat(" <meta name=\"Keywords\" content=\"", keywords, "\" />")); fWriter.WriteLine(" <meta name=\"Version\" content=\"1.00\" />"); fWriter.WriteLine(string.Concat(" <meta name=\"VersionDate\" content=\"", date, "\" />")); fWriter.WriteLine(string.Concat(" <title>", title, "</title>")); fWriter.WriteLine(" </head>"); fWriter.WriteLine(" "); fWriter.WriteLine(" <body>"); } }
// Constructor. Creates a file with the given name and writes a standard HTML header. public CHTMLFile( string filename, string title, string description, string keywords ) { // This is for CJ who ended up with 17000 files plastered all over her desktop... if( IsDesktop( filename ) ) { throw new CHTMLException( String.Format("A problem occurred when creating an HTML file:\r\nGEDmill will not place files onto the Desktop." ) ); } LogFile.TheLogFile.WriteLine( LogFile.DT_HTML, LogFile.EDebugLevel.Note, "CHTMLFile : " + filename ); if( File.Exists( filename ) ) { // Delete any current file File.SetAttributes( filename, FileAttributes.Normal ); File.Delete( filename ); } m_fs = null; try { m_fs = new FileStream( filename, FileMode.Create ); } catch( System.NotSupportedException ) { throw new CHTMLException( String.Format("A problem occurred when creating an HTML file:\r\nThe path or filename {0} is not valid.", filename ) ); } if( m_fs != null ) { string charsetString; System.Text.Encoding encoding; if( MainForm.s_config.m_ecHtmlCharset==ECharset.ISO8859_1 ) { charsetString = "iso-8859-1"; encoding = System.Text.Encoding.GetEncoding( "iso-8859-1" ); } else if( MainForm.s_config.m_bUseBom ) { charsetString = "utf-8"; encoding = System.Text.Encoding.UTF8; } else { charsetString = "utf-8"; encoding = new UTF8EncodingWithoutPreamble(); } m_sw = new StreamWriter( m_fs, encoding ); string date; DateTime dt = DateTime.Now; date = dt.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo); m_sw.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); m_sw.WriteLine("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">"); m_sw.WriteLine(" <head>"); m_sw.WriteLine(" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + MainForm.s_config.m_sStylesheetFilename + ".css\" />"); if( MainForm.s_config.m_bAllowMultipleImages ) // Multiple images feature is currently (10Dec08) the only thing that uses javascript { m_sw.WriteLine(" <script type=\"text/javascript\" src=\"gedmill.js\"></script>"); } m_sw.WriteLine(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset="+charsetString+"\" />"); m_sw.WriteLine(" <meta http-equiv=\"imagetoolbar\" content=\"no\" />"); m_sw.WriteLine(String.Concat(" <meta name=\"Title\" content=\"",title, "\" />")); m_sw.WriteLine(String.Concat(" <meta name=\"Description\" content=\"", description, "\" />")); m_sw.WriteLine(String.Concat(" <meta name=\"Keywords\" content=\"", keywords, "\" />")); m_sw.WriteLine(" <meta name=\"Version\" content=\"1.00\" />"); m_sw.WriteLine(String.Concat(" <meta name=\"VersionDate\" content=\"",date,"\" />")); m_sw.WriteLine(String.Concat(" <title>",title,"</title>")); m_sw.WriteLine(" </head>"); m_sw.WriteLine(" "); m_sw.WriteLine(" <body>"); } // end if (m_fs != null ) }