Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
main.cc File Reference
#include <cstdlib>
#include <iostream>
#include <list>
#include <string>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>
#include <gtk/gtk.h>
#include <scroom/logger.hh>
#include "callbacks.hh"
Include dependency graph for main.cc:

Functions

void usage (const Scroom::Logger &logger, const std::string &me, const po::options_description &desc, const std::string &message=std::string())
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
55{
56 const std::string me = argv[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
57 std::map<std::string, std::list<std::string>> filenames;
58
59 auto loggerContainer = Scroom::LoggerContainer::instance();
60 Scroom::Logger logger(loggerContainer);
61
62#ifdef _WIN32
63 // In windows, redirect all logging to file.
64 // On the off-chance that we're running in a debugger that does capture console logging, redirect to console as well.
65 const auto logDirParent = in_devmode() ? boost::filesystem::path(TOP_SRCDIR) : boost::dll::program_location().parent_path();
66 const auto logDir = logDirParent / "logs";
67 const auto logFile = logDir / fmt::format("scroom-log-{}.txt", getpid());
68
69 boost::filesystem::create_directory(logDir);
70
71 auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
72 auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(logFile.string(), true);
73
74 auto spdlogger = std::make_shared<spdlog::logger>("scroom", spdlog::sinks_init_list{console_sink, file_sink});
75 loggerContainer->set(spdlogger);
76#else
77 auto spdlogger = loggerContainer->get();
78#endif
79
80 spdlogger->set_level(spdlog::level::trace);
81 spdlogger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%t] [%^%-5l%$] %v");
82
83 po::options_description desc("Available options");
84 desc.add_options()("help,h", "Show this help message")("load,l", po::value<std::vector<std::string>>(), "Load given filenames")(
85 "transparent-overlay", po::value<std::vector<std::string>>()->multitoken(), "Show given files in transparent overlay"
86 );
87
88 po::positional_options_description p;
89 p.add("load", -1);
90
91 po::variables_map vm;
92
93 try
94 {
95 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
96 po::notify(vm);
97
98 if(vm.count("help"))
99 {
100 usage(logger, me, desc);
101 }
102
103 if(vm.count("load"))
104 {
105 const auto& names = vm["load"].as<std::vector<std::string>>();
106 filenames[REGULAR_FILES].assign(names.begin(), names.end());
107 }
108
109 if(vm.count("transparent-overlay"))
110 {
111 const auto& names = vm["transparent-overlay"].as<std::vector<std::string>>();
112 filenames["Transparent Overlay"].assign(names.begin(), names.end());
113 }
114 }
115 catch(std::exception& ex)
116 {
117 usage(logger, me, desc, ex.what());
118 }
119
120 setlocale(LC_ALL, ""); // NOLINT(concurrency-mt-unsafe)
121 gtk_init(&argc, &argv);
122
124
125 gtk_main();
126
128 logger->debug("Scroom terminating...");
129 return 0;
130}
bool in_devmode()
Definition callbacks.cc:422
const std::string REGULAR_FILES
Definition callbacks.cc:46
void on_scroom_terminating()
Definition callbacks.cc:485
static FileNameMap filenames
Definition callbacks.cc:60
void on_scroom_bootstrap(const FileNameMap &newFilenames)
Definition callbacks.cc:424
static Ptr instance()
Definition logger.cc:21
Definition logger.hh:49
PresentationInterfaceStub::Ptr const p
Definition determine-size-test.cc:172
void usage(const Scroom::Logger &logger, const std::string &me, const po::options_description &desc, const std::string &message=std::string())
Definition main.cc:35
Scroom::Logger logger
Definition callbacks.cc:54
Here is the call graph for this function:

◆ usage()

void usage ( const Scroom::Logger logger,
const std::string &  me,
const po::options_description &  desc,
const std::string &  message = std::string() 
)
41{
42 if(!message.empty())
43 {
44 logger->error("{}", message);
45 }
46
47 logger->info("Usage: {} [options] [input files]", me);
48
49 logger->info("{}", boost::lexical_cast<std::string>(desc));
50
51 exit(-1); // NOLINT(concurrency-mt-unsafe)
52}

Referenced by main().

Here is the caller graph for this function: