#include <Lib.h>
#include <Lib/Grafica.h>
using namespace Grafica;
using namespace std;
#define TRAIDING 1
#define RETURN_COYN 2
#define DATA_COYN 3
#define COYN 4
typedef const char* CDATA;
//string sha256(string msg);
//string toHex(unsigned int num);
// Costanti per la funzione hash SHA-256
const unsigned int K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
string sha256(string msg) {
// Inizializzazione dei valori intermedi di hash
unsigned int H[8] = {
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
};
// Preparazione del messaggio
unsigned int len = msg.length();
unsigned int padLen = 64 - ((len + 9) % 64);
if (padLen < 1) {
padLen += 64;
}
unsigned char* paddedMsg = new unsigned char[len + padLen + 8];
for (unsigned int i = 0; i < len; i++) {
paddedMsg[i] = msg[i];
}
paddedMsg[len] = 0x80;
for (unsigned int i = len + 1; i < len + padLen; i++) {
paddedMsg[i] = 0x00;
}
unsigned long long bitLen = len * 8;
for (int i = 0; i < 8; i++) {
paddedMsg[len + padLen + i] = (unsigned char)(bitLen >> (56 - (i * 8)));
}
// Elaborazione del messaggio per blocchi di 512 bit
for (unsigned int i = 0; i < len + padLen + 8; i += 64) {
unsigned int W[64];
for (int j = 0; j < 16; j++) {
W[j] = ((unsigned int)paddedMsg[i + (j * 4)] << 24)
| ((unsigned int)paddedMsg[i + (j * 4) + 1] << 16)
| ((unsigned int)paddedMsg[i + (j * 4) + 2] << 8)
| ((unsigned int)paddedMsg[i + (j * 4) + 3]);
}
for (int j = 16; j < 64; j++) {
unsigned int s0 = ((W[j - 15] >> 7) | (W[j - 15] << 25))
^ ((W[j - 15] >> 18) | (W[j - 15] << 14))
^ (W[j - 15] >> 3);
unsigned int s1 = ((W[j - 2] >> 17) | (W[j - 2] << 15))
^ ((W[j - 2] >> 19) | (W[j - 2] << 13))
^ (W[j - 2] >> 10);
W[j] = W[j - 16] + s0 + W[j - 7] + s1;
}
unsigned int a = H[0];
unsigned int b = H[1];
unsigned int c = H[2];
unsigned int d = H[3];
unsigned int e = H[4];
unsigned int f = H[5];
unsigned int g = H[6];
unsigned int h = H[7];
for (int j = 0; j < 64; j++) {
unsigned int S1 = ((e >> 6) | (e << 26))
^ ((e >> 11) | (e << 21))
^ ((e >> 25) | (e << 7));
unsigned int ch = (e & f) ^ ((~e) & g);
unsigned int temp1 = h + S1 + ch + K[j] + W[j];
unsigned int S0 = ((a >> 2) | (a << 30))
^ ((a >> 13) | (a << 19))
^ ((a >> 22) | (a << 10));
unsigned int maj = (a & b) ^ (a & c) ^ (b & c);
unsigned int temp2 = S0 + maj;
h = g;
g = f;
f = e;
e = d + temp1;
d = c;
c = b;
b = a;
a = temp1 + temp2;
}
H[0] += a;
H[1] += b;
H[2] += c;
H[3] += d;
H[4] += e;
H[5] += f;
H[6] += g;
H[7] += h;
}
// Costruzione dell'hash finale
std::ostringstream result;
for (int i = 0; i < 8; i++) {
result << std::hex << std::setfill('0') << std::setw(8) << H[i];
}
delete[] paddedMsg;
return result.str();
}
struct Process
{
HANDLE* Traiding;
DWORD* TraidingError = NULL;
BOOL TraidingErrorNum = NULL;
PCHAR TraidingCom = nullptr;
DWORD TraidingNum = NULL;
LPCWCH TraidingPer;
HANDLE* ReturnCoyn;
DWORD* ReturnCoynError = NULL;
BOOL ReturnCoynErrorNum = NULL;
PCHAR ReturnCoyngCom = nullptr;
DWORD ReturnCoynNum = NULL;
LPCWCH ReturnCoynPer;
HANDLE* DataCoyn;
DWORD* DataCoynError = NULL;
BOOL DataCoynErrorNum = NULL;
PCHAR DataCoynCom = nullptr;
DWORD DataCoynNum = NULL;
LPCWCH DataCoynPer;
HANDLE* Coyn;
DWORD* CoynError = NULL;
BOOL CoynErrorNum = NULL;
PCHAR CoynCom = nullptr;
DWORD CoynNum = NULL;
LPCWCH CoynPer;
void Process_Free() {
delete Traiding;
delete[] TraidingError;
delete[] TraidingCom;
delete ReturnCoyn;
delete[] ReturnCoynError;
delete[] ReturnCoyngCom;
delete DataCoyn;
delete[] DataCoynError;
delete[] DataCoynCom;
delete Coyn;
delete[] CoynError;
delete[] CoynCom;
}
};
void Process_Per(Process& Process) {
Process.TraidingPer = TEXT("C:\\Users\\alext\\Desktop\\Traiding_C++\\x64\\Debug\\Traiding_C++.exe");
Process.ReturnCoynPer = TEXT("C:\\Users\\alext\\Desktop\\Traiding_C++\\Traiding_C++\\Return_Coyn\\x64\\Debug\\Return_Coyn.exe");
Process.DataCoynPer = TEXT("C:\\Users\\alext\\Desktop\\Traiding_C++\\Traiding_C++\\Data_Coyn\\x64\\Debug\\Data_Coyn.exe");
Process.CoynPer = TEXT("C:\\Users\\alext\\Desktop\\Traiding_C++\\Traiding_C++\\Coyn\\x64\\Debug\\Coyn.exe");
Process.TraidingCom = new char[strlen("_Traiding") + 1];
strcpy(Process.TraidingCom, "_Traiding");
Process.ReturnCoyngCom = new char[strlen("_ReturnCoyn") + 1];
strcpy(Process.ReturnCoyngCom, "_ReturnCoyn");
Process.DataCoynCom = new char[strlen("_DataCoyn") + 1];
strcpy(Process.DataCoynCom, "_DataCoyn");
Process.CoynCom = new char[strlen("_Coyn") + 1];
strcpy(Process.CoynCom, "_Coyn");
}
/*
void DirectoryCleaning(const char* path) {
std::string pathWithWildcard = std::string(path) + "\\*";
WIN32_FIND_DATAA fileData;
HANDLE hFind = FindFirstFileA(pathWithWildcard.c_str(), &fileData);
if (hFind == INVALID_HANDLE_VALUE) { std::cout << "Errore nella ricerca dei file nella directory" << endl; }
do
{
if (strcmp(fileData.cFileName, ".") != 0 && strcmp(fileData.cFileName, "..") != 0)
{
std::string fullPath = std::string(path) + "\\" + fileData.cFileName;
if (DeleteFileA(fullPath.c_str()) == FALSE)
{
std::cout << "Errore nella cancellazione del file " << fullPath << endl;
}
}
} while (FindNextFileA(hFind, &fileData) != FALSE);
FindClose(hFind);
}*/
bool IsFile(const char* path)
{
DWORD attributes = GetFileAttributesA(path);
if (attributes == INVALID_FILE_ATTRIBUTES)
{
// Il percorso non esiste
return false;
}
return (attributes & FILE_ATTRIBUTE_DIRECTORY) == 0;
}
void DirectoryCleaning(const char* path) {
std::string pathWithWildcard = std::string(path) + "\\*";
WIN32_FIND_DATAA fileData;
if (GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES && (GetFileAttributesA(path) & FILE_ATTRIBUTE_DIRECTORY)) {
HANDLE hFind = FindFirstFileA(pathWithWildcard.c_str(), &fileData);
if (hFind == INVALID_HANDLE_VALUE) { std::cout << "Errore nella ricerca dei file nella directory" << endl; }
while (FindNextFileA(hFind, &fileData))
{
if (strcmp(fileData.cFileName, ".") != 0 && strcmp(fileData.cFileName, "..") != 0)
{
std::string fullPath = std::string(path) + "\\" + fileData.cFileName;
if (IsFile(fullPath.c_str())) {
if (DeleteFileA(fullPath.c_str()) == FALSE)
{
std::cout << "Errore nella cancellazione del file " << fullPath << endl;
}
}
}
}
FindClose(hFind);
}
else {
cout << "Cartella -> " << path << " <- non esiste" << endl;
}
}
struct Comunicazione
{
PCHAR Data = nullptr;
PCHAR New = nullptr;
PCHAR Close = nullptr;
PCHAR DataD = nullptr;
PCHAR Input = nullptr;
PCHAR Output = nullptr;
PCHAR Controllo = nullptr;
PCHAR NewS = nullptr;
PCHAR CloseS = nullptr;
PCHAR DataDS = nullptr;
PCHAR InputS = nullptr;
PCHAR OutputS = nullptr;
PCHAR ControlloS = nullptr;
PCHAR Est = (char*)".txt";
// Costruttore
Comunicazione(LPCSTR data)
{
size_t dataSize = strlen(data);
Data = new CHAR[dataSize + 1];
strcpy_s(Data, dataSize + 1, data);
size_t subFolderSize = strlen("\\New");
New = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(New, dataSize + subFolderSize + 1, data);
strcat_s(New, dataSize + subFolderSize + 1, "\\New");
subFolderSize = strlen("\\Close");
Close = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(Close, dataSize + subFolderSize + 1, data);
strcat_s(Close, dataSize + subFolderSize + 1, "\\Close");
subFolderSize = strlen("\\Data");
DataD = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(DataD, dataSize + subFolderSize + 1, data);
strcat_s(DataD, dataSize + subFolderSize + 1, "\\Data");
subFolderSize = strlen("\\Data\\Input");
Input = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(Input, dataSize + subFolderSize + 1, data);
strcat_s(Input, dataSize + subFolderSize + 1, "\\Data\\Input");
subFolderSize = strlen("\\Data\\Output");
Output = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(Output, dataSize + subFolderSize + 1, data);
strcat_s(Output, dataSize + subFolderSize + 1, "\\Data\\Output");
subFolderSize = strlen("\\Data\\Controllo");
Controllo = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(Controllo, dataSize + subFolderSize + 1, data);
strcat_s(Controllo, dataSize + subFolderSize + 1, "\\Data\\Controllo");
subFolderSize = strlen("\\New\\");
NewS = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(NewS, dataSize + subFolderSize + 1, data);
strcat_s(NewS, dataSize + subFolderSize + 1, "\\New\\");
subFolderSize = strlen("\\Close\\");
CloseS = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(CloseS, dataSize + subFolderSize + 1, data);
strcat_s(CloseS, dataSize + subFolderSize + 1, "\\Close\\");
subFolderSize = strlen("\\Data\\");
DataDS = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(DataDS, dataSize + subFolderSize + 1, data);
strcat_s(DataDS, dataSize + subFolderSize + 1, "\\Data\\");
subFolderSize = strlen("\\Data\\Input\\");
InputS = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(InputS, dataSize + subFolderSize + 1, data);
strcat_s(InputS, dataSize + subFolderSize + 1, "\\Data\\Input\\");
subFolderSize = strlen("\\Data\\Output\\");
OutputS = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(OutputS, dataSize + subFolderSize + 1, data);
strcat_s(OutputS, dataSize + subFolderSize + 1, "\\Data\\Output\\");
subFolderSize = strlen("\\Data\\Controllo\\");
ControlloS = new CHAR[dataSize + subFolderSize + 1];
strcpy_s(ControlloS, dataSize + subFolderSize + 1, data);
strcat_s(ControlloS, dataSize + subFolderSize + 1, "\\Data\\Controllo\\");
}
void DirectoryCleaningComunicazione() {
DirectoryCleaning(Data);
DirectoryCleaning(New);
DirectoryCleaning(Close);
DirectoryCleaning(DataD);
DirectoryCleaning(Input);
DirectoryCleaning(Output);
DirectoryCleaning(Controllo);
}
// Distruttore
~Comunicazione()
{
delete[] Data;
delete[] New;
delete[] Close;
delete[] DataD;
delete[] Input;
delete[] Output;
delete[] Controllo;
delete[] NewS;
delete[] CloseS;
delete[] DataDS;
delete[] InputS;
delete[] OutputS;
delete[] ControlloS;
}
};
struct PosizioneCursore
{
COORD PosCar;
COORD PosAtt;
void ApperndPosAttX(int X, int Y) {
PosAtt.X = X;
PosAtt.Y = Y;
}
void ApperndPosAttY(int Y, int X) {
PosAtt.Y = Y;
PosAtt.X = X;
}
void Cycliner() {
PosCar.X = NULL;
PosCar.Y = NULL;
PosAtt.X = NULL;
PosAtt.Y = NULL;
}
};
//CREATE_NO_WINDOW
HANDLE StartProcess(LPCWCH Process) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (!CreateProcessW(Process, NULL, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
cout << "CreateProcess failed " << GetLastError() << "." << endl;
return NULL;
}
CloseHandle(pi.hThread);
if (pi.hProcess == NULL || pi.hProcess == INVALID_HANDLE_VALUE) {
printf("Invalid process handle.\n");
return NULL;
}
return pi.hProcess;
}
// Funzione per controllare se un processo con un determinato PID è in esecuzione
bool IsProcessRunning(DWORD pid)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (entry.th32ProcessID == pid)
{
CloseHandle(snapshot);
return true;
}
}
}
CloseHandle(snapshot);
return false;
}
// Funzione per controllare se un processo figlio è in esecuzione sotto a un processo padre
bool IsChildProcessRunning(HANDLE hParentProcess, HANDLE hChildProcess)
{
DWORD parentPid = GetProcessId(hParentProcess);
DWORD childPid = GetProcessId(hChildProcess);
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (entry.th32ParentProcessID == parentPid && entry.th32ProcessID == childPid)
{
CloseHandle(snapshot);
return IsProcessRunning(childPid);
}
}
}
CloseHandle(snapshot);
return false;
}
int GetFileSizeInKB(const char* filepath) {
WIN32_FILE_ATTRIBUTE_DATA fileInfo;
if (!GetFileAttributesExA(filepath, GetFileExInfoStandard, &fileInfo)) {
std::cerr << "Error: failed to get file attributes.\n";
return -1;
}
ULARGE_INTEGER size;
size.LowPart = fileInfo.nFileSizeLow;
size.HighPart = fileInfo.nFileSizeHigh;
return static_cast<int>(size.QuadPart);
}
char* CreateProcessControlPer(char* Per, int N_Pro, char* Est) {
char* Per_0 = new char[strlen(Per) + 1];
strcpy(Per_0, Per);
char* Per_1 = strcat(Per_0, (const char*)to_string(N_Pro).c_str());
char* Per_2 = strcat(Per_1, Est);
return Per_2;
}
void ControlProcess(char* Cont) {
FILE* Control = fopen(Cont, "w");
fclose(Control);
}
void StartProcess(char* Cont) {
FILE* Control = fopen(Cont, "w");
fclose(Control);
}
void CloseProcess(char* Cont) {
FILE* Control = fopen(Cont, "w");
fclose(Control);
}
char* ConCat(char* Cartella, char* File) {
char* CartellaNew = new char[strlen(Cartella) + 1];
strcpy(CartellaNew, Cartella);
char* ConCat = strcat(CartellaNew, File);
return ConCat;
}
bool ControlTF(int CileFor, int Sle, char* Per) {
for (int y = 0; y <= CileFor - 1; y++) {
Sleep(Sle);
if (GetFileSizeInKB(Per) != 0) {
y = CileFor;
return true;
}
}
return false;
}
void IDprocess(char* pach, int ID) {
FILE* File = fopen(pach, "w");
if (File != NULL) {
fprintf(File, to_string(ID).c_str());
fclose(File);
}
}
bool askUser(int TI, const char* TIC, int TS, const char* TSC) {
string input;
while (true) {
ColorText(TI, TIC);
ColorText(TS, TSC);
cin >> input;
if (input == "y" || input == "Y") {
return true;
}
else if (input == "n" || input == "N") {
return false;
}
}
}
bool SycurityUser(int TI, const char* TIC, const char* PAS) {
string input;
while (true) {
ColorText(TI, TIC);
cin >> input;
if (strcmp(input.c_str(), PAS) == 0) {
return true;
}
else {
return false;
}
}
}
// Esempio uso IsChildProcessRunning: IsChildProcessRunning(GetCurrentProcess(), Process.Coyn[0]);
HANDLE Start_Coyn() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
TCHAR szPath[] = TEXT("C:\\Users\\alext\\Desktop\\Traiding_C++\\x64\\Debug\\Traiding_C++.exe");
if (!CreateProcessW(szPath, NULL, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
printf("CreateProcess failed (%d).\n", GetLastError());
return NULL;
}
CloseHandle(pi.hThread);
if (pi.hProcess == NULL || pi.hProcess == INVALID_HANDLE_VALUE) {
printf("Invalid process handle.\n");
return NULL;
}
return pi.hProcess;
}
int main()
{
Process Process;
Process_Per(Process);
Comunicazione Comunicazione("C:\\Users\\alext\\Desktop\\Traiding_C++\\Traiding_C++\\Data");
PosizioneCursore Posizione;
//Start_Coyn();
//StartProcess(Process.TraidingPer);
//system("pause");
int total = 203;
int progress = 0;
char* Start = NULL;
cout << "Preparazione del programma" << endl;
if (askUser(color::Verde, "Sicuro di voler far partire il programma? ", color::Verde, "(y/n) ")) {
Comunicazione.DirectoryCleaningComunicazione();
// Simula il caricamento
Posizione.Cycliner();
Posizione.PosCar = getxy();
Posizione.ApperndPosAttY(Posizione.PosCar.Y + 1, NULL);
while (!PrintProgressBar(progress, total, true, color::Green, color::Green, color::Fucsia, color::Bordeaux)) {
gotoxy(Posizione.PosAtt);
bool ExitStartProcess = true;
switch (progress)
{
case 0:
IDprocess(ConCat(Comunicazione.DataDS, (char*)"IDprocess.txt"), 0);
while (ExitStartProcess)
{
Process.Traiding = new HANDLE;
Process.Traiding[0] = StartProcess(Process.TraidingPer);
if (Process.Traiding[0] != NULL) {
ControlProcess(CreateProcessControlPer(Comunicazione.ControlloS, 0, ConCat(Process.TraidingCom, Comunicazione.Est)));
if (ControlTF(20, 1, CreateProcessControlPer(Comunicazione.ControlloS, 0, ConCat(Process.TraidingCom, Comunicazione.Est)))) {
Sleep(10);
ExitStartProcess = false;
Process.TraidingNum++;
progress++;
}
else {
TerminateProcess(Process.Traiding[0], 1);
DirectoryCleaning(Comunicazione.Controllo);
}
}
}
break;
case 1:
IDprocess(ConCat(Comunicazione.DataDS, (char*)"IDprocess.txt"), 0);
while (ExitStartProcess)
{
Process.ReturnCoyn = new HANDLE;
Process.ReturnCoyn[0] = StartProcess(Process.ReturnCoynPer);
if (Process.ReturnCoyn[0] != NULL) {
ControlProcess(CreateProcessControlPer(Comunicazione.ControlloS, 0, ConCat(Process.ReturnCoyngCom, Comunicazione.Est)));
if (ControlTF(20, 1, CreateProcessControlPer(Comunicazione.ControlloS, 0, ConCat(Process.ReturnCoyngCom, Comunicazione.Est)))) {
Sleep(10);
ExitStartProcess = false;
Process.ReturnCoynNum++;
progress++;
}
else {
TerminateProcess(Process.ReturnCoyn[0], 1);
DirectoryCleaning(Comunicazione.Controllo);
}
}
}
break;
case 2:
IDprocess(ConCat(Comunicazione.DataDS, (char*)"IDprocess.txt"), 0);
while (ExitStartProcess)
{
Process.DataCoyn = new HANDLE;
Process.DataCoyn[0] = StartProcess(Process.DataCoynPer);
if (Process.DataCoyn[0] != NULL) {
ControlProcess(CreateProcessControlPer(Comunicazione.ControlloS, 0, ConCat(Process.DataCoynCom, Comunicazione.Est)));
if (ControlTF(20, 1, CreateProcessControlPer(Comunicazione.ControlloS, 0, ConCat(Process.DataCoynCom, Comunicazione.Est)))) {
Sleep(10);
ExitStartProcess = false;
Process.DataCoynNum++;
progress++;
}
else {
TerminateProcess(Process.DataCoyn[0], 1);
DirectoryCleaning(Comunicazione.Controllo);
}
}
}
break;
default:
IDprocess(ConCat(Comunicazione.DataDS, (char*)"IDprocess.txt"), Process.CoynNum);
while (ExitStartProcess)
{
Process.Coyn = new HANDLE;
Process.Coyn[Process.CoynNum] = StartProcess(Process.CoynPer);
if (Process.Coyn[Process.CoynNum] != NULL) {
ControlProcess(CreateProcessControlPer(Comunicazione.ControlloS, Process.CoynNum, Comunicazione.Est));
if (ControlTF(20, 1, CreateProcessControlPer(Comunicazione.ControlloS, Process.CoynNum, Comunicazione.Est))) {
Sleep(10);
ExitStartProcess = false;
Process.CoynNum++;
progress++;
}
else {
TerminateProcess(Process.Coyn[Process.CoynNum], 1);
DirectoryCleaning(Comunicazione.Controllo);
}
}
}
break;
}
Posizione.PosAtt = getxy();
gotoxy(Posizione.PosCar);
}
gotoxy(Posizione.PosAtt);
Sleep(1000);
DirectoryCleaning(Comunicazione.Controllo);
cout << "Programma pronto per partire" << endl;
StartProcess(ConCat(Comunicazione.DataDS, (char*)"Start.txt"));
if (askUser(color::Verde, "Start Program? ", color::Verde, "(y/n) ")) {
StartProcess(ConCat(Comunicazione.DataDS, (char*)"Start.txt"));
/*(GetAsyncKeyState(VK_CONTROL) & 0x8000) &&
(GetAsyncKeyState('X') & 0x8000) &&
(GetAsyncKeyState(VK_SHIFT) & 0x8000)*/
}
else {
if (SycurityUser(color::Verde, "Sei sicuro di voler chiudere il programma, inserichi il PIN: ", "12345")) {
CloseProcess(ConCat(Comunicazione.CloseS, (char*)"Close.txt"));
progress = 0;
total + 1;
Posizione.Cycliner();
Posizione.PosCar = getxy();
Posizione.ApperndPosAttY(Posizione.PosCar.Y + 1, NULL);
while (!PrintProgressBar(progress, total, true, color::Green, color::Green, color::Fucsia, color::Bordeaux)) {
gotoxy(Posizione.PosAtt);
if (progress <= Process.CoynNum - 1) {
CloseProcess(CreateProcessControlPer(Comunicazione.CloseS, progress, Comunicazione.Est));
progress++;
}
else if (progress - Process.CoynNum <= Process.DataCoynNum - 1) {
CloseProcess(CreateProcessControlPer(Comunicazione.CloseS, progress - Process.CoynNum, ConCat(Process.DataCoynCom, Comunicazione.Est)));
progress++;
}
else if (progress - Process.CoynNum - Process.DataCoynNum <= Process.ReturnCoynNum - 1) {
CloseProcess(CreateProcessControlPer(Comunicazione.CloseS, progress - Process.CoynNum - Process.DataCoynNum, ConCat(Process.ReturnCoyngCom, Comunicazione.Est)));
progress++;
}
else if (progress - Process.CoynNum - Process.DataCoynNum - Process.ReturnCoynNum <= Process.TraidingNum - 1) {
CloseProcess(CreateProcessControlPer(Comunicazione.CloseS, progress - Process.CoynNum - Process.DataCoynNum - Process.ReturnCoynNum, ConCat(Process.TraidingCom, Comunicazione.Est)));
progress++;
}
else {
Sleep(5000);
progress++;
}
Posizione.PosAtt = getxy();
gotoxy(Posizione.PosCar);
}
gotoxy(Posizione.PosAtt);
total - 1;
progress = 0;
Posizione.Cycliner();
Posizione.PosCar = getxy();
Posizione.ApperndPosAttY(Posizione.PosCar.Y + 1, NULL);
while (!PrintProgressBar(progress, total, true, color::Green, color::Green, color::Fucsia, color::Bordeaux)) {
gotoxy(Posizione.PosAtt);
if (progress <= Process.CoynNum - 1) {
if (!ControlTF(10, 1, CreateProcessControlPer(Comunicazione.CloseS, progress, Comunicazione.Est))) {
Process.CoynError[Process.CoynErrorNum] = progress;
Process.CoynErrorNum++;
}
progress++;
}
else if (progress - Process.CoynNum <= Process.DataCoynNum - 1) {
if (!ControlTF(10, 1, CreateProcessControlPer(Comunicazione.CloseS, progress - Process.CoynNum, ConCat(Process.DataCoynCom, Comunicazione.Est)))) {
Process.DataCoynError[Process.DataCoynErrorNum] = progress;
Process.DataCoynErrorNum++;
}
progress++;
}
else if (progress - Process.CoynNum - Process.DataCoynNum <= Process.ReturnCoynNum - 1) {
if (!ControlTF(10, 1, CreateProcessControlPer(Comunicazione.CloseS, progress - Process.CoynNum - Process.DataCoynNum, ConCat(Process.ReturnCoyngCom, Comunicazione.Est)))) {
Process.ReturnCoynError[Process.ReturnCoynErrorNum] = progress;
Process.ReturnCoynErrorNum++;
}
progress++;
}
else if (progress - Process.CoynNum - Process.DataCoynNum - Process.ReturnCoynNum <= Process.TraidingNum - 1) {
if (!ControlTF(500, 10, CreateProcessControlPer(Comunicazione.CloseS, progress - Process.CoynNum - Process.DataCoynNum - Process.ReturnCoynNum, ConCat(Process.TraidingCom, Comunicazione.Est)))) {
Process.TraidingError[Process.TraidingErrorNum] = progress;
Process.TraidingErrorNum++;
}
progress++;
}
else {
}
Posizione.PosAtt = getxy();
gotoxy(Posizione.PosCar);
}
gotoxy(Posizione.PosAtt);
total = Process.CoynErrorNum + Process.DataCoynErrorNum + Process.ReturnCoynErrorNum + Process.TraidingErrorNum;
progress = 0;
if (total != 0) {
ColorText(color::Red, "Errore Terminate Process, Avvio ciusura FORZATA ");
cout << endl;
Posizione.Cycliner();
Posizione.PosCar = getxy();
Posizione.ApperndPosAttY(Posizione.PosCar.Y + 1, NULL);
while (!PrintProgressBar(progress, total, true, color::Green, color::Green, color::Fucsia, color::Bordeaux)) {
gotoxy(Posizione.PosAtt);
if (progress <= Process.CoynNum - 1 && Process.CoynNum != 0) {
if (TerminateProcess(Process.Coyn[Process.CoynError[progress]], 1)) {
ColorTextSet(color::Verde);
cout << "Processo 'COYN' Num -> " << Process.CoynError[progress] << " <- Terminato.";
ColorTextSet(color::Bianco);
}
else {
ColorTextSet(color::Bordeaux);
cout << "ERROR " << GetLastError() << ": Impossibile terminare il processo";
ColorTextSet(color::Bianco);
}
progress++;
}
else if (progress - Process.CoynNum <= Process.DataCoynNum - 1 && Process.DataCoynNum != 0) {
if (TerminateProcess(Process.DataCoyn[Process.DataCoynError[progress - Process.CoynNum]], 1)) {
ColorTextSet(color::Verde);
cout << "Processo 'DATACOYN' Num -> " << Process.DataCoynError[progress - Process.CoynNum] << " <- Terminato.";
ColorTextSet(color::Bianco);
}
else {
ColorTextSet(color::Bordeaux);
cout << "ERROR " << GetLastError() << ": Impossibile terminare il processo";
ColorTextSet(color::Bianco);
}
progress++;
}
else if (progress - Process.CoynNum - Process.DataCoynNum <= Process.ReturnCoynNum - 1 && Process.ReturnCoynNum != 0) {
if (TerminateProcess(Process.ReturnCoyn[Process.ReturnCoynError[progress - Process.CoynNum - Process.DataCoynNum]], 1)) {
ColorTextSet(color::Verde);
cout << "Processo 'RETURNCOYN' Num -> " << Process.ReturnCoynError[progress - Process.CoynNum - Process.DataCoynNum] << " <- Terminato.";
ColorTextSet(color::Bianco);
}
else {
ColorTextSet(color::Bordeaux);
cout << "ERROR " << GetLastError() << ": Impossibile terminare il processo";
ColorTextSet(color::Bianco);
}
progress++;
}
else if (progress - Process.CoynNum - Process.DataCoynNum - Process.ReturnCoynNum <= Process.TraidingNum - 1 && Process.TraidingNum != 0) {
if (TerminateProcess(Process.Traiding[Process.TraidingError[progress - Process.CoynNum - Process.DataCoynNum - Process.ReturnCoynNum]], 1)) {
ColorTextSet(color::Verde);
cout << "Processo 'TRAIDING' Num -> " << Process.TraidingError[progress - Process.CoynNum - Process.DataCoynNum - Process.ReturnCoynNum] << " <- Terminato.";
ColorTextSet(color::Bianco);
}
else {
ColorTextSet(color::Bordeaux);
cout << "ERROR " << GetLastError() << ": Impossibile terminare il processo";
ColorTextSet(color::Bianco);
}
progress++;
}
else {
}
Posizione.PosAtt = getxy();
gotoxy(Posizione.PosCar);
}
gotoxy(Posizione.PosAtt);
}
Process.Process_Free();
Comunicazione.~Comunicazione();
}
}
}
else {
Process.Process_Free();
Comunicazione.~Comunicazione();
}
system("pause");
//return 0;
}