Пример #1
0
 /// <summary>
 /// Open a xml file with a ChmProject object serialized OR create a default
 /// ChmProject for a Word/HTML file.
 /// </summary>
 /// <param name="filePath">Path to the ChmProject file or to the Word/Html file</param>
 /// <returns>The ChmProject readed or the default project for the Word/Html file</returns>
 static public ChmProject OpenChmProjectOrWord(string filePath)
 {
     if (IsChmProjectFile(filePath))
     {
         // It's a CHMProcessor file
         return(Open(filePath));
     }
     else if (MSWord.IsHtmlDocument(filePath) || MSWord.IsWordDocument(filePath))
     {
         // A word/html file
         return(CreateProjectforHtmlWordFile(filePath));
     }
     else
     {
         throw new Exception("Unknown file extension " + Path.GetExtension(filePath));
     }
 }
Пример #2
0
        /// <summary>
        /// Throws an exception if the source file cannot be added to the source files list.
        /// </summary>
        /// <param name="sourceFilePath">Source file to check</param>
        private void CheckAddSourceFile(string sourceFilePath)
        {
            if (SourceFiles.Count == 0)
            {
                return;
            }

            bool currentListIsHtml = MSWord.IsHtmlDocument(SourceFiles[0]);
            bool fileIsHtml        = MSWord.IsHtmlDocument(sourceFilePath);

            if ((currentListIsHtml && !fileIsHtml) || (!currentListIsHtml && fileIsHtml))
            {
                throw new Exception("HTML and Word documents cannot be mixed as source documents");
            }
            if (fileIsHtml)
            {
                throw new Exception("Only one HTML document can be used as source document");
            }
        }