-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMkvParseStream.cpp
239 lines (234 loc) · 3.76 KB
/
MkvParseStream.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include "MkvParseStream.h"
MkvParseStream::MkvParseStream()
{
}
std::string MkvParseStream::ParseMessage(char* buffer, size_t len)
{
char* endPos = buffer + len;
for (char *curPos = buffer; curPos < endPos; curPos++)
{
switch (*curPos)
{
case 'M':
curPos += ParseMSG(curPos);
break;
case'P':
switch (curPos[3])
{
case 'T':
curPos += ParsePRGT(curPos);
break;
case 'C':
curPos += ParsePRGC(curPos);
break;
case 'V':
curPos += ParsePRGV(curPos);
break;
default:
curPos += LineLen(curPos);
break;
}
break;
default:
curPos += LineLen(curPos);
break;
}
}
std::string out = strMsg + "\r\n\r\n";
out += strJob + " : " + strTotalProg + "\r\n";
out += strTask + " : " + strCurProg + "\r\n";
return out;
}
size_t MkvParseStream::ParseMSG(char* line)
{
char* curPos = line + 4;
int curItem = 0;
bool done = false;
strMsg = "";
while (*curPos != '\n')
{
if (*curPos == '"' || *curPos == '\r')
{
curPos++;
continue;
}
if (*curPos == ',')
{
curItem++;
curPos++;
continue;
}
switch (curItem)
{
case 0: // message id
break;
case 1: // message code
break;
case 2: // how many format args
break;
case 3: // actual message
strMsg += *curPos;
done = true;
break;
case 4:// format version
break;
case 5: // 5 and up are the arguments
break;
}
curPos++;
if (*curPos == NULL)
{
break;
}
}
return curPos - line;
}
size_t MkvParseStream::ParsePRGT(char* line)
{
char* curPos = line + 5;
int curItem = 0;
bool done = false;
strJob = "";
while (*curPos != '\n')
{
if (*curPos == '"' || *curPos == '\r')
{
curPos++;
continue;
}
if (*curPos == ',')
{
curItem++;
curPos++;
continue;
}
switch (curItem)
{
case 0: // task id
break;
case 1: // task code
break;
case 2: // how many format args
strJob += *curPos;
done = true;
break;
}
curPos++;
if (*curPos == NULL)
{
break;
}
}
return curPos - line;
}
size_t MkvParseStream::ParsePRGC(char* line)
{
char* curPos = line + 5;
int curItem = 0;
bool done = false;
strTask = "";
while (*curPos != '\n')
{
if (*curPos == '"' || *curPos == '\r')
{
curPos++;
continue;
}
if (*curPos == ',')
{
curItem++;
curPos++;
continue;
}
switch (curItem)
{
case 0: // task id
break;
case 1: // task code
break;
case 2: // how many format args
strTask += *curPos;
done = true;
break;
}
curPos++;
if (*curPos == NULL)
{
break;
}
}
return curPos - line;
}
size_t MkvParseStream::ParsePRGV(char* line)
{
char* curPos = line + 5;
int curItem = 0;
std::string current = "";
std::string total = "";
std::string max = "";
bool done = false;
strCurProg = "";
strTotalProg = "";
while (*curPos != '\n')
{
if (*curPos == '\r')
{
curPos++;
continue;
}
if (*curPos == ',')
{
curItem++;
curPos++;
continue;
}
switch (curItem)
{
case 0: // task id
current += *curPos;
break;
case 1: // task code
total += *curPos;
break;
case 2: // how many format args
max += *curPos;
break;
}
curPos++;
if (*curPos == NULL)
{
break;
}
}
float cur = (float)atoi(current.c_str());
float curTotal = (float)atoi(total.c_str());
float maxNum = (float)atoi(max.c_str());
if (maxNum != 0)
{
char tmp[32] = { 0 };
int per = (int)((cur / maxNum) * 100.0);
int perOverall = (int)((curTotal / maxNum) * 100.0);
_itoa_s(per, tmp, 10);
strCurProg = tmp;
strCurProg += "%";
_itoa_s(perOverall, tmp, 10);
strTotalProg = tmp;
strTotalProg += "%";
}
return curPos - line;
}
size_t MkvParseStream::LineLen(char* line)
{
size_t total = 0;
char* curPos = line;
while (*curPos != '\n')
{
curPos++;
total++;
if (*curPos == NULL)
{
break;
}
}
return total;
}