public SyncLogEntry CreateNewLogEntryFromEncrPath(string encrFileName) { string encrFilePath = Path.Combine(EncrDirectory.FullName, encrFileName); FSEntry encrEntry = EncrDirectory.TryGetEntry(encrFileName); FileEntry header = HelixFile.DecryptHeader(encrFilePath, DerivedBytesProvider); var decrFileName = header.FileName; if (encrFileName != FileNameEncoder.EncodeName(decrFileName)) { throw new HelixException("Encrypted file name does not match"); //todo: prompt for action } return(new SyncLogEntry(header.EntryType, header.FileName, header.LastWriteTimeUtc, encrEntry.RelativePath, encrEntry.LastWriteTimeUtc)); }
/// <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"); }