logic: reduce access to filesystem while indexing
* use canonical filepath cache in cxx indexer * made constructors of FilePath explicit * use FilePath at more places instead of string * forward declares FilePath wherever possible
This commit is contained in:
@@ -71,10 +71,10 @@ void Application::destroyInstance()
|
||||
|
||||
void Application::loadSettings()
|
||||
{
|
||||
MessageStatus("Load settings: " + UserPaths::getAppSettingsPath()).dispatch();
|
||||
MessageStatus("Load settings: " + UserPaths::getAppSettingsPath().str()).dispatch();
|
||||
|
||||
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
|
||||
settings->load(FilePath(UserPaths::getAppSettingsPath()));
|
||||
settings->load(UserPaths::getAppSettingsPath());
|
||||
|
||||
LogManager::getInstance()->setLoggingEnabled(settings->getLoggingEnabled());
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
class FilePath;
|
||||
|
||||
class ApplicationStateMonitor
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "utility/file/FileInfo.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/tracing.h"
|
||||
@@ -241,7 +242,7 @@ void CodeController::handleMessage(MessageChangeFileView* message)
|
||||
else
|
||||
{
|
||||
std::shared_ptr<SourceLocationFile> file =
|
||||
m_storageAccess->getSourceLocationsForFile(message->filePath.str());
|
||||
m_storageAccess->getSourceLocationsForFile(message->filePath);
|
||||
|
||||
SourceLocationFile* activeLocations = m_collection->getSourceLocationFileByPath(message->filePath).get();
|
||||
if (activeLocations)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateAll.h"
|
||||
#include "utility/messaging/type/MessageActivateLocalSymbols.h"
|
||||
|
||||
@@ -81,12 +81,12 @@ void IDECommunicationController::handleSetActiveTokenMessage(
|
||||
{
|
||||
const unsigned int cursorColumn = message.column;
|
||||
|
||||
if (FileSystem::getFileInfoForPath(message.fileLocation).lastWriteTime
|
||||
== m_storageAccess->getFileInfoForFilePath(message.fileLocation).lastWriteTime)
|
||||
if (FileSystem::getFileInfoForPath(FilePath(message.fileLocation)).lastWriteTime
|
||||
== m_storageAccess->getFileInfoForFilePath(FilePath(message.fileLocation)).lastWriteTime)
|
||||
{
|
||||
// file was not modified
|
||||
std::shared_ptr<SourceLocationFile> sourceLocationFile = m_storageAccess->getSourceLocationsForLinesInFile(
|
||||
message.fileLocation, message.row, message.row
|
||||
FilePath(message.fileLocation), message.row, message.row
|
||||
);
|
||||
|
||||
std::vector<Id> selectedLocationIds;
|
||||
@@ -116,10 +116,10 @@ void IDECommunicationController::handleSetActiveTokenMessage(
|
||||
}
|
||||
}
|
||||
|
||||
Id fileId = m_storageAccess->getNodeIdForFileNode(message.fileLocation);
|
||||
Id fileId = m_storageAccess->getNodeIdForFileNode(FilePath(message.fileLocation));
|
||||
if (fileId > 0)
|
||||
{
|
||||
MessageActivateFile(message.fileLocation, message.row).dispatchImmediately();
|
||||
MessageActivateFile(FilePath(message.fileLocation), message.row).dispatchImmediately();
|
||||
MessageActivateWindow().dispatch();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
#include <memory>
|
||||
|
||||
#include "data/ErrorInfo.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
#include "component/view/helper/CodeSnippetParams.h"
|
||||
#include "component/view/View.h"
|
||||
|
||||
class CodeController;
|
||||
class FilePath;
|
||||
class SourceLocationCollection;
|
||||
|
||||
class CodeView
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef ERROR_VIEW_H
|
||||
#define ERROR_VIEW_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "component/view/View.h"
|
||||
#include "data/ErrorInfo.h"
|
||||
|
||||
|
||||
@@ -519,7 +519,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfBundleNode(bool isFocused)
|
||||
style.color = getNodeColor("bundle", isFocused);
|
||||
|
||||
addIcon(Node::NODE_ENUM, false, &style);
|
||||
style.iconPath = ResourcePaths::getGuiPath() + "graph_view/images/bundle.png";
|
||||
style.iconPath = ResourcePaths::getGuiPath().str() + "graph_view/images/bundle.png";
|
||||
|
||||
return style;
|
||||
}
|
||||
@@ -712,23 +712,23 @@ void GraphViewStyle::addIcon(Node::NodeType type, bool hasChildren, NodeStyle* s
|
||||
{
|
||||
case Node::NODE_NAMESPACE:
|
||||
case Node::NODE_PACKAGE:
|
||||
style->iconPath = ResourcePaths::getGuiPath() + "graph_view/images/namespace.png";
|
||||
style->iconPath = ResourcePaths::getGuiPath().str() + "graph_view/images/namespace.png";
|
||||
style->iconSize = s_fontSize - 4;
|
||||
style->iconOffset.x = -1;
|
||||
style->iconOffset.y = 5;
|
||||
return;
|
||||
|
||||
case Node::NODE_ENUM:
|
||||
style->iconPath = ResourcePaths::getGuiPath() + "graph_view/images/enum.png";
|
||||
style->iconPath = ResourcePaths::getGuiPath().str() + "graph_view/images/enum.png";
|
||||
break;
|
||||
case Node::NODE_TYPEDEF:
|
||||
style->iconPath = ResourcePaths::getGuiPath() + "graph_view/images/typedef.png";
|
||||
style->iconPath = ResourcePaths::getGuiPath().str() + "graph_view/images/typedef.png";
|
||||
break;
|
||||
case Node::NODE_MACRO:
|
||||
style->iconPath = ResourcePaths::getGuiPath() + "graph_view/images/macro.png";
|
||||
style->iconPath = ResourcePaths::getGuiPath().str() + "graph_view/images/macro.png";
|
||||
break;
|
||||
case Node::NODE_FILE:
|
||||
style->iconPath = ResourcePaths::getGuiPath() + "graph_view/images/file.png";
|
||||
style->iconPath = ResourcePaths::getGuiPath().str() + "graph_view/images/file.png";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
||||
@@ -48,15 +48,15 @@ void IntermediateStorage::setAllFilesIncomplete()
|
||||
|
||||
void IntermediateStorage::setFilesWithErrorsIncomplete()
|
||||
{
|
||||
std::set<FilePath> errorFiles;
|
||||
std::set<std::string> errorFileNames;
|
||||
for (StorageError& error : m_errors)
|
||||
{
|
||||
errorFiles.insert(error.filePath);
|
||||
errorFileNames.insert(error.filePath.str());
|
||||
}
|
||||
|
||||
for (StorageFile& file : m_files)
|
||||
{
|
||||
if (errorFiles.find(file.filePath) != errorFiles.end())
|
||||
if (errorFileNames.find(file.filePath) != errorFileNames.end())
|
||||
{
|
||||
file.complete = false;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <queue>
|
||||
|
||||
#include "utility/Cache.h"
|
||||
#include "utility/file/FileInfo.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/messaging/type/MessageNewErrors.h"
|
||||
@@ -1273,7 +1275,7 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
|
||||
|
||||
for (const StorageFile& file : m_sqliteIndexStorage.getAllByIds<StorageFile>(fileIds))
|
||||
{
|
||||
collection->addSourceLocationFile(m_sqliteIndexStorage.getSourceLocationsForFile(file.filePath));
|
||||
collection->addSourceLocationFile(m_sqliteIndexStorage.getSourceLocationsForFile(FilePath(file.filePath)));
|
||||
}
|
||||
|
||||
if (nonFileIds.size())
|
||||
@@ -1351,7 +1353,7 @@ std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsForFile
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
const FilePath& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const
|
||||
{
|
||||
TRACE();
|
||||
@@ -2041,7 +2043,7 @@ void PersistentStorage::buildSearchIndex()
|
||||
auto it = fileMap.find(node.id);
|
||||
if (it != fileMap.end())
|
||||
{
|
||||
FilePath filePath = it->second.filePath;
|
||||
FilePath filePath(it->second.filePath);
|
||||
|
||||
if (filePath.exists())
|
||||
{
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/fulltextsearch/FullTextSearchIndex.h"
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
@@ -125,7 +123,7 @@ public:
|
||||
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
const FilePath& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
virtual std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "data/bookmark/NodeBookmark.h"
|
||||
#include "data/SqliteStorage.h"
|
||||
#include "data/StorageTypes.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class SqliteBookmarkStorage
|
||||
|
||||
@@ -74,7 +74,7 @@ void SqliteIndexStorage::addFile(const int id, const std::string& filePath, cons
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<TextAccess> content = TextAccess::createFromFile(filePath);
|
||||
std::shared_ptr<TextAccess> content = TextAccess::createFromFile(FilePath(filePath));
|
||||
const size_t lineCount = content->getLineCount();
|
||||
|
||||
const bool success = executeStatement(
|
||||
@@ -589,7 +589,7 @@ std::shared_ptr<TextAccess> SqliteIndexStorage::getFileContentByPath(const std::
|
||||
LOG_ERROR(std::to_string(e.errorCode()) + ": " + e.errorMessage());
|
||||
}
|
||||
|
||||
return TextAccess::createFromFile(filePath);
|
||||
return TextAccess::createFromFile(FilePath(filePath));
|
||||
}
|
||||
|
||||
void SqliteIndexStorage::setFileComplete(bool complete, Id fileId)
|
||||
@@ -1176,7 +1176,7 @@ std::vector<StorageError> SqliteIndexStorage::doGetAll<StorageError>(const std::
|
||||
|
||||
if (lineNumber != -1 && columnNumber != -1)
|
||||
{
|
||||
errors.push_back(StorageError(id, message, filePath, lineNumber, columnNumber, fatal, indexed));
|
||||
errors.push_back(StorageError(id, message, FilePath(filePath), lineNumber, columnNumber, fatal, indexed));
|
||||
id++;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,13 @@
|
||||
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
#include "data/name/NameHierarchy.h"
|
||||
#include "data/StorageTypes.h"
|
||||
#include "data/SqliteDatabaseIndex.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "data/SqliteStorage.h"
|
||||
#include "data/StorageTypes.h"
|
||||
#include "utility/types.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
#include "data/SqliteStorage.h"
|
||||
|
||||
class TextAccess;
|
||||
class Version;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "component/view/DialogView.h"
|
||||
#include "data/PersistentStorage.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
#include "utility/utility.h"
|
||||
#include "Application.h"
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
#include "utility/TimePoint.h"
|
||||
|
||||
class DialogView;
|
||||
class FilePath;
|
||||
class PersistentStorage;
|
||||
|
||||
class TaskCleanStorage
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
|
||||
class DialogView;
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "utility/types.h"
|
||||
#include "utility/file/FileInfo.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
#include "data/bookmark/Bookmark.h"
|
||||
#include "data/bookmark/BookmarkCategory.h"
|
||||
@@ -20,6 +18,8 @@
|
||||
#include "data/ErrorInfo.h"
|
||||
#include "data/StorageStats.h"
|
||||
|
||||
class FilePath;
|
||||
struct FileInfo;
|
||||
class Graph;
|
||||
class SourceLocationCollection;
|
||||
class SourceLocationFile;
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
const std::vector<Id>& locationIds) const = 0;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const = 0;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0;
|
||||
const FilePath& filePath, uint firstLineNumber, uint lastLineNumber) const = 0;
|
||||
|
||||
virtual std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const = 0;
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
#include "data/location/SourceLocationCollection.h"
|
||||
#include "data/location/SourceLocationFile.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/file/FileInfo.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/messaging/type/MessageShowErrors.h"
|
||||
#include "utility/TimePoint.h"
|
||||
|
||||
@@ -224,11 +225,11 @@ std::shared_ptr<SourceLocationFile> StorageAccessProxy::getSourceLocationsForFil
|
||||
return m_subject->getSourceLocationsForFile(filePath);
|
||||
}
|
||||
|
||||
return std::make_shared<SourceLocationFile>("", false, false);
|
||||
return std::make_shared<SourceLocationFile>(FilePath(), false, false);
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> StorageAccessProxy::getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
const FilePath& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const
|
||||
{
|
||||
if (hasSubject())
|
||||
@@ -236,7 +237,7 @@ std::shared_ptr<SourceLocationFile> StorageAccessProxy::getSourceLocationsForLin
|
||||
return m_subject->getSourceLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
}
|
||||
|
||||
return std::make_shared<SourceLocationFile>("", false, false);
|
||||
return std::make_shared<SourceLocationFile>(FilePath(), false, false);
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> StorageAccessProxy::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
@@ -246,7 +247,7 @@ std::shared_ptr<SourceLocationFile> StorageAccessProxy::getCommentLocationsInFil
|
||||
return m_subject->getCommentLocationsInFile(filePath);
|
||||
}
|
||||
|
||||
return std::make_shared<SourceLocationFile>("", false, false);
|
||||
return std::make_shared<SourceLocationFile>(FilePath(), false, false);
|
||||
}
|
||||
|
||||
std::shared_ptr<TextAccess> StorageAccessProxy::getFileContent(const FilePath& filePath) const
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
) const;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
const FilePath& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
virtual std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SOURCE_LOCATION_FILE_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <set>
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class ParserClient;
|
||||
class TextAccess;
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ void Project::load()
|
||||
{
|
||||
m_state = PROJECT_STATE_OUTVERSIONED;
|
||||
}
|
||||
else if (utility::replace(TextAccess::createFromFile(projectSettingsPath.str())->getText(), "\r", "") !=
|
||||
else if (utility::replace(TextAccess::createFromFile(projectSettingsPath)->getText(), "\r", "") !=
|
||||
utility::replace(TextAccess::createFromString(m_storage->getProjectSettingsText())->getText(), "\r", ""))
|
||||
{
|
||||
m_state = PROJECT_STATE_OUTDATED;
|
||||
@@ -424,7 +424,7 @@ void Project::buildIndex(const std::set<FilePath>& filesToClean, bool fullRefres
|
||||
m_storage->clear();
|
||||
}
|
||||
|
||||
m_storage->setProjectSettingsText(TextAccess::createFromFile(getProjectSettingsFilePath().str())->getText());
|
||||
m_storage->setProjectSettingsText(TextAccess::createFromFile(getProjectSettingsFilePath())->getText());
|
||||
|
||||
std::shared_ptr<TaskGroupSequence> taskSequential = std::make_shared<TaskGroupSequence>();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "project/SourceGroup.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
SourceGroup::~SourceGroup()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "settings/LanguageType.h"
|
||||
#include "settings/SourceGroupType.h"
|
||||
|
||||
class FilePath;
|
||||
class IndexerCommand;
|
||||
|
||||
class SourceGroup
|
||||
|
||||
@@ -110,7 +110,7 @@ void ApplicationSettings::setUseAnimations(bool useAnimations)
|
||||
|
||||
FilePath ApplicationSettings::getColorSchemePath() const
|
||||
{
|
||||
FilePath defaultPath(ResourcePaths::getColorSchemesPath() + "bright.xml");
|
||||
FilePath defaultPath(ResourcePaths::getColorSchemesPath().concat(FilePath("bright.xml")));
|
||||
FilePath path(getValue<std::string>("application/color_scheme", defaultPath.str()));
|
||||
|
||||
if (path != defaultPath && !path.exists())
|
||||
@@ -276,14 +276,14 @@ void ApplicationSettings::setJavaMaximumMemory(int size)
|
||||
setValue<int>("indexing/java/java_maximum_memory", size);
|
||||
}
|
||||
|
||||
std::string ApplicationSettings::getMavenPath() const
|
||||
FilePath ApplicationSettings::getMavenPath() const
|
||||
{
|
||||
return getValue<std::string>("indexing/java/maven_path", "");
|
||||
return FilePath(getValue<std::string>("indexing/java/maven_path", ""));
|
||||
}
|
||||
|
||||
void ApplicationSettings::setMavenPath(const std::string path)
|
||||
void ApplicationSettings::setMavenPath(const FilePath& path)
|
||||
{
|
||||
setValue<std::string>("indexing/java/maven_path", path);
|
||||
setValue<std::string>("indexing/java/maven_path", path.str());
|
||||
}
|
||||
|
||||
std::vector<FilePath> ApplicationSettings::getHeaderSearchPaths() const
|
||||
@@ -369,7 +369,7 @@ std::vector<FilePath> ApplicationSettings::getRecentProjects() const
|
||||
}
|
||||
else
|
||||
{
|
||||
recentProjects.push_back(UserPaths::getSampleProjectsPath() + project.str());
|
||||
recentProjects.push_back(UserPaths::getSampleProjectsPath().concat(project));
|
||||
}
|
||||
}
|
||||
return recentProjects;
|
||||
|
||||
@@ -82,8 +82,8 @@ public:
|
||||
int getJavaMaximumMemory() const;
|
||||
void setJavaMaximumMemory(int size);
|
||||
|
||||
std::string getMavenPath() const;
|
||||
void setMavenPath(const std::string path);
|
||||
FilePath getMavenPath() const;
|
||||
void setMavenPath(const FilePath& path);
|
||||
|
||||
std::vector<FilePath> getHeaderSearchPaths() const;
|
||||
std::vector<FilePath> getHeaderSearchPathsExpanded() const;
|
||||
|
||||
@@ -31,7 +31,7 @@ bool Settings::load(const FilePath& filePath)
|
||||
{
|
||||
if (filePath.exists())
|
||||
{
|
||||
m_config = ConfigManager::createAndLoad(TextAccess::createFromFile(filePath.str()));
|
||||
m_config = ConfigManager::createAndLoad(TextAccess::createFromFile(filePath));
|
||||
m_filePath = filePath;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14,11 +14,16 @@ public:
|
||||
private:
|
||||
std::function<ValType(KeyType)> m_calculator;
|
||||
std::unordered_map<KeyType, ValType, Hasher> m_map;
|
||||
|
||||
size_t m_hitCount;
|
||||
size_t m_missCount;
|
||||
};
|
||||
|
||||
template <typename KeyType, typename ValType, typename Hasher>
|
||||
Cache<KeyType, ValType, Hasher>::Cache(std::function<ValType(KeyType)> calculator)
|
||||
: m_calculator(calculator)
|
||||
, m_hitCount(0)
|
||||
, m_missCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -28,8 +33,10 @@ ValType Cache<KeyType, ValType, Hasher>::getValue(KeyType key)
|
||||
typename std::unordered_map<KeyType, ValType>::const_iterator it = m_map.find(key);
|
||||
if (it != m_map.end())
|
||||
{
|
||||
++m_hitCount;
|
||||
return it->second;
|
||||
}
|
||||
++m_missCount;
|
||||
ValType val = m_calculator(key);
|
||||
m_map[key] = val;
|
||||
return val;
|
||||
|
||||
@@ -2,27 +2,27 @@
|
||||
|
||||
#include "AppPath.h"
|
||||
|
||||
std::string ResourcePaths::getColorSchemesPath()
|
||||
FilePath ResourcePaths::getColorSchemesPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/color_schemes/";
|
||||
return FilePath(AppPath::getAppPath() + "data/color_schemes/");
|
||||
}
|
||||
|
||||
std::string ResourcePaths::getFallbackPath()
|
||||
FilePath ResourcePaths::getFallbackPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/fallback/";
|
||||
return FilePath(AppPath::getAppPath() + "data/fallback/");
|
||||
}
|
||||
|
||||
std::string ResourcePaths::getFontsPath()
|
||||
FilePath ResourcePaths::getFontsPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/fonts/";
|
||||
return FilePath(AppPath::getAppPath() + "data/fonts/");
|
||||
}
|
||||
|
||||
std::string ResourcePaths::getGuiPath()
|
||||
FilePath ResourcePaths::getGuiPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/gui/";
|
||||
return FilePath(AppPath::getAppPath() + "data/gui/");
|
||||
}
|
||||
|
||||
std::string ResourcePaths::getJavaPath()
|
||||
FilePath ResourcePaths::getJavaPath()
|
||||
{
|
||||
return AppPath::getAppPath() + "data/java/";
|
||||
return FilePath(AppPath::getAppPath() + "data/java/");
|
||||
}
|
||||
|
||||
@@ -3,14 +3,16 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class ResourcePaths
|
||||
{
|
||||
public:
|
||||
static std::string getColorSchemesPath();
|
||||
static std::string getFallbackPath();
|
||||
static std::string getFontsPath();
|
||||
static std::string getGuiPath();
|
||||
static std::string getJavaPath();
|
||||
static FilePath getColorSchemesPath();
|
||||
static FilePath getFallbackPath();
|
||||
static FilePath getFontsPath();
|
||||
static FilePath getGuiPath();
|
||||
static FilePath getJavaPath();
|
||||
};
|
||||
|
||||
#endif // RESOURCE_PATHS_H
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#include "utility/UserPaths.h"
|
||||
|
||||
std::string UserPaths::s_userDataPath = "";
|
||||
std::string UserPaths::s_sampleProjectsPath = "";
|
||||
FilePath UserPaths::s_userDataPath;
|
||||
FilePath UserPaths::s_sampleProjectsPath;
|
||||
|
||||
std::string UserPaths::getUserDataPath()
|
||||
FilePath UserPaths::getUserDataPath()
|
||||
{
|
||||
return s_userDataPath;
|
||||
}
|
||||
|
||||
void UserPaths::setUserDataPath(const std::string& path)
|
||||
void UserPaths::setUserDataPath(const FilePath& path)
|
||||
{
|
||||
s_userDataPath = path;
|
||||
}
|
||||
|
||||
std::string UserPaths::getSampleProjectsPath()
|
||||
FilePath UserPaths::getSampleProjectsPath()
|
||||
{
|
||||
if (s_sampleProjectsPath.size())
|
||||
if (s_sampleProjectsPath.str().size())
|
||||
{
|
||||
return s_sampleProjectsPath;
|
||||
}
|
||||
@@ -23,22 +23,22 @@ std::string UserPaths::getSampleProjectsPath()
|
||||
return s_userDataPath;
|
||||
}
|
||||
|
||||
void UserPaths::setSampleProjectsPath(const std::string& path)
|
||||
void UserPaths::setSampleProjectsPath(const FilePath& path)
|
||||
{
|
||||
s_sampleProjectsPath = path;
|
||||
}
|
||||
|
||||
std::string UserPaths::getAppSettingsPath()
|
||||
FilePath UserPaths::getAppSettingsPath()
|
||||
{
|
||||
return getUserDataPath() + "ApplicationSettings.xml";
|
||||
return getUserDataPath().concat(FilePath("ApplicationSettings.xml"));
|
||||
}
|
||||
|
||||
std::string UserPaths::getWindowSettingsPath()
|
||||
FilePath UserPaths::getWindowSettingsPath()
|
||||
{
|
||||
return getUserDataPath() + "window_settings.ini";
|
||||
return getUserDataPath().concat(FilePath("window_settings.ini"));
|
||||
}
|
||||
|
||||
std::string UserPaths::getLogPath()
|
||||
FilePath UserPaths::getLogPath()
|
||||
{
|
||||
return getUserDataPath() + "log/";
|
||||
return getUserDataPath().concat(FilePath("log/"));
|
||||
}
|
||||
|
||||
@@ -3,22 +3,24 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class UserPaths
|
||||
{
|
||||
public:
|
||||
static std::string getUserDataPath();
|
||||
static void setUserDataPath(const std::string& path);
|
||||
static FilePath getUserDataPath();
|
||||
static void setUserDataPath(const FilePath& path);
|
||||
|
||||
static std::string getSampleProjectsPath();
|
||||
static void setSampleProjectsPath(const std::string& path);
|
||||
static FilePath getSampleProjectsPath();
|
||||
static void setSampleProjectsPath(const FilePath& path);
|
||||
|
||||
static std::string getAppSettingsPath();
|
||||
static std::string getWindowSettingsPath();
|
||||
static std::string getLogPath();
|
||||
static FilePath getAppSettingsPath();
|
||||
static FilePath getWindowSettingsPath();
|
||||
static FilePath getLogPath();
|
||||
|
||||
private:
|
||||
static std::string s_userDataPath;
|
||||
static std::string s_sampleProjectsPath;
|
||||
static FilePath s_userDataPath;
|
||||
static FilePath s_sampleProjectsPath;
|
||||
};
|
||||
|
||||
#endif // USER_PATHS_H
|
||||
|
||||
@@ -74,7 +74,7 @@ CommandLineParser::CommandLineParser(int argc, char** argv, const std::string& v
|
||||
if (vm.count("licenseFile"))
|
||||
{
|
||||
std::cout << "licensefile flag" << std::endl;
|
||||
if (FileSystem::exists(licensefile))
|
||||
if (FilePath(licensefile).exists())
|
||||
{
|
||||
std::cout << "licensefile exists" << std::endl;
|
||||
processLicense(m_license.loadFromFile(licensefile));
|
||||
@@ -166,7 +166,7 @@ void CommandLineParser::processProjectfile(const std::string& file)
|
||||
}
|
||||
|
||||
std::shared_ptr<ConfigManager> configManager = ConfigManager::createEmpty();
|
||||
if (!configManager->load(TextAccess::createFromFile(projectfile.str())))
|
||||
if (!configManager->load(TextAccess::createFromFile(projectfile)))
|
||||
{
|
||||
m_errorString = errorstring + " could not be loaded(invalid)";
|
||||
return;
|
||||
@@ -180,7 +180,7 @@ void CommandLineParser::projectLoad()
|
||||
if (m_projectFile.exists() &&
|
||||
(m_projectFile.extension() == ".srctrlprj" || m_projectFile.extension() == ".coatiproject"))
|
||||
{
|
||||
MessageLoadProject(m_projectFile.str(), m_force).dispatch();
|
||||
MessageLoadProject(m_projectFile, m_force).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
FilePath::FilePath()
|
||||
: m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -15,6 +18,9 @@ FilePath::FilePath(const char* filePath)
|
||||
: m_path(filePath)
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -22,6 +28,9 @@ FilePath::FilePath(const std::string& filePath)
|
||||
: m_path(filePath)
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,6 +38,9 @@ FilePath::FilePath(const boost::filesystem::path& filePath)
|
||||
: m_path(filePath)
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -36,6 +48,9 @@ FilePath::FilePath(const std::string& filePath, const std::string& base)
|
||||
: m_path(boost::filesystem::absolute(filePath, base))
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
, m_canonicalized(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -60,9 +75,21 @@ bool FilePath::exists() const
|
||||
return m_exists;
|
||||
}
|
||||
|
||||
bool FilePath::recheckExists() const
|
||||
{
|
||||
m_checkedExists = false;
|
||||
return exists();
|
||||
}
|
||||
|
||||
bool FilePath::isDirectory() const
|
||||
{
|
||||
return boost::filesystem::is_directory(m_path);
|
||||
if (!m_checkedIsDirectory)
|
||||
{
|
||||
m_isDirectory = boost::filesystem::is_directory(m_path);
|
||||
m_checkedIsDirectory = true;
|
||||
}
|
||||
|
||||
return m_isDirectory;
|
||||
}
|
||||
|
||||
bool FilePath::isAbsolute() const
|
||||
@@ -72,37 +99,50 @@ bool FilePath::isAbsolute() const
|
||||
|
||||
FilePath FilePath::parentDirectory() const
|
||||
{
|
||||
return m_path.parent_path();
|
||||
FilePath parentDirectory(m_path.parent_path());
|
||||
parentDirectory.m_checkedIsDirectory = true;
|
||||
parentDirectory.m_isDirectory = true;
|
||||
|
||||
if (m_checkedExists && m_exists)
|
||||
{
|
||||
parentDirectory.m_checkedExists = true;
|
||||
parentDirectory.m_exists = true;
|
||||
}
|
||||
return parentDirectory;
|
||||
}
|
||||
|
||||
FilePath FilePath::absolute() const
|
||||
{
|
||||
return boost::filesystem::absolute(m_path);
|
||||
return FilePath(boost::filesystem::absolute(m_path));
|
||||
}
|
||||
|
||||
FilePath FilePath::canonical() const
|
||||
{
|
||||
if (m_canonicalized)
|
||||
{
|
||||
return FilePath(*this);
|
||||
}
|
||||
if (!exists())
|
||||
{
|
||||
return FilePath(m_path);
|
||||
return FilePath(*this);
|
||||
}
|
||||
|
||||
boost::filesystem::path abs_p = boost::filesystem::absolute(m_path);
|
||||
boost::filesystem::path result;
|
||||
boost::filesystem::path canonicalPath;
|
||||
for (boost::filesystem::path::iterator it = abs_p.begin(); it != abs_p.end(); ++it)
|
||||
{
|
||||
if (*it == "..")
|
||||
{
|
||||
// /a/b/.. is not necessarily /a if b is a symbolic link
|
||||
if (boost::filesystem::is_symlink(result))
|
||||
result /= *it;
|
||||
if (boost::filesystem::is_symlink(canonicalPath))
|
||||
canonicalPath /= *it;
|
||||
// /a/b/../.. is not /a/b/.. under most circumstances
|
||||
// We can end up with ..s in our result because of symbolic links
|
||||
else if (result.filename() == "..")
|
||||
result /= *it;
|
||||
else if (canonicalPath.filename() == "..")
|
||||
canonicalPath /= *it;
|
||||
// Otherwise it should be safe to resolve the parent
|
||||
else
|
||||
result = result.parent_path();
|
||||
canonicalPath = canonicalPath.parent_path();
|
||||
}
|
||||
else if (*it == ".")
|
||||
{
|
||||
@@ -111,10 +151,12 @@ FilePath FilePath::canonical() const
|
||||
else
|
||||
{
|
||||
// Just cat other path entries
|
||||
result /= *it;
|
||||
canonicalPath /= *it;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
FilePath ret(canonicalPath);
|
||||
ret.m_canonicalized = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<FilePath> FilePath::expandEnvironmentVariables() const
|
||||
@@ -132,7 +174,7 @@ std::vector<FilePath> FilePath::expandEnvironmentVariables() const
|
||||
LOG_ERROR(match[1].str() + " is not an environment variable");
|
||||
return paths;
|
||||
}
|
||||
text.replace( match.position(0), match.length(0), s);
|
||||
text.replace(match.position(0), match.length(0), s);
|
||||
}
|
||||
|
||||
char environmentVariablePathSeparator = ':';
|
||||
@@ -145,7 +187,7 @@ std::vector<FilePath> FilePath::expandEnvironmentVariables() const
|
||||
{
|
||||
if (str.size())
|
||||
{
|
||||
paths.push_back(str);
|
||||
paths.push_back(FilePath(str));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +201,7 @@ FilePath FilePath::relativeTo(const FilePath& other) const
|
||||
|
||||
if (a.root_path() != b.root_path())
|
||||
{
|
||||
return str();
|
||||
return *this;
|
||||
}
|
||||
|
||||
boost::filesystem::path::const_iterator itA = a.begin();
|
||||
@@ -196,12 +238,12 @@ FilePath FilePath::relativeTo(const FilePath& other) const
|
||||
r = "./";
|
||||
}
|
||||
|
||||
return r;
|
||||
return FilePath(r);
|
||||
}
|
||||
|
||||
FilePath FilePath::concat(const FilePath& other) const
|
||||
{
|
||||
return boost::filesystem::path(m_path) / other.m_path;
|
||||
return FilePath(boost::filesystem::path(m_path) / other.m_path);
|
||||
}
|
||||
|
||||
bool FilePath::contains(const FilePath& other) const
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define FILE_PATH_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
@@ -9,15 +10,16 @@ class FilePath
|
||||
{
|
||||
public:
|
||||
FilePath();
|
||||
FilePath(const char* filePath);
|
||||
FilePath(const std::string& filePath);
|
||||
FilePath(const boost::filesystem::path& filePath);
|
||||
explicit FilePath(const char* filePath);
|
||||
explicit FilePath(const std::string& filePath);
|
||||
explicit FilePath(const boost::filesystem::path& filePath);
|
||||
FilePath(const std::string& filePath, const std::string& base);
|
||||
|
||||
boost::filesystem::path path() const;
|
||||
|
||||
bool empty() const;
|
||||
bool exists() const;
|
||||
bool recheckExists() const;
|
||||
bool isDirectory() const;
|
||||
bool isAbsolute() const;
|
||||
|
||||
@@ -49,6 +51,9 @@ private:
|
||||
|
||||
mutable bool m_exists;
|
||||
mutable bool m_checkedExists;
|
||||
mutable bool m_isDirectory;
|
||||
mutable bool m_checkedIsDirectory;
|
||||
mutable bool m_canonicalized;
|
||||
};
|
||||
|
||||
#endif // FILE_PATH_H
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
FileRegister::FileRegister(const FileRegisterStateData& stateData, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths)
|
||||
: m_stateData(stateData)
|
||||
, m_indexedPaths(indexedPaths)
|
||||
, m_excludedPaths(excludedPaths)
|
||||
, m_hasFilePathCache(
|
||||
[&](std::string filePath){
|
||||
[&](std::string f){
|
||||
const FilePath filePath(f);
|
||||
bool ret = false;
|
||||
for (const FilePath& indexedPath: m_indexedPaths)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "utility/file/FileRegisterStateData.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
FileRegisterStateData::FileRegisterStateData()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
#include "boost/filesystem.hpp"
|
||||
|
||||
std::vector<std::string> FileSystem::getFileNamesFromDirectory(
|
||||
const std::string& path, const std::vector<std::string>& extensions
|
||||
const FilePath& path, const std::vector<std::string>& extensions
|
||||
){
|
||||
std::set<std::string> ext(extensions.begin(), extensions.end());
|
||||
std::vector<std::string> files;
|
||||
|
||||
if (boost::filesystem::is_directory(path))
|
||||
if (boost::filesystem::is_directory(path.path()))
|
||||
{
|
||||
boost::filesystem::recursive_directory_iterator it(path);
|
||||
boost::filesystem::recursive_directory_iterator it(path.path());
|
||||
boost::filesystem::recursive_directory_iterator endit;
|
||||
while (it != endit)
|
||||
{
|
||||
@@ -38,7 +38,7 @@ std::vector<std::string> FileSystem::getFileNamesFromDirectory(
|
||||
return files;
|
||||
}
|
||||
|
||||
FileInfo FileSystem::getFileInfoForPath(FilePath filePath)
|
||||
FileInfo FileSystem::getFileInfoForPath(const FilePath& filePath)
|
||||
{
|
||||
if (filePath.exists())
|
||||
{
|
||||
@@ -110,7 +110,7 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
|
||||
|
||||
std::time_t t = boost::filesystem::last_write_time(*it);
|
||||
boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
files.push_back(FileInfo(it->path(), lastWriteTime));
|
||||
files.push_back(FileInfo(FilePath(it->path()), lastWriteTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
|
||||
TimePoint FileSystem::getLastWriteTime(const FilePath& filePath)
|
||||
{
|
||||
boost::posix_time::ptime lastWriteTime;
|
||||
if (FileSystem::exists(filePath.str()))
|
||||
if (filePath.exists())
|
||||
{
|
||||
std::time_t t = boost::filesystem::last_write_time(filePath.path());
|
||||
lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
@@ -235,13 +235,3 @@ std::string FileSystem::filePathWithoutExtension(const std::string& path)
|
||||
{
|
||||
return boost::filesystem::path(path).replace_extension().generic_string();
|
||||
}
|
||||
|
||||
bool FileSystem::equivalent(const std::string& pathA, const std::string& pathB)
|
||||
{
|
||||
if (exists(pathA) && exists(pathB))
|
||||
{
|
||||
return boost::filesystem::equivalent(boost::filesystem::path(pathA), boost::filesystem::path(pathB));
|
||||
}
|
||||
|
||||
return boost::filesystem::path(pathA).compare(boost::filesystem::path(pathB)) == 0;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ class FileSystem
|
||||
{
|
||||
public:
|
||||
static std::vector<std::string> getFileNamesFromDirectory(
|
||||
const std::string& path, const std::vector<std::string>& extensions);
|
||||
const FilePath& path, const std::vector<std::string>& extensions);
|
||||
|
||||
static FileInfo getFileInfoForPath(FilePath filePath);
|
||||
static FileInfo getFileInfoForPath(const FilePath& filePath);
|
||||
|
||||
static std::vector<FileInfo> getFileInfosFromPaths(
|
||||
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions, bool followSymLinks = true);
|
||||
@@ -36,8 +36,6 @@ public:
|
||||
|
||||
static std::string extension(const std::string& path);
|
||||
static std::string filePathWithoutExtension(const std::string& path);
|
||||
|
||||
static bool equivalent(const std::string& pathA, const std::string& pathB);
|
||||
};
|
||||
|
||||
#endif // FILE_SYSTEM_H
|
||||
|
||||
@@ -19,7 +19,7 @@ std::shared_ptr<SharedUUIDManager> SharedUUIDManager::getInstance()
|
||||
// m_instance = std::make_shared<SharedUUIDManager>();
|
||||
SharedUUIDManager* sharedUUIDManager = new SharedUUIDManager();
|
||||
m_instance = std::shared_ptr<SharedUUIDManager>(sharedUUIDManager);
|
||||
m_instance->setFilePath(UserPaths::getUserDataPath());
|
||||
m_instance->setFilePath(UserPaths::getUserDataPath().str());
|
||||
m_instance->saveInstanceUUID();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ SharedUUIDManager::~SharedUUIDManager()
|
||||
void SharedUUIDManager::setFilePath(const std::string& filePath)
|
||||
{
|
||||
m_filePath = filePath;
|
||||
FileSystem::createDirectory(m_filePath);
|
||||
FileSystem::createDirectory(FilePath(m_filePath));
|
||||
|
||||
refreshUUIDs();
|
||||
}
|
||||
@@ -121,6 +121,6 @@ void SharedUUIDManager::refreshUUIDs()
|
||||
{
|
||||
if (FilePath(m_filePath + m_fileName).exists())
|
||||
{
|
||||
m_uuids = ConfigManager::createAndLoad(TextAccess::createFromFile(m_filePath + m_fileName));
|
||||
m_uuids = ConfigManager::createAndLoad(TextAccess::createFromFile(FilePath(m_filePath + m_fileName)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ FileLogger::~FileLogger()
|
||||
{
|
||||
}
|
||||
|
||||
void FileLogger::setLogDirectory(const std::string& filePath)
|
||||
void FileLogger::setLogDirectory(const FilePath& filePath)
|
||||
{
|
||||
m_logDirectory = filePath;
|
||||
FileSystem::createDirectory(m_logDirectory);
|
||||
@@ -90,14 +90,14 @@ void FileLogger::updateLogFileName()
|
||||
|
||||
if (fileChanged)
|
||||
{
|
||||
FileSystem::remove(m_logDirectory + m_currentLogFileName);
|
||||
FileSystem::remove(m_logDirectory.concat(FilePath(m_currentLogFileName)));
|
||||
}
|
||||
}
|
||||
|
||||
void FileLogger::logMessage(const std::string& type, const LogMessage& message)
|
||||
{
|
||||
std::ofstream fileStream;
|
||||
fileStream.open(m_logDirectory + m_currentLogFileName, std::ios::app);
|
||||
fileStream.open(m_logDirectory.concat(FilePath(m_currentLogFileName)).str(), std::ios::app);
|
||||
fileStream << message.getTimeString("%H:%M:%S") << " | ";
|
||||
fileStream << message.threadId << " | ";
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/logging/Logger.h"
|
||||
#include "utility/logging/LogMessage.h"
|
||||
|
||||
@@ -12,7 +13,7 @@ public:
|
||||
FileLogger();
|
||||
virtual ~FileLogger();
|
||||
|
||||
void setLogDirectory(const std::string& filePath);
|
||||
void setLogDirectory(const FilePath& filePath);
|
||||
void setFileName(const std::string& fileName);
|
||||
void setMaxLogLineCount(unsigned int logCount);
|
||||
|
||||
@@ -28,7 +29,7 @@ private:
|
||||
void updateLogFileName();
|
||||
|
||||
std::string m_logFileName;
|
||||
std::string m_logDirectory;
|
||||
FilePath m_logDirectory;
|
||||
unsigned int m_maxLogLineCount;
|
||||
unsigned int m_maxLogFileCount;
|
||||
unsigned int m_currentLogLineCount;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
std::shared_ptr<TextAccess> TextAccess::createFromFile(const std::string& filePath)
|
||||
std::shared_ptr<TextAccess> TextAccess::createFromFile(const FilePath& filePath)
|
||||
{
|
||||
std::shared_ptr<TextAccess> result(new TextAccess());
|
||||
|
||||
@@ -32,7 +32,7 @@ unsigned int TextAccess::getLineCount() const
|
||||
return m_lines.size();
|
||||
}
|
||||
|
||||
std::string TextAccess::getFilePath() const
|
||||
FilePath TextAccess::getFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
@@ -76,16 +76,16 @@ std::string TextAccess::getText() const
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> TextAccess::readFile(const std::string& filePath)
|
||||
std::vector<std::string> TextAccess::readFile(const FilePath& filePath)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
|
||||
std::ifstream srcFile;
|
||||
srcFile.open(filePath);
|
||||
srcFile.open(filePath.str());
|
||||
|
||||
if (srcFile.fail())
|
||||
{
|
||||
LOG_ERROR("Could not open file " + filePath);
|
||||
LOG_ERROR("Could not open file " + filePath.str());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,19 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class TextAccess
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<TextAccess> createFromFile(const std::string& filePath);
|
||||
static std::shared_ptr<TextAccess> createFromFile(const FilePath& filePath);
|
||||
static std::shared_ptr<TextAccess> createFromString(const std::string& text);
|
||||
|
||||
virtual ~TextAccess();
|
||||
|
||||
unsigned int getLineCount() const;
|
||||
|
||||
std::string getFilePath() const;
|
||||
FilePath getFilePath() const;
|
||||
|
||||
/**
|
||||
* @param lineNumber: starts with 1
|
||||
@@ -30,7 +32,7 @@ public:
|
||||
std::string getText() const;
|
||||
|
||||
private:
|
||||
static std::vector<std::string> readFile(const std::string& filePath);
|
||||
static std::vector<std::string> readFile(const FilePath& filePath);
|
||||
static std::vector<std::string> splitStringByLines(const std::string& text);
|
||||
|
||||
TextAccess();
|
||||
@@ -40,7 +42,7 @@ private:
|
||||
bool checkIndexInRange(const unsigned int index) const;
|
||||
bool checkIndexIntervalInRange(const unsigned int firstIndex, const unsigned int lastIndex) const;
|
||||
|
||||
std::string m_filePath;
|
||||
FilePath m_filePath;
|
||||
std::vector<std::string> m_lines;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
|
||||
namespace utility
|
||||
{
|
||||
template <typename Ret, typename... Args>
|
||||
|
||||
Reference in New Issue
Block a user