Exemplo n.º 1
0
        public IEnumerable <FileGroup_v2> GetFiles(string directory, FileFilter fileFilter)
        {
            // not bonus files
            List <Func <EnumDirectoryInfo, EnumDirectoryFilter> > directoryFilters = new List <Func <EnumDirectoryInfo, EnumDirectoryFilter> >();

            directoryFilters.Add(InfoDirectoryFilter);
            if (fileFilter == FileFilter.NotBonusFiles)
            {
                directoryFilters.Add(NotBonusDirectoryFilter);
            }

            //if (fileFilter == FileFilter.NotBonusFiles)
            //{
            //    // skip bonus directories
            //    directoryFilter = dir =>
            //        {
            //            if (GetBonusDirectoryInfo(dir.SubDirectory).IsBonusDirectory)
            //                return new EnumDirectoryFilter { Select = false, RecurseSubDirectory = false };
            //            else
            //                return new EnumDirectoryFilter { Select = true, RecurseSubDirectory = true };
            //        };
            //}

            // bonus files
            int    bonusDirectoryLevel     = 0;
            int    bonusSubDirectoryLength = 0;
            string bonusSubDirectory       = null;
            Action <EnumDirectoryInfo> followDirectoryTree = null;

            if (fileFilter == FileFilter.BonusFiles)
            {
                followDirectoryTree = dir =>
                {
                    if (bonusDirectoryLevel == 0)
                    {
                        if (dir.SubDirectory != null)
                        {
                            BonusDirectoryInfo bonusDirectoryInfo = GetBonusDirectoryInfo(dir.SubDirectory);
                            if (bonusDirectoryInfo.IsBonusDirectory)
                            {
                                bonusDirectoryLevel     = dir.Level;
                                bonusSubDirectoryLength = dir.SubDirectory.Length + 1;
                                bonusSubDirectory       = bonusDirectoryInfo.Directory;
                            }
                        }
                    }
                    else if (dir.SubDirectory == null && dir.Level == bonusDirectoryLevel)
                    {
                        bonusDirectoryLevel     = 0;
                        bonusSubDirectoryLength = 0;
                        bonusSubDirectory       = null;
                    }
                };
            }

            IEnumerable <EnumFileInfo> files = zdir.EnumerateFilesInfo(directory,
                                                                       //directoryFilters: directoryFilter != null ? new Func<EnumDirectoryInfo, EnumDirectoryFilter>[] { directoryFilter } : null,
                                                                       directoryFilters: directoryFilters,
                                                                       followDirectoryTrees: followDirectoryTree != null ? new Action <EnumDirectoryInfo>[] { followDirectoryTree } : null);

            foreach (EnumFileInfo file in files)
            {
                FileNumber filenameNumberInfo = FileNumber.GetFileNumber(file.File);
                string     baseFilename       = filenameNumberInfo.BaseFilename;
                bool       badFile            = false;
                if (file.SubDirectory == __badFileDirectory)
                {
                    baseFilename = __badFileDirectory + "\\" + baseFilename;
                    badFile      = true;
                }
                string subDirectory = file.SubDirectory;
                if (fileFilter == FileFilter.BonusFiles)
                {
                    if (bonusDirectoryLevel == 0)
                    {
                        continue;
                    }
                    subDirectory = file.SubDirectory.Length > bonusSubDirectoryLength?file.SubDirectory.Substring(bonusSubDirectoryLength) : null;

                    if (bonusSubDirectory != null)
                    {
                        if (subDirectory != null)
                        {
                            subDirectory = zPath.Combine(bonusSubDirectory, subDirectory);
                        }
                        else
                        {
                            subDirectory = bonusSubDirectory;
                        }
                    }
                }
                //switch (fileFilter)
                //{
                //    case FileFilter.NotBonusFiles:
                //        break;
                //    case FileFilter.BonusFiles:
                //        break;
                //    case FileFilter.AllFiles:
                //        break;
                //}
                yield return(new FileGroup_v2
                {
                    Directory = directory,
                    SubDirectory = subDirectory,
                    File = file.File,
                    BaseFilename = baseFilename,
                    Number = filenameNumberInfo.Number,
                    BadFile = badFile
                              //PrintInfo = PrintIssue.GetPrintInfo(zPath.GetFileNameWithoutExtension(filenameNumberInfo.BaseFilename))
                });
            }
        }
Exemplo n.º 2
0
        public IEnumerable <FileGroup_v2> GetBonusFiles(string directory)
        {
            int    bonusDirectoryLevel     = 0;
            int    bonusSubDirectoryLength = 0;
            string bonusSubDirectory       = null;

            Action <EnumDirectoryInfo> followDirectoryTree =
                dir =>
            {
                if (bonusDirectoryLevel == 0)
                {
                    //if (dir.SubDirectory != null && IsBonusDirectory(dir.SubDirectory))
                    if (dir.SubDirectory != null)
                    {
                        BonusDirectoryInfo bonusDirectoryInfo = GetBonusDirectoryInfo(dir.SubDirectory);
                        if (bonusDirectoryInfo.IsBonusDirectory)
                        {
                            bonusDirectoryLevel     = dir.Level;
                            bonusSubDirectoryLength = dir.SubDirectory.Length + 1;
                            bonusSubDirectory       = bonusDirectoryInfo.Directory;
                        }
                    }
                }
                else if (dir.SubDirectory == null && dir.Level == bonusDirectoryLevel)
                {
                    bonusDirectoryLevel     = 0;
                    bonusSubDirectoryLength = 0;
                    bonusSubDirectory       = null;
                }
            };

            IEnumerable <EnumFileInfo> files = zdir.EnumerateFilesInfo(directory, followDirectoryTrees: new Action <EnumDirectoryInfo>[] { followDirectoryTree });

            foreach (EnumFileInfo file in files)
            {
                if (bonusDirectoryLevel != 0)
                {
                    FileNumber filenameNumberInfo = FileNumber.GetFileNumber(file.File);
                    string     subDirectory       = file.SubDirectory.Length > bonusSubDirectoryLength?file.SubDirectory.Substring(bonusSubDirectoryLength) : null;

                    if (bonusSubDirectory != null)
                    {
                        if (subDirectory != null)
                        {
                            subDirectory = zPath.Combine(bonusSubDirectory, subDirectory);
                        }
                        else
                        {
                            subDirectory = bonusSubDirectory;
                        }
                    }
                    yield return(new FileGroup_v2
                    {
                        Directory = directory,
                        SubDirectory = subDirectory,
                        File = file.File,
                        BaseFilename = filenameNumberInfo.BaseFilename,
                        Number = filenameNumberInfo.Number
                                 //PrintInfo = PrintIssue.GetPrintInfo(zPath.GetFileNameWithoutExtension(filenameNumberInfo.BaseFilename))
                    });
                }
            }
        }