Beispiel #1
0
        /// <summary>
        /// Executes the generation of a help project on the console.
        /// </summary>
        protected void GenerateOnConsole()
        {
            // User interface that will log to the console:
            ConsoleUserInterface ui = new ConsoleUserInterface();

            ui.LogLevel = LogLevel;

            try
            {
                // Read or create the default project
                ChmProject project = ChmProject.OpenChmProjectOrWord(ProjectFile);

                // Check the project
                ChmProjectVerifier verifier = new ChmProjectVerifier(project, false, false);
                if (!verifier.Verifiy())
                {
                    SetAplicationExitCode(ChmLogLevel.ERROR);
                    return;
                }

                // Generate the products
                DocumentProcessor processor = new DocumentProcessor(project, ui);
                processor.GenerateHelp();
                ui.Log("DONE!", ChmLogLevel.INFO);
            }
            catch (Exception ex)
            {
                ui.Log(ex);
                ui.Log("Failed", ChmLogLevel.ERROR);
            }

            // Set the application exit code
            SetAplicationExitCode(ui.MinimumChmLogLevel);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a default project for a HTML / Word file
        /// </summary>
        /// <param name="filePath">Path to the HTML / Word file</param>
        /// <returns>The default project</returns>
        static public ChmProject CreateProjectforHtmlWordFile(string filePath)
        {
            ChmProject defaultProject = new ChmProject();

            defaultProject.AddFileAndProposePaths(filePath);
            defaultProject.MakePathsAbsolute(filePath);
            return(defaultProject);
        }
Beispiel #3
0
        /// <summary>
        /// Deserializes this xml document and convert it to a ChmProject object.
        /// </summary>
        /// <returns>The ChmProject object readed from the xml.</returns>
        public ChmProject Deserialize()
        {
            XmlReader     reader     = new XmlNodeReader(this);
            XmlSerializer serializer = new XmlSerializer(typeof(ChmProject));
            ChmProject    cfg        = (ChmProject)serializer.Deserialize(reader);

            reader.Close();
            return(cfg);
        }
Beispiel #4
0
        ///// <summary>
        ///// Verify if a list of source files can be added to the current source files list.
        ///// Currently we cannot mix HTML and Word documents as source files, and only one
        ///// HTML document can be source file. Multiple Word documents can be defined as
        ///// source documents.
        ///// </summary>
        ///// <param name="currentSourceFiles">Current list of source files</param>
        ///// <param name="newSourceFiles">New files to add to the source files</param>
        ///// <returns>A string with the error message if the new source files cannot be
        ///// added to the source files list. null if the new source files can be added.</returns>
        //static public string CanBeAddedToSourceFiles(List<string> currentSourceFiles, List<string> newSourceFiles)
        //{
        //    bool currentListEmpty = currentSourceFiles.Count == 0;
        //    bool currentListIsHtml = false;
        //    if (!currentListEmpty)
        //        currentListIsHtml = MSWord.IsHtmlDocument((string)currentSourceFiles[0]);
        //    foreach (String file in newSourceFiles)
        //    {
        //        bool fileIsHtml = MSWord.IsHtmlDocument(file);

        //        if (currentListEmpty)
        //        {
        //            currentListEmpty = false;
        //            currentListIsHtml = fileIsHtml;
        //        }
        //        else
        //        {
        //            if ((currentListIsHtml && !fileIsHtml) || (!currentListIsHtml && fileIsHtml))
        //                return "HTML and Word documents cannot be mixed as source documents";
        //            if (fileIsHtml)
        //                return "Only one HTML document can be used as source document";
        //        }
        //    }
        //    return null;
        //}

        /// <summary>
        /// Open a xml file with a ChmProject object serialized.
        /// </summary>
        /// <param name="filePath">Path to xml file to read.</param>
        /// <returns>The ChmProject readed.</returns>
        static public ChmProject Open(string filePath)
        {
            // Load and upgrade the xml project document
            ChmProjectXml xml = new ChmProjectXml();

            xml.Load(filePath);
            xml.UpgradeXml();
            ChmProject cfg = xml.Deserialize();

            // Change relative paths to absolute:
            cfg.MakePathsAbsolute(filePath);

            return(cfg);
        }
        /// <summary>
        /// Configure decorators to add headers, footer, metas and other stuff to the generated
        /// web pages. Call this after do any change on the original page
        /// </summary>
        private void PrepareHtmlDecorators()
        {
            // CHM html files will use the encoding specified by the user:
            ChmDecorator.ui = this.UI;
            // use the selected encoding:
            ChmDecorator.OutputEncoding = ChmProject.GetChmEncoding(UI, Project.GetChmCulture(UI));

            // Web html files will be UTF-8:
            WebDecorator.ui = this.UI;
            WebDecorator.MetaDescriptionValue = Project.WebDescription;
            WebDecorator.MetaKeywordsValue    = Project.WebKeywords;
            WebDecorator.OutputEncoding       = Encoding.UTF8;
            WebDecorator.UseTidy = true;

            if (!Project.ChmHeaderFile.Equals(""))
            {
                UI.Log("Reading chm header: " + Project.ChmHeaderFile, ChmLogLevel.INFO);
                ChmDecorator.HeaderHtmlFile = Project.ChmHeaderFile;
            }

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

            if (!Project.ChmFooterFile.Equals(""))
            {
                UI.Log("Reading chm footer: " + Project.ChmFooterFile, ChmLogLevel.INFO);
                ChmDecorator.FooterHtmlFile = Project.ChmFooterFile;
            }

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

            if (Project.GenerateWeb && !Project.WebHeaderFile.Equals(""))
            {
                UI.Log("Reading web header: " + Project.WebHeaderFile, ChmLogLevel.INFO);
                WebDecorator.HeaderHtmlFile = Project.WebHeaderFile;
            }

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

            if (Project.GenerateWeb && !Project.WebFooterFile.Equals(""))
            {
                UI.Log("Reading web footer: " + Project.WebFooterFile, ChmLogLevel.INFO);
                WebDecorator.FooterHtmlFile = Project.WebFooterFile;
            }

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

            if (Project.GenerateWeb && !Project.HeadTagFile.Equals(""))
            {
                UI.Log("Reading <header> include: " + Project.HeadTagFile, ChmLogLevel.INFO);
                WebDecorator.HeadIncludeFile = Project.HeadTagFile;
            }

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

            // Prepare decorators for use. Do it after extract style tags:
            WebDecorator.PrepareHtmlPattern(HtmlDoc);
            ChmDecorator.PrepareHtmlPattern(HtmlDoc);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="project">Data about the document to convert to help.</param>
 /// <param name="ui">Log for the help generation process</param>
 public DocumentProcessor(ChmProject project, UserInterface ui)
 {
     this.Project         = project;
     this.AdditionalFiles = new List <string>(project.ArchivosAdicionales);
     this.UI = ui;
 }
        /// <summary>
        /// Get a ChmProject with the current content of the user interface.
        /// </summary>
        /// <returns>The project with the current settings on the user interface</returns>
        private ChmProject GetCurrentProject()
        {
            ChmProject cfg = new ChmProject();
            //cfg.ArchivoOrigen = txtArchivo.Text;
            cfg.DestinationProjectDirectory = txtDirDst.Text;
            cfg.ChmHeaderFile = txtArcCab.Text;
            cfg.ChmFooterFile = txtArcPie.Text;
            cfg.HelpTitle = txtTitAyu.Text;
            cfg.GenerateWeb = chkGenWeb.Checked;
            cfg.WebDirectory = txtDirWeb.Text;
            cfg.MaxHeaderContentTree = (int)numArbolContenidos.Value;
            cfg.MaxHeaderIndex = (int)numTemasIndice.Value;
            cfg.CutLevel = (int)numNivelCorte.Value;
            cfg.Compile = radCompilar.Checked;
            cfg.HelpFile = txtArchivoAyuda.Text;
            cfg.CommandLine = txtCmdLine.Text;
            cfg.GeneratePdf = chkGenPdf.Checked;
            cfg.PdfPath = txtPdf.Text;
            cfg.WebKeywords = txtKeywords.Text;
            cfg.WebDescription = txtDescription.Text;
            cfg.WebFooterFile = txtFooterWeb.Text;
            cfg.WebHeaderFile = txtHeaderWeb.Text;
            cfg.GenerateSitemap = chkGenSitemap.Checked;
            cfg.WebBase = txtWebBase.Text;
            cfg.ChangeFrequency = (ChmProject.FrequencyOfChange)cmbChangeFrequency.SelectedItem;
            cfg.WebLanguage = (string)cmbWebLanguage.SelectedItem;
            cfg.FullTextSearch = chkFullSearch.Checked;
            if (radPdfCreator.Checked)
                cfg.PdfGeneration = ChmProject.PdfGenerationWay.PdfCreator;
            else
                cfg.PdfGeneration = ChmProject.PdfGenerationWay.OfficeAddin;
            cfg.XpsPath = txtXps.Text;
            cfg.GenerateXps = chkGenerateXps.Checked;
            cfg.GenerateJavaHelp = chkJavaHelp.Checked;
            cfg.JavaHelpPath = txtJavaHelp.Text;
            cfg.HeadTagFile = txtHeadInclude.Text.Trim();

            // Source files:
            foreach (string file in lstSourceFiles.Items)
                cfg.SourceFiles.Add(file);

            // Additional files:
            foreach (string arc in lstArcAdicionales.Items)
                cfg.ArchivosAdicionales.Add(arc);

            cfg.OpenProject = chkAbrirProyecto.Checked;
            //cfg.ChmCodePage = ((EncodingItem)cmbChmLanguage.SelectedItem).EncodingInfo.CodePage;
            cfg.ChmLocaleID = ((CultureInfo)cmbChmLanguage.SelectedItem).LCID;

            return cfg;
        }
        /// <summary>
        /// Assign fields of the user interface from a project file
        /// </summary>
        /// <param name="cfg">Project object to show on the user interface</param>
        private void mapProjectToUserInterface(ChmProject cfg)
        {
            //txtArchivo.Text = cfg.ArchivoOrigen;
            txtDirDst.Text = cfg.DestinationProjectDirectory;
            txtArcCab.Text = cfg.ChmHeaderFile;
            txtArcPie.Text = cfg.ChmFooterFile;
            txtTitAyu.Text = cfg.HelpTitle;
            chkGenWeb.Checked = cfg.GenerateWeb;
            txtDirWeb.Text = cfg.WebDirectory;
            numArbolContenidos.Value = cfg.MaxHeaderContentTree;
            numTemasIndice.Value = cfg.MaxHeaderIndex;
            numNivelCorte.Value = cfg.CutLevel;
            radCompilar.Checked = cfg.Compile;
            radGenerarProyecto.Checked = !cfg.Compile;
            txtArchivoAyuda.Text = cfg.HelpFile;
            txtCmdLine.Text = cfg.CommandLine;
            chkGenPdf.Checked = cfg.GeneratePdf;
            txtPdf.Text = cfg.PdfPath;
            txtKeywords.Text = cfg.WebKeywords;
            txtDescription.Text = cfg.WebDescription;
            txtFooterWeb.Text = cfg.WebFooterFile;
            txtHeaderWeb.Text = cfg.WebHeaderFile;
            chkGenSitemap.Checked = cfg.GenerateSitemap;
            txtWebBase.Text = cfg.WebBase;
            cmbChangeFrequency.SelectedItem = cfg.ChangeFrequency;
            cmbWebLanguage.SelectedItem = cfg.WebLanguage;
            chkFullSearch.Checked = cfg.FullTextSearch;
            radPdfAddIn.Checked = (cfg.PdfGeneration == ChmProject.PdfGenerationWay.OfficeAddin);
            radPdfCreator.Checked = (cfg.PdfGeneration == ChmProject.PdfGenerationWay.PdfCreator);
            chkGenerateXps.Checked = cfg.GenerateXps;
            txtXps.Text = cfg.XpsPath;
            chkJavaHelp.Checked = cfg.GenerateJavaHelp;
            txtJavaHelp.Text = cfg.JavaHelpPath;
            txtHeadInclude.Text = cfg.HeadTagFile;

            // Source files:
            lstSourceFiles.Items.Clear();
            foreach( string file in cfg.SourceFiles )
                lstSourceFiles.Items.Add(file);

            // Additional files:
            lstArcAdicionales.Items.Clear();
            foreach (string arc in cfg.ArchivosAdicionales)
                lstArcAdicionales.Items.Add(arc);
            chkAbrirProyecto.Checked = cfg.OpenProject;

            // CHM encoding:
            /*EncodingItem encoding = chmEncodings.SearchByCodePage(cfg.ChmCodePage);
            cmbChmLanguage.SelectedItem = encoding;*/
            cmbChmLanguage.SelectedItem = CultureInfo.GetCultureInfo(cfg.ChmLocaleID);
        }
Beispiel #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="project">Project to verify</param>
 /// <param name="askConfirmations">True if we can ask confirmations to the user. False if not</param>
 /// <param name="showUIMessages">Show user interface for errors? If not, an exception will be throw.</param>
 public ChmProjectVerifier(ChmProject project, bool askConfirmations, bool showUIMessages)
 {
     this.ShowUIMessages   = showUIMessages;
     this.AskConfirmations = askConfirmations;
     this.Project          = project;
 }
        public GenerationDialog(ChmProject project, bool exitAfterEnd, bool askConfirmations, int LogLevel)
        {
            InitializeComponent();

            this.project = project;
            this.exitAfterEnd = exitAfterEnd;
            this.askConfirmations = askConfirmations;

            this.UI = new GenerationDialogUserInterface(this);
            this.UI.LogLevel = LogLevel;

            this.processor = new DocumentProcessor(project);
            this.processor.UI = UI;

            bgWorker.RunWorkerAsync();
        }
 public DocumentProcessor( ChmProject configuration)
 {
     this.Project = configuration;
     this.ArchivosAdicionales = new ArrayList(configuration.ArchivosAdicionales);
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="project">Data about the document to convert to help.</param>
        public DocumentProcessor( ChmProject project )
        {
            this.Project = project;
            this.ArchivosAdicionales = new ArrayList(project.ArchivosAdicionales);
            this.replaceBrokenLinks = AppSettings.ReplaceBrokenLinks;
            try
            {
                this.helpWorkshopCulture = CultureInfo.GetCultureInfo(project.ChmLocaleID);
            }
            catch (Exception ex)
            {
                log(ex);
                throw new Exception("The locale ID (LCID) " + project.ChmLocaleID + " is not found.", ex);
            }

            try
            {
                this.helpWorkshopEncoding = Encoding.GetEncoding(helpWorkshopCulture.TextInfo.ANSICodePage);
            }
            catch (Exception ex)
            {
                log(ex);
                throw new Exception("The ANSI codepage " + helpWorkshopCulture.TextInfo.ANSICodePage + " is not found.", ex);
            }
        }