aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Project.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-04-01 22:18:46 -0700
committerrtk0c <[email protected]>2021-04-01 22:18:46 -0700
commit2f4b9db39239ed5150094a81743beea42a3eedc2 (patch)
tree7d5795f7c23eb4f92ccffe2476da019db9977f2b /core/src/Model/Project.cpp
parent44f5fa5c8f258e8fc1f7d7e2e45e0485bd6cc490 (diff)
Initial work on SQLite database
Diffstat (limited to 'core/src/Model/Project.cpp')
-rw-r--r--core/src/Model/Project.cpp40
1 files changed, 16 insertions, 24 deletions
diff --git a/core/src/Model/Project.cpp b/core/src/Model/Project.cpp
index cdb88c6..c20e0c8 100644
--- a/core/src/Model/Project.cpp
+++ b/core/src/Model/Project.cpp
@@ -21,23 +21,22 @@ void ReadItemList(ItemList<T>& list, const fs::path& filePath) {
}
}
-Project Project::Load(const fs::path& projectFilePath) {
+Project::Project(const fs::path& rootPath)
+ : mRootPath{ rootPath }
+ , mRootPathString{ mRootPath.string() }
+ , mDb(*this) {
// TODO better diagnostic
const char* kInvalidFormatErr = "Failed to load project: invalid format.";
- std::ifstream ifs(projectFilePath);
+ std::ifstream ifs(rootPath / "cplt_project.json");
if (!ifs) {
std::string message;
message += "Failed to load project file at '";
- message += projectFilePath.string();
+ message += rootPath.string();
message += "'.";
throw std::runtime_error(message);
}
- Project proj;
- proj.mRootPath = projectFilePath.parent_path();
- proj.mRootPathString = proj.mRootPath.string();
-
{
Json::Value root;
ifs >> root;
@@ -48,30 +47,23 @@ Project Project::Load(const fs::path& projectFilePath) {
}
if (auto& name = croot["Name"]; name.isString()) {
- proj.mName = name.asString();
+ mName = name.asString();
} else {
throw std::runtime_error(kInvalidFormatErr);
}
}
- auto itemsDir = proj.mRootPath / "items";
- ReadItemList(proj.Products, itemsDir / "products.json");
- ReadItemList(proj.Factories, itemsDir / "factories.json");
- ReadItemList(proj.Customers, itemsDir / "customers.json");
-
- return proj;
-}
-
-Project Project::LoadDir(const std::filesystem::path& projectPath) {
- return Load(projectPath / "cplt_project.json");
+ auto itemsDir = mRootPath / "items";
+ ReadItemList(Products, itemsDir / "products.json");
+ ReadItemList(Factories, itemsDir / "factories.json");
+ ReadItemList(Customers, itemsDir / "customers.json");
}
-Project Project::Create(std::string name, const fs::path& path) {
- Project proj;
- proj.mRootPath = path;
- proj.mRootPathString = path.string();
- proj.mName = std::move(name);
- return proj;
+Project::Project(std::filesystem::path rootPath, std::string name)
+ : mRootPath{ std::move(rootPath) }
+ , mRootPathString{ mRootPath.string() }
+ , mName{ std::move(name) }
+ , mDb(*this) {
}
const fs::path& Project::GetPath() const {