mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-03 23:26:40 +00:00 
			
		
		
		
	Merge branch 'fix_portable_config_48' into 'openmw-48'
Fix logging and config for portable setup (0.48) See merge request OpenMW/openmw!3089
This commit is contained in:
		
						commit
						36f16cffe5
					
				
					 8 changed files with 33 additions and 31 deletions
				
			
		| 
						 | 
					@ -34,6 +34,8 @@ namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    using StringsVector = std::vector<std::string>;
 | 
					    using StringsVector = std::vector<std::string>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    constexpr std::string_view applicationName = "BulletObjectTool";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bpo::options_description makeOptionsDescription()
 | 
					    bpo::options_description makeOptionsDescription()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        using Fallback::FallbackMap;
 | 
					        using Fallback::FallbackMap;
 | 
				
			||||||
| 
						 | 
					@ -126,10 +128,9 @@ namespace
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Files::ConfigurationManager config;
 | 
					        Files::ConfigurationManager config;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        bpo::variables_map composingVariables = Files::separateComposingVariables(variables, desc);
 | 
					 | 
				
			||||||
        config.readConfiguration(variables, desc);
 | 
					        config.readConfiguration(variables, desc);
 | 
				
			||||||
        Files::mergeComposingVariables(variables, composingVariables, desc);
 | 
					
 | 
				
			||||||
 | 
					        setupLogging(config.getLogPath().string(), applicationName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const std::string encoding(variables["encoding"].as<std::string>());
 | 
					        const std::string encoding(variables["encoding"].as<std::string>());
 | 
				
			||||||
        Log(Debug::Info) << ToUTF8::encodingUsingMessage(encoding);
 | 
					        Log(Debug::Info) << ToUTF8::encodingUsingMessage(encoding);
 | 
				
			||||||
| 
						 | 
					@ -199,5 +200,5 @@ namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char *argv[])
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return wrapApplication(runBulletObjectTool, argc, argv, "BulletObjectTool");
 | 
					    return wrapApplication(runBulletObjectTool, argc, argv, applicationName);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,6 +48,8 @@ namespace NavMeshTool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        using StringsVector = std::vector<std::string>;
 | 
					        using StringsVector = std::vector<std::string>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        constexpr std::string_view applicationName = "NavMeshTool";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        bpo::options_description makeOptionsDescription()
 | 
					        bpo::options_description makeOptionsDescription()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            using Fallback::FallbackMap;
 | 
					            using Fallback::FallbackMap;
 | 
				
			||||||
| 
						 | 
					@ -124,10 +126,9 @@ namespace NavMeshTool
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Files::ConfigurationManager config;
 | 
					            Files::ConfigurationManager config;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            bpo::variables_map composingVariables = Files::separateComposingVariables(variables, desc);
 | 
					 | 
				
			||||||
            config.readConfiguration(variables, desc);
 | 
					            config.readConfiguration(variables, desc);
 | 
				
			||||||
            Files::mergeComposingVariables(variables, composingVariables, desc);
 | 
					
 | 
				
			||||||
 | 
					            setupLogging(config.getLogPath().string(), applicationName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const std::string encoding(variables["encoding"].as<std::string>());
 | 
					            const std::string encoding(variables["encoding"].as<std::string>());
 | 
				
			||||||
            Log(Debug::Info) << ToUTF8::encodingUsingMessage(encoding);
 | 
					            Log(Debug::Info) << ToUTF8::encodingUsingMessage(encoding);
 | 
				
			||||||
| 
						 | 
					@ -181,6 +182,8 @@ namespace NavMeshTool
 | 
				
			||||||
            const std::uint64_t maxDbFileSize = static_cast<std::uint64_t>(Settings::Manager::getInt64("max navmeshdb file size", "Navigator"));
 | 
					            const std::uint64_t maxDbFileSize = static_cast<std::uint64_t>(Settings::Manager::getInt64("max navmeshdb file size", "Navigator"));
 | 
				
			||||||
            const std::string dbPath = (config.getUserDataPath() / "navmesh.db").string();
 | 
					            const std::string dbPath = (config.getUserDataPath() / "navmesh.db").string();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Log(Debug::Info) << "Using navmeshdb at " << dbPath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            DetourNavigator::NavMeshDb db(dbPath, maxDbFileSize);
 | 
					            DetourNavigator::NavMeshDb db(dbPath, maxDbFileSize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ESM::ReadersCache readers;
 | 
					            ESM::ReadersCache readers;
 | 
				
			||||||
| 
						 | 
					@ -231,5 +234,5 @@ namespace NavMeshTool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char *argv[])
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return wrapApplication(NavMeshTool::runNavMeshTool, argc, argv, "NavMeshTool");
 | 
					    return wrapApplication(NavMeshTool::runNavMeshTool, argc, argv, NavMeshTool::applicationName);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,7 +111,7 @@ boost::program_options::variables_map CS::Editor::readConfiguration()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mCfgMgr.readConfiguration(variables, desc, false);
 | 
					    mCfgMgr.readConfiguration(variables, desc, false);
 | 
				
			||||||
    Settings::Manager::load(mCfgMgr, true);
 | 
					    Settings::Manager::load(mCfgMgr, true);
 | 
				
			||||||
    setupLogging(mCfgMgr.getLogPath().string(), "OpenMW-CS");
 | 
					    setupLogging(mCfgMgr.getLogPath().string(), applicationName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return variables;
 | 
					    return variables;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,6 +36,8 @@ namespace CSMDoc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace CS
 | 
					namespace CS
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    inline constexpr std::string_view applicationName = "OpenMW-CS";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class Editor : public QObject
 | 
					    class Editor : public QObject
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
            Q_OBJECT
 | 
					            Q_OBJECT
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,5 +81,5 @@ int runApplication(int argc, char *argv[])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char *argv[])
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return wrapApplication(&runApplication, argc, argv, "OpenMW-CS", false);
 | 
					    return wrapApplication(&runApplication, argc, argv, CS::applicationName);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,11 @@ extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace Fallback;
 | 
					using namespace Fallback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    constexpr std::string_view applicationName = "OpenMW";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * \brief Parses application command line and calls \ref Cfg::ConfigurationManager
 | 
					 * \brief Parses application command line and calls \ref Cfg::ConfigurationManager
 | 
				
			||||||
 * to parse configuration files.
 | 
					 * to parse configuration files.
 | 
				
			||||||
| 
						 | 
					@ -67,7 +72,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
 | 
				
			||||||
    cfgMgr.readConfiguration(variables, desc);
 | 
					    cfgMgr.readConfiguration(variables, desc);
 | 
				
			||||||
    Settings::Manager::load(cfgMgr);
 | 
					    Settings::Manager::load(cfgMgr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setupLogging(cfgMgr.getLogPath().string(), "OpenMW");
 | 
					    setupLogging(cfgMgr.getLogPath().string(), applicationName);
 | 
				
			||||||
    MWGui::DebugWindow::startLogRecording();
 | 
					    MWGui::DebugWindow::startLogRecording();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Version::Version v = Version::getOpenmwVersion(variables["resources"].as<Files::MaybeQuotedPath>().string());
 | 
					    Version::Version v = Version::getOpenmwVersion(variables["resources"].as<Files::MaybeQuotedPath>().string());
 | 
				
			||||||
| 
						 | 
					@ -235,7 +240,7 @@ extern "C" int SDL_main(int argc, char**argv)
 | 
				
			||||||
int main(int argc, char**argv)
 | 
					int main(int argc, char**argv)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return wrapApplication(&runApplication, argc, argv, "OpenMW", false);
 | 
					    return wrapApplication(&runApplication, argc, argv, applicationName);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Platform specific for Windows when there is no console built into the executable.
 | 
					// Platform specific for Windows when there is no console built into the executable.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -267,7 +267,7 @@ Misc::Locked<std::ostream&> getLockedRawStderr()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Redirect cout and cerr to the log file
 | 
					// Redirect cout and cerr to the log file
 | 
				
			||||||
void setupLogging(const std::string& logDir, const std::string& appName, std::ios_base::openmode mode)
 | 
					void setupLogging(const std::string& logDir, std::string_view appName)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined(_WIN32) && defined(_DEBUG)
 | 
					#if defined(_WIN32) && defined(_DEBUG)
 | 
				
			||||||
    // Redirect cout and cerr to VS debug output when running in debug mode
 | 
					    // Redirect cout and cerr to VS debug output when running in debug mode
 | 
				
			||||||
| 
						 | 
					@ -276,7 +276,7 @@ void setupLogging(const std::string& logDir, const std::string& appName, std::io
 | 
				
			||||||
    std::cerr.rdbuf(&sb);
 | 
					    std::cerr.rdbuf(&sb);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
    const std::string logName = Misc::StringUtils::lowerCase(appName) + ".log";
 | 
					    const std::string logName = Misc::StringUtils::lowerCase(appName) + ".log";
 | 
				
			||||||
    logfile.open(boost::filesystem::path(logDir) / logName, mode);
 | 
					    logfile.open(boost::filesystem::path(logDir) / logName, std::ios::out);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    coutsb.open(Debug::Tee(logfile, *rawStdout));
 | 
					    coutsb.open(Debug::Tee(logfile, *rawStdout));
 | 
				
			||||||
    cerrsb.open(Debug::Tee(logfile, *rawStderr));
 | 
					    cerrsb.open(Debug::Tee(logfile, *rawStderr));
 | 
				
			||||||
| 
						 | 
					@ -287,7 +287,7 @@ void setupLogging(const std::string& logDir, const std::string& appName, std::io
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, char *argv[],
 | 
					int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, char *argv[],
 | 
				
			||||||
                    const std::string& appName, bool autoSetupLogging)
 | 
					                    std::string_view appName)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#if defined _WIN32
 | 
					#if defined _WIN32
 | 
				
			||||||
    (void)Debug::attachParentConsole();
 | 
					    (void)Debug::attachParentConsole();
 | 
				
			||||||
| 
						 | 
					@ -301,27 +301,16 @@ int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, c
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Files::ConfigurationManager cfgMgr;
 | 
					        Files::ConfigurationManager cfgMgr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (autoSetupLogging)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            std::ios_base::openmode mode = std::ios::out;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // If we are collecting a stack trace, append to existing log file
 | 
					 | 
				
			||||||
            if (argc == 2 && strcmp(argv[1], crash_switch) == 0)
 | 
					 | 
				
			||||||
                mode |= std::ios::app;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            setupLogging(cfgMgr.getLogPath().string(), appName, mode);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (const auto env = std::getenv("OPENMW_DISABLE_CRASH_CATCHER"); env == nullptr || std::atol(env) == 0)
 | 
					        if (const auto env = std::getenv("OPENMW_DISABLE_CRASH_CATCHER"); env == nullptr || std::atol(env) == 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
#if defined(_WIN32)
 | 
					#if defined(_WIN32)
 | 
				
			||||||
            const std::string crashLogName = Misc::StringUtils::lowerCase(appName) + "-crash.dmp";
 | 
					            const std::string crashLogName = Misc::StringUtils::lowerCase(appName) + "-crash.dmp";
 | 
				
			||||||
            Crash::CrashCatcher crashy(argc, argv, (cfgMgr.getLogPath() / crashLogName).make_preferred().string());
 | 
					            Crash::CrashCatcher crashy(argc, argv, (boost::filesystem::temp_directory_path() / crashLogName).make_preferred().string());
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
            const std::string crashLogName = Misc::StringUtils::lowerCase(appName) + "-crash.log";
 | 
					            const std::string crashLogName = Misc::StringUtils::lowerCase(appName) + "-crash.log";
 | 
				
			||||||
            // install the crash handler as soon as possible. note that the log path
 | 
					            // install the crash handler as soon as possible. note that the log path
 | 
				
			||||||
            // does not depend on config being read.
 | 
					            // does not depend on config being read.
 | 
				
			||||||
            crashCatcherInstall(argc, argv, (cfgMgr.getLogPath() / crashLogName).string());
 | 
					            crashCatcherInstall(argc, argv, (boost::filesystem::temp_directory_path() / crashLogName).string());
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
            ret = innerApplication(argc, argv);
 | 
					            ret = innerApplication(argc, argv);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -333,7 +322,7 @@ int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, c
 | 
				
			||||||
#if (defined(__APPLE__) || defined(__linux) || defined(__unix) || defined(__posix))
 | 
					#if (defined(__APPLE__) || defined(__linux) || defined(__unix) || defined(__posix))
 | 
				
			||||||
        if (!isatty(fileno(stdin)))
 | 
					        if (!isatty(fileno(stdin)))
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
            SDL_ShowSimpleMessageBox(0, (appName + ": Fatal error").c_str(), e.what(), nullptr);
 | 
					            SDL_ShowSimpleMessageBox(0, (std::string(appName) + ": Fatal error").c_str(), e.what(), nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Log(Debug::Error) << "Error: " << e.what();
 | 
					        Log(Debug::Error) << "Error: " << e.what();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,8 @@
 | 
				
			||||||
#ifndef DEBUG_DEBUGGING_H
 | 
					#ifndef DEBUG_DEBUGGING_H
 | 
				
			||||||
#define DEBUG_DEBUGGING_H
 | 
					#define DEBUG_DEBUGGING_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <string_view>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <boost/filesystem/fstream.hpp>
 | 
					#include <boost/filesystem/fstream.hpp>
 | 
				
			||||||
#include <boost/iostreams/stream.hpp>
 | 
					#include <boost/iostreams/stream.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,9 +36,9 @@ std::ostream& getRawStderr();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Misc::Locked<std::ostream&> getLockedRawStderr();
 | 
					Misc::Locked<std::ostream&> getLockedRawStderr();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void setupLogging(const std::string& logDir, const std::string& appName, std::ios_base::openmode = std::ios::out);
 | 
					void setupLogging(const std::string& logDir, std::string_view appName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, char *argv[],
 | 
					int wrapApplication(int (*innerApplication)(int argc, char *argv[]), int argc, char *argv[],
 | 
				
			||||||
                    const std::string& appName, bool autoSetupLogging = true);
 | 
					                    std::string_view appName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue