-
Notifications
You must be signed in to change notification settings - Fork 0
/
location.cpp
40 lines (33 loc) · 956 Bytes
/
location.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
#include "location.h"
#include <filesystem>
#include "mylib.h"
using namespace std;
using namespace filesystem;
path locationOf(const string& recipeName) {
path fname;
path location;
try { //Might throw if there's an invalid path name
//Get the real filename,
//and make sure the recipe file exists
fname = path(recipeName + ".rcp");
}
catch(filesystem_error&) {
throw InvalidFileErr("`" + fname.string() + "' is not a valid file name.");
}
if (exists(config.rcp_path / (recipeName + ".rcp"))) {
location = config.rcp_path / (recipeName + ".rcp");
} else if (exists(config.rcp_path / (recipeName + ".txt"))) {
location = config.rcp_path / (recipeName + ".txt");
}
else {
throw InvalidFileErr("The file for " + recipeName + " was not found.");
}
return location;
}
void readInto(Recipe& recipe)
{
path filename = locationOf(recipe.name);
ifstream recipeFile(filename);
recipeFile >> recipe;
}
Config config;