//压缩文件
    public static void CompressFileLZMA(string inFile, string outFile, Action callBack)
    {
        Encoder coder = new SevenZip.Compression.LZMA.Encoder();

        DGFileUtil.CreateDirectoryWhenNotExists(outFile);

        FileStream input  = new FileStream(inFile, FileMode.Open);
        FileStream output = new FileStream(outFile, FileMode.Create);

        // Write the encoder properties
        coder.WriteCoderProperties(output);

        // Write the decompressed file size.
        output.Write(BitConverter.GetBytes(input.Length), 0, 8);

        // Encode the file.
        coder.Code(input, output, input.Length, -1, null);
        output.Flush();
        output.Close();
        input.Close();
        output.Dispose();
        input.Dispose();

        if (callBack != null)
        {
            callBack();
        }
    }
    //解压缩文件
    public static void DecompressFileLZMA(byte[] inFile, string outFile, Action callBack)
    {
        DGFileUtil.CreateDirectoryWhenNotExists(outFile);

        SevenZip.Compression.LZMA.Decoder coder = new SevenZip.Compression.LZMA.Decoder();
        MemoryStream input  = new MemoryStream(inFile);
        FileStream   output = new FileStream(outFile, FileMode.Create);

        // Read the decoder properties
        byte[] properties = new byte[5];
        input.Read(properties, 0, 5);

        // Read in the decompress file size.
        byte [] fileLengthBytes = new byte[8];
        input.Read(fileLengthBytes, 0, 8);
        long fileLength = BitConverter.ToInt64(fileLengthBytes, 0);

        // Decompress the file.
        coder.SetDecoderProperties(properties);
        coder.Code(input, output, input.Length, fileLength, null);
        output.Flush();
        output.Close();
        input.Close();
        output.Dispose();
        input.Dispose();
        if (callBack != null)
        {
            callBack();
        }
    }
Beispiel #3
0
    public static void CopyFileOrDirectory(string source, string destination, string except = null)
    {
        List <string> list = DGFileUtil.GetAllFiles(new DirectoryInfo(source), except);

        for (int i = 0; i < list.Count; i++)
        {
            string path     = list[i];
            string destPath = destination + path.Substring(source.Length);
            DGFileUtil.CopyFile(path, destPath);
        }
    }