| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  | #include "includes.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void prepare_logdir() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-03-28 02:08:18 +03:00
										 |  |  |     spdlog::drop_all(); | 
					
						
							| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  | #ifdef _WIN32
 | 
					
						
							| 
									
										
										
										
											2017-03-28 02:08:18 +03:00
										 |  |  |     system("if not exist logs mkdir logs"); | 
					
						
							| 
									
										
										
										
											2017-03-28 01:54:33 +03:00
										 |  |  |     system("del /F /Q logs\\*"); | 
					
						
							| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2017-03-28 02:08:18 +03:00
										 |  |  |     auto rv = system("mkdir -p logs"); | 
					
						
							| 
									
										
										
										
											2017-03-28 02:05:59 +03:00
										 |  |  |     rv = system("rm -f logs/*"); | 
					
						
							|  |  |  |     (void)rv; | 
					
						
							| 
									
										
										
										
											2017-03-28 02:08:18 +03:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  | std::string file_contents(const std::string &filename) | 
					
						
							| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     std::ifstream ifs(filename); | 
					
						
							|  |  |  |     if (!ifs) | 
					
						
							|  |  |  |         throw std::runtime_error("Failed open file "); | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  |     return std::string((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); | 
					
						
							| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  | std::size_t count_lines(const std::string &filename) | 
					
						
							| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     std::ifstream ifs(filename); | 
					
						
							|  |  |  |     if (!ifs) | 
					
						
							|  |  |  |         throw std::runtime_error("Failed open file "); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::string line; | 
					
						
							|  |  |  |     size_t counter = 0; | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  |     while (std::getline(ifs, line)) | 
					
						
							| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  |         counter++; | 
					
						
							|  |  |  |     return counter; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  | std::size_t get_filesize(const std::string &filename) | 
					
						
							| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary); | 
					
						
							|  |  |  |     if (!ifs) | 
					
						
							|  |  |  |         throw std::runtime_error("Failed open file "); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 18:58:00 +03:00
										 |  |  |     return static_cast<std::size_t>(ifs.tellg()); | 
					
						
							| 
									
										
										
										
											2016-04-20 11:57:49 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-13 02:04:31 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | // source: https://stackoverflow.com/a/2072890/192001
 | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  | bool ends_with(std::string const &value, std::string const &ending) | 
					
						
							| 
									
										
										
										
											2017-11-06 12:39:04 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  |     if (ending.size() > value.size()) | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2017-11-06 12:39:04 +02:00
										 |  |  |     return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); | 
					
						
							| 
									
										
										
										
											2017-10-13 02:04:31 +03:00
										 |  |  | } |