diff --git a/src/app/main.cpp b/src/app/main.cpp index 04e592e6..edfb85ca 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -20,7 +20,6 @@ #include "utility/commandline/CommandLineParser.h" #include "utility/logging/ConsoleLogger.h" #include "utility/logging/FileLogger.h" -#include "utility/logging/LoggerUtility.h" #include "utility/logging/logging.h" #include "utility/logging/LogManager.h" #include "utility/messaging/type/MessageInterruptTasks.h" @@ -52,7 +51,7 @@ void setupLogging() std::shared_ptr fileLogger = std::make_shared(); fileLogger->setLogDirectory(UserPaths::getLogPath()); - fileLogger->setFileName(LoggerUtility::generateDatedFileName("log")); + fileLogger->setFileName(FileLogger::generateDatedFileName(L"log")); fileLogger->setLogLevel(Logger::LOG_ALL); logManager->addLogger(fileLogger); } diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 51c71015..903c7c09 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -370,8 +370,6 @@ add_files( utility/logging/FileLogger.h utility/logging/Logger.cpp utility/logging/Logger.h - utility/logging/LoggerUtility.cpp - utility/logging/LoggerUtility.h utility/logging/logging.h utility/logging/LogManager.cpp utility/logging/LogManager.h diff --git a/src/lib/data/indexer/IndexerCommand.cpp b/src/lib/data/indexer/IndexerCommand.cpp index f19c096c..684c3e7e 100644 --- a/src/lib/data/indexer/IndexerCommand.cpp +++ b/src/lib/data/indexer/IndexerCommand.cpp @@ -1,5 +1,7 @@ #include "data/indexer/IndexerCommand.h" +#include "utility/utilityString.h" + IndexerCommand::IndexerCommand( const FilePath& sourceFilePath, const std::set& indexedPaths, const std::set& excludedPaths ) @@ -15,16 +17,16 @@ IndexerCommand::~IndexerCommand() size_t IndexerCommand::getByteSize(size_t stringSize) const { - size_t size = m_sourceFilePath.str().size(); + size_t size = utility::encodeToUtf8(m_sourceFilePath.wstr()).size(); for (const FilePath& path: m_indexedPaths) { - size += stringSize + path.str().size(); + size += stringSize + utility::encodeToUtf8(path.wstr()).size(); } for (const FilePath& path : m_excludedPaths) { - size += stringSize + path.str().size(); + size += stringSize + utility::encodeToUtf8(path.wstr()).size(); } return size; diff --git a/src/lib/data/storage/PersistentStorage.cpp b/src/lib/data/storage/PersistentStorage.cpp index 9590243b..8e3326a7 100644 --- a/src/lib/data/storage/PersistentStorage.cpp +++ b/src/lib/data/storage/PersistentStorage.cpp @@ -1885,7 +1885,7 @@ TooltipInfo PersistentStorage::getTooltipInfoForSourceLocationIdsAndLocalSymbolI const NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName); snippet.code = codec.encode(nameHierarchy.getQualifiedName()); snippet.locationFile = std::make_shared( - FilePath(nameHierarchy.getDelimiter() == NAME_DELIMITER_JAVA ? "main.java" : "main.cpp"), true, true); + FilePath(nameHierarchy.getDelimiter() == NAME_DELIMITER_JAVA ? L"main.java" : L"main.cpp"), true, true); snippet.locationFile->addSourceLocation( LOCATION_TOKEN, 0, std::vector(1, node.id), 1, 1, 1, snippet.code.size()); @@ -2645,7 +2645,7 @@ void PersistentStorage::buildMemberEdgeIdOrderMap() intToLocationType(location.type), location.id, std::vector(), - FilePath(std::to_string(location.fileNodeId)), + FilePath(std::to_wstring(location.fileNodeId)), location.startLine, location.startCol, location.endLine, diff --git a/src/lib/utility/logging/FileLogger.cpp b/src/lib/utility/logging/FileLogger.cpp index 09a2d2b0..4648408a 100644 --- a/src/lib/utility/logging/FileLogger.cpp +++ b/src/lib/utility/logging/FileLogger.cpp @@ -2,14 +2,43 @@ #include #include +#include #include #include "utility/file/FileSystem.h" #include "utility/utilityString.h" +std::wstring FileLogger::generateDatedFileName(const std::wstring& prefix, const std::wstring& suffix) +{ + time_t time; + std::time(&time); + tm t = *std::localtime(&time); + + std::wstringstream filename; + if (!prefix.empty()) + { + filename << prefix; + filename << L"_"; + } + filename << t.tm_year + 1900 << L"-"; + filename << (t.tm_mon < 9 ? L"0" : L"") << t.tm_mon + 1 << L"-"; + filename << (t.tm_mday < 10 ? L"0" : L"") << t.tm_mday << L"_"; + filename << (t.tm_hour < 10 ? L"0" : L"") << t.tm_hour << L"-"; + filename << (t.tm_min < 10 ? L"0" : L"") << t.tm_min << L"-"; + filename << (t.tm_sec < 10 ? L"0" : L"") << t.tm_sec; + + if (!suffix.empty()) + { + filename << L"_"; + filename << suffix; + } + + return filename.str(); +} + FileLogger::FileLogger() : Logger("FileLogger") - , m_logFileName("log") + , m_logFileName(L"log") , m_logDirectory(L"user/log/") , m_maxLogLineCount(0) , m_maxLogFileCount(0) @@ -31,7 +60,7 @@ FilePath FileLogger::getLogFilePath() const void FileLogger::setLogFilePath(const FilePath& filePath) { m_currentLogFilePath = filePath; - m_logFileName = ""; + m_logFileName = L""; } void FileLogger::setLogDirectory(const FilePath& filePath) @@ -40,7 +69,7 @@ void FileLogger::setLogDirectory(const FilePath& filePath) FileSystem::createDirectory(m_logDirectory); } -void FileLogger::setFileName(const std::string& fileName) +void FileLogger::setFileName(const std::wstring& fileName) { if (fileName != m_logFileName) { @@ -78,17 +107,17 @@ void FileLogger::setMaxLogFileCount(unsigned int fileCount) void FileLogger::updateLogFileName() { - if (!m_logFileName.size()) + if (m_logFileName.empty()) { return; } bool fileChanged = false; - std::string currentLogFilePath = m_logDirectory.str() + m_logFileName; + std::wstring currentLogFilePath = m_logDirectory.wstr() + m_logFileName; if (m_maxLogFileCount > 0) { - currentLogFilePath += "_"; + currentLogFilePath += L"_"; if (m_currentLogLineCount >= m_maxLogLineCount) { m_currentLogLineCount = 0; @@ -100,10 +129,10 @@ void FileLogger::updateLogFileName() } fileChanged = true; } - currentLogFilePath += std::to_string(m_currentLogFileCount); + currentLogFilePath += std::to_wstring(m_currentLogFileCount); } - currentLogFilePath += ".txt"; + currentLogFilePath += L".txt"; m_currentLogFilePath = FilePath(currentLogFilePath); diff --git a/src/lib/utility/logging/FileLogger.h b/src/lib/utility/logging/FileLogger.h index 854e26cd..4e2b4789 100644 --- a/src/lib/utility/logging/FileLogger.h +++ b/src/lib/utility/logging/FileLogger.h @@ -10,6 +10,8 @@ class FileLogger: public Logger { public: + static std::wstring generateDatedFileName(const std::wstring& prefix = L"", const std::wstring& suffix = L""); + FileLogger(); virtual ~FileLogger(); @@ -17,7 +19,7 @@ public: void setLogFilePath(const FilePath& filePath); void setLogDirectory(const FilePath& filePath); - void setFileName(const std::string& fileName); + void setFileName(const std::wstring& fileName); void setMaxLogLineCount(unsigned int logCount); // setting the max log file count to 0 will disable ringlogging @@ -31,7 +33,7 @@ private: void logMessage(const std::string& type, const LogMessage& message); void updateLogFileName(); - std::string m_logFileName; + std::wstring m_logFileName; FilePath m_logDirectory; FilePath m_currentLogFilePath; diff --git a/src/lib/utility/logging/LoggerUtility.cpp b/src/lib/utility/logging/LoggerUtility.cpp deleted file mode 100644 index 927f582a..00000000 --- a/src/lib/utility/logging/LoggerUtility.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "LoggerUtility.h" - -#include -#include - -std::string LoggerUtility::generateDatedFileName(const std::string& prefix, const std::string& suffix) -{ - time_t time; - std::time(&time); - tm t = *std::localtime(&time); - - std::stringstream filename; - if (prefix.length() > 0) - { - filename << prefix; - filename << "_"; - } - filename << t.tm_year + 1900 << "-"; - filename << (t.tm_mon < 9 ? "0" : "") << t.tm_mon + 1 << "-"; - filename << (t.tm_mday < 10 ? "0" : "") << t.tm_mday << "_"; - filename << (t.tm_hour < 10 ? "0" : "") << t.tm_hour << "-"; - filename << (t.tm_min < 10 ? "0" : "") << t.tm_min << "-"; - filename << (t.tm_sec < 10 ? "0" : "") << t.tm_sec; - - if (suffix.length() > 0) - { - filename << "_"; - filename << suffix; - } - - return filename.str(); -} diff --git a/src/lib/utility/logging/LoggerUtility.h b/src/lib/utility/logging/LoggerUtility.h deleted file mode 100644 index ca90b80c..00000000 --- a/src/lib/utility/logging/LoggerUtility.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef LOGGER_UTILITY_H -#define LOGGER_UTILITY_H - -#include - -class LoggerUtility -{ -public: - static std::string generateDatedFileName(const std::string& prefix = "", const std::string& suffix = ""); -}; - -#endif // LOGGER_UTILITY_H \ No newline at end of file diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp index e95ffa68..41c224e8 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp +++ b/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp @@ -1,5 +1,7 @@ #include "data/indexer/IndexerCommandCxx.h" +#include "utility/utilityString.h" + IndexerCommandCxx::IndexerCommandCxx( const FilePath& sourceFilePath, const std::set& indexedPaths, @@ -23,12 +25,12 @@ size_t IndexerCommandCxx::getByteSize(size_t stringSize) const for (auto& i : m_systemHeaderSearchPaths) { - size += stringSize + i.str().size(); + size += stringSize + utility::encodeToUtf8(i.wstr()).size(); } for (auto& i : m_frameworkSearchPaths) { - size += stringSize + i.str().size(); + size += stringSize + utility::encodeToUtf8(i.wstr()).size(); } for (auto& i : m_compilerFlags) diff --git a/src/lib_gui/qt/element/QtLocationPicker.cpp b/src/lib_gui/qt/element/QtLocationPicker.cpp index 59ec05fb..fc561f36 100644 --- a/src/lib_gui/qt/element/QtLocationPicker.cpp +++ b/src/lib_gui/qt/element/QtLocationPicker.cpp @@ -120,9 +120,9 @@ void QtLocationPicker::handleButtonPress() { if (!m_relativeRootDirectory.empty()) { - const FilePath path(fileName.toStdString()); + const FilePath path(fileName.toStdWString()); const FilePath relPath = path.getRelativeTo(m_relativeRootDirectory); - if (relPath.str().size() < path.str().size()) + if (relPath.wstr().size() < path.wstr().size()) { fileName = QString::fromStdWString(relPath.wstr()); } diff --git a/src/lib_gui/qt/element/QtStatusBar.cpp b/src/lib_gui/qt/element/QtStatusBar.cpp index ad4afeb4..146e3cae 100644 --- a/src/lib_gui/qt/element/QtStatusBar.cpp +++ b/src/lib_gui/qt/element/QtStatusBar.cpp @@ -13,7 +13,7 @@ QtStatusBar::QtStatusBar() { addWidget(new QWidget()); // add some space - m_movie = std::make_shared((ResourcePaths::getGuiPath().str() + "statusbar_view/loader.gif").c_str()); + m_movie = std::make_shared(QString::fromStdWString(ResourcePaths::getGuiPath().concatenate(L"statusbar_view/loader.gif").wstr())); // if movie doesn't loop forever, force it to. if (m_movie->loopCount() != -1) { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index 323de651..89fb3b66 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -697,7 +697,7 @@ void QtProjectWizzardContentPathsHeaderSearch::showDetectedIncludesResult(const if (!relativeRoot.empty()) { const FilePath relPath = path.getRelativeTo(relativeRoot); - if (relPath.str().size() < path.str().size()) + if (relPath.wstr().size() < path.wstr().size()) { detailedText += relPath.wstr() + L"\n"; } diff --git a/src/lib_java/data/indexer/IndexerCommandJava.cpp b/src/lib_java/data/indexer/IndexerCommandJava.cpp index 6f6940b9..d4ef8309 100644 --- a/src/lib_java/data/indexer/IndexerCommandJava.cpp +++ b/src/lib_java/data/indexer/IndexerCommandJava.cpp @@ -1,5 +1,7 @@ #include "data/indexer/IndexerCommandJava.h" +#include "utility/utilityString.h" + IndexerCommandType IndexerCommandJava::getStaticIndexerCommandType() { return INDEXER_COMMAND_JAVA; @@ -33,7 +35,7 @@ size_t IndexerCommandJava::getByteSize(size_t stringSize) const for (auto& i : m_classPath) { - size += stringSize + i.str().size(); + size += stringSize + utility::encodeToUtf8(i.wstr()).size(); } return size; diff --git a/src/test/CommandlineTestSuite.h b/src/test/CommandlineTestSuite.h index fcd90135..aa838cb2 100644 --- a/src/test/CommandlineTestSuite.h +++ b/src/test/CommandlineTestSuite.h @@ -84,7 +84,7 @@ public: std::cout.rdbuf( oldBuf ); FilePath path = ApplicationSettings::getInstance()->getMavenPath(); - TS_ASSERT_EQUALS( path.str(), "/opt/testpath/mvn") + TS_ASSERT_EQUALS( path.wstr(), L"/opt/testpath/mvn") } @@ -102,10 +102,10 @@ public: parser.parse(); std::vector paths = ApplicationSettings::getInstance()->getHeaderSearchPaths(); - TS_ASSERT_EQUALS( paths[0].str(), "/usr") - TS_ASSERT_EQUALS( paths[1].str(), "/usr/include") - TS_ASSERT_EQUALS( paths[2].str(), "/include") - TS_ASSERT_EQUALS( paths[3].str(), "/opt/include") + TS_ASSERT_EQUALS( paths[0].wstr(), L"/usr") + TS_ASSERT_EQUALS( paths[1].wstr(), L"/usr/include") + TS_ASSERT_EQUALS( paths[2].wstr(), L"/include") + TS_ASSERT_EQUALS( paths[3].wstr(), L"/opt/include") } diff --git a/src/test/FileSystemTestSuite.h b/src/test/FileSystemTestSuite.h index b624a1be..65432318 100644 --- a/src/test/FileSystemTestSuite.h +++ b/src/test/FileSystemTestSuite.h @@ -28,7 +28,7 @@ public: void test_find_h_files() { std::vector headerFiles = utility::convert( - FileSystem::getFilePathsFromDirectory(FilePath("data/FileSystemTestSuite"), { L".h" }), + FileSystem::getFilePathsFromDirectory(FilePath(L"data/FileSystemTestSuite"), { L".h" }), [](const FilePath& filePath){ return filePath.wstr(); } );