Exemple #1
0
        private bool VerifyFile(FileShim actual, SyncableFileBase expctd)
        {
            var s = "Downloaded files is corrupted.";

            if (actual.Name != expctd.Name)
                return Error_n(s, $"expected name: {expctd.Name}  ==>  actual: {actual.Name}");

            if (actual.Size != expctd.Size)
                return Error_n(s, $"expected size: {expctd.Size.KB()}  ==>  actual: {actual.Size.KB()}");

            if (actual.SHA1 != expctd.SHA1)
                return Error_n(s, $"expected hash: {expctd.SHA1}  ==>  actual: {actual.SHA1}");

            return true;
        }
Exemple #2
0
        private FileDiff GetComparison(SyncableFileBase remoteFile,
                                       SyncableFileBase localFile,
                                       SyncDirection syncDirection)
        {
            if (localFile == null && remoteFile == null)
            {
                DoNext(Target.Both, FileTask.Analyze);
                return FileDiff.Unavailable;
            }

            if (localFile == null)
            {
                if (syncDirection == SyncDirection.Upload)
                    DoNext(Target.Remote, FileTask.Delete);

                else if (syncDirection == SyncDirection.Download)
                    DoNext(Target.Local, FileTask.Create);

                return FileDiff.NotInLocal;
            }

            if (remoteFile == null)
            {
                if (syncDirection == SyncDirection.Upload)
                    DoNext(Target.Remote, FileTask.Create);

                else if (syncDirection == SyncDirection.Download)
                    DoNext(Target.Local, FileTask.Ignore);

                return FileDiff.NotInRemote;
            }

            if (remoteFile.Size != localFile.Size)
            {
                OddProperty = nameof(localFile.Size);
                PropertyDiffs = $"↑ {remoteFile.Size.KB()}{L.f}↓ {localFile.Size.KB()}";

                if (syncDirection == SyncDirection.Upload)
                    DoNext(Target.Remote, FileTask.Replace);

                else if (syncDirection == SyncDirection.Download)
                    DoNext(Target.Local, FileTask.Replace);

                return FileDiff.Changed;
            }

            if (remoteFile.Version != localFile.Version)
            {
                OddProperty = nameof(localFile.Version);
                PropertyDiffs = $"↑ “{remoteFile.Version}”{L.f}↓ “{localFile.Version}”";

                if (syncDirection == SyncDirection.Upload)
                    DoNext(Target.Remote, FileTask.Replace);

                else if (syncDirection == SyncDirection.Download)
                    DoNext(Target.Local, FileTask.Replace);

                return FileDiff.Changed;
            }

            if (remoteFile.SHA1 != localFile.SHA1)
            {
                OddProperty = nameof(localFile.SHA1);
                PropertyDiffs = $"↑ {remoteFile.SHA1}{L.f}↓ {localFile.SHA1}";

                if (syncDirection == SyncDirection.Upload)
                    DoNext(Target.Remote, FileTask.Replace);

                else if (syncDirection == SyncDirection.Download)
                    DoNext(Target.Local, FileTask.Replace);

                return FileDiff.Changed;
            }

            DoNext(Target.Both, FileTask.Ignore);
            return FileDiff.Same;
        }
Exemple #3
0
        private FileDiff GetComparison(SyncableFileBase remoteFile,
                                       SyncableFileBase localFile,
                                       SyncDirection syncDirection)
        {
            if (localFile == null && remoteFile == null)
            {
                DoNext(Target.Both, FileTask.Analyze);
                return(FileDiff.Unavailable);
            }

            if (localFile == null)
            {
                if (syncDirection == SyncDirection.Upload)
                {
                    DoNext(Target.Remote, FileTask.Delete);
                }

                else if (syncDirection == SyncDirection.Download)
                {
                    DoNext(Target.Local, FileTask.Create);
                }

                return(FileDiff.NotInLocal);
            }

            if (remoteFile == null)
            {
                if (syncDirection == SyncDirection.Upload)
                {
                    DoNext(Target.Remote, FileTask.Create);
                }

                else if (syncDirection == SyncDirection.Download)
                {
                    DoNext(Target.Local, FileTask.Ignore);
                }

                return(FileDiff.NotInRemote);
            }

            if (remoteFile.Size != localFile.Size)
            {
                OddProperty   = nameof(localFile.Size);
                PropertyDiffs = $"↑ {remoteFile.Size.KB()}{L.f}↓ {localFile.Size.KB()}";

                if (syncDirection == SyncDirection.Upload)
                {
                    DoNext(Target.Remote, FileTask.Replace);
                }

                else if (syncDirection == SyncDirection.Download)
                {
                    DoNext(Target.Local, FileTask.Replace);
                }

                return(FileDiff.Changed);
            }

            if (remoteFile.Version != localFile.Version)
            {
                OddProperty   = nameof(localFile.Version);
                PropertyDiffs = $"↑ “{remoteFile.Version}”{L.f}↓ “{localFile.Version}”";

                if (syncDirection == SyncDirection.Upload)
                {
                    DoNext(Target.Remote, FileTask.Replace);
                }

                else if (syncDirection == SyncDirection.Download)
                {
                    DoNext(Target.Local, FileTask.Replace);
                }

                return(FileDiff.Changed);
            }

            if (remoteFile.SHA1 != localFile.SHA1)
            {
                OddProperty   = nameof(localFile.SHA1);
                PropertyDiffs = $"↑ {remoteFile.SHA1}{L.f}↓ {localFile.SHA1}";

                if (syncDirection == SyncDirection.Upload)
                {
                    DoNext(Target.Remote, FileTask.Replace);
                }

                else if (syncDirection == SyncDirection.Download)
                {
                    DoNext(Target.Local, FileTask.Replace);
                }

                return(FileDiff.Changed);
            }

            DoNext(Target.Both, FileTask.Ignore);
            return(FileDiff.Same);
        }