public (bool isValid, string errorMessage) Validate(string sourceFilename, string destinationFilename) { if (string.IsNullOrEmpty(sourceFilename)) { return(false, ConstructEmptyFilenameMessage(Source)); } if (string.IsNullOrEmpty(destinationFilename)) { return(false, ConstructEmptyFilenameMessage(Destination)); } var sourceFileInfo = new FileInfo(sourceFilename); var destinationFileInfo = new FileInfo(ZipSettings.GetFilenameWithZipExtension(destinationFilename)); if (sourceFileInfo == destinationFileInfo) { return(false, $"{Source} and {Destination} should not be the same"); } if (!sourceFileInfo.Exists) { return(false, $"{Source} file name does not exists, please check ${Source} file name"); } if (destinationFileInfo.Exists) { return(false, $"{ZipSettings.GetFilenameWithZipExtension(destinationFilename)} already exists"); } return(true, string.Empty); }
private static void DeleteFileOnAbortion(string destinationFilename) { var filenameWithZipExtension = ZipSettings.GetFilenameWithZipExtension(destinationFilename); Console.WriteLine($"Operation was canceled - deleting {filenameWithZipExtension}."); try { System.IO.File.Delete(filenameWithZipExtension); Console.WriteLine($"{filenameWithZipExtension} is deleted."); } catch (Exception exception) { Console.WriteLine( $"Failed deleting {filenameWithZipExtension} due to an exception below. Please contact a developer and send him the exception."); Console.WriteLine(exception); } }
private void Write(ByteBlock byteBlock) { CancellationToken.ThrowIfCancellationRequested(); using (var fileCompressed = new FileStream(ZipSettings.GetFilenameWithZipExtension(DestinationFilename), FileMode.Append)) { try { var idAsByteArray = BitConverter.GetBytes(byteBlock.Id); fileCompressed.Write(idAsByteArray, 0, idAsByteArray.Length); var dataLengthAsByteArray = BitConverter.GetBytes(byteBlock.Data.Length); fileCompressed.Write(dataLengthAsByteArray, 0, dataLengthAsByteArray.Length); var compressedLengthAsByteArray = BitConverter.GetBytes(byteBlock.CompressedData.Length); fileCompressed.Write(compressedLengthAsByteArray, 0, compressedLengthAsByteArray.Length); fileCompressed.Write(byteBlock.CompressedData, 0, byteBlock.CompressedData.Length); } catch (Exception e) { OnException(Command, e); } } }
public ZipFactory(ZipSettings settings) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); }
public Zip(ZipSettings settings) { _settings = settings; }