1
- #include " winPulsar.h"
1
+ // Неообходимые библиотеки/модули
2
+ #include " winPulsar.h"
2
3
#include < atomic>
3
4
#include < chrono>
4
5
#include < cstdlib>
13
14
#include < fstream>
14
15
#include < cctype>
15
16
#include " C:\Users\user\source\repos\PulsarVenv\PulsarVenv\pulsFileSystem.h"
17
+
18
+ // Пространство имен std
16
19
using namespace std ;
20
+
21
+
22
+ // Глобальные переменные
17
23
string current_path;
18
24
string build_ID;
19
25
string style = " " ;
20
26
bool isLog = true ;
21
27
bool isError = true ;
22
- // TODO смена имени аккаугта \ создание файлов + работа с ними
23
- /* Коды возвращаемых ошибок
24
- 0001 - код выхода из системы*/
25
-
26
28
atomic<bool > timeThreadRunning (true );
27
29
mutex consoleMutex;
28
30
31
+ // Скелеты (прототипы) функций
29
32
int PulsarConsoleClear ();
30
33
int configAnalyze (string bildn, string AccountName, string pas);
31
34
bool isValidHexColor (string s);
35
+ int changeStyle ();
36
+ bool isValidHexDigit (char c);
37
+ void puls_calc (string line);
38
+ void puls_sysconfig (string line);
39
+ void show_help ();
40
+ int PulsarConsoleClear ();
41
+ int neuro ();
42
+ int AccountCommand (string line);
43
+ int configAnalyze (string bildn, string AccountName, string pas);
44
+ int comAnalyze (string line);
45
+ int executePulsarScript (string line);
46
+ int pulsStarterScript ();
47
+ int writeInLog (string message, bool isTime, bool isTrunc);
32
48
49
+ // Главный класс информации о пульсаре
33
50
class CurrentPulsarInfo {
34
51
public:
35
52
static string title;
@@ -63,13 +80,62 @@ class CurrentPulsarInfo {
63
80
cout << " ----------------------------------------------" << endl;
64
81
}
65
82
};
83
+
84
+ // Реализация статический переменных class CurrentPulsarInfo
66
85
string CurrentPulsarInfo::title = " PulsarVenv 0.2.5" ;
67
86
string CurrentPulsarInfo::platform_version = " Windows" ;
68
87
string CurrentPulsarInfo::account = " " ;
69
88
int CurrentPulsarInfo::start_time = 0 ;
70
89
string CurrentPulsarInfo::bildingid = " " ;
71
90
string CurrentPulsarInfo::password = " " ;
72
91
92
+
93
+ // Основная функция. Здесь начинается жизнь пульсара
94
+ int pulsarStart (string bildn, string AccountName, string pas) {
95
+ setlocale (LC_ALL, " Ru" );
96
+ ofstream logfile;
97
+ CurrentPulsarInfo::start_time = clock ();
98
+ configAnalyze (bildn, AccountName, pas);
99
+ writeInLog (" $startpulsar" , true , false );
100
+ string com;
101
+ int code;
102
+ system (" cls" );
103
+ PulsarConsoleClear ();
104
+ pulsStarterScript ();
105
+ while (true ) {
106
+ cout << " $> " ;
107
+ getline (cin, com);
108
+ com.erase (0 , com.find_first_not_of (' ' ));
109
+ com.erase (com.find_last_not_of (' ' ) + 1 );
110
+ if (com.starts_with (" script" )) {
111
+ com.replace (0 , 6 , " " );
112
+ com.erase (0 , com.find_first_not_of (' ' ));
113
+ com.erase (com.find_last_not_of (' ' ) + 1 );
114
+ code = executePulsarScript (com);
115
+ }
116
+ else {
117
+ code = comAnalyze (com);
118
+ }
119
+ if (code == 0101 ) {
120
+ writeInLog (" $exitpulsar" , true , false );
121
+ return 0101 ;
122
+ }
123
+
124
+ }
125
+ }
126
+
127
+
128
+ // Реализация всех функций
129
+
130
+ int writeInLog (string message, bool isTime, bool isTrunc){
131
+ ofstream logfile;
132
+ logfile.open (current_path + " \\ accounts\\ " + CurrentPulsarInfo::account + " \\ accountcfg\\ log.plog" , fstream::in | fstream::out | ((isTrunc) ? ios::trunc : ios::app));
133
+ logfile << message;
134
+ logfile << ((isTime) ? " " + CurrentPulsarInfo::getCurrentDateTime () : " " );
135
+ logfile << " \n " ;
136
+ logfile.close ();
137
+ }
138
+
73
139
int changeStyle () {
74
140
string newColor, newStyle;
75
141
string name = CurrentPulsarInfo::account;
@@ -110,7 +176,7 @@ int changeStyle() {
110
176
f.close ();
111
177
configAnalyze (build_ID, CurrentPulsarInfo::account, CurrentPulsarInfo::password);
112
178
PulsarConsoleClear ();
113
-
179
+
114
180
115
181
}
116
182
@@ -145,16 +211,6 @@ void puls_sysconfig(string line) {
145
211
146
212
}
147
213
148
- void sumulator_pulsar () {
149
- string pathToSumPuls = " cd " + current_path + " \\ SystemPuls\\ systemmodules && pulsarem.exe" ;
150
- cout << " Внимание скоро начнется эмуляция пульсара.\n Во время эмуляции не нажимайте по консольному окну.\n "
151
- << " Если нажали нажмите enter чтобы продолжить эмуляцию" << endl;
152
- this_thread::sleep_for (std::chrono::milliseconds (1000 ));
153
- system (" cls" );
154
- system (pathToSumPuls.c_str ());
155
- PulsarConsoleClear ();
156
- }
157
-
158
214
void show_help () {
159
215
cout << " PulsarVenv 0.0.1-alpha - Справочник по командам" << endl << endl;
160
216
@@ -164,7 +220,7 @@ void show_help() {
164
220
cout << " exit - Выйти из системы" << endl;
165
221
cout << " clear - Очистить экран консоли" << endl;
166
222
cout << " pinfo - Показать информацию о Pulsar (версия, время работы и т.д.)" << endl << endl;
167
- cout << " сруьви - Химическая база данных" << endl << endl;
223
+ cout << " chemdb - Химическая база данных" << endl << endl;
168
224
169
225
cout << " Команды работы с системой:" << endl;
170
226
cout << " =========================" << endl;
@@ -386,7 +442,7 @@ int AccountCommand(string line) {
386
442
cout << " Такого аккаунта не существует" << endl;
387
443
}
388
444
}
389
- else if (line.starts_with (" change password" )){
445
+ else if (line.starts_with (" change password" )) {
390
446
string check_true_password;
391
447
cout << " Введите пароль от аккаунта: " ;
392
448
getline (cin, check_true_password);
@@ -398,7 +454,8 @@ int AccountCommand(string line) {
398
454
f.open (current_path + " \\ accounts\\ " + CurrentPulsarInfo::account + " \\ accountcfg\\ password.ppas" , ios::trunc );
399
455
if (!f.is_open ()) {
400
456
cout << " Ошибка смены пароля" << endl;
401
- } else {
457
+ }
458
+ else {
402
459
f << newPassword;
403
460
configAnalyze (build_ID, CurrentPulsarInfo::account, newPassword);
404
461
}
@@ -408,7 +465,7 @@ int AccountCommand(string line) {
408
465
cout << " Неверный пароль" << endl;
409
466
}
410
467
}
411
-
468
+
412
469
413
470
414
471
}
@@ -435,17 +492,13 @@ int configAnalyze(string bildn, string AccountName, string pas) {
435
492
if (color != " normal" ) {
436
493
string setColor = " color " + color;
437
494
system (setColor.c_str ());
438
- }
495
+ }
439
496
return 0 ;
440
497
}
441
498
442
499
int comAnalyze (string line) {
443
- ofstream logfile;
444
500
if (isLog) {
445
- logfile.open (current_path + " \\ accounts\\ " + CurrentPulsarInfo::account + " \\ accountcfg\\ log.plog" , fstream::in | fstream::out | ios::app);
446
- logfile << line;
447
- logfile << " \n " ;
448
- logfile.close ();
501
+ writeInLog (line, false , false );
449
502
}
450
503
if (line.empty ()) {
451
504
return 0 ;
@@ -479,9 +532,6 @@ int comAnalyze(string line) {
479
532
else if (line == " help" || line.substr (0 , 4 ) == " help" ) {
480
533
show_help ();
481
534
}
482
- else if (line == " sumulator_pulsar" ) {
483
- sumulator_pulsar ();
484
- }
485
535
else if (line.substr (0 , 7 ) == " account" ) {
486
536
AccountCommand (line);
487
537
}
@@ -507,15 +557,16 @@ int comAnalyze(string line) {
507
557
line.erase (0 , line.find_first_not_of (' ' ));
508
558
line.erase (line.find_last_not_of (' ' ) + 1 );
509
559
if (line.starts_with (" off" )) {
510
- if (isLog == false ) {
560
+ if (isLog == false ) {
511
561
cout << " Логирование команд уже выключено " << endl;
512
- return 0 ; }
562
+ return 0 ;
563
+ }
513
564
cout << " Логирование команд выключено " << endl;
514
565
isLog = false ;
515
566
}
516
567
else if (line.starts_with (" on" )) {
517
568
if (isLog == true ) {
518
- cout << " Логирование команд уже включено " << endl;
569
+ cout << " Логирование команд уже включено " << endl;
519
570
return 0 ;
520
571
}
521
572
cout << " Логирование команд включено " << endl;
@@ -527,10 +578,7 @@ int comAnalyze(string line) {
527
578
cout << " Очистка лога команд - опасна операция. \n Код опасности 1; \n Выполнить операцию? [Y/n] :" ;
528
579
cin >> answer;
529
580
if (answer == " Y" ) {
530
- logfile.open (current_path + " \\ accounts\\ " + CurrentPulsarInfo::account + " \\ accountcfg\\ log.plog" , fstream::in | fstream::out | ios::trunc );
531
- logfile << " #pulsar log delete " + CurrentPulsarInfo::getCurrentDateTime ();
532
- logfile << " \n " ;
533
- logfile.close ();
581
+ writeInLog (" $pulsar log delete" , true , false );
534
582
cout << " Лог команд очищен" << endl;
535
583
break ;
536
584
}
@@ -567,12 +615,12 @@ int comAnalyze(string line) {
567
615
system (cdmodule.c_str ());
568
616
}
569
617
else {
570
- if (isError) cout << " Ошибка: Команда не распознана. Введите 'help' для справки." << endl;
618
+ if (isError) cout << " Ошибка: Команда не распознана. Введите 'help' для справки." << endl;
571
619
}
572
620
}
573
621
}
574
622
575
- int startPulsScript (string line) {
623
+ int executePulsarScript (string line) {
576
624
string comInFile;
577
625
if (filesystem::exists (line)) {
578
626
fstream scrFile;
@@ -591,8 +639,8 @@ int startPulsScript(string line) {
591
639
}
592
640
}
593
641
scrFile.close ();
594
-
595
-
642
+
643
+
596
644
}
597
645
598
646
}
@@ -635,43 +683,4 @@ int pulsStarterScript() {
635
683
}
636
684
scrsFile.close ();
637
685
}
638
- }
639
-
640
- int pulsarStart (string bildn, string AccountName, string pas) {
641
- setlocale (LC_ALL, " Ru" );
642
- ofstream logfile;
643
- CurrentPulsarInfo::start_time = clock ();
644
- configAnalyze (bildn, AccountName, pas);
645
- logfile.open (current_path + " \\ accounts\\ " + CurrentPulsarInfo::account + " \\ accountcfg\\ log.plog" , fstream::in | fstream::out | ios::app);
646
- logfile << " $startpulsar " + CurrentPulsarInfo::getCurrentDateTime ();
647
- logfile << " \n " ;
648
- logfile.close ();
649
- string com;
650
- int code;
651
- system (" cls" );
652
- PulsarConsoleClear ();
653
- pulsStarterScript ();
654
- while (true ) {
655
- cout << " $> " ;
656
- getline (cin, com);
657
- com.erase (0 , com.find_first_not_of (' ' ));
658
- com.erase (com.find_last_not_of (' ' ) + 1 );
659
- if (com.starts_with (" script" )) {
660
- com.replace (0 , 6 , " " );
661
- com.erase (0 , com.find_first_not_of (' ' ));
662
- com.erase (com.find_last_not_of (' ' ) + 1 );
663
- code = startPulsScript (com);
664
- }
665
- else {
666
- code = comAnalyze (com);
667
- }
668
- if (code == 0101 ) {
669
- logfile.open (current_path + " \\ accounts\\ " + CurrentPulsarInfo::account + " \\ accountcfg\\ log.plog" , fstream::in | fstream::out | ios::app);
670
- logfile << " $exitpulsar " + CurrentPulsarInfo::getCurrentDateTime ();
671
- logfile << " \n " ;
672
- logfile.close ();
673
- return 0101 ;
674
- }
675
-
676
- }
677
686
}
0 commit comments