Scroom  0.14
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 "callbacks.hh"
Include dependency graph for main.cc:

Functions

void usage (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[] 
)
48 {
49  const std::string me = argv[0]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
50  std::map<std::string, std::list<std::string>> filenames;
51 
52 #ifdef _WIN32
53  // In windows, redirect all logging to file.
54  // On the off-chance that we're running in a debugger that does capture console logging, redirect to console as well.
55  const auto logDirParent = in_devmode() ? boost::filesystem::path(TOP_SRCDIR) : boost::dll::program_location().parent_path();
56  const auto logDir = logDirParent / "logs";
57  const auto logFile = logDir / fmt::format("scroom-log-{}.txt", getpid());
58 
59  boost::filesystem::create_directory(logDir);
60 
61  auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
62  auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(logFile.string(), true);
63 
64  std::shared_ptr<spdlog::logger> logger(new spdlog::logger("scroom", {console_sink, file_sink}));
65  spdlog::set_default_logger(logger);
66 #endif
67 
68  spdlog::set_level(spdlog::level::trace);
69  spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%t] [%^%-5l%$] %v");
70 
71  po::options_description desc("Available options");
72  desc.add_options()("help,h", "Show this help message")("load,l", po::value<std::vector<std::string>>(), "Load given filenames")(
73  "transparent-overlay", po::value<std::vector<std::string>>()->multitoken(), "Show given files in transparent overlay");
74 
75  po::positional_options_description p;
76  p.add("load", -1);
77 
78  po::variables_map vm;
79 
80  try
81  {
82  po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
83  po::notify(vm);
84 
85  if(vm.count("help"))
86  {
87  usage(me, desc);
88  }
89 
90  if(vm.count("load"))
91  {
92  const auto& names = vm["load"].as<std::vector<std::string>>();
93  filenames[REGULAR_FILES].assign(names.begin(), names.end());
94  }
95 
96  if(vm.count("transparent-overlay"))
97  {
98  const auto& names = vm["transparent-overlay"].as<std::vector<std::string>>();
99  filenames["Transparent Overlay"].assign(names.begin(), names.end());
100  }
101  }
102  catch(std::exception& ex)
103  {
104  usage(me, desc, ex.what());
105  }
106 
107  setlocale(LC_ALL, ""); // NOLINT(concurrency-mt-unsafe)
108  gtk_init(&argc, &argv);
109 
111 
112  gtk_main();
113 
115  spdlog::debug("Scroom terminating...");
116  return 0;
117 }
Here is the call graph for this function:

◆ usage()

void usage ( const std::string &  me,
const po::options_description &  desc,
const std::string &  message = std::string() 
)
34 {
35  if(message.length() != 0)
36  {
37  spdlog::error("{}", message);
38  }
39 
40  spdlog::info("Usage: {} [options] [input files]", me);
41 
42  spdlog::info("{}", boost::lexical_cast<std::string>(desc));
43 
44  exit(-1); // NOLINT(concurrency-mt-unsafe)
45 }

Referenced by main().

Here is the caller graph for this function:
on_scroom_terminating
void on_scroom_terminating()
Definition: callbacks.cc:479
in_devmode
bool in_devmode()
Definition: callbacks.cc:416
usage
void usage(const std::string &me, const po::options_description &desc, const std::string &message=std::string())
Definition: main.cc:33
on_scroom_bootstrap
void on_scroom_bootstrap(const FileNameMap &newFilenames)
Definition: callbacks.cc:418
REGULAR_FILES
const std::string REGULAR_FILES
Definition: callbacks.cc:49
filenames
static FileNameMap filenames
Definition: callbacks.cc:58