-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (48 loc) · 2.24 KB
/
main.cpp
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
#include <ctime>
#include <iomanip>
#include <iostream>
#include <filesystem>
#include "./src/app/processes/ProcessManagement.hpp"
#include "./src/app/processes/Task.hpp"
namespace fs = std::filesystem;
int main(int argc, char *argv[]) {
std::string directory;
std::string actionStr;
std::cout<<"Enter the directory path: ";
std::getline(std::cin, directory);
std::cout<<"Enter the action (ENCRYPT/DECRYPT): ";
std::getline(std::cin, actionStr);
try {
if(fs::exists(directory) && fs::is_directory(directory)) {
ProcessManagement ProcessManagement;
for(const auto &entry : fs::recursive_directory_iterator(directory)) {
if(entry.is_regular_file()) {
std::string filePath = entry.path().string();
IO io(filePath);
std::fstream f_stream = std::move(io.getFileStream());
if(f_stream.is_open()) {
Action action = (actionStr == "ENCRYPT") ? Action::ENCRYPT : Action::DECRYPT;
auto task = std::make_unique<Task>(std::move(f_stream), action, filePath);
std::time_t t = std::time(nullptr);
std::tm* now = std::localtime(&t);
std::cout << "Starting the encryption/decryption at: " << std::put_time(now, "%Y-%m-%d %H:%M:%S") << std::endl;
if (!task) {
std::cerr << "Failed to create task for file: " << filePath << std::endl;
continue;
}
ProcessManagement.submitToQueue(std::move(task));
} else {
std::cout<<"Error opening file: " << filePath << std::endl;
}
} else {
std::cout<<"Skipping directory: " << entry.path().string() << std::endl;
}
}
} else {
std::cout<<"Invalid directory path: " << directory << std::endl;
}
} catch(const fs::filesystem_error &e) {
std::cout<<"Filesystem Error: " << e.what() << std::endl;
}
return 0;
}