Skip to content

Commit 9465a74

Browse files
committed
code refactor and lunix ultra beta
1 parent b44db56 commit 9465a74

File tree

6 files changed

+90
-80
lines changed

6 files changed

+90
-80
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#pragma once
2+
int pulsarStart();

public/source/WinPulsar.cpp renamed to public/source/WindowsPulsar/winPulsar.cpp

Lines changed: 88 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#include "winPulsar.h"
1+
// Неообходимые библиотеки/модули
2+
#include "winPulsar.h"
23
#include <atomic>
34
#include <chrono>
45
#include <cstdlib>
@@ -13,23 +14,39 @@
1314
#include <fstream>
1415
#include <cctype>
1516
#include "C:\Users\user\source\repos\PulsarVenv\PulsarVenv\pulsFileSystem.h"
17+
18+
//Пространство имен std
1619
using namespace std;
20+
21+
22+
// Глобальные переменные
1723
string current_path;
1824
string build_ID;
1925
string style = "";
2026
bool isLog = true;
2127
bool isError = true;
22-
//TODO смена имени аккаугта \ создание файлов + работа с ними
23-
/*Коды возвращаемых ошибок
24-
0001 - код выхода из системы*/
25-
2628
atomic<bool> timeThreadRunning(true);
2729
mutex consoleMutex;
2830

31+
// Скелеты (прототипы) функций
2932
int PulsarConsoleClear();
3033
int configAnalyze(string bildn, string AccountName, string pas);
3134
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);
3248

49+
// Главный класс информации о пульсаре
3350
class CurrentPulsarInfo {
3451
public:
3552
static string title;
@@ -63,13 +80,62 @@ class CurrentPulsarInfo {
6380
cout << "----------------------------------------------" << endl;
6481
}
6582
};
83+
84+
// Реализация статический переменных class CurrentPulsarInfo
6685
string CurrentPulsarInfo::title = "PulsarVenv 0.2.5";
6786
string CurrentPulsarInfo::platform_version = "Windows";
6887
string CurrentPulsarInfo::account = "";
6988
int CurrentPulsarInfo::start_time = 0;
7089
string CurrentPulsarInfo::bildingid = "";
7190
string CurrentPulsarInfo::password = "";
7291

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+
73139
int changeStyle() {
74140
string newColor, newStyle;
75141
string name = CurrentPulsarInfo::account;
@@ -110,7 +176,7 @@ int changeStyle() {
110176
f.close();
111177
configAnalyze(build_ID, CurrentPulsarInfo::account, CurrentPulsarInfo::password);
112178
PulsarConsoleClear();
113-
179+
114180

115181
}
116182

@@ -145,16 +211,6 @@ void puls_sysconfig(string line) {
145211

146212
}
147213

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-
158214
void show_help() {
159215
cout << "PulsarVenv 0.0.1-alpha - Справочник по командам" << endl << endl;
160216

@@ -164,7 +220,7 @@ void show_help() {
164220
cout << "exit - Выйти из системы" << endl;
165221
cout << "clear - Очистить экран консоли" << endl;
166222
cout << "pinfo - Показать информацию о Pulsar (версия, время работы и т.д.)" << endl << endl;
167-
cout << "сруьви - Химическая база данных" << endl << endl;
223+
cout << "chemdb - Химическая база данных" << endl << endl;
168224

169225
cout << "Команды работы с системой:" << endl;
170226
cout << "=========================" << endl;
@@ -386,7 +442,7 @@ int AccountCommand(string line) {
386442
cout << "Такого аккаунта не существует" << endl;
387443
}
388444
}
389-
else if(line.starts_with("change password")){
445+
else if (line.starts_with("change password")) {
390446
string check_true_password;
391447
cout << "Введите пароль от аккаунта: ";
392448
getline(cin, check_true_password);
@@ -398,7 +454,8 @@ int AccountCommand(string line) {
398454
f.open(current_path + "\\accounts\\" + CurrentPulsarInfo::account + "\\accountcfg\\password.ppas", ios::trunc);
399455
if (!f.is_open()) {
400456
cout << "Ошибка смены пароля" << endl;
401-
} else {
457+
}
458+
else {
402459
f << newPassword;
403460
configAnalyze(build_ID, CurrentPulsarInfo::account, newPassword);
404461
}
@@ -408,7 +465,7 @@ int AccountCommand(string line) {
408465
cout << "Неверный пароль" << endl;
409466
}
410467
}
411-
468+
412469

413470

414471
}
@@ -435,17 +492,13 @@ int configAnalyze(string bildn, string AccountName, string pas) {
435492
if (color != "normal") {
436493
string setColor = "color " + color;
437494
system(setColor.c_str());
438-
}
495+
}
439496
return 0;
440497
}
441498

442499
int comAnalyze(string line) {
443-
ofstream logfile;
444500
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);
449502
}
450503
if (line.empty()) {
451504
return 0;
@@ -479,9 +532,6 @@ int comAnalyze(string line) {
479532
else if (line == "help" || line.substr(0, 4) == "help") {
480533
show_help();
481534
}
482-
else if (line == "sumulator_pulsar") {
483-
sumulator_pulsar();
484-
}
485535
else if (line.substr(0, 7) == "account") {
486536
AccountCommand(line);
487537
}
@@ -507,15 +557,16 @@ int comAnalyze(string line) {
507557
line.erase(0, line.find_first_not_of(' '));
508558
line.erase(line.find_last_not_of(' ') + 1);
509559
if (line.starts_with("off")) {
510-
if (isLog == false) {
560+
if (isLog == false) {
511561
cout << "Логирование команд уже выключено " << endl;
512-
return 0; }
562+
return 0;
563+
}
513564
cout << "Логирование команд выключено " << endl;
514565
isLog = false;
515566
}
516567
else if (line.starts_with("on")) {
517568
if (isLog == true) {
518-
cout << "Логирование команд уже включено " << endl;
569+
cout << "Логирование команд уже включено " << endl;
519570
return 0;
520571
}
521572
cout << "Логирование команд включено " << endl;
@@ -527,10 +578,7 @@ int comAnalyze(string line) {
527578
cout << "Очистка лога команд - опасна операция. \n Код опасности 1; \n Выполнить операцию? [Y/n] :";
528579
cin >> answer;
529580
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);
534582
cout << "Лог команд очищен" << endl;
535583
break;
536584
}
@@ -567,12 +615,12 @@ int comAnalyze(string line) {
567615
system(cdmodule.c_str());
568616
}
569617
else {
570-
if(isError) cout << "Ошибка: Команда не распознана. Введите 'help' для справки." << endl;
618+
if (isError) cout << "Ошибка: Команда не распознана. Введите 'help' для справки." << endl;
571619
}
572620
}
573621
}
574622

575-
int startPulsScript(string line) {
623+
int executePulsarScript(string line) {
576624
string comInFile;
577625
if (filesystem::exists(line)) {
578626
fstream scrFile;
@@ -591,8 +639,8 @@ int startPulsScript(string line) {
591639
}
592640
}
593641
scrFile.close();
594-
595-
642+
643+
596644
}
597645

598646
}
@@ -635,43 +683,4 @@ int pulsStarterScript() {
635683
}
636684
scrsFile.close();
637685
}
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-
}
677686
}
File renamed without changes.

public/source/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <chrono>
66
#include <thread>
77
#include <fstream>
8-
#include <Windows.h>;
98
#include <filesystem>
109
#include <cstdlib>
1110

0 commit comments

Comments
 (0)