Esempio n. 1
0
		void CompareItems(List<FileInfo> leftAct, List<FileInfo> leftLast, List<FileInfo> rightAct, List<FileInfo> rightLast, FileInfoCompareItem parentDir)
		{
			int indexOnLA, indexOnLL, indexOnRA, indexOnRL, count;
			FileInfoCompareItem fici;
			string[] fileSortString;
			string refString;

			indexOnLL = indexOnLA = indexOnRA = indexOnRL = 0;

			while ((leftAct != null && indexOnLA < leftAct.Count) || (leftLast != null && indexOnLL < leftLast.Count) ||
				   (rightAct != null && indexOnRA < rightAct.Count) || (rightLast != null && indexOnRL < rightLast.Count))
			{
				fici = new FileInfoCompareItem();
				fici.parentDir = parentDir;

				// What files are missing ?
				fici.fLAMissing = (leftAct == null || indexOnLA == leftAct.Count);
				fici.fLLMissing = (leftLast == null || indexOnLL == leftLast.Count);
				fici.fRAMissing = (rightAct == null || indexOnRA == rightAct.Count);
				fici.fRLMissing = (rightLast == null || indexOnRL == rightLast.Count);

				// We need the first file => ref string!
				fileSortString = new string[] { fici.fLAMissing ? "" : leftAct[indexOnLA].FileName, fici.fLLMissing ? "" : leftLast[indexOnLL].FileName,
                    fici.fRAMissing ? "" : rightAct[indexOnRA].FileName, fici.fRLMissing ? "" : rightLast[indexOnRL].FileName};
				Array.Sort(fileSortString);

				refString = "";
				for (count = 0; count < 4; count++)
				{
					if (fileSortString[count].Length > 0)
					{
						refString = fileSortString[count];
						break;
					}
				}

				// Add the infos !
				if (!fici.fLAMissing && string.Compare(refString, leftAct[indexOnLA].FileName, true) == 0)
					fici.fLeftAct = leftAct[indexOnLA++];
				else
					fici.fLAMissing = true;
				if (!fici.fLLMissing && string.Compare(refString, leftLast[indexOnLL].FileName, true) == 0)
					fici.fLeftLast = leftLast[indexOnLL++];
				else
					fici.fLLMissing = true;
				if (!fici.fRAMissing && string.Compare(refString, rightAct[indexOnRA].FileName, true) == 0)
					fici.fRightAct = rightAct[indexOnRA++];
				else
					fici.fRAMissing = true;
				if (!fici.fRLMissing && string.Compare(refString, rightLast[indexOnRL].FileName, true) == 0)
					fici.fRightLast = rightLast[indexOnRL++];
				else
					fici.fRLMissing = true;

				// Left is not existing but on right side
				if (fici.fLeftAct == null && fici.fRightAct != null)
				{
					fici.fDiffer = true;
					if (compareType == FileInfoCompareType.FullSync)
					{
						// was the file there at the last sync
						if (fici.fLeftLast != null)
						{
							// yes, so we must delete the right file; if it was not altered since last sync
							if (fici.fLeftLast.FileTimeWrite == fici.fRightAct.FileTimeWrite &&
								fici.fLeftLast.FileLength == fici.fRightAct.FileLength)
								fici.fRightDelete = true;
							else
								// Else copy the right one
								fici.fRightCopy = true;
						}
						else
							// no, just copy right
							fici.fRightCopy = true;
					}
					else
						// On Left-to-Right, if right is existing, delete !
						fici.fRightDelete = true;
				}
				// Right is not existing but on the left side
				else if (fici.fRightAct == null && fici.fLeftAct != null)
				{
					fici.fDiffer = true;
					if (compareType == FileInfoCompareType.FullSync)
					{
						// was the file there at the last sync
						if (fici.fRightLast != null)
						{
							// yes, so we must delete the left file; if it was not altered since last sync
							if (fici.fRightLast.FileTimeWrite == fici.fLeftAct.FileTimeWrite &&
								fici.fRightLast.FileLength == fici.fLeftAct.FileLength)
								fici.fLeftDelete = true;
							else
								// Else copy the left one
								fici.fLeftCopy = true;
						}
						else
							// no, just copy left
							fici.fLeftCopy = true;
					}
					else
						// On Left-To-Right, if right is not existing, copy left
						fici.fLeftCopy = true;
				}
				// Both files are existing
				else if (fici.fRightAct != null && fici.fLeftAct != null)
				{
					// Do the files differ ?
					if (fici.fLeftAct.FileTimeWrite != fici.fRightAct.FileTimeWrite ||
						fici.fLeftAct.FileLength != fici.fRightAct.FileLength)
					{
						bool leftChanged, rightChanged;

						fici.fDiffer = true;

						if (compareType == FileInfoCompareType.FullSync)
						{
							leftChanged = !(fici.fLeftLast != null &&
											fici.fLeftAct.FileTimeWrite == fici.fLeftLast.FileTimeWrite &&
											fici.fLeftAct.FileLength == fici.fLeftLast.FileLength);
							rightChanged = !(fici.fRightLast != null &&
											fici.fRightAct.FileTimeWrite == fici.fRightLast.FileTimeWrite &&
											fici.fRightAct.FileLength == fici.fRightLast.FileLength);
							// Left changed and right unchanged, copy the left one !
							if (leftChanged && !rightChanged)
								fici.fLeftCopy = true;
							// Right changed and left unchanged, copy the right one !
							else if (!leftChanged && rightChanged)
								fici.fRightCopy = true;
							// We have a conflict !
							else
								fici.fConflict = true;
						}
						else
							// On Left-To-Right, if differ copy the left
							fici.fLeftCopy = true;
					}
				}

				compareItems.Add(fici);
			};
		}
Esempio n. 2
0
        void CompareDirectoryWithSub(FileInfo fiLeftAct, FileInfo fiLeftLast, FileInfo fiRightAct, FileInfo fiRightLast, FileInfoCompareItem parentDir)
        {
            int lastRecFici = 0;

            CompareItems(fiLeftAct == null ? null : fiLeftAct.Files, fiLeftLast == null ? null : fiLeftLast.Files,
                         fiRightAct == null ? null : fiRightAct.Files, fiRightLast == null ? null : fiRightLast.Files, parentDir);
            CompareItems(fiLeftAct == null ? null : fiLeftAct.Directories, fiLeftLast == null ? null : fiLeftLast.Directories,
                         fiRightAct == null ? null : fiRightAct.Directories, fiRightLast == null ? null : fiRightLast.Directories, parentDir);

            while (compareItems.Count > lastRecFici)
            {
                if (compareItems[lastRecFici].IsDirectory)
                {
                    CompareItems(compareItems[lastRecFici].fLeftAct == null ? null : compareItems[lastRecFici].fLeftAct.Files,
                                 compareItems[lastRecFici].fLeftLast == null ? null : compareItems[lastRecFici].fLeftLast.Files,
                                 compareItems[lastRecFici].fRightAct == null ? null : compareItems[lastRecFici].fRightAct.Files,
                                 compareItems[lastRecFici].fRightLast == null ? null : compareItems[lastRecFici].fRightLast.Files, parentDir);
                    CompareItems(compareItems[lastRecFici].fLeftAct == null ? null : compareItems[lastRecFici].fLeftAct.Directories,
                                 compareItems[lastRecFici].fLeftLast == null ? null : compareItems[lastRecFici].fLeftLast.Directories,
                                 compareItems[lastRecFici].fRightAct == null ? null : compareItems[lastRecFici].fRightAct.Directories,
                                 compareItems[lastRecFici].fRightLast == null ? null : compareItems[lastRecFici].fRightLast.Directories, parentDir);
                }
                lastRecFici++;
            }
        }
Esempio n. 3
0
		void CompareDirectoryWithSub(FileInfo fiLeftAct, FileInfo fiLeftLast, FileInfo fiRightAct, FileInfo fiRightLast, FileInfoCompareItem parentDir)
		{
			int		lastRecFici = 0;

			CompareItems(fiLeftAct == null ? null : fiLeftAct.Files, fiLeftLast == null ? null : fiLeftLast.Files,
				fiRightAct == null ? null : fiRightAct.Files, fiRightLast == null ? null : fiRightLast.Files, parentDir);
			CompareItems(fiLeftAct == null ? null : fiLeftAct.Directories, fiLeftLast == null ? null : fiLeftLast.Directories,
				fiRightAct == null ? null : fiRightAct.Directories, fiRightLast == null ? null : fiRightLast.Directories, parentDir);

			while (compareItems.Count > lastRecFici)
			{
				if (compareItems[lastRecFici].IsDirectory)
				{
					CompareItems(compareItems[lastRecFici].fLeftAct == null ? null : compareItems[lastRecFici].fLeftAct.Files, 
						compareItems[lastRecFici].fLeftLast == null ? null : compareItems[lastRecFici].fLeftLast.Files,
						compareItems[lastRecFici].fRightAct == null ? null : compareItems[lastRecFici].fRightAct.Files, 
						compareItems[lastRecFici].fRightLast == null ? null : compareItems[lastRecFici].fRightLast.Files, parentDir);
					CompareItems(compareItems[lastRecFici].fLeftAct == null ? null : compareItems[lastRecFici].fLeftAct.Directories, 
						compareItems[lastRecFici].fLeftLast == null ? null : compareItems[lastRecFici].fLeftLast.Directories,
						compareItems[lastRecFici].fRightAct == null ? null : compareItems[lastRecFici].fRightAct.Directories, 
						compareItems[lastRecFici].fRightLast == null ? null : compareItems[lastRecFici].fRightLast.Directories, parentDir);
				}
				lastRecFici++;
			}
		}
Esempio n. 4
0
        void CompareItems(List <FileInfo> leftAct, List <FileInfo> leftLast, List <FileInfo> rightAct, List <FileInfo> rightLast, FileInfoCompareItem parentDir)
        {
            int indexOnLA, indexOnLL, indexOnRA, indexOnRL, count;
            FileInfoCompareItem fici;

            string[] fileSortString;
            string   refString;

            indexOnLL = indexOnLA = indexOnRA = indexOnRL = 0;

            while ((leftAct != null && indexOnLA < leftAct.Count) || (leftLast != null && indexOnLL < leftLast.Count) ||
                   (rightAct != null && indexOnRA < rightAct.Count) || (rightLast != null && indexOnRL < rightLast.Count))
            {
                fici           = new FileInfoCompareItem();
                fici.parentDir = parentDir;

                // What files are missing ?
                fici.fLAMissing = (leftAct == null || indexOnLA == leftAct.Count);
                fici.fLLMissing = (leftLast == null || indexOnLL == leftLast.Count);
                fici.fRAMissing = (rightAct == null || indexOnRA == rightAct.Count);
                fici.fRLMissing = (rightLast == null || indexOnRL == rightLast.Count);

                // We need the first file => ref string!
                fileSortString = new string[] { fici.fLAMissing ? "" : leftAct[indexOnLA].FileName, fici.fLLMissing ? "" : leftLast[indexOnLL].FileName,
                                                                       fici.fRAMissing ? "" : rightAct[indexOnRA].FileName, fici.fRLMissing ? "" : rightLast[indexOnRL].FileName };
                Array.Sort(fileSortString);

                refString = "";
                for (count = 0; count < 4; count++)
                {
                    if (fileSortString[count].Length > 0)
                    {
                        refString = fileSortString[count];
                        break;
                    }
                }

                // Add the infos !
                if (!fici.fLAMissing && string.Compare(refString, leftAct[indexOnLA].FileName, true) == 0)
                {
                    fici.fLeftAct = leftAct[indexOnLA++];
                }
                else
                {
                    fici.fLAMissing = true;
                }
                if (!fici.fLLMissing && string.Compare(refString, leftLast[indexOnLL].FileName, true) == 0)
                {
                    fici.fLeftLast = leftLast[indexOnLL++];
                }
                else
                {
                    fici.fLLMissing = true;
                }
                if (!fici.fRAMissing && string.Compare(refString, rightAct[indexOnRA].FileName, true) == 0)
                {
                    fici.fRightAct = rightAct[indexOnRA++];
                }
                else
                {
                    fici.fRAMissing = true;
                }
                if (!fici.fRLMissing && string.Compare(refString, rightLast[indexOnRL].FileName, true) == 0)
                {
                    fici.fRightLast = rightLast[indexOnRL++];
                }
                else
                {
                    fici.fRLMissing = true;
                }

                // Left is not existing but on right side
                if (fici.fLeftAct == null && fici.fRightAct != null)
                {
                    fici.fDiffer = true;
                    if (compareType == FileInfoCompareType.FullSync)
                    {
                        // was the file there at the last sync
                        if (fici.fLeftLast != null)
                        {
                            // yes, so we must delete the right file; if it was not altered since last sync
                            if (fici.fLeftLast.FileTimeWrite == fici.fRightAct.FileTimeWrite &&
                                fici.fLeftLast.FileLength == fici.fRightAct.FileLength)
                            {
                                fici.fRightDelete = true;
                            }
                            else
                            {
                                // Else copy the right one
                                fici.fRightCopy = true;
                            }
                        }
                        else
                        {
                            // no, just copy right
                            fici.fRightCopy = true;
                        }
                    }
                    else
                    {
                        // On Left-to-Right, if right is existing, delete !
                        fici.fRightDelete = true;
                    }
                }
                // Right is not existing but on the left side
                else if (fici.fRightAct == null && fici.fLeftAct != null)
                {
                    fici.fDiffer = true;
                    if (compareType == FileInfoCompareType.FullSync)
                    {
                        // was the file there at the last sync
                        if (fici.fRightLast != null)
                        {
                            // yes, so we must delete the left file; if it was not altered since last sync
                            if (fici.fRightLast.FileTimeWrite == fici.fLeftAct.FileTimeWrite &&
                                fici.fRightLast.FileLength == fici.fLeftAct.FileLength)
                            {
                                fici.fLeftDelete = true;
                            }
                            else
                            {
                                // Else copy the left one
                                fici.fLeftCopy = true;
                            }
                        }
                        else
                        {
                            // no, just copy left
                            fici.fLeftCopy = true;
                        }
                    }
                    else
                    {
                        // On Left-To-Right, if right is not existing, copy left
                        fici.fLeftCopy = true;
                    }
                }
                // Both files are existing
                else if (fici.fRightAct != null && fici.fLeftAct != null)
                {
                    // Do the files differ ?
                    if (fici.fLeftAct.FileTimeWrite != fici.fRightAct.FileTimeWrite ||
                        fici.fLeftAct.FileLength != fici.fRightAct.FileLength)
                    {
                        bool leftChanged, rightChanged;

                        fici.fDiffer = true;

                        if (compareType == FileInfoCompareType.FullSync)
                        {
                            leftChanged = !(fici.fLeftLast != null &&
                                            fici.fLeftAct.FileTimeWrite == fici.fLeftLast.FileTimeWrite &&
                                            fici.fLeftAct.FileLength == fici.fLeftLast.FileLength);
                            rightChanged = !(fici.fRightLast != null &&
                                             fici.fRightAct.FileTimeWrite == fici.fRightLast.FileTimeWrite &&
                                             fici.fRightAct.FileLength == fici.fRightLast.FileLength);
                            // Left changed and right unchanged, copy the left one !
                            if (leftChanged && !rightChanged)
                            {
                                fici.fLeftCopy = true;
                            }
                            // Right changed and left unchanged, copy the right one !
                            else if (!leftChanged && rightChanged)
                            {
                                fici.fRightCopy = true;
                            }
                            // We have a conflict !
                            else
                            {
                                fici.fConflict = true;
                            }
                        }
                        else
                        {
                            // On Left-To-Right, if differ copy the left
                            fici.fLeftCopy = true;
                        }
                    }
                }

                compareItems.Add(fici);
            }
            ;
        }