FAES/Packaging/Compressors/LZMA.cs
/// <summary>
/// Compress (LZMA) an unencrypted FAES File.
/// </summary>
/// <param name="unencryptedFile">Unencrypted FAES File</param>
/// <param name="percentComplete">Percent complete for compression</param>
/// <returns>Path of the unencrypted, LZMA compressed file</returns>
Compress (LZMA) an unencrypted FAES File.
Compress ( LZMA ) an unencrypted FAES File .
public string CompressFAESFile(FAES_File unencryptedFile, ref decimal percentComplete)
        {
            FileAES_IntUtilities.CreateEncryptionFilePath(unencryptedFile, "LZMA", out string tempRawPath, out _, out string tempOutputPath);
            WriterOptions wo = new WriterOptions(CompressionType.LZMA);
            using (Stream stream = File.OpenWrite(tempOutputPath))
            using (var writer = WriterFactory.Open(stream, ArchiveType.Zip, wo))
            {
                List<string> filesList = Directory.EnumerateFiles(tempRawPath, "*", SearchOption.AllDirectories).ToList();
                int maxFiles = filesList.Count;
                for (int i = 0; i < filesList.Count; i++)
                {
                    string file = filesList[i];
                    string archivePath = file.Replace(tempRawPath, "");
                    writer.Write(archivePath, file);
                    try
                    {
                        percentComplete = Math.Ceiling((decimal)((Convert.ToDouble(i + 1) / Convert.ToDouble(maxFiles)) * 100));
                        if (percentComplete > 100) percentComplete = 100;
                    }
                    catch (Exception)
                    {
                        percentComplete = 100;
                    }
                }
                percentComplete = 100;
            }
            return tempOutputPath;
        }
public string CompressFAESFile ( FAES_File unencryptedFile , ref decimal percentComplete ) { FileAES_IntUtilities . CreateEncryptionFilePath ( unencryptedFile , " " , out string tempRawPath , out _ , out string tempOutputPath ) ; WriterOptions wo = new WriterOptions ( CompressionType . LZMA ) ; using ( Stream stream = File . OpenWrite ( tempOutputPath ) ) using ( var writer = WriterFactory . Open ( stream , ArchiveType . Zip , wo ) ) { List < string > filesList = Directory . EnumerateFiles ( tempRawPath , " " , SearchOption . AllDirectories ) . ToList ( ) ; int maxFiles = filesList . Count ; for ( int i = 0 ; i < filesList . Count ; i ++ ) { string file = filesList [ i ] ; string archivePath = file . Replace ( tempRawPath , " " ) ; writer . Write ( archivePath , file ) ; try { percentComplete = Math . Ceiling ( ( decimal ) ( ( Convert . ToDouble ( i + 1 ) / Convert . ToDouble ( maxFiles ) ) * 100 ) ) ; if ( percentComplete > 100 ) percentComplete = 100 ; } catch ( Exception ) { percentComplete = 100 ; } } percentComplete = 100 ; } return tempOutputPath ; }
Compress (LZMA) an unencrypted FAES File.
Compress ( LZMA ) an unencrypted FAES File .
Path of the unencrypted, LZMA compressed file
Path of the unencrypted LZMA compressed file
unencryptedFile
FAES_File
Unencrypted FAES File
Unencrypted FAES File
decimal
ref
percentComplete
Percent complete for compression
Percent complete for compression