blob: 7be5e0184dde75a0447a3902abd5292f16d23f9b (
plain)
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
|
#include "cmd.h"
#include "settings.h"
#include <vector>
#include <string>
#include <filesystem>
#include <algorithm>
namespace cmd {
std::vector<std::string> getVirtDirs() {
return {"weapons", "armor", "spells", "creatures"};
}
// Not idempotent: only do once!
std::filesystem::path getTruePath(std::filesystem::path virtPath) {
std::filesystem::path p;
auto virtPaths = getVirtDirs();
if(std::find(virtPaths.begin(), virtPaths.end(), *virtPath.begin()) != virtPaths.end()) {
p = settings::getString(*virtPath.begin());
// Erase root (part to be replaced by virtPaths)
std::filesystem::path tmp;
auto it = virtPath.begin();
while(++it != virtPath.end()) {
tmp /= *it;
}
virtPath = tmp;
} else {
p = settings::getString("savedir");
}
p /= virtPath;
if(std::filesystem::directory_entry(p.string() + ".json").is_regular_file()) return p.string() + ".json";
return p;
}
}
|