private void ChmInit() { _reader = new HtmlHelpSystem(); HtmlHelpSystem.UrlPrefix = "mk:@MSITStore:"; // use temporary folder for data dumping string sTemp = System.Environment.GetEnvironmentVariable("TEMP"); if (sTemp.Length <= 0) { sTemp = System.Environment.GetEnvironmentVariable("TMP"); } _prefDumpOutput = sTemp; // create a dump info instance used for dumping data _dmpInfo = new DumpingInfo(DumpingFlags.DumpBinaryTOC | DumpingFlags.DumpTextTOC | DumpingFlags.DumpTextIndex | DumpingFlags.DumpBinaryIndex | DumpingFlags.DumpUrlStr | DumpingFlags.DumpStrings, sTemp, DumpCompression.Medium); LoadRegistryPreferences(); HtmlHelpSystem.UrlPrefix = _prefURLPrefix; HtmlHelpSystem.UseHH2TreePics = _prefUseHH2TreePics; }
/// <summary> /// Constructor of the class /// </summary> public Viewer() { Viewer._current = this; // create a new instance of the classlibrary's main class _reader = new HtmlHelpSystem(); HtmlHelpSystem.UrlPrefix = "mk:@MSITStore:"; // use temporary folder for data dumping string sTemp = System.Environment.GetEnvironmentVariable("TEMP"); if (sTemp.Length <= 0) { sTemp = System.Environment.GetEnvironmentVariable("TMP"); } _prefDumpOutput = sTemp; // create a dump info instance used for dumping data _dmpInfo = new DumpingInfo(DumpingFlags.DumpBinaryTOC | DumpingFlags.DumpTextTOC | DumpingFlags.DumpTextIndex | DumpingFlags.DumpBinaryIndex | DumpingFlags.DumpUrlStr | DumpingFlags.DumpStrings, sTemp, DumpCompression.Medium); LoadRegistryPreferences(); HtmlHelpSystem.UrlPrefix = _prefURLPrefix; HtmlHelpSystem.UseHH2TreePics = _prefUseHH2TreePics; InitializeComponent(); }
/// <summary> /// Opens a chm file and creates /// </summary> /// <param name="chmFile">full file path of the chm file to open</param> /// <param name="dmpInfo">dumping info</param> /// <remarks>If you call this method, all existing merged files will be cleared.</remarks> public void OpenFile(string chmFile, DumpingInfo dmpInfo) { if (File.Exists(chmFile)) { _chmFiles.Clear(); _toc.Clear(); _index.Clear(); _informationTypes.Clear(); _categories.Clear(); CHMFile newFile = new CHMFile(this, chmFile, dmpInfo); _toc = new HtmlHelpToc(newFile.TOC); _index = new HtmlHelpIndex(newFile.IndexKLinks, newFile.IndexALinks); _chmFiles.Add(newFile); // add all infotypes and categories of the read file to this system instance MergeFileInfoTypesCategories(newFile); // check if the file has a merged files list if (newFile.MergedFiles.Length > 0) { // extract the path of the chm file (usually merged files are in the same path) FileInfo fi = new FileInfo(chmFile); string sPath = fi.DirectoryName; for (int i = 0; i < newFile.MergedFiles.Length; i++) { string sFile = newFile.MergedFiles[i]; if (sFile.Length > 0) { if (sFile[1] != ':') // no full path setting { sFile = Path.Combine(sPath, sFile); } MergeFile(sFile, dmpInfo, true); } } if (newFile.MergLinks.Count > 0) { RecalculateMergeLinks(newFile); } RemoveMergeLinks(); // clear all merge-links which have no target ! } } }
/// <summary> /// Loads viewer preferences from registry /// </summary> private void LoadRegistryPreferences() { RegistryKey regKey = Registry.LocalMachine.CreateSubKey(LM_Key); bool bEnable = bool.Parse(regKey.GetValue("EnableDumping", true).ToString()); _prefDumpOutput = (string)regKey.GetValue("DumpOutputDir", _prefDumpOutput); _prefDumpCompression = (DumpCompression)((int)regKey.GetValue("CompressionLevel", _prefDumpCompression)); _prefDumpFlags = (DumpingFlags)((int)regKey.GetValue("DumpingFlags", _prefDumpFlags)); if (bEnable) { _dmpInfo = new DumpingInfo(_prefDumpFlags, _prefDumpOutput, _prefDumpCompression); } else { _dmpInfo = null; } _prefURLPrefix = (string)regKey.GetValue("ITSUrlPrefix", _prefURLPrefix); _prefUseHH2TreePics = bool.Parse(regKey.GetValue("UseHH2TreePics", _prefUseHH2TreePics).ToString()); }
/// <summary> /// Merges a chm file to the current help contents /// </summary> /// <param name="chmFile">full file path of the chm file to merge</param> /// <param name="dmpInfo">dumping info</param> /// <param name="mergedFileList">true if the merge is done because a merged file list /// was found in the previously loaded CHM.</param> internal void MergeFile(string chmFile, DumpingInfo dmpInfo, bool mergedFileList) { if (File.Exists(chmFile)) { if (_chmFiles.Count == 1) { // if we open the first file, we directly point into the toc and index of this file. // So that we don't merge the new toc's indexe's into the first file, we have to // clone the internal arraylists first to a new instance of the toc/index holder classes. IList <HtmlHelpTocItem> atoc = _toc.TOC; IList <HtmlHelpIndexItem> alinks = _index.ALinks; IList <HtmlHelpIndexItem> klinks = _index.KLinks; _toc = new HtmlHelpToc(); _index = new HtmlHelpIndex(); _toc.MergeToC(atoc); _index.MergeIndex(alinks, IndexType.AssiciativeLinks); _index.MergeIndex(klinks, IndexType.KeywordLinks); } CHMFile newFile = new CHMFile(this, chmFile, dmpInfo); if (mergedFileList) // if we've called this method due to a merged file list merge { RecalculateMergeLinks(newFile); _toc.MergeToC(newFile.TOC, _chmFiles); _index.MergeIndex(newFile.IndexALinks, IndexType.AssiciativeLinks); _index.MergeIndex(newFile.IndexKLinks, IndexType.KeywordLinks); _chmFiles.Add(newFile); // add all infotypes and categories of the read file to this system instance MergeFileInfoTypesCategories(newFile); } else { _toc.MergeToC(newFile.TOC, _chmFiles); _index.MergeIndex(newFile.IndexALinks, IndexType.AssiciativeLinks); _index.MergeIndex(newFile.IndexKLinks, IndexType.KeywordLinks); _chmFiles.Add(newFile); // add all infotypes and categories of the read file to this system instance MergeFileInfoTypesCategories(newFile); // check if the file has a merged files list if (newFile.MergedFiles.Length > 0) { // extract the path of the chm file (usually merged files are in the same path) FileInfo fi = new FileInfo(chmFile); string sPath = fi.DirectoryName; for (int i = 0; i < newFile.MergedFiles.Length; i++) { string sFile = newFile.MergedFiles[i]; if (sFile.Length > 0) { if (sFile[1] != ':') // no full path setting { sFile = Path.Combine(sPath, sFile); } MergeFile(sFile, dmpInfo, true); } } //if(newFile.MergLinks.Count > 0) // RecalculateMergeLinks(newFile); RemoveMergeLinks(); // clear all merge-links which have no target ! } } } }
/// <summary> /// Merges a chm file to the current help contents /// </summary> /// <param name="chmFile">full file path of the chm file to merge</param> /// <param name="dmpInfo">dumping info</param> public void MergeFile(string chmFile, DumpingInfo dmpInfo) { MergeFile(chmFile, dmpInfo, false); }
/// <summary> /// Called if the user clicks OK /// </summary> /// <param name="sender">sender of the event</param> /// <param name="e">event parameter</param> private void btnOK_Click(object sender, System.EventArgs e) { if (chkDEnableDump.Checked) { DumpingFlags flags = 0; if (chkTextTOC.Checked) { flags |= DumpingFlags.DumpTextTOC; } if (chkBinTOC.Checked) { flags |= DumpingFlags.DumpBinaryTOC; } if (chkTextIdx.Checked) { flags |= DumpingFlags.DumpTextIndex; } if (chkBinIdx.Checked) { flags |= DumpingFlags.DumpBinaryIndex; } if (chkStrings.Checked) { flags |= DumpingFlags.DumpStrings; } if (chkUrlstr.Checked) { flags |= DumpingFlags.DumpUrlStr; } if (chkUrltbl.Checked) { flags |= DumpingFlags.DumpUrlTbl; } if (chkTopics.Checked) { flags |= DumpingFlags.DumpTopics; } if (chkFulltext.Checked) { flags |= DumpingFlags.DumpFullText; } DumpCompression compression = (DumpCompression)cbCompression.SelectedIndex; string sPath = ""; if (rbSF.Checked) { sPath = GetSpecialFolderPath(); } else { sPath = txtFolderName.Text; } if (!Directory.Exists(sPath)) { MessageBox.Show("The path \n " + sPath + "\ndould not be found on your PC !", "Path error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _prefDumpOutput = sPath; _prefDumpCompression = compression; _prefDumpFlags = flags; _dmpInfo = new DumpingInfo(flags, sPath, compression); } else { _dmpInfo = null; } this.DialogResult = DialogResult.OK; this.Close(); }