예제 #1
0
        public void Custom()
        {
            string[] custom = new string[] { "*.foo", "a*b.test", "test.ego", "any*" };
            IgnoredFiles.SetIngnoredFiles(custom);
            string[] ignore = new string[]
            {
                ".foo",
                "file.foo",
                "asdb.test",
                "ab.test",
                "AvB.test",
                "test.ego",
                "anymore",
                "any",
                "any.bar"
            };
            string[] pass = new string[] { "a.foo.bar", "bacb.test", "a.test", "atest.ego", "test.egomotion", "manymore", "many" };

            foreach (var item in ignore)
            {
                Assert.IsTrue(IgnoredFiles.ShouldIgnore(item));
            }

            foreach (var item in pass)
            {
                Assert.IsFalse(IgnoredFiles.ShouldIgnore(item));
            }
        }
예제 #2
0
        public void IgnoreDefaultFiles()
        {
            string[] ignoredFiles = new string[]
            {
                ".git",
                ".svn",
                ".hg",
                "file.meta",
                ".DS_Store",
                "thumbs.db",
                "Thumbs.db",
                "file.bak",
                ".file~",
                "file~",
                "EgoXproject.dll",
                "egoxproject.settings",
                "egoxproject.configurations",
                "change.egoxc"
            };

            foreach (var item in ignoredFiles)
            {
                Assert.IsTrue(IgnoredFiles.ShouldIgnore(item));
            }

            foreach (var item in ignoredFiles)
            {
                Assert.IsTrue(IgnoredFiles.ShouldIgnore(item.ToLower()));
            }

            foreach (var item in ignoredFiles)
            {
                Assert.IsTrue(IgnoredFiles.ShouldIgnore(item.ToUpper()));
            }
        }
예제 #3
0
        public void Add([NotNull] FtpSummary other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            Deleted.AddRange(other.Deleted);
            DeletedDirectories.AddRange(other.DeletedDirectories);
            CreatedDirectories.AddRange(other.CreatedDirectories);
            UpdatedFiles.AddRange(other.UpdatedFiles);
            CreatedFiles.AddRange(other.CreatedFiles);
            CreatedFiles = CreatedFiles.Except(UpdatedFiles).ToList();
            IgnoredFiles.AddRange(other.IgnoredFiles);
            IgnoredDirectories.AddRange(other.IgnoredDirectories);
        }
예제 #4
0
        public void Clear()
        {
            FileCheckedCount = 0;

            NewFiles.Clear();
            NewFilesForGroom.Clear();
            ChangedFiles.Clear();
            MissingFiles.Clear();
            LastModifiedDateFiles.Clear();
            ErrorFiles.Clear();
            IgnoredFiles.Clear();
            NewlyIgnoredFiles.Clear();
            IgnoredFilesForGroom.Clear();
            MovedFiles.Clear();
            MovedFileOrder.Clear();
            DuplicateFiles.Clear();
        }
예제 #5
0
        public void DontIngoreFiles()
        {
            //".git", ".svn", ".hg", ".meta", ".DS_Store", "thumbs.db", "Thumbs.db", "*.bak", ".*~", "*~";
            string[] files = new string[]
            {
                "file.c",
                "file.cpp",
                "file",
                "file.framework",
                "lib.a",
                ".file",
                "file.hg.c",
                "file.meta.jpg",
                "file.bak.png",
                "file.git"
            };

            foreach (var item in files)
            {
                Assert.IsFalse(IgnoredFiles.ShouldIgnore(item));
            }
        }
 public bool IsFileIgnored(string fileName)
 {
     return(IgnoredFiles.Any(fileName.EndsWith) || !Extensions.Any(fileName.EndsWith));
 }
예제 #7
0
        void DrawIgnoredFilesAndFolders()
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.LabelField(new GUIContent("Ignored Files and Folders", "File and folders that will be ignored when adding folders to change files"));
            EditorGUI.indentLevel--;
            EditorGUILayout.BeginVertical(_style.IndentedBox());
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Default Ignored Files", "These files are always ignored when adding folders"), GUILayout.ExpandWidth(false));
            EditorGUILayout.LabelField(StringUtils.ArrayToString(IgnoredFiles.DefaultList), EditorStyles.wordWrappedLabel);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Custom Ignored Files", "Add filenames and wildcards entries here to have them ignored when adding folders"), GUILayout.ExpandWidth(false));
            EditorGUI.indentLevel++;
            bool update = false;

            int remove = -1;

            for (int ii = 0; ii < _customIgnoredFiles.Count; ++ii)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                _customIgnoredFiles[ii] = EditorGUILayout.TextField(_customIgnoredFiles[ii]);

                if (EditorGUI.EndChangeCheck())
                {
                    update = true;
                }

                EditorGUILayout.Space();

                if (_style.MinusButton("Remove ignored file pattern"))
                {
                    bool removeCheck = true;

                    if (!string.IsNullOrEmpty(_customIgnoredFiles[ii].Trim()))
                    {
                        removeCheck = EditorUtility.DisplayDialog("Remove ignored file pattern?", "Are you sure you want to remove \"" + _customIgnoredFiles[ii] + "\" from the ignore list?", "Remove", "Cancel");
                    }

                    if (removeCheck)
                    {
                        remove = ii;
                    }
                }

                EditorGUILayout.EndHorizontal();
                GUILayout.Space(2);
            }

            if (remove > -1)
            {
                IgnoredFiles.Remove(_customIgnoredFiles[remove]);
                _customIgnoredFiles.RemoveAt(remove);
                _settings.SetDirty();
                _settings.Save();
            }

            if (update)
            {
                IgnoredFiles.SetIngnoredFiles(_customIgnoredFiles.ToArray());
                _settings.SetDirty();
                _settings.Save();
                update = false;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();

            if (_style.PlusButton("Add new ignored file pattern"))
            {
                _customIgnoredFiles.Add("");
            }

            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel--;
            GUILayout.Space(4);
            EditorGUILayout.EndVertical();
        }
예제 #8
0
        protected void UpdateRecursive(
            DirectoryInfo currentDirectoryInfo,
            ManifestDirectoryInfo currentManfestDirInfo)
        {
            // Setup data for current directory
            Dictionary <String, FileInfo> fileDict =
                new Dictionary <string, FileInfo>();

            Dictionary <String, DirectoryInfo> dirDict =
                new Dictionary <string, DirectoryInfo>();

            if (currentDirectoryInfo != null)
            {
                FileInfo[] fileList = null;
                try
                {
                    fileList = currentDirectoryInfo.GetFiles();
                }
                catch (Exception)
                {
                    WriteLine(Manifest.MakeStandardPathString(
                                  currentManfestDirInfo));

                    if (IgnoreFile(Manifest.MakeStandardPathString(
                                       currentManfestDirInfo)) == true)
                    {
                        // This was implemented primarily to allow the user to
                        // silence the process of skipping over inaccessible
                        // system directories by ignoring them.  For example,
                        // in some cases the "$RECYCLE BIN" under Windows
                        // is not accessible and will generate an error.  The
                        // user can now add such directories to the ignore list
                        // and they will be silently ignored.  The special
                        // message for showProgress alerts the user that the
                        // directory is actually being skipped altogether
                        // since it can't be accessed.  The only significant
                        // implication of this is that the ignored files won't
                        // be enumerated and counted as being ignored.
                        if (ShowProgress)
                        {
                            WriteLine(
                                Manifest.MakeStandardPathString(currentManfestDirInfo) +
                                " [IGNORED DIRECTORY AND CANNOT ACCESS]");
                        }
                    }
                    else
                    {
                        ForceWriteLine("Could not access contents of: " +
                                       currentDirectoryInfo.FullName);
                    }

                    return;
                }

                foreach (FileInfo nextFileInfo in fileList)
                {
                    fileDict.Add(nextFileInfo.Name.Normalize(), nextFileInfo);
                }

                DirectoryInfo[] dirList =
                    currentDirectoryInfo.GetDirectories();

                foreach (DirectoryInfo nextDirInfo in dirList)
                {
                    dirDict.Add(nextDirInfo.Name.Normalize(), nextDirInfo);
                }
            }

            // Clone in case we modify during iteration
            List <ManifestFileInfo> fileListClone =
                new List <ManifestFileInfo>(currentManfestDirInfo.Files.Values);

            // Iterate through existing manifest entries
            foreach (ManifestFileInfo nextManFileInfo in fileListClone)
            {
                if (ShowProgress)
                {
                    Write(Manifest.MakeStandardPathString(nextManFileInfo));
                }

                if (fileDict.ContainsKey(nextManFileInfo.Name))
                {
                    FileCheckedCount++;

                    FileInfo nextFileInfo = fileDict[nextManFileInfo.Name];

                    if (IgnoreFile(Manifest.MakeStandardPathString(nextManFileInfo)))
                    {
                        Write(" [NEWLY IGNORED]");

                        currentManfestDirInfo.Files.Remove(
                            nextManFileInfo.Name);

                        NewlyIgnoredFiles.Add(nextManFileInfo);
                    }
                    else if (nextFileInfo.Length != nextManFileInfo.FileLength &&
                             Update == false &&
                             AlwaysCheckHash == false)
                    {
                        // Don't compute hash if we aren't doing an update
                        Write(" [DIFFERENT]");
                        ChangedFiles.Add(nextManFileInfo);
                    }
                    else if (AlwaysCheckHash == true ||
                             MakeNewHash == true ||
                             nextManFileInfo.FileHash == null ||
                             Manifest.CompareManifestDateToFilesystemDate(nextFileInfo.LastWriteTimeUtc, nextManFileInfo.LastModifiedUtc) == false ||
                             nextFileInfo.Length != nextManFileInfo.FileLength)
                    {
                        FileHash checkHash = null;

                        Exception exception = null;
                        try
                        {
                            string hashType = Manifest.DefaultHashMethod;
                            if (nextManFileInfo.FileHash != null)
                            {
                                hashType = nextManFileInfo.FileHash.HashType;
                            }

                            checkHash = FileHash.ComputeHash(
                                nextFileInfo,
                                hashType);
                        }
                        catch (Exception ex)
                        {
                            exception = ex;
                        }

                        if (exception != null)
                        {
                            WriteLine(" [ERROR]");
                            WriteLine(exception.ToString());

                            ErrorFiles.Add(nextManFileInfo);
                        }
                        else
                        {
                            if (nextManFileInfo.FileHash == null)
                            {
                                Write(" [NULL HASH IN MANIFEST]");
                                ChangedFiles.Add(nextManFileInfo);
                            }
                            else if (checkHash.Equals(nextManFileInfo.FileHash) == false)
                            {
                                Write(" [DIFFERENT]");
                                ChangedFiles.Add(nextManFileInfo);
                            }
                            else
                            {
                                if (Manifest.CompareManifestDateToFilesystemDate(
                                        nextFileInfo.LastWriteTimeUtc,
                                        nextManFileInfo.LastModifiedUtc) == false)
                                {
                                    Write(" [LAST MODIFIED DATE]");
                                    LastModifiedDateFiles.Add(nextManFileInfo);

                                    if (BackDate == true)
                                    {
                                        nextFileInfo.LastWriteTimeUtc =
                                            nextManFileInfo.LastModifiedUtc;
                                    }
                                }
                            }
                        }

                        FileHash newHash = checkHash;
                        if (MakeNewHash)
                        {
                            newHash = FileHash.ComputeHash(
                                nextFileInfo,
                                GetNewHashType(Manifest));
                        }

                        // Update hash and last modified date accordingly
                        nextManFileInfo.FileHash = newHash;

                        nextManFileInfo.LastModifiedUtc = nextFileInfo.LastWriteTimeUtc;
                        nextManFileInfo.FileLength      = nextFileInfo.Length;
                    }
                    else
                    {
                        Write(" [SKIPPED]");
                    }
                }
                else
                {
                    Write(" [MISSING]");
                    currentManfestDirInfo.Files.Remove(nextManFileInfo.Name);
                    MissingFiles.Add(nextManFileInfo);
                }

                WriteLine("");
            }

            // Clone in case we modify during iteration
            List <ManifestDirectoryInfo> directoryListClone =
                new List <ManifestDirectoryInfo>(
                    currentManfestDirInfo.Subdirectories.Values);

            foreach (ManifestDirectoryInfo nextManDirInfo in
                     directoryListClone)
            {
                DirectoryInfo nextDirInfo = null;
                if (dirDict.ContainsKey(nextManDirInfo.Name))
                {
                    nextDirInfo = dirDict[nextManDirInfo.Name];
                }

                UpdateRecursive(
                    nextDirInfo,
                    nextManDirInfo);

                if (nextManDirInfo.Empty)
                {
                    currentManfestDirInfo.Subdirectories.Remove(
                        nextManDirInfo.Name);
                }
            }

            // Look for new files
            foreach (String nextFileName in fileDict.Keys)
            {
                FileInfo nextFileInfo = fileDict[nextFileName];

                if (currentManfestDirInfo.Files.ContainsKey(
                        nextFileName) == false)
                {
                    ManifestFileInfo newManFileInfo =
                        new ManifestFileInfo(
                            nextFileName,
                            currentManfestDirInfo);

                    Write(Manifest.MakeStandardPathString(newManFileInfo));

                    if (IgnoreFile(Manifest.MakeStandardPathString(newManFileInfo)))
                    {
                        IgnoredFiles.Add(newManFileInfo);

                        // Don't groom the manifest file!
                        if (Manifest.MakeNativePathString(newManFileInfo) !=
                            ManifestNativeFilePath)
                        {
                            IgnoredFilesForGroom.Add(nextFileInfo);
                        }

                        Write(" [IGNORED]");
                    }
                    else
                    {
                        FileCheckedCount++;

                        bool checkHash = false;
                        if (Update == true ||
                            AlwaysCheckHash == true ||
                            TrackMoves == true)
                        {
                            checkHash = true;
                        }


                        Exception exception = null;
                        if (checkHash)
                        {
                            try
                            {
                                newManFileInfo.FileHash =
                                    FileHash.ComputeHash(
                                        nextFileInfo,
                                        GetNewHashType(Manifest));
                            }
                            catch (Exception ex)
                            {
                                exception = ex;
                            }
                        }

                        if (checkHash && newManFileInfo.FileHash == null)
                        {
                            ErrorFiles.Add(newManFileInfo);

                            WriteLine(" [ERROR]");
                            WriteLine(exception.ToString());
                        }
                        else
                        {
                            NewFiles.Add(newManFileInfo);
                            NewFilesForGroom.Add(nextFileInfo);
                            Write(" [NEW]");
                        }

                        newManFileInfo.FileLength =
                            nextFileInfo.Length;

                        newManFileInfo.LastModifiedUtc =
                            nextFileInfo.LastWriteTimeUtc;

                        newManFileInfo.RegisteredUtc =
                            DateTime.Now.ToUniversalTime();

                        currentManfestDirInfo.Files.Add(
                            nextFileName,
                            newManFileInfo);
                    }

                    WriteLine("");
                }
            }

            // Recurse looking for new directories
            foreach (String nextDirName in dirDict.Keys)
            {
                DirectoryInfo nextDirInfo = dirDict[nextDirName];

                if (currentManfestDirInfo.Subdirectories.ContainsKey(
                        nextDirName) == false)
                {
                    ManifestDirectoryInfo nextManDirInfo =
                        new ManifestDirectoryInfo(
                            nextDirName,
                            currentManfestDirInfo);

                    currentManfestDirInfo.Subdirectories.Add(
                        nextDirName,
                        nextManDirInfo);

                    UpdateRecursive(
                        nextDirInfo,
                        nextManDirInfo);

                    if (nextManDirInfo.Empty)
                    {
                        currentManfestDirInfo.Subdirectories.Remove(
                            nextDirName);
                    }
                }
            }
        }
예제 #9
0
        public static void WriteFilesToDatabase(DbFileContext ctx, Uri initialUri, DirectoryInfo root, int?id)
        {
            string virtualPath;
            string dirName;

            if (id == null)
            {
                virtualPath = "/";
                dirName     = null;
            }
            else
            {
                var currentUri   = new Uri(root.FullName);
                var tempRelative = initialUri.MakeRelativeUri(currentUri).ToString();
                var iof          = tempRelative.IndexOf('/');
                virtualPath = tempRelative.Substring(iof);

                dirName = root.Name;
            }

            foreach (var ignoredDirectory in IgnoredDirectories)
            {
                if (virtualPath.StartsWith(ignoredDirectory, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
            }

            var dbFile = new DbFile
            {
                IsDirectory = true,
                Name        = dirName,
                VirtualPath = virtualPath,
                ParentId    = id
            };

            ctx.DbFiles.Add(dbFile);
            ctx.SaveChanges();

            foreach (var fi in root.EnumerateFiles())
            {
                bool ignore = IgnoredExtensions.Any(ignoredExtension => fi.Extension.StartsWith(ignoredExtension)) ||
                              IgnoredFiles.Any(x => x.Equals(fi.Name, StringComparison.OrdinalIgnoreCase));

                if (ignore)
                {
                    continue;
                }

                Console.WriteLine(fi.FullName);

                var dbFileFolder = new DbFile
                {
                    IsDirectory = false,
                    Name        = Path.GetFileNameWithoutExtension(fi.Name),
                    Extension   = fi.Extension,
                    VirtualPath = Path.Combine(virtualPath, fi.Name).Replace('\\', '/'),
                    ParentId    = dbFile.Id,
                };

                if (IsTextFile(fi.Extension))
                {
                    var text = File.ReadAllText(fi.FullName, Encoding.UTF8);
                    dbFileFolder.Texto = text;
                }
                else
                {
                    var bytes = File.ReadAllBytes(fi.FullName);
                    dbFileFolder.Bytes    = bytes;
                    dbFileFolder.IsBinary = true;
                }

                ctx.DbFiles.Add(dbFileFolder);
                ctx.SaveChanges();
            }

            foreach (var di in root.EnumerateDirectories())
            {
                WriteFilesToDatabase(ctx, initialUri, di, dbFile.Id);
            }
        }