Exemplo n.º 1
0
        /// <summary>
        /// Function that forms a SyncData list that represents the list of conflict statements which says if the file does exist in any of the directories or
        /// if its old or if its up to date.
        /// </summary>
        /// <param name="SourceData">The directory being synchronized.</param>
        /// <param name="TargetData">The comparing directory to be synchronized with.</param>
        /// <returns>SyncData list that represents the list of conflict statements which says if the file does exist in any of the directories or
        /// if its old or if its up to date.</returns>
        public static List <SyncData> FormConflictFileDataList(DirectoryData SourceData, DirectoryData TargetData)
        {
            List <SyncData> result = new List <SyncData>();

            foreach (var item in SourceData.Files)
            {
                if (TargetData.CheckFileExistanceByRelativePath(item.RelativePath))
                {
                    if (item.Hash == TargetData.FindFileGetFileHash(item.RelativePath))
                    {
                        continue;
                    }

                    SyncConflictState currentItemSCS = CompareFileDateTimeToState(item, TargetData.FindFileGetFileData(item.RelativePath));
                    currentItemSCS |= CompareFileSizesToState(item, TargetData.FindFileGetFileData(item.RelativePath));

                    if (currentItemSCS != SyncConflictState.UpToDate)
                    {
                        result.Add(new SyncData(item, currentItemSCS));
                    }
                }
                else
                {
                    result.Add(new SyncData(item, SyncConflictState.DoesntExistInTarget));
                }
            }

            List <FileData> FilesNonExistantInSource = TargetData.Files.FindAll(x => SourceData.Files.FindIndex(y => y.RelativePath == x.RelativePath) == -1);

            for (int i = 0; i < FilesNonExistantInSource.Count; i++)
            {
                result.Add(new SyncData(FilesNonExistantInSource[i], SyncConflictState.DoesntExistInSource));
            }

            return(result);
        }