From 2c9ae7e03f24a5930488b304f6e655bb160f1f13 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 24 Aug 2021 17:03:45 -0700 Subject: refactor(soyuz): use fmtlib instead of std --- soyuz/library.cc | 5 ++--- soyuz/soyuz.cc | 5 ++--- soyuz/tray.cc | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/soyuz/library.cc b/soyuz/library.cc index a0bfbd7..0340a02 100644 --- a/soyuz/library.cc +++ b/soyuz/library.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include +#include #include #include #include @@ -56,9 +57,7 @@ auto delete_handle(DWORD pid) -> int { pid ); if (!lunar) { - std::stringstream ss; - ss << "could not open handle to lunar client: " << GetLastError(); - soyuz::log(ss.str()); + soyuz::log(fmt::format("could not open handle to lunar client: {}", GetLastError())); return 1; } diff --git a/soyuz/soyuz.cc b/soyuz/soyuz.cc index 00457b8..95b346c 100644 --- a/soyuz/soyuz.cc +++ b/soyuz/soyuz.cc @@ -3,6 +3,7 @@ #pragma comment(lib, "ntdll.lib") +#include #include #include @@ -65,9 +66,7 @@ auto WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR argument, int show) - soyuz::exit(1); } - std::stringstream ss; - ss << "located lunar client: pid " << pid; - soyuz::log(ss.str()); + soyuz::log(fmt::format("located lunar client: pid {}", GetLastError())); while (!stop.stop_requested()) { if (soyuz::delete_handle(pid) == 1) { diff --git a/soyuz/tray.cc b/soyuz/tray.cc index e57771c..d7742f5 100644 --- a/soyuz/tray.cc +++ b/soyuz/tray.cc @@ -1,6 +1,7 @@ // Copyright (C) 2021-2021 Fuwn // SPDX-License-Identifier: GPL-3.0-only +#include #include #include "soyuz/library.hh" @@ -131,10 +132,9 @@ namespace soyuz { auto log(const std::string &message) -> void { if (logs.size() == 16) { logs.erase(logs.begin()); } - std::ostringstream ss; - ss << "[" << current_date_time() << "] " << message; + std::string to_log = fmt::format("[{}] {}", current_date_time(), message); - LOG(ss.str()) write_log_file(ss.str()); + LOG(to_log.c_str()) write_log_file(to_log); RedrawWindow(window, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); } -- cgit v1.2.3