-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (92 loc) · 3.42 KB
/
main.cpp
File metadata and controls
107 lines (92 loc) · 3.42 KB
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
#include <stdio.h>
#include <curl/curl.h>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include "includes/nlohmann/json.hpp"
#include "internal/message.h"
#include "internal/messagememory.h"
#include "internal/aes.h"
#include "internal/requests.h"
#include "internal/tools.h"
#include "internal/display.h"
#include "internal/colors.h"
#include "internal/importer.h"
#include "internal/themes.h"
#include <chrono>
#include <thread>
using json = nlohmann::json;
const int MCPP_VERSION(1);
const int CONFIG_VERSION(2);
const int PROGRAM_VERSION(6);
const int THEME_VERSION(3);
const int LANGUAGE_VERSION(2);
const std::string VERSION(std::to_string(MCPP_VERSION) + "." + std::to_string(CONFIG_VERSION) + "." + std::to_string(PROGRAM_VERSION));
const int MSG_MAX_SIZE(MsgSettings::msgmaxsize);
int main(int argc, char const *argv[])
{
std::cout << "Starting MicaClient++..." << std::endl;
title("MicaClient++ - Starting...");
displayLogo();
int exitUpdateCode(0), exitSendCode(0);
std::vector<std::string> args(argv, argv + argc);
std::string cfgFilePath("config.json");
bool moderatormode(false);
bool showAll(false);
int processArgs = arguments(args, cfgFilePath, moderatormode, VERSION, showAll);
if (processArgs < 0)
return 100;
else if (processArgs == 1)
return 0;
json themeData, languageData, data;
std::string serverurl, username, token, genkey, cfgPath, input;
bool encryptenabled;
Message::messageSettings msgsettings;
MessageMemory::memorySettings memsettings;
MessageMemory mem;
// import data contained in json files
int icfg = configImporter(MCPP_VERSION, CONFIG_VERSION, MSG_MAX_SIZE, cfgFilePath, data, encryptenabled, moderatormode, genkey, serverurl, username, token, cfgPath, msgsettings, memsettings, showAll);
if (icfg > 0)
return icfg;
icfg = themeImporter(THEME_VERSION, themeData, data);
if (icfg > 0)
return icfg;
icfg = languageImporter(LANGUAGE_VERSION, languageData, data);
if (icfg > 0)
return icfg;
icfg = backupImporter(memsettings, mem, cfgPath);
if (icfg > 0)
return icfg;
//make the logo appears for x seconds
std::this_thread::sleep_for(std::chrono::seconds(themeData["displayLogoDuration"].get<int>()));
int resarg(0);
while (true)
{
exitUpdateCode = getServerUpdate(serverurl, mem, memsettings);
if (exitUpdateCode == 0)
{
clearScreen();
mem.print(languageData, themeData, data, msgsettings);
}
else
{
std::cout << "SERVER/CLIENT ERROR " << exitUpdateCode << std::endl;
printError(2, exitUpdateCode);
return exitUpdateCode;
}
themeVariables tv = themeVariables(false, msgsettings.channel != "", false, msgsettings.modmsg, msgsettings.pseudo, "", "", msgsettings.channel, "", "X");
themeProcessPrint(languageData, themeData, "prompt", tv);
std::cout << printStyle(themeData["messageInput"]["style"]);
std::cin.clear();
std::getline(std::cin, input);
std::cout << NORMAL;
resarg = getArguments(languageData, themeData, mem, msgsettings, serverurl, data, username, token, input, moderatormode, exitUpdateCode, exitSendCode);
if (resarg < 0)
break;
input = "";
}
clearScreen();
std::cout << "Exiting MicaClient++..." << std::endl;
return 0;
}