-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecentProjectService.cpp
More file actions
66 lines (56 loc) · 1.35 KB
/
recentProjectService.cpp
File metadata and controls
66 lines (56 loc) · 1.35 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
#include "services/recentProjectService.hpp"
#include "raylib.h"
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
RecentProjectService::RecentProjectService() {
path = GetWorkingDirectory();
path /= RPGPP_RECENT_FILE;
if (!std::filesystem::exists(path)) {
std::ofstream file(path);
file.close();
}
std::ifstream file(path);
if (!file.is_open()) {
std::cerr << "Failed to open recent project file" << std::endl;
return;
}
std::string s;
while (std::getline(file, s)) {
if (!std::filesystem::exists(s)) {
continue;
}
recentProjects.push_back(s);
}
file.close();
save();
}
void RecentProjectService::save() {
std::ofstream file(path);
if (!file.is_open()) {
std::cerr << "Failed to open recent project file for saving"
<< std::endl;
return;
}
for (auto i = recentProjects.begin(); i != recentProjects.end(); ++i) {
file << *i << std::endl;
}
file.close();
}
void RecentProjectService::enqueue(const std::string &projectPath) {
for (auto i = recentProjects.begin(); i != recentProjects.end(); ++i) {
if (*i == projectPath) {
recentProjects.erase(i);
break;
}
}
recentProjects.push_front(projectPath);
if (recentProjects.size() > limit) {
recentProjects.pop_back();
}
save();
}
const std::deque<std::string> &RecentProjectService::getRecentProjects() const {
return recentProjects;
}