コード例 #1
0
        /// <summary>
        /// Loads the EncrHeaders for new and updated encripted files
        /// </summary>
        private void FindChanges_St05_RefreshEncrHeaders(ConsoleEx console, List <ChangeBuilder> matchesA)
        {
            int statsRefreshHeaderCount = 0;

            foreach (ChangeBuilder preSyncDetails in matchesA.Where(m => m.EncrInfo != null && m.EncrInfo.LastWriteTimeUtc != m.LogEntry?.EncrModified))
            {
                string encrFullPath = Path.Combine(EncrDirectory.FullName, HelixUtil.PathNative(preSyncDetails.EncrFileName));
                if (File.Exists(encrFullPath))
                {
                    preSyncDetails.EncrHeader = HelixFile.DecryptHeader(encrFullPath, this.DerivedBytesProvider);

                    //Updates the DecrFileName (if necessary)
                    if (string.IsNullOrEmpty(preSyncDetails.DecrFileName) &&
                        FileNameEncoder.EncodeName(preSyncDetails.EncrHeader.FileName) == preSyncDetails.EncrInfo.RelativePath)
                    {
                        preSyncDetails.DecrFileName = preSyncDetails.EncrHeader.FileName;
                    }
                }

                statsRefreshHeaderCount++;
            }
            console?.WriteLine(VerbosityLevel.Diagnostic, 2, $"Updated {statsRefreshHeaderCount} headers");
        }
コード例 #2
0
        /// <summary>
        /// Matches files from Encr, Decr and Log Entry
        /// </summary>
        private List <ChangeBuilder> FindChanges_St04_ThreeWayJoin(List <FSEntry> encrDirectoryFiles, List <FSEntry> decrDirectoryFiles, SyncLog syncLog, ConsoleEx console)
        {
            List <ChangeBuilder> preSyncDetails = new List <ChangeBuilder>();

            //Adds Logs
            console?.WriteLine(VerbosityLevel.Diagnostic, 2, "Merging in log...");
            preSyncDetails.AddRange(syncLog.Select(entry => new ChangeBuilder {
                LogEntry = entry
            }));
            console?.WriteLine(VerbosityLevel.Diagnostic, 3, $"{preSyncDetails.Count} added");

            //Updates/Adds Decrypted File Information
            console?.WriteLine(VerbosityLevel.Diagnostic, 2, "Merging in decrypted information...");
            int decrStatAdd   = 0;
            int decrStatMerge = 0;
            var decrJoin      = decrDirectoryFiles
                                .GroupJoin(preSyncDetails,
                                           o => o.RelativePath,
                                           i => i?.LogEntry?.DecrFileName,
                                           (o, i) => new Tuple <FSEntry, ChangeBuilder>(o, i.FirstOrDefault()));

            foreach (var entry in decrJoin.ToList())
            {
                if (entry.Item2 == null)
                {
                    //New Entry (not in log)
                    preSyncDetails.Add(new ChangeBuilder {
                        DecrInfo = entry.Item1
                    });
                    decrStatAdd++;
                }
                else
                {
                    //Existing Entry (update only)
                    entry.Item2.DecrInfo = entry.Item1;
                    if (entry.Item1 != null)
                    {
                        decrStatMerge++;
                    }
                }
            }
            console?.WriteLine(VerbosityLevel.Diagnostic, 3, $"{decrStatAdd} added, {decrStatMerge} merged");

            //find encrypted file names
            foreach (var entry in preSyncDetails)
            {
                entry.DecrFileName = entry.LogEntry?.DecrFileName ?? entry.DecrInfo.RelativePath;
                entry.EncrFileName = FileNameEncoder.EncodeName(entry.DecrFileName);
            }


            //Updates/adds encrypted File Information
            console?.WriteLine(VerbosityLevel.Diagnostic, 2, "Merging in encrypted information...");
            int encrStatAdd   = 0;
            int encrStatMerge = 0;
            var encrJoin      = encrDirectoryFiles
                                .GroupJoin(preSyncDetails,
                                           o => o.RelativePath,
                                           i => i.EncrFileName,
                                           (o, i) => new Tuple <FSEntry, ChangeBuilder>(o, i.FirstOrDefault()));

            foreach (var entry in encrJoin.ToList())
            {
                if (entry.Item2 == null)
                {
                    //New Entry (not in log or decrypted file)
                    preSyncDetails.Add(new ChangeBuilder {
                        EncrInfo = entry.Item1, EncrFileName = entry.Item1.RelativePath
                    });
                    encrStatAdd++;
                }
                else
                {
                    //Existing Entry
                    entry.Item2.EncrInfo = entry.Item1;
                    if (entry.Item1 != null)
                    {
                        encrStatMerge++;
                    }
                }
            }
            console?.WriteLine(VerbosityLevel.Diagnostic, 3, $"{encrStatAdd} added, {encrStatMerge} merged");

            return(preSyncDetails);
        }