diff --git a/core/include/SourcetrailDBWriter.h b/core/include/SourcetrailDBWriter.h index fdf2f8c..5cf9816 100644 --- a/core/include/SourcetrailDBWriter.h +++ b/core/include/SourcetrailDBWriter.h @@ -51,9 +51,9 @@ namespace sourcetrail const std::string& getLastError() const; void clearLastError(); - bool openProject(const std::string& projectDirectory, const std::string& projectName); - bool closeProject(); - bool clearProject(); + bool open(const std::string& databaseFilePath); + bool close(); + bool clear(); bool isEmpty() const; bool isCompatible() const; @@ -101,8 +101,8 @@ namespace sourcetrail int addEdge(int sourceId, int targetId, EdgeKind edgeKind); void addSourceLocation(int elementId, const SourceRange& location, LocationKind kind); - std::string m_projectDirectory; - std::string m_projectName; + std::string m_projectFilePath; + std::string m_databaseFilePath; std::shared_ptr m_storage; mutable std::string m_lastError; }; diff --git a/core/src/SourcetrailDBWriter.cpp b/core/src/SourcetrailDBWriter.cpp index 1671c9d..4d376ed 100644 --- a/core/src/SourcetrailDBWriter.cpp +++ b/core/src/SourcetrailDBWriter.cpp @@ -16,6 +16,7 @@ #include "SourcetrailDBWriter.h" +#include #include #include @@ -62,10 +63,17 @@ namespace sourcetrail m_lastError.clear(); } - bool SourcetrailDBWriter::openProject(const std::string& projectDirectory, const std::string& projectName) + bool SourcetrailDBWriter::open(const std::string& databaseFilePath) { - m_projectDirectory = projectDirectory; - m_projectName = projectName; + m_databaseFilePath = databaseFilePath; + + m_projectFilePath = databaseFilePath; + const size_t pos = m_projectFilePath.rfind('.'); + if (pos != std::string::npos) + { + m_projectFilePath = m_projectFilePath.substr(0, pos); + } + m_projectFilePath += ".srctrlprj"; try { @@ -90,7 +98,7 @@ namespace sourcetrail { bool projectFileExists = false; { - std::ifstream f(getProjectFilePath().c_str()); + std::ifstream f(m_projectFilePath.c_str()); projectFileExists = f.good(); f.close(); } @@ -111,7 +119,7 @@ namespace sourcetrail return true; } - bool SourcetrailDBWriter::closeProject() + bool SourcetrailDBWriter::close() { try { @@ -126,7 +134,7 @@ namespace sourcetrail return true; } - bool SourcetrailDBWriter::clearProject() + bool SourcetrailDBWriter::clear() { try { @@ -582,15 +590,6 @@ namespace sourcetrail return serialized; } - std::string SourcetrailDBWriter::getProjectFilePath() const - { - return m_projectDirectory + "/" + m_projectName + ".srctrlprj"; - } - std::string SourcetrailDBWriter::getDatabaseFilePath() const - { - return m_projectDirectory + "/" + m_projectName + ".srctrldb"; - } - void SourcetrailDBWriter::openDatabase() { if (m_storage) @@ -600,7 +599,7 @@ namespace sourcetrail try { - m_storage = DatabaseStorage::openDatabase(getDatabaseFilePath()); + m_storage = DatabaseStorage::openDatabase(m_databaseFilePath); } catch (CppSQLite3Exception e) { @@ -641,7 +640,7 @@ namespace sourcetrail try { std::ofstream fileStream; - fileStream.open(getProjectFilePath(), std::ios::out); + fileStream.open(m_projectFilePath, std::ios::out); fileStream << std::string( "\n" "\n" diff --git a/resources_swig/include/sourcetraildb.h b/resources_swig/include/sourcetraildb.h index 4741d68..7dc7c69 100644 --- a/resources_swig/include/sourcetraildb.h +++ b/resources_swig/include/sourcetraildb.h @@ -56,11 +56,11 @@ std::string getLastError(); void clearLastError(); -bool openProject(std::string projectDirectory, std::string projectName); +bool open(std::string databaseFilePath); -bool closeProject(); +bool close(); -bool clearProject(); +bool clear(); bool isEmpty(); diff --git a/resources_swig/src/sourcetraildb.cpp b/resources_swig/src/sourcetraildb.cpp index cbb9c6e..8239c9e 100644 --- a/resources_swig/src/sourcetraildb.cpp +++ b/resources_swig/src/sourcetraildb.cpp @@ -88,19 +88,19 @@ void clearLastError() dbWriter.clearLastError(); } -bool openProject(std::string projectDirectory, std::string projectName) +bool open(std::string databaseFilePath) { - return dbWriter.openProject(projectDirectory, projectName); + return dbWriter.open(databaseFilePath); } -bool closeProject() +bool close() { - return dbWriter.closeProject(); + return dbWriter.close(); } -bool clearProject() +bool clear() { - return dbWriter.clearProject(); + return dbWriter.clear(); } bool isEmpty()