Пример #1
0
        public static async Task <(bool success, string msg)> GenerateArchive(string inputPath, string outputPath)
        {
            if (!Directory.Exists(inputPath))
            {
                return(false, "Directory to be archived does not exist!");
            }

            var outputFilePath = Path.Combine(outputPath, PanoramaFilename);

            var archive = new PkZipArchive(PanComment);

            var pathSplitIndex = inputPath.LastIndexOf(@"\") + 1;

            RecDirSearch(inputPath);

            foreach (var file in Files)
            {
                archive.AddFile(new PkZipFile(file.Substring(pathSplitIndex), await File.ReadAllBytesAsync(file)));
            }

            var header = PanHeader.Concat(new byte[PanHeaderLength - PanHeader.Length]).ToArray();

            archive.GenerateArchive(header, PanTrailer, outputFilePath);

            return(true, "Archive generated successfully!");
        }
Пример #2
0
        public static async Task <(bool success, string msg)> ExtractArchive(string inputPath, string outputPath)
        {
            if (!File.Exists(inputPath))
            {
                return(false, "File could not be found!");
            }
            if (Directory.Exists(outputPath))
            {
                return(false, "Output directory exists already, extraction terminated!");
            }

            return(await PkZipArchive.ExtractFromArchive(inputPath, outputPath));
        }