示例#1
0
    static bool CompressFile(string iFileName, string iDest, BinaryWriter writer)
    {
        int int32 = Convert.ToInt32(new FileInfo(iFileName).Length);

        Zlib.FileHeader fileHeader = default(Zlib.FileHeader);
        fileHeader.FileName         = iDest;
        fileHeader.DecompressedSize = int32;
        fileHeader.CompressedSize   = 0;
        FileStream   fileStream;
        BinaryReader binaryReader;
        bool         flag;

        try
        {
            fileStream   = new FileStream(iFileName, FileMode.Open);
            binaryReader = new BinaryReader(fileStream);
        }
        catch (Exception ex)
        {
            MessageBox.Show("An error occurred while compressing: " + ex.Message, "Buh?");
            flag = false;
            return(flag);
        }
        try
        {
            byte[] iBytes = binaryReader.ReadBytes(int32);
            byte[] buffer = Zlib.CompressChunk(ref iBytes);
            fileHeader.CompressedSize = buffer.Length;
            if (fileHeader.CompressedSize < 1)
            {
                throw new Exception("Compressed data was 0 bytes long!");
            }
            writer.Write(fileHeader.FileName);
            writer.Write(fileHeader.DecompressedSize);
            writer.Write(fileHeader.CompressedSize);
            writer.Write(buffer);
            binaryReader.Close();
            fileStream.Close();
            flag = true;
        }
        catch (Exception ex2)
        {
            MessageBox.Show("An error occurred during compression: " + ex2.Message, "Buh?");
            binaryReader.Close();
            fileStream.Close();
            flag = false;
        }
        return(flag);
    }
    static string MxDBuildSaveStringShared(ref MidsCharacterFileFormat.CompressionData cData, bool inncludeAltEnh, bool @break)
    {
        byte[] numArray = new byte[0];
        string str;

        if (!MidsCharacterFileFormat.MxDBuildSaveBuffer(ref numArray, inncludeAltEnh))
        {
            str = string.Empty;
        }
        else
        {
            ASCIIEncoding asciiEncoding = new ASCIIEncoding();
            cData.SzUncompressed = numArray.Length;
            byte[] bytes = Zlib.CompressChunk(ref numArray);
            cData.SzCompressed = bytes.Length;
            bytes           = Zlib.HexEncodeBytes(bytes);
            cData.SzEncoded = bytes.Length;
            str             = (@break ? Zlib.BreakString(asciiEncoding.GetString(bytes), 67, true) : asciiEncoding.GetString(bytes));
        }
        return(str);
    }
    static string MxDBuildSaveStringShared(
        ref CompressionData cData,
        bool includeAltEnh,
        bool @break)
    {
        byte[] numArray = Array.Empty <byte>();
        string str;

        if (!MxDBuildSaveBuffer(ref numArray, includeAltEnh))
        {
            str = string.Empty;
        }
        else
        {
            var asciiEncoding = new ASCIIEncoding();
            cData.SzUncompressed = numArray.Length;
            byte[] iBytes = Zlib.CompressChunk(ref numArray);
            cData.SzCompressed = iBytes.Length;
            byte[] bytes = Zlib.HexEncodeBytes(iBytes);
            cData.SzEncoded = bytes.Length;
            str             = @break ? Zlib.BreakString(asciiEncoding.GetString(bytes), 67, true) : asciiEncoding.GetString(bytes);
        }
        return(str);
    }