private void CompareAndSync(string relativeSrcFilePath, string relativeDestFilePath) { var isDifferentFile = !_fileComparer.GetIsEqualFile(_srcFileSystem, _destFileSystem, relativeSrcFilePath, relativeDestFilePath); if (isDifferentFile) { _fileMerger.Merge(_srcFileSystem, _destFileSystem, relativeSrcFilePath, relativeDestFilePath); } }
string MergeFileName(Header[] headers, IFileMerger merger, byte numberOfPart, long totalLength) { var ReadStreams = new MemoryStream[numberOfPart]; for (byte i = 0; i < numberOfPart; i++) ReadStreams[i] = new MemoryStream(headers[i].FileName); var WriteStream = new MemoryStream(); merger.Merge(WriteStream, ReadStreams, 0, numberOfPart, totalLength); WriteStream.Position = 0; byte[] buffer = new byte[WriteStream.Length]; int lng = WriteStream.Read(buffer, 0, buffer.Length); var filenameBytes = new byte[lng]; Array.Copy(buffer, 0, filenameBytes, 0, lng); return Encoding.Default.GetString(filenameBytes); }
public void Parse() { var inputFiles = ParseInputLines(); if (!CheckForMissingInputFiles(inputFiles)) { return; } var outputFile = this.txtOutputFile.Text; if (!CheckForExistingOutputFile(outputFile)) { return; } try { _merger.Merge(inputFiles, outputFile); } catch (Exception ex) { Debug.WriteLine(ex.Message); MessageBox.Show( $"Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // LOCAL HELPER FUNCTIONS // Return true to continue bool CheckForMissingInputFiles(IEnumerable <InputFile> files) { var dneInputs = files.Where(f => !File.Exists(f.Path)); var prompt = "Proceed even though the following files don't exist? \r\n"; var dneInputLabel = string.Join("\r\n", dneInputs); return(!dneInputs.Any() || FileExtensions.ConfirmAction($"{prompt}{dneInputLabel}")); } // Return true to continue bool CheckForExistingOutputFile(string outputPath) { var fi = new FileInfo(outputPath); if (fi.Exists) { var confirmMsg = $"{outputPath} already exists, do you want to overwrite it?"; if (!FileExtensions.ConfirmAction(confirmMsg)) { return(false); } if (!fi.SafeDelete()) { MessageBox.Show("Couldn't delete file, cancelling merge."); return(false); } } return(true); } }