-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (58 loc) · 1.99 KB
/
main.cpp
File metadata and controls
67 lines (58 loc) · 1.99 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
#include <iostream>
#include <filesystem>
#include "Engine.h"
int main(int argc, char const *argv[])
{
// gets the server address from the user
std::string address;
std::cout << "Enter an address to connect to or nothing to start a server" << std::endl;
getline(std::cin, address);
// gets the port number from the user
int port = 0;
std::string portString;
while (port == 0)
{
std::cout << "Enter a port number" << std::endl;
getline(std::cin, portString);
try
{
port = std::stoi(portString);
}
catch(const std::exception& e)
{
}
}
// gets the folder to sync from the user
std::string syncPath;
while (syncPath.length() == 0)
{
std::cout << "Enter a relative folder path to sync" << std::endl;
getline(std::cin, syncPath);
}
std::filesystem::path path = syncPath;
// continue if the path is relative and (is a server or the path doesnt exist or is empty)
// not the continue condition
while (!(path.is_relative() && (address.length() == 0 || (!std::filesystem::exists(path) || std::filesystem::is_empty(path))))) {
std::cout << "Folder path must be relative to your current working directory" << std::endl;
if (address.length() > 0){
std::cout << "If you are connecting to a server your syncing folder must not exist or must be empty" << std::endl;
}
getline(std::cin, syncPath);
path = syncPath;
}
// startes the engine
Engine* engine;
if (address.length() == 0)
{
std::cout << "Starting server with folder path " << syncPath << " on port " << port << std::endl;
engine = new Engine(syncPath, port);
}
else
{
std::cout << "Connecting to address " << address << " with folder path " << syncPath << " on port " << port << std::endl;
engine = new Engine(syncPath, port, address);
}
engine->loop();
delete engine;
return 0;
}