/// <summary>
        /// Open source files.
        /// If they are Word, they will be converted to HTML.
        /// </summary>
        private void OpenSourceFiles()
        {
            MSWord msWord = null;

            try
            {
                string archivoFinal = (string)Project.SourceFiles[0];
                IsMSWord            = MSWord.IsWordDocument(archivoFinal);
                MSWordHtmlDirectory = null;
                // Si es un documento word, convertirlo a HTML filtrado
                if (IsMSWord)
                {
                    msWord       = new MSWord();
                    archivoFinal = ConvertWordSourceFiles(msWord);

                    // Be sure we have closed word, to avoid overlapping between the html read
                    // and the reading from chmprocessor:
                    msWord.Dispose();
                    msWord = null;
                }
                else
                {
                    // There is a single source HTML file.
                    MainSourceFile = (string)Project.SourceFiles[0];
                }

                if (UI.CancellRequested())
                {
                    return;
                }

                // TODO: Check if this should be removed.
                if (AppSettings.UseTidyOverInput)
                {
                    new TidyParser(UI).Parse(archivoFinal);
                }

                if (UI.CancellRequested())
                {
                    return;
                }

                // Load the HTML file:
                HtmlDoc = new HtmlDocument();
                HtmlDoc.Load(archivoFinal);
            }
            finally
            {
                if (msWord != null)
                {
                    msWord.Dispose();
                    msWord = null;
                }
            }
        }
Example #2
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));
     }
 }