forked from ClnViewer/Android-fast-screen-capture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathascreencap-AScreenConf.cpp
239 lines (213 loc) · 6.69 KB
/
ascreencap-AScreenConf.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 "ascreencap.h"
#include "ascreencap-AScreenConf.h"
#include "extern/argh.h"
#include "version.h"
#define __CONF_CAPFILE "-f", "--file"
#define __CONF_CAPPACK "-p", "--pack"
#define __CONF_CAPRATIO "", "--ratio"
#define __CONF_CAPROTATE "", "--rotate"
#define __CONF_CAPSTREAM "-s", "--stream"
#define __CONF_CAPSTDOUT "", "--stdout"
#define __CONF_CAPSDL "", "--sdl"
#define __CONF_CAPHELP "-h", "--help"
#define __CONF_CAPINFO "-i", "--info"
#define __HELP_PRINT(A) fprintf(stdout, "\t\t%s\t%s\t%s\n", (A).key1, (A).key2, (A).desc)
#define __HELP_SET_(A,B,C) .key1 = A, .key2 = B, .desc = C
#define __HELP_SET(...) __HELP_SET_(__VA_ARGS__)
namespace ACapture
{
struct help_s
{
const char *key1;
const char *key2;
const char *desc;
};
static struct help_s helps[] =
{
{
__HELP_SET(__CONF_CAPFILE, "\t: output save to file, value is name")
},
{
__HELP_SET(__CONF_CAPSTREAM, ": output to loop stream (STDOUT)")
},
{
__HELP_SET(__CONF_CAPSTDOUT, ": output to STDOUT")
},
{
__HELP_SET(__CONF_CAPPACK, "\t: output pack lz4 algorithm")
},
{
__HELP_SET(__CONF_CAPSDL, "\t: output SDL2 texture compatible mode: Landscape screen")
},
{
__HELP_SET(__CONF_CAPRATIO, "\t: image resize ratio, valid scale 1-5")
},
{
__HELP_SET(__CONF_CAPROTATE, ": image rotate: 90,180,270, value 360 = mirror")
},
{
__HELP_SET(__CONF_CAPHELP, "\t: this help screen")
},
{
__HELP_SET(__CONF_CAPINFO, "\t: build information")
}
};
static uint32_t strToUint(std::string const opt)
{
try
{
return stoul(opt);
}
catch (std::invalid_argument & _ex)
{
# if defined(_DEBUG)
__LOG_PRINT("CONFIG ERROR: -> (%s)", _ex.what());
# endif
return 0U;
}
catch (std::out_of_range & _ex)
{
# if defined(_DEBUG)
__LOG_PRINT("CONFIG ERROR: -> (%s)", _ex.what());
# endif
return 0U;
}
catch (...)
{
return 0U;
}
}
void AScreenConf::printInfo()
{
fprintf(stdout, "ascreencap - v.%s, build: %s.%s.%s [Android v.%d, api %d]",
ACAP_FULLVERSION_STRING, ACAP_DATE, ACAP_MONTH, ACAP_YEAR,
__ANDROID_VER__, __ANDROID_API__
);
}
void AScreenConf::printHelp()
{
fprintf(stdout, "\n\tAndroid Screen Capture - v.%s, rev:%s, build: %s.%s.%s\n",
ACAP_FULLVERSION_STRING, ACAP_SVN_REVISION, ACAP_DATE, ACAP_MONTH, ACAP_YEAR
);
# if ((__ANDROID_VER__ == 9) || (__ANDROID_VER__ == 8))
fprintf(stdout, "\tBuild to Android version v.%d - API %d\n",__ANDROID_VER__, __ANDROID_API__);
# elif ((__ANDROID_VER__ <= 7) && (__ANDROID_VER__ >= 5))
fprintf(stdout, "\tBuild to Android version v.5, v.6, v.7 - API %d\n", __ANDROID_API__);
# elif (__ANDROID_API__ >= 17)
fprintf(stdout, "\tBuild to Android version >= v.4 - API %d\n", __ANDROID_API__);
# else
fprintf(stdout, "\tBuild to unknown Android version, broken..\n");
# endif
fprintf(stdout, "\tascreencap - replaced version of default screencap utility\n");
fprintf(stdout, "\tgit: https://github.com/ClnViewer/Android-fast-screen-capture.git\n\n\n");
for (uint32_t i = 0U; i < __NELE(helps); i++)
__HELP_PRINT(helps[i]);
}
AScreenConf::AScreenConf(int32_t argc, char **argv)
: _err(0),
IsCapStream(false), IsCapFile(false), IsCapStdOut(false),
IsCapRatio(false), IsCapRotate(false), IsCapPack(false),
IsSDL2Compatible(false), IsHelp(false), IsInfo(false),
Ratio(0U), Rotate(0U), FastPack(0U)
{
argh::parser lcmd({
__CONF_CAPSTREAM,
__CONF_CAPFILE,
__CONF_CAPPACK,
__CONF_CAPRATIO,
__CONF_CAPROTATE,
__CONF_CAPSTDOUT,
__CONF_CAPSDL,
__CONF_CAPHELP,
__CONF_CAPINFO
});
lcmd.parse(argc, argv);
size_t sp;
std::string sratio;
std::string srotate;
std::string spack;
IsSDL2Compatible = (lcmd[{ __CONF_CAPSDL }]);
IsHelp = (lcmd[{ __CONF_CAPHELP }]);
IsInfo = (lcmd[{ __CONF_CAPINFO }]);
IsCapStdOut = (lcmd[{ __CONF_CAPSTDOUT }]);
IsCapStream = (lcmd[{ __CONF_CAPSTREAM }]);
IsCapFile = !(!(lcmd({ __CONF_CAPFILE }) >> FileName));
IsCapRatio = !(!(lcmd({ __CONF_CAPRATIO }) >> sratio));
IsCapRotate = !(!(lcmd({ __CONF_CAPROTATE }) >> srotate));
IsCapPack = !(!(lcmd({ __CONF_CAPPACK }) >> spack));
if ((IsHelp) || (IsInfo))
return;
if (!IsCapStdOut)
{
if ((!IsCapFile) || (!FileName.length()))
FileName.assign("ACapture.bmp");
else
{
if ((sp = FileName.find_last_of(".")) != std::wstring::npos)
{
std::string ext = FileName.substr(sp, FileName.length() - sp);
if (!ext.compare(0U, ext.length(), ".bmz"))
IsCapPack = true;
}
}
if (FileName.find("/") == std::wstring::npos)
FileName.insert(0, "/data/local/tmp/");
IsCapFile = ((IsCapFile) ? IsCapFile : (!IsCapStream));
IsCapStream = ((IsCapFile) ? false : IsCapStream);
}
else
IsCapStream = IsCapFile = false;
if ((IsCapRatio) && (sratio.length()))
{
Ratio = strToUint(sratio);
if (Ratio)
{
Ratio = ((Ratio > 5U) ? 5U : Ratio);
}
else
IsCapRatio = false;
}
if ((IsCapRotate) && (srotate.length()))
{
switch ((Rotate = strToUint(srotate)))
{
case 90:
case 180:
case 270:
case 360: /// mirror mode or SDL2 mode
break;
default:
{
IsCapRotate = false;
Rotate = 0U;
break;
}
}
}
if ((IsSDL2Compatible) && (!IsCapRotate))
Rotate = 360U;
if ((IsCapPack) && (spack.length()))
{
FastPack = strToUint(spack);
FastPack = ((FastPack > 9) ? 0 : (9 - FastPack));
}
# if defined(_DEBUG)
__LOG_PRINT("CONFIG SET: ->\n" \
"\tFile path:\t[%s]\n" \
"\tRatio:\t\t[%u]\n" \
"\tRotate:\t[%u]\n" \
"\tFastPack:\t[%u]\n" \
"\tIsNoHeader:\t[%d]\n" \
"\tIsCapStdOut:\t[%d]\n" \
"\tIsCapStream:\t[%d]\n" \
"\tIsCapFile:\t[%d]\n" \
"\tIsCapRatio:\t[%d]\n" \
"\tIsCapRotate:\t[%d]\n" \
"\tIsCapPack:\t[%d]\n",
FileName.c_str(),
Ratio, Rotate, FastPack,
IsSDL2Compatible, IsCapStdOut, IsCapStream, IsCapFile, IsCapRatio, IsCapRotate, IsCapPack
);
# endif
}
}