summaryrefslogtreecommitdiff
path: root/src/views.cpp
blob: f03d794ed60730783dce31dbb2acb2b4530cc74c (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
34
35
36
37
38
39
40
#include "views.hpp"

#include <fstream>
#include <filesystem>

namespace {
    const std::filesystem::path viewsFilePath = "data/views.txt";
}

int loadViews()
{
    std::ifstream file(viewsFilePath);

    int views = 0;

    if (!file.is_open())
    {
        return views;
    }

    file >> views;

    return views;
}

bool saveViews(int views)
{
    //Create directory if doesn't exist
    std::filesystem::create_directories(viewsFilePath.parent_path());
    
    std::ofstream file(viewsFilePath);

    if (!file.is_open()) {
        return false;
    }

    file << views;

    return true;
}