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, true);
                    }

                    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, true);
                    }
                    else
                    {
                        treeNetLib.IndexFolderToTxt(strDirPath, sb, true);
                    }

                    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());
        }
        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);
                    }
                }
            }
        }
Exemple #3
0
        public override string IndexNow(IndexingMode mIndexMode, bool bWriteToFile = true)
        {
            TreeWalkIndexer tree             = new TreeWalkIndexer(mSettings);
            bool            isMergeFile      = mSettings.GetConfig().MergeFiles;
            bool            isRemoveBranches = mSettings.GetConfig().RemoveTreeBranches;

            for (int i = 0; i <= mSettings.GetConfig().FolderList.Count - 1; i++)
            {
                string batFilePath  = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\temp" + i.ToString() + ".bat";
                string CURRENT_DIR  = mSettings.GetConfig().FolderList[i];
                string TREE_COMMAND = "%windir%\\system32\\tree.com " + tree.getSourceSwitch(CURRENT_DIR) + tree.getAsciiSwitch() + tree.getAddFilesSwitch() + tree.getOutputSwitch(CURRENT_DIR, mIndexMode);

                using (StreamWriter sw = new StreamWriter(batFilePath))
                {
                    sw.WriteLine(TREE_COMMAND);
                    //1.5.3.4 Didn't tag index files created in the same folder witout appending
                    if (mIndexMode == IndexingMode.IN_EACH_DIRECTORY | i == mSettings.GetConfig().FolderList.Count - 1 | (isMergeFile == false & mIndexMode == IndexingMode.IN_ONE_FOLDER_MERGED))
                    {
                        sw.WriteLine(mSettings.getBlankLine(tree.getCurrentIndexFilePath()));
                        sw.WriteLine(mSettings.GetFooterText(tree.getCurrentIndexFilePath(), IndexingEngine.TreeLib, false));
                    }
                    sw.WriteLine("DEL " + (char)34 + batFilePath + (char)34);
                }

                Process proc = new Process();
                proc = mSettings.StartHiddenProcess(batFilePath, true);

                if (isRemoveBranches)
                {
                    tree.removeTreeBranches(tree.getCurrentIndexFilePath());
                }

                if (mIndexMode == IndexingMode.IN_EACH_DIRECTORY | i == mSettings.GetConfig().FolderList.Count - 1 | (isMergeFile == false & mIndexMode == IndexingMode.IN_ONE_FOLDER_MERGED))
                {
                    if (mSettings.GetConfig().ZipFilesInEachDir)
                    {
                        mSettings.ZipAdminFile(tree.getCurrentIndexFilePath(), null);
                    }
                    if (mSettings.GetConfig().ZipMergedFile)
                    {
                        mSettings.ZipAdminFile(tree.getCurrentIndexFilePath(), null);
                    }
                }

                if (mIndexMode == IndexingMode.IN_ONE_FOLDER_SEPERATE)
                {
                    if (mSettings.GetConfig().ZipFilesInOutputDir)
                    {
                        //MsgBox(tree.getCurrentIndexFilePath())
                        mSettings.ZipAdminFile(tree.getCurrentIndexFilePath(), null);
                    }
                }

                if (proc.HasExited)
                {
                    this.Progress         += 1;
                    this.CurrentDirMessage = "Indexed " + mSettings.GetConfig().FolderList[i];
                }
            }

            return(File.ReadAllText(tree.getCurrentIndexFilePath()));
        }