Exemple #1
0
        private string getOutputSwitch(string folderPath, IndexingMode mode)
        {
            switch (mode)
            {
            case IndexingMode.IN_EACH_DIRECTORY:
                this.setCurrentIndexFilePath(folderPath + Path.DirectorySeparatorChar + mSettings.GetConfig().GetIndexFileName());

                return(">" + (char)34 + this.getCurrentIndexFilePath() + (char)34);

            case IndexingMode.IN_ONE_FOLDER_SEPERATE:

                string strOutputFileName = null;
                string sep = mSettings.GetOptions().IndividualIndexFileWordSeperator;
                if (Path.GetFileName(folderPath).Length > 0)
                {
                    strOutputFileName = Path.GetPathRoot(folderPath).Substring(0, 1) + sep + Path.GetFileName(folderPath) + sep + mSettings.GetConfig().GetIndexFileName();
                }
                else
                {
                    strOutputFileName = Path.GetPathRoot(folderPath).Substring(0, 1) + sep + mSettings.GetConfig().GetIndexFileName();
                }

                this.setCurrentIndexFilePath(mSettings.GetConfig().OutputDir + Path.DirectorySeparatorChar + strOutputFileName);

                return(">" + (char)34 + this.getCurrentIndexFilePath() + (char)34);

            case IndexingMode.IN_ONE_FOLDER_MERGED:
                if (mSettings.GetConfig().MergeFiles)
                {
                    this.setCurrentIndexFilePath(this.mSettings.GetConfig().GetIndexFilePath());
                    if (isFirstEntryToSingleFile == true)
                    {
                        isFirstEntryToSingleFile = false;
                        return(">" + (char)34 + this.getCurrentIndexFilePath() + (char)34);
                    }
                    else
                    {
                        return(">>" + (char)34 + this.getCurrentIndexFilePath() + (char)34);
                    }
                }
                break;
            }

            return(null);
        }
Exemple #2
0
 public FilterHelper(IndexerAdapter settings)
 {
     mSettings     = settings;
     mBannedFilter = Regex.Split(mSettings.GetConfig().IgnoreFilesList, "\\" + mSettings.GetOptions().IgnoreFilesListDelimiter);
 }
        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);
        }
 public FilterHelper(IndexerAdapter settings)
 {
     mSettings = settings;
     mBannedFilter = Regex.Split(mSettings.GetConfig().IgnoreFilesList, "\\" + mSettings.GetOptions().IgnoreFilesListDelimiter);
 }