mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-04-28 13:27:58 +03:00
Fix logger eventually causing a crash without a console on Windows. (#481)
This commit is contained in:
parent
881712999c
commit
9e744ffded
6 changed files with 30 additions and 6 deletions
|
@ -9,6 +9,8 @@
|
|||
#include <shellapi.h>
|
||||
#endif
|
||||
|
||||
#include <os/logger.h>
|
||||
|
||||
// UpdateChecker
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
@ -52,7 +54,7 @@ static bool parseVersion(const std::string &versionStr, int &major, int &minor,
|
|||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
fmt::println("Error while parsing version: {}.", e.what());
|
||||
LOGF_ERROR("Error while parsing version: {}.", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -93,25 +95,25 @@ void updateCheckerThread()
|
|||
}
|
||||
else
|
||||
{
|
||||
fmt::println("Error while parsing response: tag_name does not contain a valid version string.");
|
||||
LOG_ERROR("Error while parsing response: tag_name does not contain a valid version string.");
|
||||
g_updateCheckerResult = UpdateChecker::Result::Failed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::println("Error while parsing response: tag_name not found or not the right type.");
|
||||
LOG_ERROR("Error while parsing response: tag_name not found or not the right type.");
|
||||
g_updateCheckerResult = UpdateChecker::Result::Failed;
|
||||
}
|
||||
}
|
||||
catch (const json::exception &e)
|
||||
{
|
||||
fmt::println("Error while parsing response: {}", e.what());
|
||||
LOGF_ERROR("Error while parsing response: {}", e.what());
|
||||
g_updateCheckerResult = UpdateChecker::Result::Failed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt::println("Error while performing request: {}", curl_easy_strerror(res));
|
||||
LOGF_ERROR("Error while performing request: {}", curl_easy_strerror(res));
|
||||
g_updateCheckerResult = UpdateChecker::Result::Failed;
|
||||
}
|
||||
|
||||
|
|
|
@ -153,6 +153,8 @@ int main(int argc, char *argv[])
|
|||
timeBeginPeriod(1);
|
||||
#endif
|
||||
|
||||
os::process::CheckConsole();
|
||||
|
||||
if (!os::registry::Init())
|
||||
LOGN_WARNING("OS doesn't support registry");
|
||||
|
||||
|
|
|
@ -61,6 +61,12 @@ bool os::process::StartProcess(const std::filesystem::path& path, const std::vec
|
|||
return true;
|
||||
}
|
||||
|
||||
void os::process::CheckConsole()
|
||||
{
|
||||
// Always visible on Linux.
|
||||
g_consoleVisible = true;
|
||||
}
|
||||
|
||||
void os::process::ShowConsole()
|
||||
{
|
||||
// Unnecessary on Linux.
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
namespace os::process
|
||||
{
|
||||
inline bool g_consoleVisible;
|
||||
|
||||
std::filesystem::path GetExecutablePath();
|
||||
std::filesystem::path GetWorkingDirectory();
|
||||
bool SetWorkingDirectory(const std::filesystem::path& path);
|
||||
bool StartProcess(const std::filesystem::path& path, const std::vector<std::string>& args, std::filesystem::path work = {});
|
||||
void CheckConsole();
|
||||
void ShowConsole();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include <os/logger.h>
|
||||
#include <os/process.h>
|
||||
|
||||
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
|
||||
#define FOREGROUND_YELLOW (FOREGROUND_RED | FOREGROUND_GREEN)
|
||||
|
||||
HANDLE g_hStandardOutput;
|
||||
static HANDLE g_hStandardOutput;
|
||||
|
||||
void os::logger::Init()
|
||||
{
|
||||
|
@ -12,6 +13,9 @@ void os::logger::Init()
|
|||
|
||||
void os::logger::Log(const std::string_view str, ELogType type, const char* func)
|
||||
{
|
||||
if (!os::process::g_consoleVisible)
|
||||
return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ELogType::Utility:
|
||||
|
|
|
@ -52,6 +52,11 @@ bool os::process::StartProcess(const std::filesystem::path& path, const std::vec
|
|||
return true;
|
||||
}
|
||||
|
||||
void os::process::CheckConsole()
|
||||
{
|
||||
g_consoleVisible = (GetConsoleWindow() != nullptr);
|
||||
}
|
||||
|
||||
void os::process::ShowConsole()
|
||||
{
|
||||
if (GetConsoleWindow() == nullptr)
|
||||
|
@ -60,5 +65,7 @@ void os::process::ShowConsole()
|
|||
freopen("CONIN$", "r", stdin);
|
||||
freopen("CONOUT$", "w", stderr);
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
|
||||
g_consoleVisible = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue