Exemple #1
0
        public static TraceIndex Track(FileInfo TargetFile, Repo ParentRepo)
        {
            TraceIndex traceIndex = new TraceIndex();

            {
                traceIndex.RelativeFilePath = PathHelper.GetRelativePath(ParentRepo.RepoPath, TargetFile.FullName);
                traceIndex.FileHash         = "INIT";
                //traceIndex.FileHash = SHA256Hash.ComputeSHA256(TargetFile.FullName);
            }
            traceIndex.Parent = ParentRepo;
            return(traceIndex);
        }
Exemple #2
0
        public void CheckDirectory(DirectoryInfo directory)
        {
            Debugger.CurrentDebugger.Log($"Current Folder: {directory.FullName}", Utilities.LogLevel.Development);
            if (directory.FullName.ToUpper() == Path.Combine(RepoPath, ".extgit").ToUpper() || directory.FullName.ToUpper() == Path.Combine(RepoPath, ".git").ToUpper())
            {
                Debugger.CurrentDebugger.Log($"Folder: {directory.FullName} is ignored", Utilities.LogLevel.Development);
                //Don't self copy :P.
                return;
            }
            var RP = PathHelper.GetRelativePath(RepoPath, directory.FullName);
            {
                {
                    //Get Relative Path.
                    try
                    {
                        Debugger.CurrentDebugger.Log("Check:" + RP, Utilities.LogLevel.Development);
                        if (GitRepo.Ignore.IsPathIgnored(RP + Path.DirectorySeparatorChar))
                        {
                            return;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            {
                if (!Directory.Exists(Path.Combine(RepoPath, ".extgit", RP)))
                {
                    Directory.CreateDirectory(Path.Combine(RepoPath, ".extgit", RP));
                    Directory.SetCreationTime(Path.Combine(RepoPath, ".extgit", RP), directory.CreationTime);
                }
            }
            var DirectoriesInWorkLoad = new List <String>();
            var FilesInWorkLoad       = new List <String>();

            {
                var           Workload      = Path.Combine(RepoPath, ".extgit", RP);
                DirectoryInfo directoryInfo = new DirectoryInfo(Workload);
                Debugger.CurrentDebugger.Log("Check:" + directoryInfo.FullName, Utilities.LogLevel.Development);
                foreach (var item in directoryInfo.EnumerateDirectories())
                {
                    if (item.Name.ToUpper() == ".GIT" || item.Name.ToUpper() == ".EXTGITCONF" || item.Name.ToUpper() == ".EXTGIT")
                    {
                        continue;
                    }
                    DirectoriesInWorkLoad.Add(item.Name);
                }
            }
            {
                var           Workload      = Path.Combine(RepoPath, ".extgit", RP);
                DirectoryInfo directoryInfo = new DirectoryInfo(Workload);
                foreach (var item in directoryInfo.EnumerateFiles())
                {
                    FilesInWorkLoad.Add(item.Name);
                }
            }
            foreach (var item in directory.EnumerateDirectories())
            {
                if (DirectoriesInWorkLoad.Contains(item.Name))
                {
                    DirectoriesInWorkLoad.Remove(item.Name);
                }
                Debugger.CurrentDebugger.Log($"Folder: {item.FullName}", Utilities.LogLevel.Development);
                CheckDirectory(item);
            }
            {
                foreach (var item in DirectoriesInWorkLoad)
                {
                    PathHelper.RemoveFolderR(new DirectoryInfo(Path.Combine(RepoPath, ".extgit", RP, item)));
                }
            }
            Debugger.CurrentDebugger.Log($"Deal with: {directory.FullName}", Utilities.LogLevel.Development);
            Directory.SetLastAccessTime(Path.Combine(RepoPath, ".extgit", RP), directory.LastAccessTime);
            Directory.SetLastWriteTime(Path.Combine(RepoPath, ".extgit", RP), directory.LastWriteTime);
            foreach (var item in directory.EnumerateFiles())
            {
                if (FilesInWorkLoad.Contains(item.Name))
                {
                    FilesInWorkLoad.Remove(item.Name);
                }
                Debugger.CurrentDebugger.Log($"File: {item.FullName}", Utilities.LogLevel.Development);
                var FRP = PathHelper.GetRelativePath(RepoPath, item.FullName);
                var FAP = Path.Combine(RepoPath, ".extgit", FRP);
                Debugger.CurrentDebugger.Log($"File: RelatedPath:{FRP}", Utilities.LogLevel.Development);

                {
                    bool isTracked = false;
                    {
                        //Even it is existed.
                        foreach (var titem in TracedFiles)
                        {
                            if (titem.RelativeFilePath == FRP)
                            {
                                Debugger.CurrentDebugger.Log($"Traced File:{titem.RelativeFilePath}, Now relative file:{FRP}", Utilities.LogLevel.Development);
                                isTracked = true;
                                break;
                            }
                        }
                        if (isTracked == false)
                        {
                            //File is not tracked.
                            // Detect weather to trace;
                            if (AutoTrack)
                            {
                                if (item.Length > realDetectionLine)
                                {
                                    //Add to trace.
                                    TracedFiles.Add(TraceIndex.TrackAndRecord(item, this));
                                    isTracked = true;
                                    //TraceIndex.Track(item, this);
                                    continue;
                                }
                            }
                            foreach (var type in AutoTraceFileTypes)
                            {
                                if (item.FullName.ToUpper().EndsWith(type.ToUpper()))
                                {
                                    TracedFiles.Add(TraceIndex.TrackAndRecord(item, this));
                                    isTracked = true;
                                    break;
                                }
                            }
                            foreach (var path in AutoTraceFilePaths)
                            {
                                if (FRP.StartsWith(path))
                                {
                                    TracedFiles.Add(TraceIndex.TrackAndRecord(item, this));
                                    isTracked = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (File.Exists(FAP))
                    {
                        if (isTracked == false)
                        {
                            {
                                var NFHASH = SHA256Hash.ComputeSHA256(item.FullName);
                                var OFHASH = SHA256Hash.ComputeSHA256(FAP);
                                if (NFHASH == OFHASH)
                                {
                                    continue;
                                }
                                else
                                {
                                    item.CopyTo(FAP);
                                }
                            }
                        }
                        else
                        {
                            File.Delete(FAP);
                        }
                    }
                    else
                    {
                        if (isTracked == false)
                        {
                            item.CopyTo(FAP);
                        }
                        else
                        {
                        }
                    }
                }
            }
            {
                foreach (var item in FilesInWorkLoad)
                {
                    File.Delete(Path.Combine(RepoPath, ".extgit", RP, item));
                }
            }
        }