diff --git a/OptiScaler/Logger.cpp b/OptiScaler/Logger.cpp index c89094f3..70fa8a62 100644 --- a/OptiScaler/Logger.cpp +++ b/OptiScaler/Logger.cpp @@ -114,8 +114,29 @@ void PrepareLogger() if (Config::Instance()->LogToFile.value_or_default()) { - auto file_sink = std::make_shared( - Config::Instance()->LogFileName.value_or_default(), true); + auto logPath = std::filesystem::path(Config::Instance()->LogFileName.value_or_default()); + + // if just a filename is provided, log to the executable directory + if (!logPath.has_parent_path() && !logPath.is_absolute()) + { + // if LogFileName is just a filename, use it with the executable directory + if (logPath.has_filename()) + logPath = Util::ExePath().parent_path() / Config::Instance()->LogFileName.value_or_default(); + else + logPath = Util::ExePath().parent_path() / L"OptiScaler.log"; + } + else + { + // if LogFileName is just a directory + if (std::filesystem::is_directory(logPath)) + logPath = logPath / L"OptiScaler.log"; + + // if the parent folder doesn't exist, log to the executable directory instead + if (!std::filesystem::is_directory(logPath.parent_path())) + logPath = Util::ExePath().parent_path() / L"OptiScaler.log"; + } + + auto file_sink = std::make_shared(logPath, true); file_sink->set_level(spdlog::level::level_enum::trace); #ifdef LOG_ASYNC file_sink->set_pattern("%H:%M:%S.%f\t%L\t%v"); diff --git a/OptiScaler/dllmain.cpp b/OptiScaler/dllmain.cpp index 8f812fdd..d922dd73 100644 --- a/OptiScaler/dllmain.cpp +++ b/OptiScaler/dllmain.cpp @@ -1621,12 +1621,34 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv // Main Opti DLL path if (!Config::Instance()->MainDllPath.has_value()) - Config::Instance()->MainDllPath.set_volatile_value(Util::ExePath().parent_path() / L"OptiScaler"); + { + Config::Instance()->MainDllPath.set_volatile_value(Util::ExePath().parent_path() / L"."); - if (!Config::Instance()->PluginPath.has_value()) + Config::Instance()->MainDllPath.set_volatile_value( + std::filesystem::absolute(Config::Instance()->MainDllPath.value())); + } + + // If path is not correct + if (!std::filesystem::exists(Config::Instance()->MainDllPath.value()) || + !std::filesystem::is_directory(Config::Instance()->MainDllPath.value())) + { + LOG_ERROR("MainDllPath does not exist or wrong: {}", + wstring_to_string(Config::Instance()->MainDllPath.value())); + + Config::Instance()->MainDllPath.set_volatile_value(Util::ExePath().parent_path() / L"."); + } + + // If path is not set or incorrect + if (!Config::Instance()->PluginPath.has_value() || + (!std::filesystem::exists(Config::Instance()->PluginPath.value()) || + !std::filesystem::is_directory(Config::Instance()->PluginPath.value()))) + { Config::Instance()->PluginPath.set_volatile_value( std::filesystem::path(Config::Instance()->MainDllPath.value()) / L"plugins"); + LOG_WARN("PluginPath updated: {}", wstring_to_string(Config::Instance()->PluginPath.value())); + } + CheckForExcludedProcess(); if (_passThruMode) @@ -1658,7 +1680,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv spdlog::warn("If you paid for these files, you've been scammed!"); spdlog::warn("DO NOT USE IN MULTIPLAYER GAMES"); spdlog::info(""); - spdlog::info("LogLevel: {0}", Config::Instance()->LogLevel.value_or_default()); + spdlog::info("LogLevel: {}", Config::Instance()->LogLevel.value_or_default()); spdlog::info(""); if (Util::GetRealWindowsVersion(winVer))