1 #include "includes.h"
2 
3 
prepare_logdir()4 void prepare_logdir()
5 {
6     spdlog::drop_all();
7 #ifdef _WIN32
8     system("if not exist logs mkdir logs");
9     system("del /F /Q logs\\*");
10 #else
11     auto rv = system("mkdir -p logs");
12     rv = system("rm -f logs/*");
13     (void)rv;
14 #endif
15 }
16 
17 
file_contents(const std::string& filename)18 std::string file_contents(const std::string& filename)
19 {
20     std::ifstream ifs(filename);
21     if (!ifs)
22         throw std::runtime_error("Failed open file ");
23     return std::string((std::istreambuf_iterator<char>(ifs)),
24                        (std::istreambuf_iterator<char>()));
25 
26 }
27 
count_lines(const std::string& filename)28 std::size_t count_lines(const std::string& filename)
29 {
30     std::ifstream ifs(filename);
31     if (!ifs)
32         throw std::runtime_error("Failed open file ");
33 
34     std::string line;
35     size_t counter = 0;
36     while(std::getline(ifs, line))
37         counter++;
38     return counter;
39 }
40 
get_filesize(const std::string& filename)41 std::size_t get_filesize(const std::string& filename)
42 {
43     std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary);
44     if (!ifs)
45         throw std::runtime_error("Failed open file ");
46 
47     return static_cast<std::size_t>(ifs.tellg());
48 }
49