少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.IO;
using System.Threading;
using UnityEngine;
 
namespace Xdxn {
 
    public delegate void ProgressDelegate(Int64 fileSize, Int64 processSize);
    public class FileCompressInfo {
        public string inPath;
        public string outPath;
        public ProgressDelegate progressDelegate;
    }
 
    public class CompressUtility {
 
        public class CodeProgress : SevenZipEx.ICodeProgress {
 
            private ProgressDelegate progressDelegate;
 
            public CodeProgress(ProgressDelegate callBack) {
                progressDelegate = callBack;
            }
 
            public void SetProgress(Int64 inSize, Int64 outSize) {
                if (progressDelegate != null) {
                    progressDelegate(inSize, outSize);
                }
            }
        }
 
        public static void Compress(string inPath, string outPath, ProgressDelegate progressDelegate) {
            FileCompressInfo _fileCompressInfo = new FileCompressInfo();
            _fileCompressInfo.inPath = inPath;
            _fileCompressInfo.outPath = outPath;
            _fileCompressInfo.progressDelegate = progressDelegate;
            CompressLZMA(_fileCompressInfo);
        }
 
        public static void DeCompress(string inPath, string outPath, ProgressDelegate progressDelegate) {
            FileCompressInfo _fileCompressInfo = new FileCompressInfo();
            _fileCompressInfo.inPath = inPath;
            _fileCompressInfo.outPath = outPath;
            _fileCompressInfo.progressDelegate = progressDelegate;
            DeCompressLZMA(_fileCompressInfo);
        }
 
        public static void CompressAsync(string inPath, string outPath, ProgressDelegate progressDelegate) {
            Thread _compressThread = new Thread(new ParameterizedThreadStart(CompressLZMA));
            FileCompressInfo _fileCompressInfo = new FileCompressInfo();
            _fileCompressInfo.inPath = inPath;
            _fileCompressInfo.outPath = outPath;
            _fileCompressInfo.progressDelegate = progressDelegate;
            _compressThread.Start(_fileCompressInfo);
        }
 
        public static void DeCompressAsync(string inPath, string outPath, ProgressDelegate progressDelegate) {
            Thread _deCompressThread = new Thread(new ParameterizedThreadStart(DeCompressLZMA));
            FileCompressInfo _fileCompressInfo = new FileCompressInfo();
            _fileCompressInfo.inPath = inPath;
            _fileCompressInfo.outPath = outPath;
            _fileCompressInfo.progressDelegate = progressDelegate;
            _deCompressThread.Start(_fileCompressInfo);
        }
 
        private static void CompressLZMA(object obj) {
 
            FileCompressInfo _fileCompressInfo = obj as FileCompressInfo;
 
            FileStream _input = null;
            FileStream _output = null;
            SevenZipEx.Compression.LZMA.Encoder _encoder = null;
 
            CodeProgress _codeProgress = null;
            if (_fileCompressInfo.progressDelegate != null) {
                _codeProgress = new CodeProgress(_fileCompressInfo.progressDelegate);
            }
 
            try {
                _encoder = new SevenZipEx.Compression.LZMA.Encoder();
 
                _input = new FileStream(_fileCompressInfo.inPath, FileMode.Open);
                _output = new FileStream(_fileCompressInfo.outPath, FileMode.Create);
 
                _encoder.WriteCoderProperties(_output);
 
                _output.Write(BitConverter.GetBytes(_input.Length), 0, 8);
                _encoder.Code(_input, _output, _input.Length, -1, _codeProgress);
 
                _output.Flush();
            }
            catch (Exception e) {
                DebugEx.LogFormat(e.Message);
            }
            finally {
                if (_encoder != null) {
                    _encoder = null;
                }
                if (_input != null) {
                    _input.Close();
                    _input = null;
                }
                if (_output != null) {
                    _output.Close();
                    _output = null;
                }
            }
        }
 
        private static void DeCompressLZMA(object obj) {
 
            FileCompressInfo _fileCompressInfo = obj as FileCompressInfo;
 
            SevenZipEx.Compression.LZMA.Decoder _decoder = null;
            FileStream _input = null;
            FileStream _output = null;
 
            CodeProgress _codeProgress = null;
            if (_fileCompressInfo.progressDelegate != null) {
                _codeProgress = new CodeProgress(_fileCompressInfo.progressDelegate);
            }
 
            try {
 
                _decoder = new SevenZipEx.Compression.LZMA.Decoder();
 
                _input = new FileStream(_fileCompressInfo.inPath, FileMode.Open);
                _output = new FileStream(_fileCompressInfo.outPath, FileMode.Create);
 
                byte[] _properties = new byte[5];
                _input.Read(_properties, 0, 5);
 
                byte[] fileLengthBytes = new byte[8];
                _input.Read(fileLengthBytes, 0, 8);
                long _fileLength = BitConverter.ToInt64(fileLengthBytes, 0);
 
                _decoder.SetDecoderProperties(_properties);
                _decoder.Code(_input, _output, _input.Length, _fileLength, _codeProgress);
 
                _output.Flush();
 
            }
            catch (Exception e) {
                DebugEx.LogFormat(e.Message);
            }
            finally {
                if (_decoder != null) {
                    _decoder = null;
                }
                if (_input != null) {
                    _input.Close();
                    _input = null;
                }
                if (_output != null) {
                    _output.Close();
                    _output = null;
                }
            }
        }
    }
 
}