コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: EvgeniyZ/GZipConsoleApp
        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);
            }
        }
コード例 #3
0
        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);
                }
            }
        }
コード例 #4
0
 public ZipFactory(ZipSettings settings)
 {
     _settings = settings ?? throw new ArgumentNullException(nameof(settings));
 }
コード例 #5
0
ファイル: Zip.cs プロジェクト: kuritka/FileOps
 public Zip(ZipSettings settings)
 {
     _settings = settings;
 }