コード例 #1
0
ファイル: IndexerHtml.cs プロジェクト: andre-d/ShareXYZ
        protected override string GetFolderNameRow(FolderInfo dir, int level)
        {
            int heading = (level + 1).Between(1, 6);

            string folderInfoText = string.Empty;

            if (!dir.IsEmpty)
            {
                folderInfoText = dir.Size.ToSizeString(config.BinaryUnits) + " (";

                if (dir.TotalFileCount > 0)
                {
                    folderInfoText += dir.TotalFileCount + " file" + (dir.TotalFileCount > 1 ? "s" : "");
                }

                if (dir.TotalFolderCount > 0)
                {
                    if (dir.TotalFileCount > 0)
                    {
                        folderInfoText += ", ";
                    }

                    folderInfoText += dir.TotalFolderCount + " folder" + (dir.TotalFolderCount > 1 ? "s" : "");
                }

                folderInfoText += ")";
                folderInfoText = "  " + HtmlHelper.Tag("span", folderInfoText, "", "class=\"folderinfo\"");
            }

            return HtmlHelper.StartTag("h" + heading) + URLHelpers.HtmlEncode(dir.FolderName) + folderInfoText + HtmlHelper.EndTag("h" + heading);
        }
コード例 #2
0
ファイル: IndexerText.cs プロジェクト: andre-d/ShareXYZ
        protected override void IndexFolder(FolderInfo dir, int level)
        {
            sbContent.AppendLine(GetFolderNameRow(dir, level));

            foreach (FolderInfo subdir in dir.Folders)
            {
                if (config.AddEmptyLineAfterFolders)
                {
                    sbContent.AppendLine();
                }

                IndexFolder(subdir, level + 1);
            }

            if (dir.Files.Count > 0)
            {
                if (config.AddEmptyLineAfterFolders)
                {
                    sbContent.AppendLine();
                }

                foreach (FileInfo fi in dir.Files)
                {
                    sbContent.AppendLine(GetFileNameRow(fi, level + 1));
                }
            }
        }
コード例 #3
0
ファイル: IndexerXml.cs プロジェクト: andre-d/ShareXYZ
        protected override void IndexFolder(FolderInfo dir, int level = 0)
        {
            xmlWriter.WriteStartElement("Folder");

            if (config.UseAttribute)
            {
                xmlWriter.WriteAttributeString("Name", dir.FolderName);
                if (!dir.IsEmpty) xmlWriter.WriteAttributeString("Size", dir.Size.ToSizeString(config.BinaryUnits));
            }
            else
            {
                xmlWriter.WriteElementString("Name", dir.FolderName);
                if (!dir.IsEmpty) xmlWriter.WriteElementString("Size", dir.Size.ToSizeString(config.BinaryUnits));
            }

            if (dir.Files.Count > 0)
            {
                xmlWriter.WriteStartElement("Files");

                foreach (FileInfo fi in dir.Files)
                {
                    xmlWriter.WriteStartElement("File");

                    if (config.UseAttribute)
                    {
                        xmlWriter.WriteAttributeString("Name", fi.Name);
                        xmlWriter.WriteAttributeString("Size", fi.Length.ToSizeString(config.BinaryUnits));
                    }
                    else
                    {
                        xmlWriter.WriteElementString("Name", fi.Name);
                        xmlWriter.WriteElementString("Size", fi.Length.ToSizeString(config.BinaryUnits));
                    }

                    xmlWriter.WriteEndElement();
                }

                xmlWriter.WriteEndElement();
            }

            if (dir.Folders.Count > 0)
            {
                xmlWriter.WriteStartElement("Folders");

                foreach (FolderInfo subdir in dir.Folders)
                {
                    IndexFolder(subdir);
                }

                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
        }
コード例 #4
0
ファイル: IndexerHtml.cs プロジェクト: andre-d/ShareXYZ
        protected override void IndexFolder(FolderInfo dir, int level)
        {
            sbContent.AppendLine(GetFolderNameRow(dir, level));

            string divClass = level > 0 ? "FolderBorder" : "MainFolderBorder";
            sbContent.AppendLine(HtmlHelper.StartTag("div", "", "class=\"" + divClass + "\""));

            if (dir.Files.Count > 0)
            {
                sbContent.AppendLine(HtmlHelper.StartTag("ul"));

                foreach (FileInfo fi in dir.Files)
                {
                    sbContent.AppendLine(GetFileNameRow(fi, level));
                }

                sbContent.AppendLine(HtmlHelper.EndTag("ul"));
            }

            foreach (FolderInfo subdir in dir.Folders)
            {
                IndexFolder(subdir, level + 1);
            }

            sbContent.AppendLine(HtmlHelper.EndTag("div"));
        }
コード例 #5
0
ファイル: Indexer.cs プロジェクト: andre-d/ShareXYZ
        protected FolderInfo GetFolderInfo(string folderPath, int level = 0)
        {
            FolderInfo folderInfo = new FolderInfo(folderPath);

            if (config.MaxDepthLevel == 0 || level < config.MaxDepthLevel)
            {
                try
                {
                    DirectoryInfo currentDirectoryInfo = new DirectoryInfo(folderPath);

                    foreach (DirectoryInfo directoryInfo in currentDirectoryInfo.GetDirectories())
                    {
                        if (config.SkipHiddenFolders && directoryInfo.Attributes.HasFlag(FileAttributes.Hidden))
                        {
                            continue;
                        }

                        FolderInfo subFolderInfo = GetFolderInfo(directoryInfo.FullName, level + 1);
                        folderInfo.Folders.Add(subFolderInfo);
                        subFolderInfo.Parent = folderInfo;
                    }

                    foreach (FileInfo fileInfo in currentDirectoryInfo.GetFiles())
                    {
                        if (config.SkipHiddenFiles && fileInfo.Attributes.HasFlag(FileAttributes.Hidden))
                        {
                            continue;
                        }

                        folderInfo.Files.Add(fileInfo);
                    }

                    folderInfo.Files.Sort((x, y) => x.Name.CompareTo(y.Name));
                }
                catch (UnauthorizedAccessException)
                {
                }
            }

            return folderInfo;
        }
コード例 #6
0
ファイル: Indexer.cs プロジェクト: andre-d/ShareXYZ
 protected abstract void IndexFolder(FolderInfo dir, int level = 0);
コード例 #7
0
ファイル: Indexer.cs プロジェクト: andre-d/ShareXYZ
        protected virtual string GetFolderNameRow(FolderInfo dir, int level = 0)
        {
            string text = string.Format("{0}{1}", config.IndentationText.Repeat(level), dir.FolderName);

            if (dir.Size > 0)
            {
                text += string.Format(" [{0}]", dir.Size.ToSizeString(config.BinaryUnits));
            }

            return text;
        }
コード例 #8
0
 protected abstract void IndexFolder(FolderInfo dir, int level = 0);