private string IndexRootFolderToHtml(string folderPath, StringBuilder sb, bool bAddFooter)
        {
            if (mBooFirstIndexFile)
            {
                sb.AppendLine(Xhtml.GetDocType());
                if (mSettings.GetConfig().CollapseFolders)
                {
                    sb.AppendLine(Xhtml.GetCollapseJs());
                    sb.AppendLine(Xhtml.GetCollapseCss());
                }
                sb.AppendLine(Xhtml.GetCssStyle(mSettings.GetConfig().CssFilePath));

                if (mBooMoreFilesToCome)
                {
                    sb.AppendLine(Xhtml.GetTitle(mSettings.GetConfig().MergedHtmlTitle));
                    mBooMoreFilesToCome = false;
                }
                else
                {
                    string[] c = folderPath.Split(Path.DirectorySeparatorChar);
                    if (c[1].Length == 0)
                    {
                        sb.AppendLine(Xhtml.GetTitle("Index for " + folderPath));
                    }
                    else
                    {
                        sb.AppendLine(Xhtml.GetTitle("Index for " + Path.GetFileName(folderPath)));
                    }
                }

                sb.AppendLine(Xhtml.CloseHead());
                sb.AppendLine(Xhtml.OpenBody());

                mBooFirstIndexFile = false;
            }

            TreeDir rootDir = new TreeDir(folderPath);

            rootDir = Analyze(rootDir.DirectoryPath());

            this.IndexToHtmlFile(rootDir, sb);

            if (bAddFooter)
            {
                sb.AppendLine(Xhtml.OpenDiv());
                sb.AppendLine("<hr />");
                sb.AppendLine(mSettings.GetFooterText(null, IndexingEngine.TreeNetLib, true));
                sb.AppendLine(Xhtml.CloseDiv());
                sb.AppendLine(Xhtml.CloseBody());
            }

            mBooFirstDir = true;

            return(sb.ToString());
        }
        public string GetFooterText(string myCurrentIndexFilePath, IndexingEngine myEngine, bool html)
        {
            string appName = string.Format("{0} v{1}", Application.ProductName, Application.ProductVersion);
            string appUrl  = "http://code.google.com/p/zscreen";

            string strDateTime;

            if (mOptions.IndexedTimeInUTC)
            {
                strDateTime = DateTime.UtcNow.ToString("yyyy-MM-dd 'at' HH:mm:ss 'UTC'");
            }
            else
            {
                strDateTime = DateTime.Now.ToString("yyyy-MM-dd 'at ' HH:mm:ss 'local time'");
            }

            if (html)
            {
                appName = Xhtml.MakeAnchor(appUrl, appName);
            }

            string footer = string.Format("Generated on {0} using {1}", strDateTime, appName);

            if (html)
            {
                if (mConfig.ShowValidXhtmlIcons)
                {
                    footer += GetText("valid_xhtml.txt");
                }
            }
            else
            {
                footer += "\r\nLatest version of can be downloaded from " + appUrl;
            }

            switch (myEngine)
            {
            case IndexingEngine.TreeLib:
                return("ECHO " + footer + " >> " + (char)34 + myCurrentIndexFilePath + (char)34);

            default:
                return(footer);
            }
        }
        private TreeDir IndexToHtmlFile(TreeDir dir, StringBuilder where)
        {
            bool isNotIndexableDir = mFilter.isBannedFolder(dir);

            string dirName = fGetDirPath(dir);
            string dirSize = (string)fGetDirSizeString(dir);

            string dirTitle = null;

            if (mSettings.GetConfig().EnabledFiltering&& mSettings.GetConfig().IgnoreEmptyFolders&& dir.DirectorySize() == 0.0)
            {
                //war59312 - dont show empty folders
                dirTitle = "";
            }
            else
            {
                if (mSettings.GetConfig().ShowDirSize)
                {
                    dirTitle = Xhtml.GetValidXhtmlLine(string.Format("{0} [{1}]", dirName, dirSize));
                }
                else
                {
                    dirTitle = Xhtml.GetValidXhtmlLine(dirName);
                }
            }

            if (mBooFirstDir)
            {
                rootDir = dir.DirectoryPath();
                where.AppendLine("<h1>" + dirTitle + "</h1>");
                mBooFirstDir = false;
                mNumTabs     = 1;
            }
            else
            {
                if (!isNotIndexableDir)
                {
                    if (mSettings.GetConfig().EnabledFiltering&& mSettings.GetConfig().IgnoreEmptyFolders&& dir.DirectorySize() == 0.0)
                    {
                        //war59312 - dont show empty folders
                    }
                    else
                    {
                        if (mSettings.GetConfig().ShowFolderPathOnStatusBar)
                        {
                            string hyperlinkDir = null;
                            if (mSettings.GetConfig().ShowVirtualFolders)
                            {
                                // Virtual Folders
                                hyperlinkDir = mSettings.GetConfig().ServerInfo + "/" + fGetVirtualDirName(dir.DirectoryPath()).Replace("\\", "/");
                            }
                            else
                            {
                                // Locally Browse
                                hyperlinkDir = "file://" + dir.DirectoryPath();
                            }
                            hyperlinkDir = "<a href=" + (char)34 + hyperlinkDir + (char)34 + ">" + dirTitle + "</a>";
                            where.AppendLine(GetHeadingOpen(dir) + hyperlinkDir + GetHeadingClose());
                        }
                        else
                        {
                            where.AppendLine(GetHeadingOpen(dir) + dirTitle + GetHeadingClose());
                        }
                    }
                }
            }

            if (!isNotIndexableDir)
            {
                if (mSettings.GetConfig().EnabledFiltering&& mSettings.GetConfig().IgnoreEmptyFolders&& dir.DirectorySize() == 0.0)
                {
                    //war59312 - dont show empty folders
                }
                else
                {
                    List <TreeFile> files = dir.GetFilesColl(mSettings);

                    if (fDivWrap(dir))
                    {
                        where.AppendLine(Xhtml.OpenDiv());
                    }

                    if (double.Parse(Regex.Split(dir.DirectorySizeToString(TreeDir.BinaryPrefix.Kibibytes), " ")[0]) > 0 | files.Count > 0)
                    {
                        if (mSettings.GetConfig().ShowFileCount)
                        {
                            if (files.Count > 0)
                            {
                                where.AppendLine(Xhtml.OpenPara("foldercount"));
                                where.AppendLine("Files Count: " + files.Count.ToString());
                                where.AppendLine(Xhtml.ClosePara());
                            }
                        }
                    }
                    else
                    {
                        //Note:
                        // dir.GetFilesColl().Count = 0 DOESNT ALWAYS MEAN THAT
                        // it is an empty directory because there can be subfolders
                        // with files
                        //System.Windows.Forms.MessageBox.Show(dir.GetFilesColl().Count)
                        where.AppendLine(Xhtml.OpenPara(""));
                        where.AppendLine(mSettings.GetOptions().EmptyFolderMessage + Xhtml.AddBreak());
                        where.AppendLine(Xhtml.ClosePara());
                    }

                    if (files.Count > 0)
                    {
                        // Check if there is AT LEAST ONE valid file
                        bool booPrintList = false;
                        foreach (TreeFile fp in files)
                        {
                            if (!mFilter.IsBannedFile(fp.GetFilePath()))
                            {
                                booPrintList = true;
                                break;
                            }
                        }

                        if (mSettings.GetConfig().ShowFilesTreeNet)
                        {
                            if (booPrintList)
                            {
                                switch (mSettings.GetConfig().IndexListType)
                                {
                                case XHTMLFileListMode.Bullets:
                                    where.AppendLine(Xhtml.OpenBulletedList());
                                    break;

                                case XHTMLFileListMode.Numbered:
                                    where.AppendLine(Xhtml.OpenNumberedList());
                                    break;
                                }
                            }

                            if (mSettings.GetConfig().RevereFileOrder)
                            {
                                files.Reverse();
                            }

                            foreach (TreeFile f in files)
                            {
                                string lLine = null;

                                if (!mFilter.IsBannedFile(f.GetFilePath()))
                                {
                                    string strFilePath = null;

                                    if (mSettings.GetConfig().ShowFilePath)
                                    {
                                        if (mSettings.GetConfig().ShowVirtualFolders)
                                        {
                                            strFilePath = fGetVirtualDirName(f.GetFilePath());
                                        }
                                        else
                                        {
                                            strFilePath = f.GetFilePath();
                                        }
                                    }
                                    else
                                    {
                                        if (mSettings.GetConfig().HideExtension)
                                        {
                                            strFilePath = f.GetFileNameWithoutExtension();
                                        }
                                        else
                                        {
                                            strFilePath = f.GetFileName();
                                        }
                                    }

                                    if (mSettings.GetConfig().ShowFileSize)
                                    {
                                        string fileSize = f.GetSizeToString(TreeDir.BinaryPrefix.Mebibytes);
                                        if (double.Parse(Regex.Split(fileSize, "\\" + mDecimalSymbol)[0]) == 0)
                                        {
                                            fileSize = f.GetSizeToString(TreeDir.BinaryPrefix.Kibibytes);
                                        }
                                        lLine = Xhtml.GetValidXhtmlLine(strFilePath) + " " + Xhtml.GetSpan(string.Format(" [{0}]", fileSize), "filesize");
                                    }
                                    else
                                    {
                                        lLine = Xhtml.GetValidXhtmlLine(strFilePath);
                                    }

                                    if (mSettings.GetConfig().AudioInfo&& fIsAudio(f.GetFileExtension().ToLower()) == true)
                                    {
                                        try
                                        {
                                            TagLib.File audioFile = TagLib.File.Create(f.GetFilePath());
                                            double      fsize     = f.GetSize(TreeDir.BinaryPrefix.Kibibits);
                                            double      dura      = audioFile.Properties.Duration.TotalSeconds;

                                            if (dura > 0)
                                            {
                                                Debug.WriteLine(fsize / dura);
                                                lLine += Xhtml.GetSpan(string.Format(" [{0} kb/s]", (fsize / dura).ToString("0.00"), fGetHMS(audioFile.Properties.Duration.TotalSeconds)), "audioinfo");
                                                lLine += Xhtml.GetSpan(string.Format(" [{0}]", fGetHMS(audioFile.Properties.Duration.TotalSeconds)), "audiolength");
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine(ex.ToString() + "\n" + f.GetFilePath());
                                        }
                                    }

                                    where.AppendLine("<li>" + lLine + "</li>");
                                }
                            }

                            if (booPrintList)
                            {
                                switch (mSettings.GetConfig().IndexListType)
                                {
                                case XHTMLFileListMode.Bullets:
                                    where.AppendLine(Xhtml.CloseBulletedList());
                                    break;

                                case XHTMLFileListMode.Numbered:
                                    where.AppendLine(Xhtml.CloseNumberedList());
                                    break;
                                }
                            }
                            // Show Files for TreeNet
                        }
                    }

                    mNumTabs += 1;

                    foreach (TreeDir d in dir.GetSubDirColl())
                    {
                        TreeDir sd = new TreeDir(d.DirectoryPath());
                        sd = IndexToHtmlFile(d, where);
                    }

                    if (fDivWrap(dir))
                    {
                        where.AppendLine(Xhtml.CloseDiv());
                    }

                    mNumTabs -= 1;
                }
            }

            return(dir);
        }