2021-10-14 18:54:29 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 Peter Repukat - FlatspotSoftware
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifdef _WIN32
|
2021-10-15 13:02:36 +00:00
|
|
|
#define NOMINMAX
|
2021-10-14 18:54:29 +00:00
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2021-10-28 10:28:20 +00:00
|
|
|
#include <spdlog/sinks/basic_file_sink.h>
|
|
|
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
2021-10-14 18:54:29 +00:00
|
|
|
#include "SteamTarget.h"
|
|
|
|
|
2021-10-28 09:41:27 +00:00
|
|
|
#include "OverlayLogSink.h"
|
|
|
|
#include "Settings.h"
|
2021-10-16 20:36:30 +00:00
|
|
|
|
2021-10-17 19:04:41 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef CONSOLE
|
2021-10-20 19:47:24 +00:00
|
|
|
int main(int argc, char* argv[])
|
2021-10-17 19:04:41 +00:00
|
|
|
#else
|
|
|
|
int CALLBACK WinMain(
|
2021-10-20 19:47:24 +00:00
|
|
|
_In_ HINSTANCE hInstance,
|
|
|
|
_In_ HINSTANCE hPrevInstance,
|
|
|
|
_In_ LPSTR lpCmdLine,
|
|
|
|
_In_ int nCmdShow)
|
2021-10-17 19:04:41 +00:00
|
|
|
#endif
|
|
|
|
#else
|
2021-10-20 19:47:24 +00:00
|
|
|
int main(int argc, char* argv[])
|
2021-10-17 19:04:41 +00:00
|
|
|
#endif
|
2021-10-15 15:10:57 +00:00
|
|
|
{
|
2021-10-16 20:36:30 +00:00
|
|
|
const auto console_sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
|
|
|
|
console_sink->set_level(spdlog::level::trace);
|
|
|
|
#ifdef _WIN32
|
2021-10-23 14:57:49 +00:00
|
|
|
auto path = std::filesystem::temp_directory_path()
|
2021-10-23 15:17:05 +00:00
|
|
|
.parent_path()
|
2021-10-23 14:57:49 +00:00
|
|
|
.parent_path()
|
|
|
|
.parent_path();
|
|
|
|
|
|
|
|
path /= "Roaming";
|
|
|
|
path /= "GlosSI";
|
|
|
|
if (!std::filesystem::exists(path))
|
|
|
|
std::filesystem::create_directories(path);
|
|
|
|
path /= "glossitarget.log";
|
|
|
|
const auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path.string(), true);
|
2021-10-16 20:36:30 +00:00
|
|
|
#else
|
|
|
|
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("/tmp/glossitarget.log", true);
|
|
|
|
#endif
|
|
|
|
file_sink->set_level(spdlog::level::trace);
|
2021-10-22 13:40:37 +00:00
|
|
|
|
|
|
|
const auto overlay_sink = std::make_shared<spdlog::sinks::overlay_sink_mt>();
|
|
|
|
#ifdef _DEBUG
|
|
|
|
overlay_sink->set_level(spdlog::level::debug); // TODO: make configurable
|
|
|
|
#else
|
|
|
|
overlay_sink->set_level(spdlog::level::info);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::vector<spdlog::sink_ptr> sinks{file_sink, console_sink, overlay_sink};
|
2021-10-16 20:36:30 +00:00
|
|
|
auto logger = std::make_shared<spdlog::logger>("log", sinks.begin(), sinks.end());
|
|
|
|
logger->set_level(spdlog::level::trace);
|
|
|
|
logger->flush_on(spdlog::level::info);
|
|
|
|
spdlog::set_default_logger(logger);
|
2021-10-17 19:04:41 +00:00
|
|
|
#ifdef _WIN32
|
2021-10-28 11:38:16 +00:00
|
|
|
Settings::Parse(__argc > 1 ? __argv[1] : "");
|
2021-10-17 19:04:41 +00:00
|
|
|
SteamTarget target(__argc, __argv);
|
|
|
|
#else
|
2021-10-28 11:38:16 +00:00
|
|
|
Settings::Parse(argc > 1 ? argv[1] : "");
|
2021-10-15 15:10:57 +00:00
|
|
|
SteamTarget target(argc, argv);
|
2021-10-17 19:04:41 +00:00
|
|
|
#endif
|
2021-10-16 20:36:30 +00:00
|
|
|
const auto exit = target.run();
|
|
|
|
spdlog::shutdown();
|
|
|
|
return exit;
|
2021-10-14 18:54:29 +00:00
|
|
|
}
|