-
Notifications
You must be signed in to change notification settings - Fork 0
/
LZMACompressDrivers.cpp
91 lines (77 loc) · 1.89 KB
/
LZMACompressDrivers.cpp
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
#include <iostream>
#include <Windows.h>
#pragma comment(lib,"LZ32.lib")
bool compress(LPSTR infile, LPSTR outfile)
{
INT hin, hout = 0;
OFSTRUCT ofin = { 0 };
OFSTRUCT ofout = { 0 };
LONG error = 0;
if ((hin = LZOpenFileA(infile, &ofin, OF_READ)) < 0)
{
std::cerr << "Can't open input file: " << infile << "\n";
return false;
}
if ((hout = LZOpenFileA(outfile, &ofout, OF_CREATE | OF_WRITE)) < 0)
{
LZClose(hin);
std::cerr << "Can't open output file: " << outfile << "\n";
return false;
}
error = LZCopy(hin, hout);
LZClose(hin);
LZClose(hout);
if (error < 0)
{
std::cerr << "LZCopy failed, error is: " << error << "\n";
return false;
}
return true;
}
bool compress(LPSTR infile, LPSTR outfile)
{
INT hin, hout = 0;
OFSTRUCT ofin = { 0 };
OFSTRUCT ofout = { 0 };
LONG error = 0;
if ((hin = LZOpenFileA(infile, &ofin, OF_READ)) < 0)
{
std::cerr << "Can't open input file: " << infile << "\n";
return false;
}
if ((hout = LZOpenFileA(outfile, &ofout, OF_CREATE | OF_WRITE)) < 0)
{
LZClose(hin);
std::cerr << "Can't open output file: " << outfile << "\n";
return false;
}
error = LZCopy(hin, hout);
LZClose(hin);
LZClose(hout);
if (error < 0)
{
std::cerr << "LZCopy failed, error is: " << error << "\n";
return false;
}
return true;
}
int main(int argc, char *argv[])
{
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " <input_file> <output_file>\n";
return 1;
}
const char *inputFile = argv[1];
const char *outputFile = argv[2];
if (compress(inputFile, outputFile))
{
std::cout << "Compression successful.\n";
}
else
{
std::cerr << "Compression failed.\n";
return 1;
}
return 0;
}