Exemple #1
0
        protected void TrackMoves()
        {
            // For large number of moved files it's probably faster to
            // rebuild these lists from scratch than to remove many
            // individual items from them.
            List <ManifestFileInfo> sourceOnlyFilesUpdated =
                new List <ManifestFileInfo>();

            List <ManifestFileInfo> destOnlyFilesUpdated =
                new List <ManifestFileInfo>();

            // Make files easy to find by their hashcodes
            HashFileDict sourceFileDict = new HashFileDict();

            foreach (ManifestFileInfo sourceFile in SourceOnlyFiles)
            {
                sourceFileDict.Add(sourceFile);
            }

            HashFileDict destFileDict = new HashFileDict();

            foreach (ManifestFileInfo destFile in DestOnlyFiles)
            {
                destFileDict.Add(destFile);
            }

            // Note which new files are really moved files for later when
            // we rebuild the new files list.
            HashSet <ManifestFileInfo> movedFiles =
                new HashSet <ManifestFileInfo>();

            foreach (ManifestFileInfo checkSourceFile in SourceOnlyFiles)
            {
                if (destFileDict.Dict.ContainsKey(checkSourceFile.FileHash))
                {
                    if (MovedFiles.ContainsKey(checkSourceFile.FileHash) == false)
                    {
                        MovedFiles.Add(
                            checkSourceFile.FileHash,
                            new MovedFileSet());

                        MovedFileOrder.Add(checkSourceFile.FileHash);
                    }

                    MovedFiles[checkSourceFile.FileHash].SourceFiles.Add(checkSourceFile);

                    if (MovedFiles[checkSourceFile.FileHash].DestFiles.Count == 0)
                    {
                        // First time only
                        foreach (ManifestFileInfo nextNewFile in
                                 destFileDict.Dict[checkSourceFile.FileHash])
                        {
                            MovedFiles[checkSourceFile.FileHash].DestFiles.Add(nextNewFile);

                            // Remember for later rebuild
                            movedFiles.Add(nextNewFile);
                        }
                    }
                }
                else
                {
                    sourceOnlyFilesUpdated.Add(checkSourceFile);
                }
            }

            // Rebuild new file list
            foreach (ManifestFileInfo checkDestFile in DestOnlyFiles)
            {
                if (movedFiles.Contains(checkDestFile) == false)
                {
                    destOnlyFilesUpdated.Add(checkDestFile);
                }
            }

            // Replace with updated lists
            SourceOnlyFiles = sourceOnlyFilesUpdated;
            DestOnlyFiles   = destOnlyFilesUpdated;
        }
Exemple #2
0
        protected void DoTrackMoves()
        {
            // For large number of moved files it's probably faster to
            // rebuild these lists from scratch than to remove many
            // individual items from them.
            List <ManifestFileInfo> missingFilesUpdated =
                new List <ManifestFileInfo>();

            List <ManifestFileInfo> newFilesUpdated =
                new List <ManifestFileInfo>();

            // Make files easy to find by their hashcodes
            HashFileDict missingFileDict = new HashFileDict();

            foreach (ManifestFileInfo missingFile in MissingFiles)
            {
                missingFileDict.Add(missingFile);
            }

            HashFileDict newFileDict = new HashFileDict();

            foreach (ManifestFileInfo newFile in NewFiles)
            {
                newFileDict.Add(newFile);
            }

            // Note which new files are really moved files for later when
            // we rebuild the new files list.
            HashSet <ManifestFileInfo> movedFiles =
                new HashSet <ManifestFileInfo>();

            foreach (ManifestFileInfo checkMissingFile in MissingFiles)
            {
                if (newFileDict.Dict.ContainsKey(checkMissingFile.FileHash))
                {
                    if (MovedFiles.ContainsKey(checkMissingFile.FileHash) == false)
                    {
                        MovedFiles.Add(
                            checkMissingFile.FileHash,
                            new MovedFileSet());

                        MovedFileOrder.Add(checkMissingFile.FileHash);
                    }

                    MovedFiles[checkMissingFile.FileHash].OldFiles.Add(checkMissingFile);

                    if (MovedFiles[checkMissingFile.FileHash].NewFiles.Count == 0)
                    {
                        // First time only
                        foreach (ManifestFileInfo nextNewFile in
                                 newFileDict.Dict[checkMissingFile.FileHash])
                        {
                            MovedFiles[checkMissingFile.FileHash].NewFiles.Add(nextNewFile);

                            // Remember for later rebuild
                            movedFiles.Add(nextNewFile);
                        }
                    }
                }
                else
                {
                    missingFilesUpdated.Add(checkMissingFile);
                }
            }

            // Rebuild new file list
            NewFilesForGroom.Clear();
            foreach (ManifestFileInfo checkNewFile in NewFiles)
            {
                if (movedFiles.Contains(checkNewFile) == false)
                {
                    newFilesUpdated.Add(checkNewFile);

                    String checkNewFilePath =
                        Manifest.MakeNativePathString(checkNewFile);

                    if (checkNewFilePath != ManifestNativeFilePath)
                    {
                        NewFilesForGroom.Add(
                            new FileInfo(checkNewFilePath));
                    }
                }
            }

            // Replace with updated lists
            MissingFiles = missingFilesUpdated;
            NewFiles     = newFilesUpdated;
        }