summaryrefslogtreecommitdiffhomepage
path: root/statistics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'statistics.cpp')
-rw-r--r--statistics.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/statistics.cpp b/statistics.cpp
index 1d67bfd..fb7148b 100644
--- a/statistics.cpp
+++ b/statistics.cpp
@@ -8,14 +8,14 @@ namespace fs = std::filesystem;
using namespace std::string_literals;
namespace {
- const fs::path statsfilepath{ "/var/lib/webserver/stats.db" };
+ const fs::path default_statsfilepath{ "stats.db" };
} // anonymous namespace
void Statistics::load()
{
std::lock_guard<std::mutex> lock(mMutex);
std::cout << "Loading statistics..." << std::endl;
- std::ifstream file{statsfilepath, std::ios::in | std::ios::binary};
+ std::ifstream file{mPath, std::ios::in | std::ios::binary};
if (file.is_open()) {
Reichwein::Serialization::IArchive archive{file};
@@ -32,7 +32,7 @@ void Statistics::save()
if (mChanged) {
std::lock_guard<std::mutex> lock(mMutex);
std::cout << "Saving statistics..." << std::endl;
- std::ofstream file{statsfilepath, std::ios::out | std::ios::binary | std::ios::trunc};
+ std::ofstream file{mPath, std::ios::out | std::ios::binary | std::ios::trunc};
if (file.is_open()) {
Reichwein::Serialization::OArchive archive{file};
@@ -45,7 +45,12 @@ void Statistics::save()
}
}
-Statistics::Statistics()
+Statistics::Statistics(): mPath{default_statsfilepath}
+{
+ load();
+}
+
+Statistics::Statistics(const fs::path& path): mPath{path.empty() ? default_statsfilepath : path}
{
load();
}