コード例 #1
0
 //Compresses a folder and returns the new path
 protected async Task <string> CompressFolderAsync(string path, string tempPath)
 {
     try
     {
         return(await Task.Run(() =>
         {
             FolderCompressor.Compress(Path.GetFullPath(path), Path.GetFullPath(tempPath));
             return tempPath;
         }, Token));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex);
     }
 }
コード例 #2
0
        /// <summary>
        /// Decompress the received file or folder
        /// <para>Returns the path of the folder or file.</para>
        /// </summary>
        /// <param name="path"></param>
        public string Decompress(string path)
        {
            FileInfo info = new FileInfo(path);

            if (info.Extension == FileCompressor.Extension)
            {
                FileInfo decompressedFile = FileCompressor.Decompress(info);
                File.Delete(info.FullName);
                return(decompressedFile.Name);
            }

            if (info.Extension == FolderCompressor.Extension)
            {
                DirectoryInfo extractedFolder = new DirectoryInfo(info.FullName.Remove(info.FullName.Length - info.Extension.Length));
                FolderCompressor.Extract(info.FullName, extractedFolder.FullName);
                File.Delete(info.FullName);
                return(extractedFolder.Name);
            }

            return(info.Name);
        }