From 07d3d6a596042195e503e3fee2790766b0e46e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 17 Apr 2022 01:26:38 -0300 Subject: [PATCH] ecode: Moved ecode logs to ecode config path. --- include/eepp/system/log.hpp | 14 +++++++++--- premake4.lua | 6 ------ premake5.lua | 6 ------ src/eepp/system/log.cpp | 40 ++++++++++++++++++++++++----------- src/tools/ecode/appconfig.cpp | 6 +----- src/tools/ecode/appconfig.hpp | 7 +++--- src/tools/ecode/ecode.cpp | 17 ++++++++++----- 7 files changed, 56 insertions(+), 40 deletions(-) diff --git a/include/eepp/system/log.hpp b/include/eepp/system/log.hpp index a660a0360..a1e9b4239 100644 --- a/include/eepp/system/log.hpp +++ b/include/eepp/system/log.hpp @@ -32,6 +32,8 @@ class EE_API Log : protected Mutex { SINGLETON_DECLARE_HEADERS( Log ) public: + static Log* create( const std::string& logPath, const LogLevel& level, bool consoleOutput, + bool liveWrite ); static Log* create( const LogLevel& level, bool consoleOutput, bool liveWrite ); @@ -100,6 +102,12 @@ class EE_API Log : protected Mutex { * logged. */ void setLogLevelThreshold( const LogLevel& logLevelThreshold ); + /** @return The file path of the log file (if any). */ + const std::string& getFilePath() const; + + /** Sets the file path of the log file. */ + void setFilePath( const std::string& filePath ); + static void debug( const std::string& text ) { Log::instance()->writel( LogLevel::Debug, text ); } @@ -157,7 +165,7 @@ class EE_API Log : protected Mutex { protected: Log(); - Log( const LogLevel& level, bool consoleOutput, bool liveWrite ); + Log( const std::string& logPath, const LogLevel& level, bool consoleOutput, bool liveWrite ); std::string mData; std::string mFilePath; @@ -165,9 +173,9 @@ class EE_API Log : protected Mutex { bool mConsoleOutput; bool mLiveWrite; #ifdef EE_DEBUG - LogLevel mLogLevelThreshold{LogLevel::Debug}; + LogLevel mLogLevelThreshold{ LogLevel::Debug }; #else - LogLevel mLogLevelThreshold{LogLevel::Notice}; + LogLevel mLogLevelThreshold{ LogLevel::Notice }; #endif IOStreamFile* mFS; std::list mReaders; diff --git a/premake4.lua b/premake4.lua index 671202a52..392600d59 100644 --- a/premake4.lua +++ b/premake4.lua @@ -1007,12 +1007,6 @@ solution "eepp" build_base_cpp_configuration( "efsw" ) -- Library - project "eepp-main" - kind "StaticLib" - language "C++" - set_targetdir("libs/" .. os.get_real() .. "/") - files { "src/eepp/main/eepp_main.cpp" } - project "eepp-static" kind "StaticLib" language "C++" diff --git a/premake5.lua b/premake5.lua index 95f20cfa4..2cbbfbc78 100644 --- a/premake5.lua +++ b/premake5.lua @@ -761,12 +761,6 @@ workspace "eepp" files { "src/thirdparty/efsw/src/efsw/platform/posix/*.cpp" } -- Library - project "eepp-main" - kind "StaticLib" - language "C++" - targetdir("libs/" .. os.target() .. "/") - files { "src/eepp/main/eepp_main.cpp" } - project "eepp-static" kind "StaticLib" language "C++" diff --git a/src/eepp/system/log.cpp b/src/eepp/system/log.cpp index 588a0eeb0..b5d70db92 100644 --- a/src/eepp/system/log.cpp +++ b/src/eepp/system/log.cpp @@ -20,9 +20,17 @@ namespace EE { namespace System { SINGLETON_DECLARE_IMPLEMENTATION( Log ) +Log* Log::create( const std::string& logPath, const LogLevel& level, bool consoleOutput, + bool liveWrite ) { + if ( NULL == ms_singleton ) { + ms_singleton = eeNew( Log, ( logPath, level, consoleOutput, liveWrite ) ); + } + return ms_singleton; +} + Log* Log::create( const LogLevel& level, bool consoleOutput, bool liveWrite ) { if ( NULL == ms_singleton ) { - ms_singleton = eeNew( Log, ( level, consoleOutput, liveWrite ) ); + ms_singleton = eeNew( Log, ( "", level, consoleOutput, liveWrite ) ); } return ms_singleton; } @@ -31,7 +39,8 @@ Log::Log() : mSave( false ), mConsoleOutput( false ), mLiveWrite( false ), mFS( writel( LogLevel::Info, "eepp initialized" ); } -Log::Log( const LogLevel& level, bool consoleOutput, bool liveWrite ) : +Log::Log( const std::string& logPath, const LogLevel& level, bool consoleOutput, bool liveWrite ) : + mFilePath( logPath ), mSave( false ), mConsoleOutput( consoleOutput ), mLiveWrite( liveWrite ), @@ -40,6 +49,17 @@ Log::Log( const LogLevel& level, bool consoleOutput, bool liveWrite ) : writel( LogLevel::Info, "eepp initialized" ); } +const std::string& Log::getFilePath() const { + return mFilePath; +} + +void Log::setFilePath( const std::string& filePath ) { + if ( filePath != mFilePath ) { + closeFS(); + mFilePath = filePath; + } +} + Log::~Log() { writel( LogLevel::Info, "eepp stoped\n" ); @@ -61,10 +81,10 @@ void Log::setLogLevelThreshold( const LogLevel& logLevelThreshold ) { } void Log::save( const std::string& filepath ) { - if ( filepath.size() ) { + if ( !filepath.empty() ) { mFilePath = filepath; } else { - mFilePath = Sys::getProcessPath(); + mFilePath = Sys::getProcessPath() + "log.log"; } mSave = true; @@ -171,15 +191,11 @@ void Log::writel( const LogLevel& level, const std::string& text ) { } void Log::openFS() { - if ( mFilePath.empty() ) { - mFilePath = Sys::getProcessPath(); - } + if ( mFilePath.empty() ) + mFilePath = Sys::getProcessPath() + "log.log"; - if ( NULL == mFS ) { - std::string str = mFilePath + "log.log"; - - mFS = IOStreamFile::New( str, "a" ); - } + if ( NULL == mFS ) + mFS = IOStreamFile::New( mFilePath, "a" ); } void Log::closeFS() { diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index 59fc27e6a..f3af41b30 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -32,14 +32,10 @@ static std::vector urlDecode( const std::vector& vec ) return decoded; } -void AppConfig::load( std::string& confPath, std::string& keybindingsPath, +void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, std::string& initColorScheme, std::vector& recentFiles, std::vector& recentFolders, const std::string& resPath, const Float& displayDPI ) { - confPath = Sys::getConfigPath( "ecode" ); - if ( !FileSystem::fileExists( confPath ) ) - FileSystem::makeDir( confPath ); - FileSystem::dirAddSlashAtEnd( confPath ); keybindingsPath = confPath + "keybindings.cfg"; ini.loadFromFile( confPath + "config.cfg" ); iniState.loadFromFile( confPath + "state.cfg" ); diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index fd87c5bb0..df6e93d52 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -78,9 +78,10 @@ struct AppConfig { IniFile iniState; FileInfo iniInfo; - void load( std::string& confPath, std::string& keybindingsPath, std::string& initColorScheme, - std::vector& recentFiles, std::vector& recentFolders, - const std::string& resPath, const Float& displayDPI ); + void load( const std::string& confPath, std::string& keybindingsPath, + std::string& initColorScheme, std::vector& recentFiles, + std::vector& recentFolders, const std::string& resPath, + const Float& displayDPI ); void save( const std::vector& recentFiles, const std::vector& recentFolders, const std::string& panelPartition, diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index d22cf1315..765fe25b1 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -272,6 +272,16 @@ void App::runCommand( const std::string& command ) { } void App::loadConfig() { + mConfigPath = Sys::getConfigPath( "ecode" ); + if ( !FileSystem::fileExists( mConfigPath ) ) + FileSystem::makeDir( mConfigPath ); + FileSystem::dirAddSlashAtEnd( mConfigPath ); +#ifndef EE_DEBUG + Log::create( mConfigPath + "ecode.log", LogLevel::Info, false, true ); +#else + Log::create( mConfigPath + "ecode.log", LogLevel::Debug, true, true ); +#endif + mConfig.load( mConfigPath, mKeybindingsPath, mInitColorScheme, mRecentFiles, mRecentFolders, mResPath, mDisplayDPI ); } @@ -1228,6 +1238,8 @@ void App::closeEditors() { mDirTree = nullptr; if ( mFileSystemListener ) mFileSystemListener->setDirTree( mDirTree ); + // Force to update the closed tabs. + SceneManager::instance()->update(); } void App::closeFolder() { @@ -2544,11 +2556,6 @@ void App::init( const std::string& file, const Float& pidelDensity, } EE_MAIN_FUNC int main( int argc, char* argv[] ) { -#ifndef EE_DEBUG - Log::create( LogLevel::Info, false, true ); -#else - Log::create( LogLevel::Debug, true, true ); -#endif args::ArgumentParser parser( "ecode" ); args::HelpFlag help( parser, "help", "Display this help menu", { 'h', "help" } ); args::Positional file( parser, "file", "The file path" );