-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
127 lines (117 loc) · 4.68 KB
/
main.cpp
File metadata and controls
127 lines (117 loc) · 4.68 KB
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
#include"Compress.h"
#include"Decompress.h"
#include<chrono>
#include<thread>
using namespace std;
void show_start()
{
int slept=350;
cout<<"========================================================="<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"| |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"| |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"| |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"| welcome! this is Huffman Compress System |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"| |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"| |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"| author: @Tarime |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"========================================================="<<endl;
}
void show_list()
{
int slept=50;
cout<<"========================================================="<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"|command list: |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"|dircp: show file Supported for compressed files |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"|dirdcp: show file Supported for decompressed files |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"|compress <filename.***> :Compress a file |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"|decompress <filename.***> :Decompress a file |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"|list : show this list again |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"|exit : exit the system |"<<endl;
std::this_thread::sleep_for(std::chrono::milliseconds(slept));
cout<<"========================================================="<<endl;
}
void Cp(string filename)
{
cout<<filename<<endl;
char* org_data=new char[100000000];//最多100M
ifstream iff(filename,ios::binary);
if(!iff)
{
cout<<"file not found!"<<endl;
return;
}
iff.seekg(0,ios::end); int size=iff.tellg(); iff.seekg(0,ios::beg);
iff.read(org_data,size);
cout<<"Accepted file size:"<<size<<" KB"<<endl;
Compressor cp=Compressor(org_data,org_data+size-1,filename);
cp.encode();
cp.write_dictionary();
cout<<"compress file is in folder:"<<filename+"_compress"<<endl;
// cp.~Compressor();
}
void Dcp(string filename){
Decompressor dcp=Decompressor(filename);
dcp.read_dic();
dcp.decode();
// dcp.~Decompressor();
cout<<"decompress file is in folder:"<<filename+"_decompress"<<endl;
}
int main(){
show_start();
show_list();
string ip;
cout<<">>";
while(1){
cin>>ip;
if(ip=="compress"){
string filename;
cin>>filename;
Cp(filename);
}
else if(ip=="dircp"){
cout<<"============================================"<<endl;
system("dir /s");
cout<<"============================================"<<endl;
}
else if(ip=="dirdcp")
{
cout<<"============================================"<<endl;
cout<<"Please remain not to input \".huf\" or \".dct\" in your commands "<<endl<<endl;
system("dir /s *.huf");
system("dir /s *.dct");
cout<<"============================================"<<endl;
}
else if(ip=="decompress"){
string filename;
cin>>filename;
Dcp(filename);
}
else if(ip=="list"){
show_list();
}
else if(ip=="exit"){
cout<<"bye bye!"<<endl;
break;
}
else{
cout<<"wrong command!"<<endl;
}
cout<<endl<<">>";
}
system("pause");
}