예제 #1
0
        public virtual IList <File> GetFiles()
        {
            try
            {
                List <File> files = new List <File>();

                string lastFileName      = "";
                string lastFileExtension = "";
                File   lastFile          = null;
                foreach (var fd in FileSystem.GetFiles(Url))
                {
                    var file = new File(fd, this);
                    file.Set(FileSystem);
                    file.Set(ImageSizes);

                    if (lastFile != null &&
                        file.Name.StartsWith(lastFileName + ImagesUtility.Separator) &&
                        file.Name.EndsWith(lastFileExtension))
                    {
                        if (!ImageSizes.ImageSizes.Contains(GetSizeName(lastFileName, lastFileExtension, file)))
                        {
                            files.Add(file);
                            continue;
                        }

                        if (GetSizeName(lastFileName, lastFileExtension, file) == "icon")
                        {
                            file.IsIcon = true;
                        }
                        lastFile.Add(file);
                    }
                    else
                    {
                        files.Add(file);

                        int dotIndex = file.Name.LastIndexOf('.');
                        if (dotIndex >= 0)
                        {
                            lastFileName      = file.Name.Substring(0, dotIndex);
                            lastFileExtension = file.Name.Substring(dotIndex);
                            lastFile          = file;
                        }
                    }
                }
                files.Sort(new TitleComparer <File>());
                return(files);
            }
            catch (DirectoryNotFoundException ex)
            {
                Trace.TraceWarning(ex.ToString());
                return(new List <File>());
            }
        }
예제 #2
0
        public virtual IList <File> GetFiles()
        {
            try
            {
                List <File> files = new List <File>();

                var fileMap = new Dictionary <string, File>(StringComparer.OrdinalIgnoreCase);
                foreach (var fd in FileSystem.GetFiles(LocalUrl))
                {
                    var file = new File(fd, this);
                    file.Set(FileSystem);
                    file.Set(ImageSizes);

                    var unresizedFileName = ImageSizes.RemoveImageSize(file.Name);
                    if (unresizedFileName != null && fileMap.ContainsKey(unresizedFileName))
                    {
                        fileMap[unresizedFileName].Add(file);

                        if (ImageSizes.GetSizeName(file.Name) == "icon")
                        {
                            file.IsIcon = true;
                        }
                    }
                    else
                    {
                        files.Add(file);
                        fileMap[file.Name] = file;
                    }
                }
                files.Sort(new TitleComparer <File>());
                return(files);
            }
            catch (DirectoryNotFoundException ex)
            {
                Engine.Logger.Warn(ex);
                return(new List <File>());
            }
        }