Repository navigation
Expand file tree
/
Copy pathSettings.cpp
More file actions
63 lines (52 loc) · 1.48 KB
/
Copy pathSettings.cpp
File metadata and controls
63 lines (52 loc) · 1.48 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
//
// Created by Oliver Mrovcak on 05/01/2024.
//
#include "Settings.h"
#include <iomanip>
#include <chrono>
Settings::Settings() {
this->savePath = loadSavePath();
}
Settings::~Settings() {
}
void Settings::saveDownload(std::string url, std::string path) {
std::ofstream file;
file.open("../history.txt", std::ios_base::app);
if (!file.is_open()) {
std::cerr << "Failed to open history.txt for appending." << std::endl;
return;
}
auto now = std::chrono::system_clock::now();
auto in_time_t = std::chrono::system_clock::to_time_t(now);
file << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d %X") << " - " << url << " " << path << std::endl;
file.close();
}
std::string Settings::loadSavePath() {
std::ifstream file("../settings.txt");
std::string line;
if (file.is_open()) {
// Assuming the path is on the first line
std::getline(file, line);
file.close();
} else {
std::cerr << "Unable to open file" << std::endl;
}
return line;
}
std::vector<std::string> Settings::loadHistory() {
std::ifstream file("../history.txt");
std::vector<std::string> lines;
std::string line;
if (file.is_open()) {
while (std::getline(file, line)) {
lines.push_back(line);
}
file.close();
} else {
std::cerr << "Unable to open file: history.txt" << std::endl;
}
return lines;
}
std::string Settings::getSavePath() {
return this->savePath;
}