public static string Index(string dir, bool html, IndexerConfig config = null) { var settings = new IndexerAdapter(); if (config == null) config = new IndexerConfig(); config.CollapseFolders = false; config.FolderExpandLevel = 2; settings.LoadConfig(config); config.FolderList.Clear(); settings.GetConfig().SetSingleIndexPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), html ? "temp.html" : "temp.txt")); settings.GetConfig().FolderList.Add(dir); Indexer indexer = null; if (html) { indexer = new TreeNetIndexer(settings); } else { indexer = new TreeWalkIndexer(settings); } return indexer.IndexNow(IndexingMode.IN_ONE_FOLDER_MERGED, false); }
private void IndexInEachDir(IndexerAdapter myReader) { string where = null; List<string> folderList = new List<string>(); folderList = myReader.GetConfig().FolderList; TreeNetIndexer treeNetLib = new TreeNetIndexer(myReader); string ext = myReader.GetConfig().IndexFileExt; for (int i = 0; i <= myReader.GetConfig().FolderList.Count - 1; i++) { string strDirPath = myReader.GetConfig().FolderList[i]; // 2.5.1.1 Indexer halted if a configuration file had non-existent folders paths if (Directory.Exists(strDirPath)) { where = myReader.fGetIndexFilePath(i, IndexingMode.IN_EACH_DIRECTORY); if (Directory.Exists(Path.GetDirectoryName(where)) == false) { Directory.CreateDirectory(Path.GetDirectoryName(where)); } StreamWriter sw = new StreamWriter(where, false); StringBuilder sb = new StringBuilder(); try { this.CurrentDirMessage = "Indexing " + strDirPath; if (ext.Contains("html")) { //MessageBox.Show(myReader.GetConfig().mCssFilePath) treeNetLib.mBooFirstIndexFile = true; treeNetLib.IndexRootFolderToHtml(strDirPath, sb, mSettings.GetConfig().AddFooter); } else { treeNetLib.IndexFolderToTxt(strDirPath, sb, mSettings.GetConfig().AddFooter); } this.Progress += 1; } catch (UnauthorizedAccessException ex) { MessageBox.Show(ex.Message + "\n" + "Please Run TreeGUI As Administrator or Change Output Directory.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK); return; } finally { sw.Write(sb.ToString()); sw.Close(); } // Zip after sw is closed if (myReader.GetConfig().ZipFilesInEachDir) { myReader.ZipAdminFile(where, null); } } } }
public override string IndexNow(IndexingMode IndexMode, bool bWriteToFile = true) { string fp = null; StringBuilder sb = new StringBuilder(); List<string> folderList = new List<string>(); folderList = mSettings.GetConfig().FolderList; TreeNetIndexer treeNetLib = new TreeNetIndexer(mSettings); string ext = mSettings.GetConfig().IndexFileExt; switch (IndexMode) { case IndexingMode.IN_EACH_DIRECTORY: IndexInEachDir(mSettings); break; case IndexingMode.IN_ONE_FOLDER_MERGED: if (mSettings.GetConfig().MergeFiles) { fp = mSettings.fGetIndexFilePath(-1, IndexingMode.IN_ONE_FOLDER_MERGED); if (mSettings.GetConfig().FolderList.Count > 1) { for (int i = 0; i <= mSettings.GetConfig().FolderList.Count - 2; i++) { string strDirPath = mSettings.GetConfig().FolderList[i]; TreeDir dir = new TreeDir(strDirPath); this.CurrentDirMessage = "Indexing " + strDirPath; if (ext.Contains(".html")) { treeNetLib.mBooMoreFilesToCome = true; treeNetLib.IndexRootFolderToHtml(strDirPath, sb, false); } else { treeNetLib.IndexFolderToTxt(strDirPath, sb, false); } this.Progress += 1; } } TreeDir lastDir = new TreeDir(mSettings.GetConfig().FolderList[mSettings.GetConfig().FolderList.Count - 1]); this.CurrentDirMessage = "Indexing " + lastDir.DirectoryPath(); if (ext.Contains(".html")) { treeNetLib.mBooFirstIndexFile = false || mSettings.GetConfig().FolderList.Count == 1; treeNetLib.IndexRootFolderToHtml(lastDir.DirectoryPath(), sb, true); } else { treeNetLib.IndexFolderToTxt(lastDir.DirectoryPath(), sb, mSettings.GetConfig().AddFooter); } if (mSettings.GetConfig().ZipMergedFile) { mSettings.ZipAdminFile(fp, null); } this.Progress += 1; } break; case IndexingMode.IN_ONE_FOLDER_SEPERATE: // DO NOT MERGE INDEX FILES if (!Directory.Exists(mSettings.GetConfig().OutputDir)) { MessageBox.Show(string.Format("{0} does not exist." + Environment.NewLine + Environment.NewLine + "Please change the Output folder in Configuration." + Environment.NewLine + "The index file will be created in the same folder you chose to index.", mSettings.GetConfig().OutputDir), Application.ProductName, MessageBoxButtons.OK); } for (int i = 0; i <= mSettings.GetConfig().FolderList.Count - 1; i++) { string strDirPath = mSettings.GetConfig().FolderList[i]; string sDrive = Path.GetPathRoot(strDirPath).Substring(0, 1); string sDirName = Path.GetFileName(strDirPath); string sep = mSettings.GetOptions().IndividualIndexFileWordSeperator; //where = mSettings.GetConfig().OutputDir + "\" + sDrive + sep + sDirName + sep + mSettings.GetConfig().GetIndexFileName // New Behavior for getting where location fp = mSettings.fGetIndexFilePath(i, IndexingMode.IN_ONE_FOLDER_SEPERATE); mSettings.GetConfig().SetIndexPath(fp); //MsgBox(where = mSettings.GetConfig().OutputDir + "\" + sDrive + sep + sDirName + sep + mSettings.GetConfig().GetIndexFileName) this.CurrentDirMessage = "Indexing " + strDirPath; if (ext.Contains(".html")) { treeNetLib.mBooFirstIndexFile = true; treeNetLib.IndexRootFolderToHtml(strDirPath, sb, mSettings.GetConfig().AddFooter); } else { treeNetLib.IndexFolderToTxt(strDirPath, sb, mSettings.GetConfig().AddFooter); } if (mSettings.GetConfig().ZipFilesInOutputDir) { mSettings.ZipAdminFile(fp, null); } this.Progress += 1; } break; } if (bWriteToFile) { using (StreamWriter sw = new StreamWriter(fp, false)) { sw.Write(sb.ToString()); sw.Close(); } } return sb.ToString(); }