-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppCore.h
547 lines (511 loc) · 14 KB
/
AppCore.h
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/* ****************************************************************
* AppCore.h helps with shared app functions
* ****************************************************************/
#ifndef APPCORE_H
#define APPCORE_H
#include <sys/stat.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <conio.h>
class AppCore
{
public:
AppCore() {};
//getters
int getMsgBoxWidth();
//setters
void setMsgBoxWidth(int width);
void setWindowTitle(std::string);
void setWindowColors();
//others
void clearDisplay();
void drawStaightLine(int width);
void drawMessageBox(std::string message);
bool fileExists(const std::string &file);
void showMenuResolutionMenu();
protected:
private:
int msgBoxWidth = 80;
std::string windowTitle = "Phone Resolution Tool";
std::string centerConsoleMessage(std::string message, unsigned int consoleWidth);
void applyDPI(std::string dpi);
void applyResolution(std::string resolution);
int customHeight = 0;
int customWidth = 0;
void drawBottomLeftCorner();
void drawBottomRightCorner();
void drawTopLeftCorner();
void drawTopRightCorner();
void drawVerticalLine();
int promptDPI();
int promptWidthPixels();
int promptHeightPixels();
void resetAll();
bool showEnterCustomDPI();
bool showEnterCustomResolution();
void showMenuEndMenu();
void showMenuDPIMenu();
};
/******************
* Getters
*******************/
// returns the width (character columns) currently set for the messageBox drawing functions
int AppCore::getMsgBoxWidth()
{
return this->msgBoxWidth;
}
/******************
* Setters
*******************/
// Sets the width (character columns) for drawing functions.
void AppCore::setMsgBoxWidth(int width)
{
this->msgBoxWidth = width;
}
// Sets the App Window title.
void AppCore::setWindowTitle(std::string title)
{
this->windowTitle = title;
std::system(("@Title " + title).c_str());
}
/******************
* Other functions
*******************/
// Clears console display.
void AppCore::clearDisplay()
{
std::system("cls");
}
// Draws a straight line for the specified number (width) of characters.
void AppCore::drawStaightLine(int width)
{
for (int i = 0; i < width; i++)
{
std::cout << "\xCD";
}
}
// Prints out a top left corner line.
void AppCore::drawTopLeftCorner()
{
std::cout << "\xC9";
}
// Prints out a bottom right corner line.
void AppCore::drawTopRightCorner()
{
std::cout << "\xBB";
}
// Prints out a bottom left corner line.
void AppCore::drawBottomLeftCorner()
{
std::cout << "\xC8";
}
// Prints out a bottom right corner line.
void AppCore::drawBottomRightCorner()
{
std::cout << "\xBC";
}
// Prints a single vertical line.
void AppCore::drawVerticalLine()
{
std::cout << "\xBA";
}
// Prints out a box with a centered message.
void AppCore::drawMessageBox(std::string message)
{
this->drawTopLeftCorner();
this->drawStaightLine(this->msgBoxWidth - 2);
this->drawTopRightCorner();
if(this->msgBoxWidth < 80)
{
std::cout << std::endl;
}
this->drawVerticalLine();
std::cout << this->centerConsoleMessage(message, (this->msgBoxWidth - 2));
this->drawVerticalLine();
if(this->msgBoxWidth < 80)
{
std::cout << std::endl;
}
this->drawBottomLeftCorner();
this->drawStaightLine(this->msgBoxWidth - 2);
this->drawBottomRightCorner();
std::cout << std::endl;
}
// Centers a message by padding the sides with spaces.
std::string AppCore::centerConsoleMessage(std::string message, unsigned int consoleWidth)
{
if(message.length() > consoleWidth)
{
return message;
}
int diff = consoleWidth - message.length();
std::string tmpString = "";
for(int i = 0; i < (diff/2); i++)
{
tmpString += " ";
}
std::string returnString = (tmpString + message + tmpString).c_str();
if(returnString.length() < consoleWidth)
{
return returnString + " ";
}
return returnString;
}
// Executes the ADB apply DPI command and shows exit menu.
void AppCore::applyDPI(std::string dpi)
{
this->clearDisplay();
std::cout << "Applying " << dpi << " DPI..." << std::endl;
std::cout << std::endl;
system(("adb shell wm density " + dpi).c_str());
this->showMenuEndMenu();
}
// Executes the ADB apply resolution command and advances to show the DPI settings.
void AppCore::applyResolution(std::string resolution)
{
this->clearDisplay();
std::cout << "Applying " << resolution << "..." << std::endl;
std::cout << std::endl;
system(("adb shell wm size " + resolution).c_str());
this->showMenuDPIMenu();
}
// Checks if specified file exists.
bool AppCore::fileExists(const std::string &file)
{
struct stat buf;
return (stat(file.c_str(), &buf) == 0);
}
// Executes ADB command to reset all settings.
void AppCore::resetAll()
{
this->clearDisplay();
std::cout << "Resetting..." << std::endl;
std::cout << std::endl;
system("adb shell wm size reset");
system("adb shell wm density reset");
std::cout << std::endl;
std::cout << std::endl;
std::cout << "Your resolution and DPI settings have been reset " << std::endl;
std::cout << std::endl;
this->showMenuEndMenu();
}
// Prints out DPI settings menu.
void AppCore::showMenuDPIMenu()
{
std::string userChoice;
this->clearDisplay();
this->drawMessageBox("Set DPI:");
std::cout << " 1. 480" << std::endl;
std::cout << " 2. 400" << std::endl;
std::cout << " 3. 320" << std::endl;
std::cout << " 4. 240" << std::endl;
std::cout << " 5. 160" << std::endl;
std::cout << std::endl;
std::cout << " 6. Enter Custom DPI (Advanced Users only)" << std::endl;
std::cout << " 7. Do not change DPI" << std::endl;
std::cout << " 8. Back to Resolution Settings" << std::endl;
this->drawStaightLine(this->msgBoxWidth);
std::cout << std::endl;
std::cout << "Enter a choice>" ;
while (true)
{
userChoice = getch();
if (userChoice == "1")
{
applyDPI("480");
break;
}
if (userChoice == "2")
{
applyDPI("400");
break;
}
if (userChoice == "3")
{
applyDPI("320");
break;
}
if (userChoice == "4")
{
applyDPI("240");
break;
}
if (userChoice == "5")
{
applyDPI("160");
break;
}
if (userChoice == "6")
{
bool isEnteredCustomDPI = this->showEnterCustomDPI();
if (isEnteredCustomDPI == true)
{
break;
}
else
{
this->showMenuDPIMenu();
break;
}
}
if (userChoice == "7")
{
this->clearDisplay();
std::cout << "Your DPI will not be changed " << std::endl;
std::cout << std::endl;
system("pause");
this->showMenuEndMenu();
break;
}
if (userChoice == "8")
{
this->showMenuResolutionMenu();
break;
}
};
}
// Prints out the Application exit menu.
void AppCore::showMenuEndMenu()
{
std::string userChoice;
system("color 0A");
this->clearDisplay();
this->drawMessageBox("ALL DONE!");
std::cout << "Resolution:" << std::endl;
system("adb shell wm size");
std::cout << std::endl;
std::cout << "DPI:" << std::endl;
system("adb shell wm density");
std::cout << std::endl;
this->drawStaightLine(this->msgBoxWidth);
std::cout << std::endl;
std::cout << "Do you want to reboot your phone (yes recommended)? [Y/N]>";
while (true)
{
userChoice = getch();
if (userChoice == "y" || userChoice == "Y")
{
this->clearDisplay();
std::cout << "Rebooting..." << std::endl;
system("adb reboot");
break;
}
if (userChoice == "n" || userChoice == "N")
{
break;
}
}
this->clearDisplay();
system("exit");
}
// Prints out the Resolution settings Menu.
void AppCore::showMenuResolutionMenu()
{
std::string userChoice;
this->clearDisplay();
this->drawMessageBox("Set RESOLUTION:");
std::cout << " 1. 1080x1920" << std::endl;
std::cout << " 2. 900x1600" << std::endl;
std::cout << " 3. 720x1280" << std::endl;
std::cout << " 4. 540x960" << std::endl;
std::cout << " 5. 480x800" << std::endl;
std::cout << " 6. Other (Custom) Resolution..." << std::endl;
std::cout << std::endl;
std::cout << " 7. Reset All (Resolution and DPI)" << std::endl;
std::cout << " 8. Do not change resolution" << std::endl;
std::cout << " 9. Exit" << std::endl;
this->drawStaightLine(this->msgBoxWidth);
std::cout << std::endl;
std::cout << "Enter a choices>";
while (true)
{
userChoice = getch();
if (userChoice == "1")
{
this->applyResolution("1080x1920");
break;
}
if (userChoice == "2")
{
this->applyResolution("900x1600");
break;
}
if (userChoice == "3")
{
this->applyResolution("720x1280");
break;
}
if (userChoice == "4")
{
this->applyResolution("540x960");
break;
}
if (userChoice == "5")
{
this->applyResolution("480x800");
break;
}
if (userChoice == "6")
{
bool isEnteredCustomResolution = this->showEnterCustomResolution();
if (isEnteredCustomResolution == true)
{
break;
}
else
{
this->showMenuResolutionMenu();
break;
}
}
if (userChoice == "7")
{
this->resetAll();
break;
}
if (userChoice == "8")
{
this->showMenuDPIMenu();
break;
}
if (userChoice == "9")
{
this->clearDisplay();
break;
}
}
}
// Prompts user to enter custom DPI.
int AppCore::promptDPI()
{
int custdpi;
this->clearDisplay();
this->drawMessageBox("CUSTOM DPI");
std::cout << std::endl;
std::cout << "Enter custom DPI. Min 120, Max 640>";
std::cin >> custdpi;
if (std::cin.fail() || custdpi < 120 || custdpi > 640)
{
std::cin.clear();
std::cin.ignore(256, '\n');
this->promptDPI();
}
else
{
this->clearDisplay();
std::cout << std::endl;
this->drawMessageBox("CUSTOM DPI");
std::cout << "Selected DPI :" << custdpi << std::endl;
applyDPI(std::to_string(custdpi));
}
return custdpi;
}
// Prints out the Enter Custom DPI menu.
bool AppCore::showEnterCustomDPI()
{
std::string userChoice;
system("color 0C");
this->clearDisplay();
this->drawMessageBox("CAUTION!");
std::cout << std::endl;
std::cout << "Entering custom DPI is recommended only for Advanced Users." << std::endl;
std::cout << std::endl;
this->drawStaightLine(this->msgBoxWidth);
std::cout << std::endl;
std::cout << "Are you sure you want to continue? [Y/N]>";
while (true)
{
userChoice = getch();
if (userChoice == "y" || userChoice == "Y")
{
system("color 0F");
this->promptDPI();
return true;
break;
}
if (userChoice == "n" || userChoice == "N")
{
break;
}
}
system("color 0F");
return false;
}
// Prompts user to enter width in pixels.
int AppCore::promptWidthPixels()
{
this->clearDisplay();
this->drawMessageBox("CUSTOM RESOLUTION");
std::cout << "Enter custom width in pixels. Min 240, Max 2960>";
std::cin >> this->customWidth;
if (std::cin.fail() || this->customWidth < 240 || this->customWidth > 2960)
{
std::cin.clear();
std::cin.ignore(256, '\n');
return this->promptWidthPixels();
}
else
{
return this->customWidth;
}
}
// Prompts user to enter height in pixels.
int AppCore::promptHeightPixels()
{
this->clearDisplay();
this->drawMessageBox("CUSTOM RESOLUTION");
std::cout << "Selected width:" << this->customWidth << std::endl;
std::cout << std::endl;
std::cout << "Enter custom height in pixels. Min 240, Max 2960>" ;
std::cin >> this->customHeight;
if (std::cin.fail() || this->customHeight < 240 || this->customHeight > 2960)
{
std::cin.clear();
std::cin.ignore(256, '\n');
return this->promptHeightPixels();
}
else
{
return this->customHeight;
}
}
// Prints out the Enter Custom Resolution menu.
bool AppCore::showEnterCustomResolution()
{
std::string userChoice;
system("color 0C");
this->clearDisplay();
this->drawMessageBox("CAUTION!");
std::cout << "Entering custom resolutions is recommended only for Advanced Users." << std::endl;
std::cout << std::endl;
this->drawStaightLine(this->msgBoxWidth);
std::cout << std::endl;
std::cout << "Are you sure you want to continue? [Y/N]>" ;
while (true)
{
userChoice = getch();
if (userChoice == "y" || userChoice == "Y")
{
system("color 0F");
this->promptWidthPixels();
this->promptHeightPixels();
this->clearDisplay();
std::cout << std::endl;
this->drawMessageBox("CUSTOM RESOLUTION");
std::cout << "Selected width :" << this->customWidth << std::endl;
std::cout << "Selected height :" << this->customHeight << std::endl;
applyResolution(std::to_string(this->customWidth) + "x" + std::to_string(this->customHeight));
return true;
break;
}
if (userChoice == "n" || userChoice == "N")
{
break;
}
};
system("color 0F");
return false;
}
#endif // AppCore_H