示例#1
0
        public static ForestNode <DirectoryInfoCache> ForestWithSync(DirectoryInfo cur)
        {
            var dic = DirectoryInfoCache.CreateRoot(cur);

            dic.SyncAllToFileSystem();
            return(Forest(dic));
        }
示例#2
0
        private DirectoryInfoCache SaveToCache(DirectoryInfo di)
        {
            var diCache = new DirectoryInfoCache(this, di);

            _children.Add(diCache);
            return(diCache);
        }
示例#3
0
        private static DirectoryInfoCache CreateRoot(DirectoryInfo baseDi)
        {
            var baseDic = new DirectoryInfoCache(null, baseDi);

            baseDic.PossiblyMoveFromOutside = true;
            return(baseDic);
        }
示例#4
0
        internal virtual void MoveTo(DirectoryInfoCache from, FileInfo target, string destRelative)
        {
            var destDIC = EnsureSubdirectory(from, destRelative);

            WriteBlack(destDIC.FullName);
            SafeMoveTo(from, target, destDIC);
        }
示例#5
0
 public void MoveTo(FileInfo target, DirectoryInfoCache to, string newName)
 {
     // Debug.Assert(Array.Exists(Item.GetFiles(InterestedFilePattern), (x) => x == target));
     RawMoveTo(target, to.FullName, newName);
     to.AddFileCount(1);
     AddFileCount(-1);
 }
示例#6
0
 public static Dumper CreateHtmlGenerater(string bzipPath, bool isJapanese, DirectoryInfoCache result, PerfCounter counter)
 {
     DumpAction htmlAction = DumpAction.CreateHtmlGeneraterAction(bzipPath, result.Item);
     var dumper = new Dumper(bzipPath, htmlAction, counter);
     SplitFolder sf = CreateSplitFolder(isJapanese, result);
     PostCreate(dumper, isJapanese, sf);
     return dumper;
 }
示例#7
0
 // do not contain top.
 internal void WriteGrayBetween(DirectoryInfoCache top, DirectoryInfoCache bottom)
 {
     while (bottom != top)
     {
         WriteGray(bottom.FullName);
         bottom = bottom.Parent;
     }
 }
示例#8
0
        public static Dumper CreateHtmlGenerater(string bzipPath, bool isJapanese, DirectoryInfoCache result, PerfCounter counter)
        {
            DumpAction  htmlAction = DumpAction.CreateHtmlGeneraterAction(bzipPath, result.Item);
            var         dumper     = new Dumper(bzipPath, htmlAction, counter);
            SplitFolder sf         = CreateSplitFolder(isJapanese, result);

            PostCreate(dumper, isJapanese, sf);
            return(dumper);
        }
示例#9
0
            public ArchiveTask(DirectoryInfoCache workDir, Action <IEnumerable <FileInfo>, string> archive, string extension)
            {
                Archive = archive;
                var node = DirectoryInfoCache.Forest(workDir);

                _walker         = node.Walker;
                Extension       = extension;
                SourceExtension = ".html";
            }
示例#10
0
 public DirectoryInfoCache(DirectoryInfoCache parent, DirectoryInfo item)
 {
     Parent = parent;
     if (parent != null)
         InterestedFilePattern = parent.InterestedFilePattern;
     PossiblyMoveFromOutside = false;
     Item = item;
     _fullName = NormalizedFullName(item.FullName);
     FileCount = 0;
 }
示例#11
0
 public static Dumper CreateRawDumper(string bzipPath, bool isJapanese, DirectoryInfoCache result, PerfCounter counter)
 {
     DumpAction rawDump = DumpAction.CreateRawDumpAction(bzipPath, result.Item);
     Dumper dumper =  new Dumper(bzipPath, rawDump, counter);
     SplitFolder sf = CreateSplitFolder(isJapanese, result);
     // not DRY!
     sf.InterestedFilePattern = "*.wiki";
     PostCreate(dumper, isJapanese, sf);
     return dumper;
 }
示例#12
0
        public static Dumper CreateRawDumper(string bzipPath, bool isJapanese, DirectoryInfoCache result, PerfCounter counter)
        {
            DumpAction  rawDump = DumpAction.CreateRawDumpAction(bzipPath, result.Item);
            Dumper      dumper  = new Dumper(bzipPath, rawDump, counter);
            SplitFolder sf      = CreateSplitFolder(isJapanese, result);

            // not DRY!
            sf.InterestedFilePattern = "*.wiki";
            PostCreate(dumper, isJapanese, sf);
            return(dumper);
        }
示例#13
0
        public static ForestNode <DirectoryInfoCache> Forest(DirectoryInfoCache dic)
        {
            ForestNode <DirectoryInfoCache> root = new ForestNode <DirectoryInfoCache>(ForestNode <DirectoryInfoCache> .Edge.Leading,
                                                                                       dic,
                                                                                       (x, i) => x.GetChild(i),
                                                                                       (x) => x.Parent,
                                                                                       (x) => x.ChildrenLength,
                                                                                       (x) => x.ChildIndex,
                                                                                       (x, y) => x.FullName == y.FullName);

            return(root);
        }
示例#14
0
 public DirectoryInfoCache(DirectoryInfoCache parent, DirectoryInfo item)
 {
     Parent = parent;
     if (parent != null)
     {
         InterestedFilePattern = parent.InterestedFilePattern;
     }
     PossiblyMoveFromOutside = false;
     Item      = item;
     _fullName = NormalizedFullName(item.FullName);
     FileCount = 0;
 }
示例#15
0
        public void StartSplit()
        {
            Abort   = false;
            Current = StartDirectory;
            var root = DirectoryInfoCache.Forest(StartDirectory);

            _walker = root.Walker;

            _dirty.Clear();
            WriteBlack(StartDirectory.FullName);

            SyncDirectoryInfoCacheToFileSystem();
        }
示例#16
0
 public override bool Equals(object other)
 {
     if (other == null)
     {
         return(((object)this) == null);
     }
     if (other is DirectoryInfoCache)
     {
         DirectoryInfoCache dic = other as DirectoryInfoCache;
         return(_fullName == dic.FullName);
     }
     return(false);
 }
示例#17
0
        public SplitFolder(DirectoryInfoCache baseDi, ISplitTactics tactics)
        {
            _splitDictInit = true;
            Base           = baseDi;

            Abort    = false;
            _tactics = tactics;


            Current        = Base;
            StartDirectory = Current;
            MaxFileNum     = WikipediaConv.Properties.Settings.Default.OneFolderMaxFileNum;
            _dirty         = new Dictionary <string, Dirtiness>();
        }
示例#18
0
        public void SyncAllToFileSystem()
        {
            Debug.Assert(this.Parent == null);
            var walker = DirectoryInfoCache.Forest(this).Walker;

            while (walker.HasNext)
            {
                walker.MoveNext();
                var node = walker.Current;
                if (node.CurrentEdge == ForestNode <DirectoryInfoCache> .Edge.Trailing)
                {
                    continue;
                }
                node.Element.SyncToFileSystem();
            }
        }
示例#19
0
        DirectoryInfoCache GetWorkingDirectory(string bzipPath, string dirName, string interestedFilePattern)
        {
            if (_workingDir != null)
            {
                return(_workingDir);
            }
            var           parent = new FileInfo(bzipPath).Directory;
            DirectoryInfo di     = new DirectoryInfo(Path.Combine(parent.FullName, dirName));

            if (!di.Exists)
            {
                di.Create();
            }
            _workingDir = DirectoryInfoCache.CreateRoot(di);
            _workingDir.InterestedFilePattern = interestedFilePattern;
            _workingDir.SyncAllToFileSystem();
            return(_workingDir);
        }
示例#20
0
        // rename if name is dup
        private static void SafeMoveTo(DirectoryInfoCache from, FileInfo target, DirectoryInfoCache destDIC)
        {
            var newName = target.Name;

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    from.MoveTo(target, destDIC, newName);
                    return;
                }
                catch (IOException)
                {
                    var fname     = Path.GetFileNameWithoutExtension(newName);
                    var extension = Path.GetExtension(newName);
                    fname  += 'X';
                    newName = fname + extension;
                }
            }
        }
示例#21
0
        private bool SortToSubdirectories()
        {
            bool moveSomething = false;

            foreach (var file in FileEnum)
            {
                DirectoryInfoCache dest = GetDest(file);
                if (dest != null)
                {
                    moveSomething = true;
                    MoveToDirect(Current, file, dest);
                }
                else
                {
                    var destRelative = GetOneMatchedSubdirectoryRelativePath(file);
                    if (!String.IsNullOrEmpty(destRelative))
                    {
                        moveSomething = true;
                        MoveTo(Current, file, destRelative);
                    }
                }
            }
            return(moveSomething);
        }
示例#22
0
 // rename if name is dup
 private static void SafeMoveTo(DirectoryInfoCache from, FileInfo target, DirectoryInfoCache destDIC)
 {
     var newName = target.Name;
     for (int i = 0; i < 10; i++)
     {
         try
         {
             from.MoveTo(target, destDIC, newName);
             return;
         }
         catch (IOException)
         {
             var fname = Path.GetFileNameWithoutExtension(newName);
             var extension = Path.GetExtension(newName);
             fname += 'X';
             newName = fname + extension;
         }
     }
 }
示例#23
0
 private static DirectoryInfoCache CreateRoot(DirectoryInfo baseDi)
 {
     var baseDic = new DirectoryInfoCache(null, baseDi);
     baseDic.PossiblyMoveFromOutside = true;
     return baseDic;
 }
示例#24
0
 // do not contain top.
 internal void WriteGrayBetween(DirectoryInfoCache top, DirectoryInfoCache bottom)
 {
     while (bottom != top)
     {
         WriteGray(bottom.FullName);
         bottom = bottom.Parent;
     }
 }
示例#25
0
 internal void MoveToDirect(DirectoryInfoCache from, FileInfo file, DirectoryInfoCache dest)
 {
     WriteBlack(dest.FullName);
     WriteGrayBetween(from, dest.Parent);
     SafeMoveTo(from, file, dest);
 }
示例#26
0
 private SplitFolder CreateSplitFolderForEnglish(DirectoryInfoCache root, DirectoryInfoCache c)
 {
     return CreateSplitFolder(root, c, new EnglishTactics());
 }
示例#27
0
 SplitFolder CreateSplitFolder(DirectoryInfoCache baseDIC, DirectoryInfoCache curDIC, ISplitTactics tactics)
 {
     var sf = new SplitFolder(baseDIC, tactics);
     sf.Current = curDIC;
     return sf;
 }
示例#28
0
 private static DirectoryInfoCache SetupDICParent(DirectoryInfoCache baseDIC, DirectoryInfoCache cur)
 {
     while (baseDIC != cur)
     {
         var parentCand = new DirectoryInfoCache(null, cur.Item.Parent);
         if (baseDIC.FullName == parentCand.FullName)
             parentCand = baseDIC;
         cur.Parent = parentCand;
         cur.Parent.Children.Add(cur);
         cur = cur.Parent;
     }
     return cur;
 }
示例#29
0
 DirectoryInfoCache GetWorkingDirectory(string bzipPath, string dirName, string interestedFilePattern)
 {
     if (_workingDir != null)
         return _workingDir;
     var parent = new FileInfo(bzipPath).Directory;
     DirectoryInfo di = new DirectoryInfo(Path.Combine(parent.FullName, dirName));
     if (!di.Exists)
     {
         di.Create();
     }
     _workingDir = DirectoryInfoCache.CreateRoot(di);
     _workingDir.InterestedFilePattern = interestedFilePattern;
     _workingDir.SyncAllToFileSystem();
     return _workingDir;
 }
示例#30
0
        private void DumpFileToArchive(string[] files, Action <IEnumerable <FileInfo>, string> archive, Func <string, bool, DirectoryInfoCache, PerfCounter, Dumper> createDumper, DirectoryInfoCache workingDir, string outputExtension, string sourceExtension)
        {
            if (EnableAutoLogging)
            {
                // use parent of pdf/epub folder.
                _counter.SetOutputFolder(workingDir.Item.Parent.FullName);
            }

            using (var uwAll = _counter.UsingWatch("All"))
            {
                foreach (string file in files)
                {
                    bool   isJapanese = IsJapanese(file);
                    Dumper gen        = createDumper(file, isJapanese, workingDir, _counter);
                    gen.EnableAutoLogging = EnableAutoLogging;
                    if (DialogResult.OK != new ProgressDialog(gen.LongTask, _counter).ShowDialog(this))
                    {
                        // MessageBox.Show("generate html cancelled");
                        // tmp fall through.
                        // return;
                    }
                }

                using (var uwArchive = _counter.UsingWatch("Archive"))
                {
                    ArchiveTask archiveTask = new ArchiveTask(workingDir, archive, outputExtension);
                    archiveTask.SourceExtension = sourceExtension;
                    if (DialogResult.OK != new ProgressDialog(archiveTask, _counter).ShowDialog(this))
                    {
                        MessageBox.Show("generate epub cancelled");
                        return;
                    }
                }
            }
            if (EnableAutoLogging)
            {
                _counter.DumpToLog();
            }
        }
示例#31
0
 DirectoryInfoCache EnsureSubdirectory(DirectoryInfoCache parent, string relativeSub)
 {
     return(parent.EnsureSubdirectory(relativeSub));
 }
示例#32
0
        private static SplitFolder CreateSplitFolder(bool isJapanese, DirectoryInfoCache result)
        {
            SplitFolder sf = new SplitFolder(result, GetTactics(isJapanese));

            return(sf);
        }
示例#33
0
 internal void MoveToDirect(DirectoryInfoCache from, FileInfo file, DirectoryInfoCache dest)
 {
     WriteBlack(dest.FullName);
     WriteGrayBetween(from, dest.Parent);
     SafeMoveTo(from, file, dest);
 }
示例#34
0
 DirectoryInfoCache EnsureSubdirectory(DirectoryInfoCache parent, string relativeSub)
 {
     return parent.EnsureSubdirectory(relativeSub);
 }
示例#35
0
 SplitFolder CreateSplitFolder(DirectoryInfo baseDi, DirectoryInfo curDi)
 {
     var sf = new SplitFolder(baseDi);
     var cur = new DirectoryInfoCache(null, curDi);
     sf.Current = cur;
     // setup parent
     var baseDIC = sf.StartDirectory;
     cur = SetupDICParent(baseDIC, cur);
     Assert.AreEqual(sf.StartDirectory, cur);
     return sf;
 }
示例#36
0
        public SplitFolder(DirectoryInfoCache baseDi, ISplitTactics tactics)
        {
            _splitDictInit = true;
            Base = baseDi;

            Abort = false;
            _tactics = tactics;

            Current = Base;
            StartDirectory = Current;
            MaxFileNum = WikipediaConv.Properties.Settings.Default.OneFolderMaxFileNum;
            _dirty = new Dictionary<string, Dirtiness>();
        }
示例#37
0
 private static SplitFolder CreateSplitFolder(bool isJapanese, DirectoryInfoCache result)
 {
     SplitFolder sf = new SplitFolder(result, GetTactics(isJapanese));
     return sf;
 }
示例#38
0
 private DirectoryInfoCache CreateDIC(DirectoryInfoCache baseDIC, string path)
 {
     var dic = CreateDIC(path);
     SetupDICParent(baseDIC, dic);
     return dic;
 }
示例#39
0
 public static ForestNode<DirectoryInfoCache> Forest(DirectoryInfoCache dic)
 {
     ForestNode<DirectoryInfoCache> root = new ForestNode<DirectoryInfoCache>(ForestNode<DirectoryInfoCache>.Edge.Leading,
         dic,
         (x, i) => x.GetChild(i),
         (x) => x.Parent,
         (x) => x.ChildrenLength,
         (x) => x.ChildIndex,
         (x, y) => x.FullName == y.FullName);
     return root;
 }
示例#40
0
 internal virtual void MoveTo(DirectoryInfoCache from, FileInfo target, string destRelative)
 {
     var destDIC = EnsureSubdirectory(from, destRelative);
     WriteBlack(destDIC.FullName);
     SafeMoveTo(from, target, destDIC);
 }
示例#41
0
        private void DumpFileToArchive(string[] files, Action<IEnumerable<FileInfo>, string> archive, Func<string, bool, DirectoryInfoCache, PerfCounter, Dumper> createDumper, DirectoryInfoCache workingDir, string outputExtension, string sourceExtension)
        {
            if (EnableAutoLogging)
            {
                // use parent of pdf/epub folder.
                _counter.SetOutputFolder(workingDir.Item.Parent.FullName);
            }

            using (var uwAll = _counter.UsingWatch("All"))
            {
                foreach (string file in files)
                {
                    bool isJapanese = IsJapanese(file);
                    Dumper gen = createDumper(file, isJapanese, workingDir, _counter);
                    gen.EnableAutoLogging = EnableAutoLogging;
                    if (DialogResult.OK != new ProgressDialog(gen.LongTask, _counter).ShowDialog(this))
                    {
                        // MessageBox.Show("generate html cancelled");
                        // tmp fall through.
                        // return;
                    }
                }

                using (var uwArchive = _counter.UsingWatch("Archive"))
                {
                    ArchiveTask archiveTask = new ArchiveTask(workingDir, archive, outputExtension);
                    archiveTask.SourceExtension = sourceExtension;
                    if (DialogResult.OK != new ProgressDialog(archiveTask, _counter).ShowDialog(this))
                    {
                        MessageBox.Show("generate epub cancelled");
                        return;
                    }
                }
            }
            if (EnableAutoLogging)
                _counter.DumpToLog();
        }
示例#42
0
 public void MoveTo(FileInfo target, DirectoryInfoCache to, string newName)
 {
     // Debug.Assert(Array.Exists(Item.GetFiles(InterestedFilePattern), (x) => x == target));
     RawMoveTo(target, to.FullName, newName);
     to.AddFileCount(1);
     AddFileCount(-1);
 }
示例#43
0
 public ArchiveTask(DirectoryInfoCache workDir, Action<IEnumerable<FileInfo>, string> archive, string extension)
 {
     Archive = archive;
     var node = DirectoryInfoCache.Forest(workDir);
     _walker = node.Walker;
     Extension = extension;
     SourceExtension = ".html";
 }
示例#44
0
 private DirectoryInfoCache SaveToCache(DirectoryInfo di)
 {
     var diCache = new DirectoryInfoCache(this, di);
     _children.Add(diCache);
     return diCache;
 }